Shutdown and drain¶
A node asked to stop does three things in order: it records the request with its reason, it stops accepting new work, and it waits until nothing is in flight before the process may exit. The same drain state is entered by backpressure, so draining is reversible as well as a path to exit.
This page covers the request, the state it produces, and the condition the node must satisfy before it exits.
The request¶
flowchart TB
SIG(["Shutdown signal<br/>or operator request"])
subgraph PROC["XRATUD PROCESS"]
direction TB
REG[("Registry:<br/>shutdown_requested,<br/>shutdown_reason")]
HLM["Health lifecycle: DRAINING"]
Q[("Local queue")]
ORCH["Runtime orchestrator"]
EXIT{{"Exit gate"}}
end
DONE(["Process exits"])
SIG --> REG
SIG --> HLM
REG -->|"each cycle: drain state"| ORCH
Q -->|"depth"| EXIT
ORCH -->|"active runtimes"| EXIT
REG -->|"requested"| EXIT
EXIT -->|"all three hold"| DONE
One signal writes Registry: shutdown_requested, shutdown_reason and moves
Health lifecycle to DRAINING together. Exit gate reads three things each
cycle: the request, the depth of Local queue, and the active count from
Runtime orchestrator.
The reason defaults to operator_requested when the caller supplies none.
The drain state each cycle¶
The drain state is a xratud.runtime_drain.v1 document. Its content depends on
whether a shutdown has been requested and whether project runtimes are still
active:
| Shutdown requested | Active runtimes | cleanup_reason_code |
decommission_state |
|---|---|---|---|
| No | Any | shutdown_drain_not_required |
empty |
| Yes | None | shutdown_drain_not_required |
drain_requested |
| Yes | One or more | shutdown_drain_stop_all |
draining |
The third row is the hard stop: with a shutdown requested and runtimes still
active, the node stops all of them with the shutdown reason and reports
DECOMMISSION_HARD_STOP. The second row reports
DECOMMISSION_DRAIN_COMPLETED, because the runtimes are already gone.
Every document carries the generation pair and the finalization evidence references alongside those fields:
desired_generation the generation the node was asked to reach
observed_generation the generation it has reached
finalization_evidence_refs references to the evidence produced while finalizing
cleanup_reason_code why cleanup ran, or why it was not required
decommission_state drain_requested or draining
decommission_reason_code DECOMMISSION_DRAIN_COMPLETED or DECOMMISSION_HARD_STOP
stopped, active_count what the stop pass did and what remains
The generation pair is how an operator sees whether a decommission has converged: a node is done when the observed generation reaches the desired one and the active count is zero.
The exit condition¶
Four things must hold together:
a shutdown was requested
the local queue depth is zero
the runtime orchestrator reports no active runtimes
the cycle's own active count is zero
A node that has drained its queue while a runtime is still stopping stays in the loop. The condition is checked on the post-cycle numbers, so one cycle's work is always accounted for before the process may exit.
Draining is also a backpressure state¶
The same DRAINING phase is entered without any shutdown request, from queue
backpressure or from the performance governor. In that case the node pauses
intake, finishes what it holds, and returns to ACTIVE once the queue is empty,
no runtimes are active and bootstrap is complete.
| Reason reported while draining | Entered from |
|---|---|
drain_requested |
A shutdown request or an operator drain |
queue_backpressure |
The local queue at its limit |
governor_backpressure |
The performance governor holding work back |
drain_inflight |
The drain signal has cleared and work is still finishing |
drain_complete |
The node has returned to ACTIVE |
See Health probes and lifecycle management.
Related¶
- Two-phase drain for what each phase refuses.
- Jobs garbage collector runtime for the cleanup that follows a decommission.
- Lease dedupe and finalize for how each assignment's hold ends.