Skip to content

Persisting cursors across restart

One of a node's four positions is written to its volume: the assignment watch record. This page covers when that write happens, the rule that keeps it from recording progress a node has not made, and what the write path guarantees to a process that stops mid-way.

When the write happens

The position is persisted when a watch returns a revision different from the one the node holds. The live value in the process can be ahead of the file only for the moment between those two steps:

flowchart TB
  CP["Control plane watch"]
  subgraph PROC["XRATUD PROCESS"]
    direction TB
    DEC{{"Recovery decision:<br/>target revision"}}
    WCO["Watch cursor owner"]
    REG[("Registry: watch_revision")]
  end
  subgraph VOL["NODE VOLUME, cursor/"]
    direction TB
    TMP["Temporary file,<br/>written and fsynced"]
    CUR[("Cursor file")]
  end
  CP -->|"returned revision"| DEC
  DEC -->|"only when the target<br/>differs from the live position"| WCO
  WCO -->|"live position"| REG
  WCO --> TMP
  TMP -->|"rename"| CUR

Recovery decision is the only path to a write, and it reaches Watch cursor owner only when the stream has moved. The owner updates the live position in Registry: watch_revision and writes Cursor file through Temporary file, so the file on the volume is always a complete record.

The write path

1. build the record and its digest
2. check its own ordering invariants
3. load the record on disk and check the stream key, the identity binding
   and that no revision would regress
4. write to <path>.tmp, flush, fsync
5. rename over the target

A process that stops at any point leaves either the previous record or the new one, both of which are valid and both of which are behind or at the true position. See Assignment cursor runtime for the checks in step 3 and the reasons they produce.

A lower position is a reset

The node takes the greater of what it is asked to persist and what is already stored. A request to persist a revision lower than the stored one is treated as a reset: the cursor file is removed and persistence restarts from zero.

Requested against the stored value Result
Higher Recorded
Equal Recorded, with a refreshed timestamp
Lower The file is removed, and the next write starts a new record

A node that has reset reads the range again, which its dedupe records absorb. See Resume direction.

Applied and acknowledged are carried forward

A write carries the applied and acknowledged revisions from the record the node loaded, clamped to what has been seen. The node never raises either of them past its own stream position, so a record written by a previous process cannot describe work beyond what the current one knows about. See The assignment cursor.

When a write is refused

A write that fails its checks raises the reason that failed it. The node treats four of those reasons as recoverable when it is already holding a corruption condition: a stream key mismatch, a detected corruption, a digest mismatch and a binding mismatch. In that case it removes the cursor file and writes a fresh record for the current stream and identity.

A node re-identified against a new control-plane identity revision drops the position it can no longer prove on this path, without a restart.

The three process-scoped positions

The status acknowledgement state, the outbox checkpoints and the kernel return cursors are written with the same temporary-file-and-rename discipline, into the process working area, so a reader always sees a complete record. They track the work of the running process: what it has sent, what has been confirmed, and what is still waiting. See Durable node state layout.