Cluster Jobs¶
Cluster jobs group existing jobs. Those jobs start together on separate workers. Evaluation jobs, build jobs, and the nodes of an exec job can join as members. Groups start in full or not at all. Members stay regular jobs and carry a reference to their cluster. Every try of the whole group counts as a cluster attempt.
flowchart LR
C[cluster_job] --> M[cluster_member]
C --> A[cluster_attempt]
M --> E[evaluation]
M --> R[exec_job]
M --> B[derivation_build]
A --> D[dispatched_job]
Tables¶
| Table | Links to | Role |
|---|---|---|
cluster_job |
- | The group record. Holds status (Queued, Running, Completed, Failed, Aborted), same_zone, attempts, attempts_outside_budget and retry_budget |
cluster_member |
cluster_job |
One job in the group. Names exactly one of evaluation, derivation_build (the shared build) or exec_job (one node), plus role, primary and pin |
cluster_attempt |
cluster_job |
One try of the group. Tracks created_at, started_at (set only after every member accepted), finished_at, and outcome (Succeeded, Failed, PrepareFailed, Aborted) |
dispatched_job |
cluster_attempt |
The assignment row for a single member. Stays NULL for a standalone assignment |
| Constraint | Effect |
|---|---|
CHECK (num_nonnulls(evaluation, derivation_build, exec_job) = 1) |
A member names exactly one job. Two or none count as invalid |
idx-cluster_member-evaluation (unique on evaluation, coalesce(eval_index, 0)), idx-cluster_member-derivation_build, idx-cluster_member-exec_job (unique, partial) |
A job can belong to at most one cluster. A split evaluation can hold one member per eval_index |
idx-cluster_attempt-open (unique on cluster_job WHERE finished_at IS NULL) |
A cluster can hold at most one open attempt |
dispatched_job.cluster_attempt ON DELETE SET NULL |
Member rows survive their attempt as plain telemetry |
cluster_member, cluster_attempt ON DELETE CASCADE |
The hourly retention pass can remove a finished cluster job past retentionDays. Once evaluation garbage collection removed the members, deletion happens immediately. Active cluster jobs never get deleted by the pass |
Claim¶
The claim_cluster function in backend/gradient-db/src/scheduling/cluster/claim.rs runs all of its steps inside a single transaction.
- Insert the
cluster_attemptrow, on the conditioncluster_job.status = Queued. A conflict onidx-cluster_attempt-openwill insert nothing (ON CONFLICT). - Claim each member with
claim_assignment, the single-assignment claim statement. Claims setcluster_attemptand use the start condition of the member.- Members retain their own job keys
eval:<evaluation>,build:<shared_build>orexec:<exec_job>.
- Members retain their own job keys
-
The first statement inserting nothing will roll the whole transaction back. The return value of
claim_clusteris thenfalse. -
idx-cluster_attempt-opencan arbitrate between server instances claiming one cluster.idx-dispatched_job-open-jobcan do the same for a single job. - A member already open as a single assignment will lose its claim, and the whole attempt will roll back.
Close¶
close_cluster_attempt can close an attempt with its outcome only while the attempt is open. The same transaction must mark every open member row of the attempt as Abandoned too.
- A second close (a prepare timeout racing a member failure) will return
falsewithout touching anything.
Tracking¶
| Stage | Where a member is | Rule |
|---|---|---|
| Can start | Cluster book, under its own key | The eval and build assignment passes fetch each batch's memberships with one query (cluster_membership). Members of a Queued cluster enter the book. Members of any other cluster wait for that cluster. Non-members queue as before. |
| Waiting | Cluster book | A cluster can start only after every member arrived. A member key in the book count as tracked. A member that can no longer run (resync removal, evaluation cancel) hold its cluster back until the feed bring the member back. |
| Running | Active jobs, marked with its attempt | A reject, a revoked peer or a disconnect can never requeue a member as a single job. |
- Member evaluations always run in one job, never as a split fetch-only job. A split job can place its follow-up outside the cluster. Companions of a split evaluation evaluate from the source the primary fetched.
- An empty answer to
RequestJobrecord an idle slot(worker, kind)for the worker. An assignment, a full worker or a disconnect clear the slot. The planner can ignore entries older than 25 s (two worker heartbeats). Idle slots give the planner the only view of free capacity. - The placement pass can score members against the store summary of each connected worker. The function for single-job assignment (
take_best_of_kind) cannot select a member.
Placement¶
The cluster-dispatch pass can run every 5 s. It can also run whenever RequestJob messages go unanswered. Expire overdue prepares first. Then place all clusters that can start, prioritized clusters before the oldest ones.
- A worker can seat a member when three conditions hold. It must have an idle slot of the member's kind, match the member's
pin, and be able to run the job (capabilities, project access). - Bipartite matching: each member sits on its own worker, one worker per member.
- Under
same_zone, all members sit in one zone. Workers without a zone form a zone of their own. - Use store summaries to choose the zone where the sum of missing NAR sizes is smallest. Consider only zones that can hold all members.
- Once the pass seats a worker for one cluster, it cannot offer that worker to the next cluster.
- A cluster that cannot fill all seats must wait. Single assignment follow separate rules and remain unchanged.
Prepare and Start¶
- The scheduler can claim the cluster and all its seats in a single step. It refuse the claim when a seat's worker turned busy after the snapshot.
claim_clusterwrite the attempt plus adispatched_jobrow for every member. Each build member get anAssignedtransition.- Every seat session send
AssignJobwithcluster(attempt,role,index,hold_secs). The worker hold the job and do not start it. - Once every member accept,
start_cluster_attemptmark the attempt started and the clusterRunning. All member then receiveStartClusterwith the roster.
| Event | Result |
|---|---|
| Every member accepted | StartCluster to every member |
| A member rejected | Attempt closed PrepareFailed, AbortCluster to every member, cluster waiting again after 30 s |
scheduler.clusterPrepareTimeoutSecs passed before the attempt started |
Same as a reject |
A held member reporting JobFailed before the start (hold expired, drain, AbortJob) |
Same as a reject. The report never reach the build or evaluation |
| The claim is lost | Nothing written. The member go back to the assignment pass, and those pass re-read their cluster |
- A failed prepare do not consume the cluster's retry budget.
- Set
hold_secstoclusterPrepareTimeoutSecsplus 10 s. A worker that never receiveStartClusterrelease the slot on its own.
Signals¶
- A
ClusterSignalcan be forwarded by the server only from a member of a started attempt. In every other case the server discards the signal. - Set
toto target a single member by role and index. Omittoto deliver the signal to every member.
Recovery¶
When a member reports JobCompleted or JobFailed, its job can be released. The build or evaluation transition has to wait for the attempt verdict. The first deciding report settles the attempt, and that verdict then applies to every member.
| Verdict | When | Attempt | Cluster | Members |
|---|---|---|---|---|
| Complete | Every member succeeded, or the primary succeeded | Succeeded |
Completed |
Reported members settle. Still-running ones end Aborted |
| Retry | A member failed or was lost, budget left, every member can still start | Failed |
Queued |
Every member job going back to the assignment passes |
| Fail | Same as Retry without budget, or a member can no longer start | Failed |
Failed |
Members settle with their own outcome. Requeueing failure kinds become Permanent. Survivors end Aborted |
| Abort | An evaluation abort reached a member | Aborted |
Aborted |
Survivors end Aborted |
- Reports that arrive while the attempt is being settled follow the decided verdict.
- A member with an open attempt count as tracked, so
abandoned-dispatch-sweepand the evaluation watchdog skip them. cluster_job.retry_budgetcan hold the count of automatic retries after the first start. A requeue needsattempts - attempts_outside_budget <= retry_budget. This budget is separate from the per-evaluation assignment budget. A user retry of a build disregard it.- Members lost with their worker, or reaped after an unconfirmed abort, report into the same verdict.
Aging Reservations¶
A cluster can be ready to start while no set of workers remain idle long enough to satisfy scheduler.clusterReserveAfterSecs (600 s). In that case, the cluster reserve a placement instead of waiting for idle workers to line up by chance.
- Target: the planner select a match across all connected eligible workers, seating idle workers first.
- Seats: a reserved worker keeps its current jobs, but the scheduler assign no new job of the reserved kind to it.
- Commit: once every seat reach an idle state, the reservation commit like a normal placement.
- One at a time: a single cluster can hold a reservation at any moment. Other clusters plan over the unreserved idle workers.
- Release: Reservations expire after
scheduler.clusterReserveTimeoutSecs(1800 seconds), when workers with seat assignments disconnect, or when clusters leave the queue. Clusters get onescheduler.clusterReserveAfterSecsperiod after the timeout before a new reservation. Other clusters can reserve during that period. Other releases allow a new reservation at the next planning pass.
Split Evaluations¶
One evaluation can run on multiple eval workers as a cluster job. The primary member can fetch the flake and plan the shards. All members then take shards from a Postgres queue. They stop at an empty queue.
flowchart LR
D[eval-dispatch] -->|decide_split| C[cluster_job]
C --> P[primary]
C --> M[companions]
P -->|plan| Q[(eval_shard)]
Q -->|take| P
Q -->|take| M
Creation¶
decide_split in backend/gradient-scheduler/src/eval_split/create.rs can run once per queued evaluation, before routing.
| Rule | Effect |
|---|---|
Task without multi_node_evaluation |
No split |
| No learned costs for the task | No split. The first evaluation of a task stays on one worker |
| Seats | Distinct idle eval workers, at most MAX_SPLIT_MEMBERS (4). Workers with the federate capability never count |
| Member count | The cost planner can pick the count with the shortest predicted wall clock. Fewer than 2 members: no split |
| One transaction | No open eval dispatch of the evaluation, then the cluster_job row, the members and the eval_split row |
| Placement | A worker can seat a member only with free memory of at least min_free_ram_mb, the largest max_peak_rss_mb of the task. federate workers never seat a member |
| Too few free seats | cluster-dispatch can drop the companions with the highest eval_index down to the fillable seats. Below 2 fillable seats, the cluster gets deleted on the same pass |
| Unplaced | A cluster still Queued after dissolve_after (30 s) gets deleted by cluster-dispatch. The evaluation then runs on one worker |
- The in-memory set of decided evaluations can only save work. A restart can repeat a decision.
- Split clusters never wait for an aging reservation.
Members¶
| Member | Job key | Role |
|---|---|---|
Primary (eval_index 0) |
eval:<evaluation> |
split-evaluation-primary |
Companion (eval_index 1..n-1) |
eval:<evaluation>:<index> |
split-evaluation-companion |
- Member keys get one job each from the eval assignment pass.
- Open eval
dispatched_jobrows keep an evaluation in the dispatched state. - Evaluation aborts cancel every possible member key.
Shard Queue¶
| Table | Content |
|---|---|
eval_split |
One row per split evaluation: cluster_job, source_store_path, fingerprint, planned_at |
eval_shard |
One row per shard: pattern, children, predicted_ms, state, attempts, reported_by_job, taken_job |
state |
Meaning |
|---|---|
Queued (0) |
Waiting for a member |
Running (1) |
Taken by taken_job |
Done (2) |
Listed |
Failed (3) |
Lost twice, reported as an attribute error |
Split (4) |
Replaced by two halves |
- A take is one
UPDATEwithFOR UPDATE SKIP LOCKED. Two members asking at once get different shards. - Take order: the member's own deferred sets, planned shards, deferred sets of other members, then lowest
seq. - Appends lock the
eval_splitrow first.seqvalues stay unique per evaluation. - The server can only answer
Finished, when no shard isQueuedorRunning. -
A member can have at most two running shards. A worker can request a second shard with the first shard still on the list. The second shard can keep other evaluation subprocesses busy while the slow attribute can finish the first. Servers older than protocol 55 receive one shard at a time.
-
All shard requests get an immediate response at any stage (no source yet, no plan yet, or shards to fetch). Previous evaluation results from the same worker never delay that response. Source reports and plan reports go into storage before the server can read the next message on that connection.
- The
Donemarks for reportedfinishedshards wait in the job event lane behind those evaluation results.Doneshards always have a committed result. - The job take step can treat the shard as held before arrival of the
Donemark. The server response is thenWait, notFinished, because the shard is stillRunning. - Failed
Donemarks leave the shard asRunning. Later job takes return the shard to the queue.
Recovery¶
| Event | Result |
|---|---|
Primary lost or failed before planned_at |
Retry of the attempt, as for any cluster |
Source announcement the server cannot store, before planned_at |
The server fails the primary. Retry of the attempt |
Member lost or failed after planned_at |
Its running shards go back to the queue. No verdict. The others continue |
| Returned shard with 2 or more children | Split into two queued halves |
| Returned shard with 1 child or none | Queued again once (MAX_SHARD_ATTEMPTS = 2), then Failed with an attribute error |
Every member lost after planned_at |
Retry. The queue survives into the next attempt. Staged EvalStats of the failed attempt get deleted |
Request with a member key whose running shard is absent from both finished and held |
That shard returns to the queue first |
Verdict¶
- Members can only report success, after
Finished. Members send theirEvalStatsbefore the success. - The verdict can only come after a report from every member. One success among those reports can settle the attempt as
Complete. - Members still taking shards get
Finishedon the next request. Members of a completed attempt never receive an abort. - Aborted members end the attempt as
Abortat once. - The evaluation completion can happen once, for the first success. The merge of the staged
EvalStatsthen covers every member.
Exec Jobs¶
Exec apps with nodes > 1 produce a cluster job at evaluation time. All the writes share one transaction. Those writes are the cluster_job, one exec_job row per node, and one member per row.
| Field | Value |
|---|---|
same_zone |
true |
retry_budget |
3 |
| Member | role = "node", primary = false, pin = NULL, index = exec_job.node_index |
| Job key | exec:<exec_job>, one per node |
- Exec members with a hold take a guest address lease on the worker. Workers include that address in
AssignJobResponse.endpoint. - Entries in the
StartClusterroster list the address asClusterPeer.endpointfor the member. The server can also write the address toexec_job_attempt.guest_address. - Workers free the address if a hold ended before
StartCluster.
Exec Verdict¶
Exec clusters swap the verdict above for exec_verdict. Checks run in table order.
| Verdict | When | Requeue | Nodes |
|---|---|---|---|
| Complete | Every node succeeded | - | Completed |
| Abort | A node aborted | - | Every node Aborted |
| Retry | A node lost | Inside retry_budget |
Queued, no retry used |
| Fail | A node failed with keepRunning, after every node reported |
- | Own outcome per node |
| Restart | A node failed or timed out without keepRunning, retries left |
attempts_outside_budget + 1 |
Queued, one retry used on every row |
| Fail | Same as Restart without retries, or Retry without budget | - | Own outcome per node, survivors Aborted |
- After a server restart, the server can requeue every open cluster with
attempts_outside_budget + 1. Those requeues never count againstretry_budget. - Members never survive a lost worker connection or a server restart. Both lead to a restart of every node from its last phase.
- Survivor reports after a restart change nothing.
Related¶
- Shared Builds
- Waiting and Recovery
- Workers: Zones
- Jobs: Cluster Members
- Exec Jobs: Multi-Node Jobs
- Find the
gradient-clusterVM test innix/tests/gradient/cluster/. - Find the
gradient-execVM test innix/tests/gradient/exec/with a two-node job.