Cross-cluster atomic visibility
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 cross-cluster-atomic-visibility.md, and llms.txt lists every page.Part of Atomic Multi-Key Writes.
Cross-cluster atomic visibility ships universally through the
same per-tree transaction-registry linearization point used locally.
Prepared writes ride the standard per-key WAL and replication transport
carrying an additive IsPrepared slot and the saga's
TransactionId; every per-shard TxCommit / TxAbort terminal mark
ships as a single record exempt from the producer-side per-key
filter. On the receiver, prepared records install each entry into the
destination leaf's per-tx pending bucket. Terminal records gate the
per-tree linearization flip
on a per-source-shard arrival tally before fanning the terminal out
to the receiver's leaves.
Multi-shard receiver gate
A saga that touched N source shards emits N independent
TxCommit (or TxAbort) WAL records, one per source shard. Each one
ships through the change feed under its own backpressure / batching
cadence, so the receiver can observe them in any order and arbitrarily
spaced in wall-clock time. The receiver must therefore hold back the
per-tree visibility flip until it has seen every per-source-shard
terminal; otherwise a remote reader concurrent with replication can
observe post-saga values on the drained-shard keys and pre-saga
values on the still-pending-shard keys - a partial-batch visibility
split the atomicity contract makes impossible.
The producer stamps the saga's authoritative touched-shard count on
each terminal record via the additive
LatticeMutation.AtomicShardCount slot. The saga publishes the count
through an ambient scope around each per-shard terminal mark, and the
shard root reads it at the moment the terminal mutation is assembled - so a producer-side mid-saga shadow-forward
split that grows the touched-shard set between successive per-shard
terminals stamps the post-growth count on the later terminals and the
receiver adopts the larger value (max(seen, incoming)) without ever
under-counting.
On the receiver, the tree's transaction registry records each terminal arrival, deduplicated per (transaction, source shard), in a persistent per-transaction set of source-shard indices, and tracks each transaction's expected total alongside it. The expected total only ever grows: each arrival raises it to the larger of the recorded and the incoming count. Each arrival returns a verdict carrying:
| Part of the verdict | Meaning |
|---|---|
| Final | true once the distinct source-shard arrivals for the transaction reach the expected total - or at once, with no tally kept, when the record carries no count (a legacy producer). |
| Outcome | The commit-or-abort outcome of the arrival being recorded; every per-source-shard terminal of a saga carries the same outcome. An arrival whose outcome conflicts with a decision the registry has already recorded is rejected with InvalidOperationException rather than absorbed. |
| Observed source shards | The sorted set of source-shard indices seen, returned only on the final arrival (a legacy arrival returns just its own index); empty otherwise, so the non-final path allocates no array. |
The receiver's terminal-apply path consults the tally first. A
non-final tally leaves the per-tree linearization mark unset and the
receiver leaves' pending buckets undrained - readers dialling back
through the transaction registry observe InFlight for the
whole saga and fall through to the pre-saga value. Only on the final
arrival does the receiver (for a cross-tree write, only once the
receiver barrier
has also decided):
- Mark the registry's decision (committed or aborted) - the single per-tree visibility flip.
- Resolve the transitive split-forward closure of every observed source-shard and dispatch the per-shard terminal mark to each destination in a single parallel hop, under the saga's source HLC and origin-cluster id.
The gate handles producer/receiver shard-count divergence naturally
because the tally key is the producer-stamped source-side shard
index, not the receiver's shard layout. A receiver whose adaptive
splits or operator resize have produced a different shard count than
the source still observes exactly atomicShardCount distinct source
terminals (one per source shard the saga touched).
The tally is forward- and backward-compatible across mixed-version
deployments. A legacy persisted registry row that predates the tally
decodes its arrival and expected-total maps as empty (the correct "no
terminals tallied yet" default). A receiver consuming records from a
legacy producer that never stamps AtomicShardCount sees a count of
0 on every arrival, which the gate treats as "no expected-total
information" and falls back to first-terminal-wins semantics -
equivalent to the pre-gate behaviour. The registry's cleanup call for a
finished saga clears both maps when it tombstones the decision entry,
so the persisted footprint stays bounded by the in-flight +
recently-completed saga set.
Prepared writes never enter the receiver's batched merge path
The receiver's batched apply path classifies inbound WalRecord
entries into a fast-path batched last-writer-wins merge and a
per-entry fallback. The classifier explicitly excludes any entry with
IsPrepared == true: prepared Set / Delete records are forced
onto the per-entry path, where they are staged into the destination
leaf's per-transaction pending bucket rather than merged into its
visible entries. Unprepared writes continue to consume the batched
merge path. Without this exclusion, prepared writes would commit
directly into the receiver leaf's visible entries and the saga's
terminal mark would find no matching pending entries to flip - so the
cross-cluster reader would observe the
prepared write as visible before the registry gate ever flipped,
purely as a function of whether the inbound run happened to be
batched (steady-state load) or single-entry (cold start). The
exclusion makes the strict-isolation invariant independent of the
receiver's batching cadence.
Read cache: cursor-based delivery, not HLC-based
A cross-cluster apply on the receiver preserves the source cluster's HLC verbatim on every committed entry - the destination leaf does not bump the source HLC into its local clock, because LWW convergence across clusters with skewed wall clocks requires the authoring cluster's HLC to remain the comparator. Whenever the source HLC is below the destination leaf's already-published version-vector entry for its own replica, an HLC-based delta filter on the read cache silently drops the entry from the per-key delta and continues serving the stale local value indefinitely.
To decouple cache delivery from LWW HLC ordering,
a leaf lookup cache's refresh pulls from the primary leaf through an
internal delivery-cursor delta call rather than the legacy HLC-keyed
delta. The cursor is an
activation-scoped (Epoch, Sequence) pair: Sequence is bumped
once per entry stored or removed on the leaf - regardless of the
write's LWW HLC - so the cache pulls every write strictly newer than
its last delivered sequence even when the underlying HLC has rewound.
Epoch is bumped on every leaf activation, so a cache holding a
stale cursor across a leaf re-activation falls back to a full-
snapshot delivery on its next refresh. The cursor is intentionally
non-persistent: the WAL replay path remains the sole projection
source-of-truth, and the cursor adds zero per-write durable I/O. The
cache also delegates reads back to the primary leaf for any cached
row carrying IsMigrated = true, so the leaf-side shadow guard
protecting an in-flight cross-shard migration is never bypassed by
the cache fast path.