Recovery and rebuild
This page is part of the documentation for Orleans.Lattice 10.5.0 (release line 10.5), built 2026-12-05. It is also published as markdown, with every table and list, at recovery-and-rebuild.md, and llms.txt lists every page.Part of Write-Ahead Log.
Formal model.
ReplayPermits checks permit
conservation, observed admission decisions, memory withholding and retained replay
prefixes. Admission observes depth before incrementing the waiter count; this is
not a hard queue-cardinality cap. Draining fan-out may exceed that observed bound,
while fresh excessive mean wait can refuse even below it.
StarvationDriveBudget bounds a starvation-drive owner's residency under runtime opportunities,
not elapsed time or a cold-replay owner's lifetime: caller deadlines do not cancel
shared cold replay. Cold ownership ends on completion or actual activation-lifetime
cancellation, with continuation, prefix-banking and teardown completion
premises; a permanently hung uncancelled owner has no residency guarantee.
When a leaf grain activates, it rebuilds its in-memory projection by replaying the WAL through a per-partition replay coordinator, seeding the cache first from its own latest durable snapshot - when that snapshot is newer than its partition-0 checkpoint, and also when it is at or behind it but the cache starts empty or a WAL prefix has been trimmed (see Snapshot-on-fall-off safety net). Three cases:
- Tail replay. The leaf's latest snapshot covers the WAL through offset
N - the checkpoint the capture stamped, to which activation resets the
leaf's checkpoint - and the newest WAL entry is at offset M (the WAL head,
the next offset to be assigned, is
M + 1). The leaf reloads the snapshot, reads entries(N, M]in bounded slices and applies each to its projection, soM - Ngrows with the time since the last snapshot capture rather than with the checkpoint interval. Replay is in-process and typically completes in a few milliseconds. - Fresh-leaf tail replay. A leaf created mid-run by a split (or by the
first write to a virgin shard) has no checkpoint yet: a never-assigned
checkpoint reads as the -1 "nothing applied" sentinel on every partition
(issue #2703). The fall-off-log detector exempts the
sentinel from the replay-budget and trim triggers: the leaf has no
projection state to lose, and the per-leaf range filter inside the
materialiser drops every WAL entry that falls
outside this leaf's
[LowKeyInclusive, HighKeyExclusive)ownership range, so the leaf applies only its own records - and a provider that classifies records before decoding them decodes only those (see below). The read itself still walks the whole retained window, inWalReplaySliceBudget-sized slices. A leaf that has checkpointed but never kept a covering snapshot replays the same whole window, because its cache starts empty. An unreadable snapshot, or an absent one recorded as previously kept, instead fails the projection closed without replay (see A vanished leaf snapshot). For a permitted cold rebuild, a separate guard compares the oldest readable offset with its durable checkpoint and refuses the leaf when an offset it still needs has been trimmed (the genuine-loss case below). - Genuine loss. The persisted checkpoint is older than the WAL trim
watermark - the entries it would replay are no longer available - and no
snapshot covers the gap. Activation refuses the leaf with
LeafProjectionStaleExceptionunder everyProjectionRebuildPolicy: neither the snapshot-then-WAL recovery beyond the snapshot rehydrate nor the full-rebuild path is integrated yet, and replaying only the surviving suffix would rebuild the leaf over the lost prefix. Seeprojection-rebuild.mdfor the policies and the operator remedies. The grain-state row holds only tree metadata (sibling and parent pointers, tree id, shard index, key range, moved-away slots, split lifecycle, last-compaction-version), the leaf's hybrid-logical clock and version vector, the projection checkpoints, the running projection hash and its publish sequence, a snapshot-size hint, the replay ledger and the discarded-prepare records, the kept-snapshot and row-record flags, and the leaf-reclaim retirement record - it is never the source of truth for committed entry values.
With correctly stamped records, the projection that a reader observes after activation is byte-equivalent to the projection at the moment the leaf last deactivated (for a freshly-created leaf, the records the WAL holds for its own range).
Committed row replay also rebuilds the leaf's delta version watermark from the original row HLC, without minting a newer timestamp. This keeps recovered live rows and retained tombstones visible to delta readers, including the committed tombstone pass used by replication re-seed. Unresolved prepared rows do not advance this watermark before their terminal decision.
Single-key delete ownership and older WAL records
Single-key DeleteAsync and its tracked leaf path persist the leaf's owning
shard index on the tombstone, just as single-key sets do. Replay uses the
current authoritative shard map when available; otherwise it compares that
persisted stamp with the leaf's shard index. Both paths retain the leaf's
key-range check, so sharing a WAL partition never grants another shard's delete
ownership.
Older producers omitted the shard index on single-key delete WAL records,
leaving it at 0 even for nonzero shards (issue #4928). A retained tombstone
with that shape can be recovered when an authoritative map assigns its key to
the leaf before that replay. With no map, the record is indistinguishable
from a legitimate shard-0 delete; upgrading the producer does not repair those
already-written records, and replay must not apply them to every shard. A
registered tree can legitimately have no explicit map, so a successful registry
lookup alone does not remove this limitation.
For a suspected historical resurrection, preserve a pristine copy of grain storage, snapshots and the retained WAL before attempting recovery. Verify the key's ownership and the set/delete HLCs against that copy; do not rewrite shard stamps, reset checkpoints, or discard snapshots on the live deployment. There is no automatic historical repair in this fix. If replay has already consumed the malformed record, publishing a map and restarting alone is not a repair: the checkpoint or a newly captured snapshot can already cover that offset. Recovery of such data needs a separately reviewed rebuild or restore from verified evidence, not relaxed cross-shard filtering.
For evidence-preserving assessment and recovery of historical records, see Acknowledged deletes reappear after cold replay in the troubleshooting guide.
Replay reads are filtered at the source
A WAL partition is shared by every leaf whose keys hash to it, so a leaf
replaying a partition would otherwise read its neighbours' records as well as
its own. The leaf therefore passes its ownership - its key range and, when the
tree's shard map is known, the slots of its shard - down the read path as a
WalKeyFilter: the slice reader hands it to the leaf replay coordination seam,
which reads through the WAL partition filtered read and, beneath that,
IWalStorageProvider.ReadFilteredAsync. A provider that can classify a record
before decoding it skips every record the leaf does not own, so a replay
allocates in proportion to the leaf's own records rather than to the partition
(issue #3565). See
wal-storage-providers.md
for the read's exact contract.
The filter and the leaf's own per-entry apply check are built from one capture of the leaf's state, so the filter never drops a record the leaf would have applied, and the leaf still runs that check on everything it receives. Each read bounds the entries it examines rather than the entries it returns, and delivers the last examined entry routing-only when it is excluded, so the projection checkpoint still advances past a window that held only other leaves' records. A leaf whose ownership excludes nothing - an unbounded key range with no shard constraint - reads unfiltered, exactly as before.
The coordinator's five-second slice cache is keyed by the filter as well as the window, because a filtered slice is missing every other owner's records. Leaves with different ownership therefore no longer share one slice read when they replay the same window back to back. Each makes its own storage read instead and, with a provider that classifies records before decoding them, decodes only its own records in it.