Every reconciliation start and every BeginBaseInstall bumps a generation.
A worker selects slices, records compare results and certifies the dirty
set only while its own generation is current, so:
- a worker running when a BASE install begins can no longer finish over
it and clear the install guard (Base=Installing), in memory or on disk;
finishReconcile also refuses while the guard is set (two independent
guards);
- a worker that saw its set empty, or compared a chunk, before a BASE
install restarted reconciliation can neither certify the replacement
run nor delete from its set.
A replaced run closes its channel, and waitReconciled re-checks against
the current run.
Deterministic schedules (test hook at slice, compare and certify):
- held worker -> BeginBaseInstall -> worker resumes: cuts stay refused
as base_installing, the persisted header keeps Installing, a restart
still refuses;
- old worker paused at certify -> Begin/EndBaseInstall -> old resumes:
the replacement stays reconciling and untouched, cuts refused;
- old worker paused after a compare -> Begin/End -> old resumes: the
replacement set is untouched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The typed control codes map every unlisted cause to 500 internal, so a cut
refused while the layer reconciles its dirty set (and a detach whose
deadline ended during reconciliation) reported internal. They now answer
409 with code reconciling, retryable, as ruled for the reconciler.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a layer's dirty set is unknown, its first cut used to hash-compare
every chunk under the capture barrier, which paused writes for a
whole-volume copy. The unknown case is a lost or mismatched bitmap, or
a BASE install that just finished.
Now the layer reconciles in the background, outside the barrier:
- The reconcile set is every chunk with a local copy (an absent chunk
never written locally is HEAD's content).
- A layer-owned reconciler, joined on Close, takes bounded slices. Per
chunk it reads through the normal read path, hashes, and compares
with HEAD; a mismatch sets the chunk's dirty bit. A write racing the
comparison marks its chunk dirty anyway.
- When the set is empty, the dirty set is saved first, then a header
naming HEAD. A crash between the two leaves a mismatching header, so
the next attach reconciles again rather than trusting an incomplete
bitmap. Then cuts resume, uploading only dirty chunks.
While reconciling, no HEAD moves:
- Cut, Capture and MakeRemoteDurable return ErrChunkReconciling
(retryable).
- Detach waits for reconciliation within its deadline, then makes its
normal cut; otherwise ErrChunkReconciling.
- The automatic cut scheduler skips the tick (not a failure, no
backoff).
A fresh host (FreshFromHead) starts with an empty dirty set instead of
an unknown one. Its local volume is new and accepts no write before
attach, so a new volume never reconciles.
Stats gains Reconciling and ReconcileDone/ReconcileTotal. DirtyChunks
(the scheduler's threshold) does not count chunks awaiting
reconciliation.
Test changes:
- The storage fixture waits for reconciliation after attach.
- The BASE tests wait after EndBaseInstall.
- The chunkstore source-host fixtures (including the catalog fork test)
attach as fresh hosts, which is what a new empty volume is.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Recover republishes the dirty map but did not take captureMu, so it could
run inside a quiesced cut: after the cut's Sync fixed H and before its
copy, a same-open Recover could publish a newer complete record (H+1) and
the cut would copy those bytes into a HEAD labelled H. Recover now holds
captureMu shared (order captureMu -> lifecycleMu -> mu), as Write,
WriteBatch, ApplyEntry and WriteExtentDirect do; nothing calls Recover
under captureMu.
Control: a real partial batch pwrite leaves a complete record at H+1; the
cut parks right after its barrier Sync fixed H and starts a same-open
Recover, which waits for the barrier; HEAD at H holds no post-H bytes and
the next cut publishes the recovered bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Recover republishes the dirty map outside the write path: a partial batch
append can leave a complete newer record that same-open Recover publishes.
It only invalidated the WAL-sync coverage generation, so a chunk staged
before it could be reused over the recovered bytes. Recover now tells an
attached chunk layer, which counts a mutation of every chunk (O(chunks),
recovery only), also on a failed or partial scan, before s.mu is released
so no read sees recovered bytes first.
Control: stage chunk 0, then a real partial batch pwrite and same-open
Recover before the barrier: HEAD at the recovered H has the recovered
bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chunk's highest write LSN is not a change detector: a replica apply
may land a block at an LSN below another block of the same chunk, so the
maximum does not move and a stale stage could be reused. Each chunk now
has a mutation count, raised after every dirty-map insert (a write, a
batch write, a replica apply at any LSN) and every BASE block; flushing
moves bytes without changing them and never counts. It is an atomic
per-chunk counter on the write path (O(1), lock-free), sampled before the
staging read and compared at the barrier.
A barrier Sync failure after staging is a clean abort: the cut's staging
intents are deleted (a failed delete is kept and retried by the next cut).
Real-caller controls:
- chunk 0 holds a@10 and b@5; after the staging read, ApplyEntry(b, 6)
through the production apply path, in the WAL and flushed: HEAD at H
has b@6;
- staged uploads, then the local fsync fails at the barrier: no intent
is left; with the intent delete failing too, the intent is kept and the
next cut settles it and publishes the exact image.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ruling (B9 W3 bound): the dirty threshold, now the layer's BarrierBound,
bounds how many chunks a cut copies under its barrier; it never triggers
a cut.
- While more candidates than the bound would be copied, the cut stages up
to the bound per round outside the barrier: current bytes, compared to
HEAD, uploaded under fresh content keys named by an intent written
before the round's first upload.
- Each staged chunk records its version: the chunk's highest write LSN,
flushed or still in the WAL, taken before the read. Flushing never
changes it; any later write raises it, so a stale stage is never used.
- At the barrier a staged chunk stands for the copy only while its
version and HEAD are unchanged; the rest is copied, so the image at H
is exact.
- At most three staging rounds; then the barrier copies the rest
(correctness over pause), counts BarrierOverBound and reports the
barrier copy size (BarrierCopyChunks).
- Every intent of the cut (staging rounds and the barrier) is settled
with it: deleted after the confirmed CAS or a clean abort, kept with an
unresolved proposal. Superseded staged keys stay under their intent
until then.
- Snapshot, explicit Cut and Detach's final cut share the path.
The barrier copy and staging share one readChunk helper. The provider
passes ChunkDirtyThreshold (default 512) as the bound.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The remote holds snapshots, not live data. Cuts are published at Snapshot,
Detach/stop and explicit Cut, and automatically only by the operator's
timer (off by default). The dirty-chunk count no longer triggers a cut:
the loop runs only with a timer, and the policy has no threshold trigger.
A successful cut of any kind observed after a failed automatic cut makes
that failure's backoff obsolete, so an explicit success followed by the
timer is no longer suppressed until the old retry time. A success older
than the failure leaves the backoff in force.
A fenced layer can never publish again: its loop ends instead of retrying
refused cuts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The remote holds snapshots, not live data: cuts are published at
snapshots, at detach/stop and on explicit request. The periodic timer is
now off by default (operators may set one, e.g. 15m, as a host-loss
safety net) and the dirty threshold is 512 chunks (2 GiB at 4 MiB),
kept only as a bound on one cut's size. Success resets, failure backoff,
no cut with nothing dirty and no cut while reconciling are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A walstore-chunk volume's VolumeStatus (/status/durable) gains a Chunk
section: Attached, AwaitingAuthority, Fenced, RemoteLSN and the layer's
Stats (cut counters, the last cut's stats, the dirty-chunk count).
Other implementations have no Chunk section.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The volume's automatic cuts follow the W3 ruling:
- Timer: a cut is due once ChunkCaptureInterval has passed since the
last successful cut of any kind; an explicit Cut, Snapshot or Detach
restarts it.
- Threshold: a cut is due once ChunkDirtyThreshold chunks are dirty
since the last HEAD. Whichever fires first triggers; zero disables
either.
- Automatic cuts are at least 1 s apart.
- A failed automatic cut resets nothing and is retried after a backoff
doubling from 1 s to 30 s.
- A successful cut, including a no-op one (no CAS), clears the backoff
and restarts the timer.
The decision is a pure policy (cutPolicy), tested with explicit times.
The provider loop polls the layer's Stats every 100 ms for the dirty
count and the last successful cut.
blockvolume defaults: --chunk-capture-interval=30s, and a new
--chunk-dirty-threshold=64 (256 MiB of 4 MiB chunks). The --chunk-*
flags stay refused with other implementations when set away from their
defaults.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every cut now fills its ChunkCutStats:
- barrier pause, sync and copy time;
- candidate, uploaded, zeroed and unchanged chunks, and uploaded bytes;
- upload time; CAS time and result (ok, precondition, unknown,
resolved-by-reread; empty for a no-op cut);
- total time.
The layer keeps cumulative counters, exposed by Stats():
- cuts ok, no-op and failed;
- refusals by reason (admission, fenced, detached);
- CAS conflicts, and unknown CAS outcomes left unresolved by the HEAD
re-read;
- whether a proposal is pending, and the current dirty-chunk count (the
C11 bitmap popcount, for the cut scheduler's threshold);
- the last successful cut's stats, LSN and time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* storage: capture-path intent schedules (RED)
A cut that uploads writes an intent naming exactly its keys before the
first upload and deletes its own intent after the confirmed CAS; no
upload, no intent; a failed intent write uploads nothing; a failed
upload or a refused CAS deletes the intent; an unknown CAS outcome keeps
it until the next cut settles the proposal; a lost CAS response
confirmed by re-read deletes it; a failed delete is retried at the next
cut; other intents are untouched. The fake remote gains intent failure
hooks and records written intents.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* storage: the capture path writes an intent before uploading and settles it
A cut that uploads chunks now writes one intent naming exactly the keys
it will upload, at the cut's base HEAD generation with the layer's epoch
and holder. The intent is durable before the first upload; if it cannot
be written, nothing is uploaded. A cut that only drops chunks writes
none.
The cut deletes only its own intent, once its outcome is settled:
- after the HEAD CAS succeeds, or a HEAD re-read confirms its proposal;
- on a clean abort: a failed upload, a refused admission, a fence, or a
HEAD that moved past the CAS's base.
An unknown CAS outcome keeps the intent with the pending proposal. The
next cut deletes it once that proposal is settled, whether it landed or
can never land. A failed delete never fails a settled cut; the next cut
retries it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A fresh host restoring an epoch-1 HEAD with an LSN-ordering observer
installed: at the takeover CAS the observer must already be rebased to the
seeded next LSN, and a refused post-seed rebase must fail the restore with
HEAD still owned by its previous holder and I/O refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SetWriteObserver published the observer first and only logged a refused
ship-LSN rebase, so the volume kept serving writes its observer would
mis-order.
Now:
- SetWriteObserver rebases an LSN-ordering observer to the store's next
LSN before installing it. If the rebase is refused, the observer is
not installed and the error is returned. The backend also records the
fault and refuses every I/O until an install succeeds, so a later
attach that marks the volume operational cannot reopen it. blockvolume
reports the error.
- The frontier seed and its observer rebase run in one critical section
with observer installs (observerMu). Whichever runs second sees the
other's result; a seed landing between an install's rebase and its
publication can no longer leave the observer on the old LSN. A refused
rebase after the seed records the same fault.
- RebaseShipLSN documents that it moves only the ordering cursor:
entries already dispatched to peer queues carry lower LSNs and are
untouched.
The composition test checks the install error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An observer whose RebaseShipLSN is refused at install must not be
published with I/O left open: the next write must be refused. A later
install whose rebase succeeds reopens I/O.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A ReplicationVolume orders writes from the store's next LSN, captured
when it is built. On a restored walstore-chunk host the frontier seed
moves that LSN to HEAD.remote_lsn+1 later, during the deferred attach.
The resequencer then waited forever for the LSNs below it, and writes
and flushes hung.
Whoever moves the next LSN now tells every component that cached it:
- ReplicationVolume.RebaseShipLSN(lsn) moves the ship order forward. It
is refused while any write is pending or in flight, never dropping
one, and never moves backwards; an equal LSN is a no-op.
- The provider calls it through the backend's observer right after
SeedChunkFrontier, before the layer attaches and the volume serves
I/O.
- StorageBackend.SetWriteObserver rebases a newly installed observer
to the store's next LSN, covering a seed that landed before the
observer was installed (blockvolume installs it after
SetReplicationVolume, while the attach is still deferred).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fresh walstore-chunk host restoring from a remote HEAD, in the
production order of cmd/blockvolume, with the real RF=1
ReplicationVolume as the backend's write observer:
1. Recovery runs before the master's assignment is visible, so the
chunk layer attach is deferred.
2. blockvolume builds the ReplicationVolume, which captures the store's
next LSN.
3. The replayed assignment lets the deferred attach claim HEAD and seed
the frontier to HEAD.remote_lsn.
4. A frontend write and flush then wait forever for LSNs below the
seeded frontier to be shipped.
The control differs only in having no remote HEAD, so nothing is
seeded; it writes and flushes fine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the attempt-scoped layout (one rule for both P1s: the decision
comes from ONE read of the entry acted on, and success from re-reading the
entry the operation tried to create):
- EnsureVolume decides a fork's attach from one HEAD read: absent and
aborted both refuse (fork_incomplete), so a sweep between two reads can
no longer pass an aborted HEAD.
- Fork decides from the HEAD it re-reads after its create: a real HEAD
completes the fork; an aborted tombstone means the fork lost to a sweep
(target_exists, its intent dropped, the tombstone is permanent); an
unreadable HEAD after a refusal is retryable, never a replay.
- A snapshot completes from its own attempt entry, never by resolving the
reusable name again; a snapshot tombstone carries no attempt stamp, so it
is never taken for this attempt's create.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
W5 ruling (2026-11-15 17:30Z), W2 part: a GC sweep settles a dead copy
attempt by claiming the operation's final publishing entry with an aborted
tombstone, and every attempt publishes to a target that is never freed.
- Snapshot: the name is taken by an exclusive name record
snapnames/<name> {request, attempt}; the intent names the attempt
(holder "snapshot:<vol>/<name>/<attempt>"); the snapshot is published by
an exclusive create at snaps/<name>/<attempt>. A retry of the same
request publishes to the same attempt path. List and Fork resolve names
through the record and skip aborted or unpublished attempts.
DeleteSnapshot marks the attempt deleting (or claims an unpublished
attempt's path with a tombstone) and removes the name record, freeing
the name; attempt paths are never removed, so a late insert always
fails. Catalog.AbortSnapshot(vol, name, attempt) is the sweep's claim.
- Fork: the publishing entry is the target's HEAD. Catalog.AbortFork
claims it with an aborted HEAD tombstone (state "aborted", gen 1, no
chunks); a fork whose HEAD is a tombstone never attaches
(fork_incomplete) and its replay is target_exists.
- The copy-intent deadline stays as metadata only.
A deleted snapshot no longer holds its name: it is no longer listed (even
with includeDeleting) and a fork of its name is snapshot_not_found; its
attempt entry stays for GC.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cut that uploads chunks now writes one intent naming exactly the keys
it will upload, at the cut's base HEAD generation with the layer's epoch
and holder. The intent is durable before the first upload; if it cannot
be written, nothing is uploaded. A cut that only drops chunks writes
none.
The cut deletes only its own intent, once its outcome is settled:
- after the HEAD CAS succeeds, or a HEAD re-read confirms its proposal;
- on a clean abort: a failed upload, a refused admission, a fence, or a
HEAD that moved past the CAS's base.
An unknown CAS outcome keeps the intent with the pending proposal. The
next cut deletes it once that proposal is settled, whether it landed or
can never land. A failed delete never fails a settled cut; the next cut
retries it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cut that uploads writes an intent naming exactly its keys before the
first upload and deletes its own intent after the confirmed CAS; no
upload, no intent; a failed intent write uploads nothing; a failed
upload or a refused CAS deletes the intent; an unknown CAS outcome keeps
it until the next cut settles the proposal; a lost CAS response
confirmed by re-read deletes it; a failed delete is retried at the next
cut; other intents are untouched. The fake remote gains intent failure
hooks and records written intents.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
W5 ruling (2026-11-15 17:06Z), W2 part: a snapshot or fork copy intent
records its absolute publication deadline (DeadlineNs: the read time plus
OpDeadline); the deadline is re-checked immediately before the publishing
exclusive create, and that create runs under a context bounded by the same
deadline, so it never publishes after it. GC may then expire a copy intent
by its recorded deadline (plus RPC timeout and grace) instead of by epoch.
The re-read that settles an ambiguous create keeps the caller's context.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>