Scheduler state and ingestion
Scheduler state is the durable record that lets Armada rebuild scheduling decisions after a restart or leader change. The scheduler ingester turns job events and control-plane events into database instructions. The scheduler reads those records and the executor API adds current cluster state. This page explains that state boundary and its role in the scheduling system, with placement policy covered in Scheduling algorithms and constraints.
State model
The scheduler uses durable records for work identity, life-cycle state, placement, and executor observations. It also builds a short-lived in-memory view for fast scheduling. That view is rebuilt from PostgreSQL and is not the source of truth.
Job state
A job record represents work submitted to a queue and job set. It holds the data needed to decide if the job can enter scheduling. It also records requests and outcomes that move the job through its life cycle.
The scheduler uses a compact scheduling view for placement. The full submit message remains separate so the executor can receive the original workload after a run is leased. This split keeps scheduling decisions small while preserving the data needed to start the job.
Important job state includes:
- Queue and job-set identity.
- In-queue priority and pool eligibility.
- A queued flag and its update version.
- Cancellation, validation, success, and failure state.
- Scheduling requirements and their update version.
- The original submit message and group data in job metadata.
References: internal/…/models.go• L27-59 internal/…/schedulerobjects.proto• L76-133 internal/…/instructions.go• L151-210
Run state
A run record represents one placement attempt for a job. It links the job to an executor and node. It then records progress and the final outcome so the scheduler can compare worker reports with its own view.
Run state covers the handoff from lease to execution. A run can be leased, pending, or running. It can later be cancelled, preempted, completed, or failed. A terminated marker keeps a run out of active scheduling. Failure records remain separate so later events can include the original run error.
When a failed run can be tried again, the scheduler requeues the job with a newer queued version and publishes its current scheduling information. Retry policy can change placement requirements before the requeue. If the new requirements do not fit the cluster, the scheduler records a terminal failure instead of leaving the job queued.
References: internal/…/models.go• L61-103 internal/…/instructions.go• L213-331 internal/…/schedulerdb.go• L228-386 internal/…/scheduler.go• L1304-1412 internal/…/031_add_runs_terminated_column.sql• L1-2
Executor and node state
An executor is a worker cluster that offers nodes and capacity to the scheduler. Node state comes from the executor's latest report. The scheduler does not keep it as a separate durable row.
The report gives the scheduler a current view of node identity, resources, labels, taints, scheduling limits, pool, and assigned runs. It can also report runs that belong to the cluster but have no node assignment. The report time acts as a liveness signal. Executor settings such as cordoning are applied before new work is selected.
References: internal/…/schedulerobjects.proto• L9-22 internal/…/schedulerobjects.proto• L24-56 internal/…/models.go• L13-25 internal/…/executor_repository.go• L16-26 internal/…/api.go• L87-117
Scheduling node state
The scheduling node view is a short-lived in-memory model used to match jobs to capacity. It tracks node resources and current bindings. It also retains evicted jobs so preemption can account for their rescheduling order.
The view keeps two resource perspectives when urgency-first preemption is enabled. The normal view gives back resources from evicted work. The no-eviction view keeps those resources accounted for so urgency preemption only considers work that urgency can remove. The scheduler builds separate indexes for these views and uses the matching view when it searches for a node.
The view records allocation by scheduling priority. When the scheduler handles a pool, it can also mark work from another pool as cross-pool work. A PodSchedulingContext is the per-job result of node selection. It reports the selected node or exclusion reasons. It also records the attempted priority, whether placement used another pool or node type, and the scheduling method. The scheduler uses this context in lease and preemption events and in operational metrics.
The node view uses indexed resource buckets to find possible matches quickly. The buckets round resource values down to a configured resolution. This makes lookup faster, but a coarse resolution can reject a job that would fit. Final resource checks still decide whether a node is valid. Urgency indexes are sparse: nodes enter them only when they hold resources that a higher-priority job can urgency-preempt.
References: internal/…/nodedb.go• L77-190 internal/…/nodedb.go• L555-647 internal/…/nodedb.go• L741-944 internal/…/nodedb.go• L1001-1142 internal/…/nodeiteration.go• L50-89 internal/…/nodeiteration.go• L92-174 internal/…/pod.go• L10-59 internal/…/scheduler.go• L1001-1045 internal/…/nodeiteration_test.go• L763-843
Node matching state
Node matching narrows the candidate set before the scheduler considers resources and preemption. A node type groups nodes with shared taints and labels. Indexed taints and labels can exclude whole node types early. Non-indexed attributes are checked when a concrete node is considered.
Matching combines resource capacity with job requirements. These requirements include resource requests, node selectors, node affinity, and taints with tolerations. The resource check uses the view selected by the preemption strategy. The result carries a reason for each exclusion so the scheduler can explain why placement failed.
References: internal/…/nodedb.go• L1215-1231 internal/…/nodematching.go• L124-204 internal/…/nodematching.go• L206-273 internal/…/nodeiteration_test.go• L411-697
Pool and preemption state
The node view keeps special accounting for evicted work and cross-pool work. Evicted work has a global rescheduling order. Cross-pool work uses a separate accounting priority when the view has a pool, which lets home work preempt it first regardless of its configured away priority.
The scheduler can try fair-share preemption before urgency preemption, or reverse that order through its scheduling setting. In urgency-first mode, the scheduler can use both strategies when either one alone cannot make enough room. The scheduling result records whether placement used urgency, fair-share, or both.
Scheduling can bind, evict, or unbind work. A gang is a group of jobs that must move together. If one evicted gang member is selected for preemption, the other active members of that gang are also removed from their nodes. The whole operation runs in one transaction so a failed gang attempt does not leave partial placement state.
References: internal/…/nodedb.go• L77-94 internal/…/nodedb.go• L435-543 internal/…/nodedb.go• L741-844 internal/…/nodedb.go• L1001-1142 internal/…/nodedb.go• L1144-1167 internal/…/nodedb_test.go• L58-137 internal/…/nodedb_test.go• L1078-1233 internal/…/nodedb_test.go• L2007-2070
Durable scheduler databases
PostgreSQL provides durable state shared by the scheduler, scheduler ingester, and executor-facing API. The database separates job and run state from full job metadata, executor observations, run errors, and event position markers.
Job and run records
The jobs and runs records form the scheduler's durable work model. Jobs describe demand and life-cycle state. Runs describe each attempt and its placement. Updates to both records receive a serial position and modification time. The scheduler uses those positions to read a stream of changes instead of scanning all active work on every cycle.
Job metadata holds the compressed submit message and groups. Scheduling information is smaller and contains only the requirements needed by the scheduler. The executor lease path joins these data sources when it returns a run to a worker.
References: internal/…/001_initialize_schema.up.sql• L6-70 internal/…/038_add_job_metadata_table.sql• L1-10 internal/…/job_repository.go• L344-390
Executor records and settings
The executors record stores the latest compressed executor report and its update time. This lets the scheduler find known clusters and decide whether their reports are fresh enough for scheduling.
Executor settings are a separate durable record for operator-controlled state. They include cordon state and its reason. Control-plane events update or remove these settings. The scheduling path reads them with the latest executor report.
References: internal/…/001_initialize_schema.up.sql• L80-87 internal/…/015_add_executor_settings_table.sql• L1-5 internal/…/executor_repository.go• L45-119 internal/…/instructions.go• L509-541
Serial positions
Each job and run write receives a monotonic serial position. The scheduler stores the last job and run positions that it has read. On the next cycle it asks for rows after those positions. This gives the in-memory job view an incremental refresh path.
The ingester uses a PostgreSQL transaction lock for job-affecting writes. Without that lock, concurrent transactions could commit rows whose serial positions do not follow commit order. The scheduler could then move past a row and miss it in a later update window.
References: internal/…/001_initialize_schema.up.sql• L102-127 internal/…/schedulerdb.go• L55-97 internal/…/job_repository.go• L233-302 internal/…/scheduler.go• L475-558
Version protection
Queued state and scheduling information each have a version. The ingester applies an update only when its version is newer than the stored version. This protects state when an event is replayed or when messages arrive out of order.
Other life-cycle changes use the event stream and database transaction as their ordering boundary. The scheduler then reconciles the resulting job and run view before it makes a new decision.
References: internal/…/models.go• L27-45 internal/…/dbops.go• L351-385 internal/…/schedulerdb.go• L147-170
Event ingestion
The scheduler ingester runs two consumers that share one database sink. One consumes job-set event sequences. The other consumes control-plane events. Both convert messages into database operations and retain the consumed Pulsar message IDs until the sink handles the batch.
Event sources
Job-set events carry changes to jobs and runs. They come from submission, executor reports, scheduler decisions, and other job life-cycle actions. Control-plane events carry operator or service actions that target executors, nodes, queues, or selected job states.
The two streams have different state effects:
| Event stream | Main durable effect |
|---|---|
| Job-set events | Create jobs and runs. Update life-cycle state, scheduling requirements, priorities, cancellations, preemption requests, errors, and partition markers. |
| Control-plane events | Update executor settings. Delete executor records. Turn scoped cancellation and preemption requests into changes to matching active work. |
An event with no scheduler state effect can be ignored. An unknown event type is logged so a contract change is visible instead of being silently treated as a supported update.
References: internal/…/ingester.go• L24-25 internal/…/ingester.go• L51-86 internal/…/instructions.go• L81-148 internal/…/instructions.go• L474-506
Instruction conversion
An instruction is the database effect produced from one or more event messages. The converter keeps message IDs with the instruction batch. The common ingestion pipeline uses them to complete the database handoff before it acknowledges the source messages.
Submission creates durable job data and a compact scheduling view. Run and life-cycle events update the matching job or run. A scoped control-plane action first finds active work that matches its filters. It then creates the related state request.
The converter can combine compatible operations in a batch. It can also move independent operations without changing the final state. It does not move operations that could overwrite one another. Examples include job and job-set priority changes and operations for the same job or run.
References: internal/…/dbops.go• L21-25 internal/…/dbops.go• L142-197 internal/…/schedulerdb.go• L100-127 internal/…/schedulerdb.go• L443-624
Batch persistence
The common ingestion pipeline moves messages through receive, decode, batch, merge, convert, store, and acknowledge stages. The scheduler ingester supplies the event converter and SchedulerDb sink. Batching reduces database work while keeping each message ID linked to the resulting database operation.
The sink writes one batch in a PostgreSQL transaction. It retries database failures with backoff. The pipeline owns message acknowledgement after the sink returns. This makes the database transaction the durable point for an instruction batch.
The following diagram shows how an event becomes durable scheduler state and then becomes available to the scheduler or an executor.
flowchart LR
P[Pulsar event message] --> R[Receive and decode]
R --> B[Batch and merge]
B --> C[Convert to database instructions]
C --> T[PostgreSQL transaction]
T --> A[Acknowledge message IDs]
T --> S[Scheduler reads job and run state]
T --> E[Executor API reads leases and sends work]
References: internal/…/ingestion_pipeline.go• L21-63 internal/…/ingestion_pipeline.go• L114-243 internal/…/schedulerdb.go• L29-81 internal/…/config.go• L14-30
Event publication and recovery
The event stream is both the change path and the recovery path. The scheduler publishes decisions to Pulsar. The ingester persists those decisions. A later scheduler cycle reads the resulting rows back into its working view.
Scheduler publication
The scheduler publishes lease, preemption, cancellation, retry, and outcome events instead of changing durable state directly for those decisions. The ingester applies these events through the same state path used by executor and other life-cycle reports.
The scheduler advances its database read positions only after publication succeeds. If publication fails, it can read the same changed rows again and recreate the required events. This is an at-least-once boundary. Event conversion and database updates must therefore tolerate replay.
Retry policy uses the same event path. A policy can produce a requeue event or a terminal error. The event carries the scheduling information needed for later placement and lease reconstruction. The scheduler reports the decision after it checks placement changes, so metrics describe the outcome recorded by the event stream.
References: internal/…/scheduler.go• L294-318 internal/…/scheduler.go• L380-455 internal/…/scheduler.go• L1319-1412 internal/…/publisher.go• L10-19 internal/…/pulsar_publisher.go• L73-80
Stream catch-up
A partition marker is a small event sent to each partition of the job-set topic. It carries a shared group ID and its partition number. The ingester stores each marker in the markers table. The scheduler can then count markers for that group.
When a scheduler becomes leader, it sends a marker group and waits until the database contains one marker for every sent partition. This proves that durable state includes events published before the check. Only then does the new leader make decisions from its refreshed working view.
References: internal/…/publisher.go• L16-19 internal/…/pulsar_publisher.go• L82-119 internal/…/instructions.go• L433-442 internal/…/scheduler.go• L219-235 internal/…/scheduler.go• L1793-1845
Scheduler refresh
At startup, the scheduler loads non-terminal jobs and their runs from the database. During normal cycles, it reads only rows after its job and run serial positions. It applies those changes to the in-memory job view. It removes terminal work and creates reconciliation events when the event stream must reflect durable state.
The refresh reads jobs and runs in one consistent database view. This matters because a job and its latest run describe one scheduling decision. The same read path finds run errors for failed runs and retrieves unconsumed leases for an executor.
References: internal/…/job_repository.go• L37-62 internal/…/job_repository.go• L80-177 internal/…/job_repository.go• L233-302 internal/…/scheduler.go• L475-558
Lease reconstruction
The executor-facing API uses durable state to compare a worker's report with the scheduler's records. It stores the latest executor and node snapshot. It tells the executor about runs that are no longer active. It returns runs assigned to that executor that the worker does not already know.
The returned lease joins compact job state with the stored submit message. The API adds selected node and pool context and any per-run overlay before it sends the workload to the executor. This turns a scheduling decision persisted through events into an executable workload after recovery or an executor reconnect.
References: internal/…/api.go• L36-57 internal/…/api.go• L87-205 internal/…/job_repository.go• L344-390 internal/…/scheduler.go• L1003-1046
Change checklist
When these files or sections are changed, remember to consider these:
- Keep job and run serial assignment aligned with the scheduler's two refresh cursors and the retry path after event publication.
- Keep queued-state and scheduling-information version rules aligned with event replay and database updates.
- Keep retry-policy decisions aligned with requeue versions, scheduling-information changes, terminal errors, and lease reconstruction.
- Keep event fields aligned across scheduler publication, ingester conversion, durable records, and executor lease reconstruction.
- Keep the full submit message, compact scheduling information, and per-run overlay compatible so the scheduler does not need full job data while the executor still receives a valid workload.
- Keep partition marker routing and marker counting aligned with the leader catch-up check.
- Keep executor report fields aligned with the nested node state used for scheduling and the run IDs used for lease reconciliation.
- Keep resource index resolution aligned with the supported resource scale. A change can alter which nodes enter the candidate set.
- Keep urgency index membership, its no-eviction resource view, and iterator ordering aligned with the setting that enables urgency-first preemption.
- Keep pool-aware node accounting aligned with the pool used by each scheduling pass and with the placement type reported in metrics.
- Keep the configured preemption order aligned with the scheduling method and preempted-job details reported in events.
- Keep gang rollback and sibling preemption aligned with the single transaction used for multi-job placement.
- Keep node matching reason categories aligned with the placement events and operational metrics that report them.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Concurrent job-data transactions write serial positions without the shared lock | The scheduler can move its cursor past a row and miss a state change | SchedulerDb uses a transaction advisory lock for job-data operations |
| A queued-state or scheduling-information event is replayed with an older version | Durable state can move backward and produce a stale scheduling view | Database updates require a newer version |
| A retry policy grows a job's requirements beyond available capacity | The retry is abandoned and the job becomes terminally failed instead of remaining queued | The scheduler checks the changed requirements before publishing the requeue |
| A resource index uses a resolution smaller than the supported resource scale or rounds a request incorrectly | Candidate lookup can reject a valid node or fail to represent the configured resource | Node database construction validates resolution and final matching checks actual requirements |
| An urgency index is built from the eviction-aware view or iterated with that view | Node ordering can skip a fitting node or make urgency preemption use the wrong capacity | Urgency indexes and iterators use the no-eviction view |
| The urgency-first setting changes after nodes are inserted | The node database can lack the indexes needed for the selected preemption order | Configure the setting before inserting nodes and rebuild the view when it changes |
| A pool-aware node view uses the wrong pool for a scheduling pass | Cross-pool work can receive the wrong resource and preemption accounting | Set the node view's pool to match the scheduling pool and keep cross-pool accounting rules aligned |
| A gang attempt commits only part of its placement | Some members can remain bound while the gang is reported as failed | Schedule the gang in one transaction and abort the transaction on failure |
| A new leader schedules before marker events reach the database | It can make decisions from incomplete state | Leader activation waits for all sent partition markers |
| Event publication fails after the scheduler reads changed rows | Decisions can be published again on a later cycle | Scheduler cursors advance only after successful publication. Consumers must tolerate replay |
| The sink returns a non-shutdown terminal error after its retry work | The ingestion pipeline can acknowledge the batch even though some state was not stored | Sink retry and error monitoring must treat terminal store errors as data-loss incidents |
| A worker reconnects with stale or missing run IDs | The executor can keep an inactive run or miss a lease that belongs to it | Lease reconciliation checks inactive runs and fetches unreported active runs |
| An event type is unsupported by the converter | The message's intended state change is not persisted | Event contract changes must update the converter and its metrics or logs |
Key files
| File | Why to read it |
|---|---|
| internal/…/ingester.go | Shows the two Pulsar ingestion pipelines and their shared database sink. |
| internal/…/instructions.go | Shows how job-set and control-plane events become scheduler database instructions. |
| internal/…/dbops.go | Defines instruction groups and the rules for safe merge and reorder. |
| internal/…/schedulerdb.go | Shows transactional persistence, retry, locking, and state effects. |
| internal/…/ingestion_pipeline.go | Shows batching, conversion, sink handoff, and message acknowledgement. |
| internal/…/models.go | Defines durable job, run, executor, metadata, error, and marker records. |
| internal/…/job_repository.go | Shows initial load, serial-based refresh, marker checks, and lease reads. |
| internal/…/executor_repository.go | Shows how executor reports and settings enter the scheduler. |
| internal/…/nodedb.go | Shows the in-memory node view, resource accounting, pool handling, and preemption state used by allocation. |
| internal/…/nodeiteration.go | Shows how normal and urgency resource views guide ordered node search. |
| internal/…/nodematching.go | Shows how node attributes and resources become match or exclusion results. |
| internal/…/pod.go | Defines the scheduling result passed from node selection to event and metric reporting. |
| internal/…/scheduler.go | Shows refresh cursors, retry and reconciliation events, publication ordering, leader catch-up, and recovery. |
| internal/…/api.go | Shows executor report storage, lease reconciliation, and workload reconstruction. |
| internal/…/pulsar_publisher.go | Shows event publication and partition marker routing. |
| internal/…/schedulerobjects.proto | Defines the compact scheduling view and executor/node state passed between boundaries. |
| Scheduling system | Parent page for the scheduler cycle and system boundaries. |
| Scheduling algorithms and constraints | Related page for placement, fairness, and preemption policy. |