Lease dedupe and finalize¶
Two operations bracket a lease's life beyond the ordinary claim and release. At startup, recovery clears any claims a previous process left in the state file so they are claimable again. At the end of an assignment, finalize stops the project runtime it started and releases the lease, in that order and with the release unconditional.
This page covers both, and the state each one leaves.
Recovery runs once per process¶
flowchart TB
subgraph PROC["XRATUD PROCESS"]
direction TB
CYC["First reconcile cycle"]
REC{{"Lease recovery,<br/>guarded by the registry"}}
REG[("Registry: lease_recovery")]
MUX["Telemetry mux, logs channel"]
end
STATE[("Lease state file")]
CP["Control plane log ingest"]
CYC --> REC
REC -->|"expire this worker's claims,<br/>sweep due leases"| STATE
REC -->|"executed, counts"| REG
REC -->|"WARN event when a<br/>count is non-zero"| MUX
MUX --> CP
Lease recovery runs on the first cycle and records itself in
Registry: lease_recovery, and that entry skips it on every later cycle. It acts
on whatever Lease state file holds when the process starts.
The result is recorded in the registry:
| Entry | Means |
|---|---|
executed |
Recovery has run in this process |
recovered_claims |
Claims held by this worker id that were moved to expired |
expired_due_claims |
Leases whose expiry had passed, moved to expired by the sweep |
A node that recovered nothing records zero for both, which is the result of a clean start.
Recovery is observable¶
When either count is non-zero the node emits one log event, so a restart that inherited work is visible without reading the state file:
{
"level": "WARN",
"service_name": "xratud",
"component": "dataplane",
"feature": "lease_recovery",
"operation": "startup_recover",
"message": "recovered stale worker claims during startup",
"details": {
"worker_id": "local-worker",
"recovered_claims": 3,
"expired_due_claims": 1
}
}
The event goes through the telemetry mux on the logs channel, so it reaches
the control plane through the ordinary path and through the outbox during an
outage. A node emitting this on every restart is a node whose work is being
interrupted. See
Diagnosing failures.
Recovery leaves the record in place¶
A recovered claim moves to expired with its expiry set to zero, and the record
stays. The claim count, the creation time and the attempt survive, so the next
claim on that assignment is recorded as a further hold on the same work. See
Lease acquisition, renewal, and expiry.
Finalize¶
Finalize is the end of one assignment's hold:
1. if the assignment started a project runtime, stop it
2. if stopping failed, log it with the error
3. release the lease
The release happens whichever way step 1 went. The unconditional release lets the control plane dispatch the assignment again
even when its runtime could not be stopped. The stop failure is reported as a log event carrying
runtime stop failed and the error, with the run, node, assignment and trace
identifiers attached.
What remains after finalize:
| State | After finalize |
|---|---|
| The local lease | released, with an expiry of zero |
| The execution dedupe record | Kept, carrying the terminal status and the result |
| The project runtime | Stopped, or reported as a failed stop |
| The control-plane lease | Finalized by the status report, or lapsed by expiry |
Related¶
- Idempotency and replay-safe reprocessing for the record finalize leaves in place.
- Recovery reconcile runtime for the recovery actions a cycle resolves.
- Shutdown and drain for the ordered path that finalizes leases on purpose.