blockvolume: a runtime HEAD fence exits 78 head_fenced; serve only while the lease is held

A chunk layer that fences after startup (HEAD has another publication
owner) while the lease is still valid now latches the backend not
operational with that evidence, and the process owner chooses the
no-restart exit 78 head_fenced through processExit.choose. I/O is refused
from the fence itself.

The first-grant log line is written only for a reply that grants: a first
reply that revokes fences the guard and logs no grant.

The frontend-gate tests own their workers: cleanup is registered before
each worker starts and every receive is bounded.

docs/design/invariants.md: INV-WS-SERVE-LEASE-HELD-001 (V1-SPEC r2.37);
INV-FE-PRIMARY-READY-OPERATIONAL-001 statement within 300 characters, with
the runtime fence enforcement and tests; M1 diagram and table carry the
lease-held order and the runtime fence exit; C.W names the runVolume
receive of the stop waiter's result. 306 rows, 220 ACTIVE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-22 07:14:02 -08:00
1 parent 1b675b39d0
commit 22a540d34d
11 files changed
+329 -37

No files matched your search

@@ -11,13 +11,47 @@ type gateResult struct {
start bool
}
func runGate(serving <-chan struct{}, stopWait <-chan workspaceStopWait) <-chan gateResult {
// gateWait bounds every receive of a gate result in these tests.
const gateWait = 5 * time.Second
// runGate runs awaitFrontendStart on serving and a stop channel it owns
// (buffered, returned for the test to send on). Its cleanup, registered
// before the worker starts, releases a gate that is still waiting with a
// stop and joins the worker within gateWait, so a failing check never
// strands it.
func runGate(t *testing.T, serving <-chan struct{}) (<-chan gateResult, chan<- workspaceStopWait) {
t.Helper()
out := make(chan gateResult, 1)
stopWait := make(chan workspaceStopWait, 1)
exited := make(chan struct{})
t.Cleanup(func() {
select {
case stopWait <- workspaceStopWait{}:
default:
}
select {
case <-exited:
case <-time.After(gateWait):
t.Errorf("the gate worker did not exit within %s of a stop", gateWait)
}
})
go func() {
defer close(exited)
s, ok := awaitFrontendStart(serving, stopWait)
out <- gateResult{s, ok}
}()
return out
return out, stopWait
}
func receiveGate(t *testing.T, res <-chan gateResult, what string) gateResult {
t.Helper()
select {
case r := <-res:
return r
case <-time.After(gateWait):
t.Fatalf("%s: the gate did not return within %s", what, gateWait)
return gateResult{}
}
}
// INV-FE-PRIMARY-READY-OPERATIONAL-001: the frontends start only once the
@@ -26,26 +60,17 @@ func runGate(serving <-chan struct{}, stopWait <-chan workspaceStopWait) <-chan
// admits no I/O (a chunk volume before its storage claim), the gate never
// releases; it releases as soon as the backend's first-serving channel closes.
func TestFrontendGateWaitsForTheStorageClaim(t *testing.T) {
for name, serving := range map[string]chan struct{}{"no durable backend": nil, "already serving": make(chan struct{})} {
if serving != nil {
close(serving)
}
var ch <-chan struct{}
if serving != nil {
ch = serving
}
select {
case r := <-runGate(ch, make(chan workspaceStopWait)):
if !r.start || r.stopped != nil {
t.Fatalf("%s: %+v, want the frontends started at once", name, r)
}
case <-time.After(time.Second):
t.Fatalf("%s: the gate did not release at once", name)
served := make(chan struct{})
close(served)
for name, ch := range map[string]<-chan struct{}{"no durable backend": nil, "already serving": served} {
res, _ := runGate(t, ch)
if r := receiveGate(t, res, name); !r.start || r.stopped != nil {
t.Fatalf("%s: %+v, want the frontends started at once", name, r)
}
}
serving := make(chan struct{})
res := runGate(serving, make(chan workspaceStopWait))
res, _ := runGate(t, serving)
for i := 0; i < 30; i++ { // 300 ms of samples while the claim is pending
select {
case r := <-res:
@@ -54,13 +79,8 @@ func TestFrontendGateWaitsForTheStorageClaim(t *testing.T) {
}
}
close(serving) // the storage claim succeeded
select {
case r := <-res:
if !r.start {
t.Fatalf("after the claim: %+v, want the frontends started", r)
}
case <-time.After(time.Second):
t.Fatal("the gate did not release after the backend admitted I/O")
if r := receiveGate(t, res, "after the claim"); !r.start {
t.Fatalf("after the claim: %+v, want the frontends started", r)
}
}
@@ -69,8 +89,7 @@ func TestFrontendGateWaitsForTheStorageClaim(t *testing.T) {
// latched exit 75/78) and no frontend starts: the stop is handed back for
// the ordinary shutdown, its lease drain request included.
func TestFrontendGateStopsWithoutStartingTheFrontends(t *testing.T) {
stopWait := make(chan workspaceStopWait, 1)
res := runGate(make(chan struct{}), stopWait) // fenced: never serves
res, stopWait := runGate(t, make(chan struct{})) // fenced: never serves
select {
case r := <-res:
t.Fatalf("a backend that never serves released the gate: %+v", r)
@@ -78,8 +97,7 @@ func TestFrontendGateStopsWithoutStartingTheFrontends(t *testing.T) {
}
req := &workspaceStopRequest{ctx: context.Background()}
stopWait <- workspaceStopWait{leaseStop: req}
r := <-res
if r.start || r.stopped == nil || r.stopped.leaseStop != req {
if r := receiveGate(t, res, "stop before serving"); r.start || r.stopped == nil || r.stopped.leaseStop != req {
t.Fatalf("stop before serving: %+v, want no frontends and the lease drain request handed back", r)
}
}
+1
View File
@@ -724,6 +724,7 @@ func runVolume(f flags, exits *processExit) int {
watchCtx, stopWatch := context.WithCancel(exits.parent)
defer stopWatch()
go watchChunkStartup(watchCtx, exits, f, h, dp)
go watchChunkRuntimeFence(watchCtx, exits, f, dp)
provider = dp
if status != nil {
status.SetDurableStatusSource(dp)
@@ -149,6 +149,35 @@ func watchChunkStartup(ctx context.Context, e *processExit, f flags, h *volume.H
}
}
// chunkRuntimeFenceProvider reports a runtime HEAD fence of the attached layer.
type chunkRuntimeFenceProvider interface {
ChunkRuntimeFenced(string) bool
ChunkRuntimeFenceUpdates() <-chan struct{}
}
// watchChunkRuntimeFence: a HEAD fence after startup, while the lease may
// still be valid, ends the process with no restart (78 head_fenced): another
// holder owns HEAD (INV-FE-PRIMARY-READY-OPERATIONAL-001). Workspace chunk
// primaries only.
func watchChunkRuntimeFence(ctx context.Context, e *processExit, f flags, p chunkRuntimeFenceProvider) {
if !f.workspaceLease || f.durableImpl != "walstore-chunk" {
return
}
for {
if p.ChunkRuntimeFenced(f.volumeID) {
e.choose(workspaceExit{exitWorkspaceSuperseded, "head_fenced"})
return
}
select {
case <-ctx.Done():
return
case <-e.done:
return
case <-p.ChunkRuntimeFenceUpdates():
}
}
}
// M2 process exit / Revoking -> Revoked; INV-WS-STARTUP-RETRY-001.
func waitWorkspaceStop(e *processExit, f flags, h *volume.Host, requests <-chan workspaceStopRequest, done <-chan error) (*workspaceStopRequest, <-chan error) {
select {
@@ -0,0 +1,54 @@
package main
import (
"context"
"sync/atomic"
"testing"
"time"
)
type runtimeFenceStub struct {
fenced atomic.Bool
updates chan struct{}
}
func (s *runtimeFenceStub) ChunkRuntimeFenced(string) bool { return s.fenced.Load() }
func (s *runtimeFenceStub) ChunkRuntimeFenceUpdates() <-chan struct{} { return s.updates }
// INV-FE-PRIMARY-READY-OPERATIONAL-001 (condition A): a runtime HEAD fence of
// a workspace chunk primary chooses the no-restart exit 78 head_fenced through
// the process owner's one chooser; nothing is chosen while not fenced, and a
// non-workspace volume never watches.
func TestRuntimeHeadFenceChoosesHeadFencedExit(t *testing.T) {
f := flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v1"}
e := newProcessExit(context.Background())
stub := &runtimeFenceStub{updates: make(chan struct{}, 1)}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
done := make(chan struct{})
go func() { watchChunkRuntimeFence(ctx, e, f, stub); close(done) }()
select {
case out := <-e.decision:
t.Fatalf("an exit was chosen while not fenced: %+v", out)
case <-time.After(100 * time.Millisecond):
}
stub.fenced.Store(true)
stub.updates <- struct{}{}
select {
case out := <-e.decision:
if out != (workspaceExit{exitWorkspaceSuperseded, "head_fenced"}) {
t.Fatalf("exit %+v, want 78 head_fenced", out)
}
case <-time.After(5 * time.Second):
t.Fatal("no exit chosen after the runtime fence")
}
<-done
plain := newProcessExit(context.Background())
watchChunkRuntimeFence(ctx, plain, flags{volumeID: "v1"}, stub) // returns at once: not a workspace chunk primary
select {
case out := <-plain.decision:
t.Fatalf("a non-workspace volume chose %+v", out)
default:
}
}
@@ -238,6 +238,7 @@ type DurableProvider struct {
opening map[string]*sync.Mutex // keyed by volumeID; serializes open/create
closed bool
startupUpdates chan struct{} // wake only; the generation-bound result stays on the handle
fenceUpdates chan struct{} // wake only; runtimeFenced stays on the handle
// testAfterChunkResolve, test-only, runs in CutVolume right after the
// volume's handle and layer are resolved.
@@ -289,6 +290,7 @@ type volHandle struct {
waitGen uint64
startupSuperseded bool // exact foreign-holder claim proof for startupEnded; guarded by p.mu
startupEnded uint64 // recovery generation with a terminal startup outcome; guarded by p.mu
runtimeFenced bool // the attached layer fenced after startup (HEAD has another owner); guarded by p.mu
chunk storage.ChunkLayer // after RecoverVolume
chunkLineage chunkLineage // immutable authority captured by this attachment
// Private until the owner commit succeeds; retained for attach retry.
@@ -402,6 +404,7 @@ func NewDurableProvider(cfg ProviderConfig, view frontend.ProjectionView) (*Dura
closeCtx: closeCtx,
closeCancel: closeCancel,
startupUpdates: make(chan struct{}, 1),
fenceUpdates: make(chan struct{}, 1),
}, nil
}
@@ -336,6 +336,7 @@ func (p *DurableProvider) attachChunk(ctx context.Context, volumeID string, h *v
h.backend.chunkFenced = layer.Fenced
h.backend.mu.Unlock()
p.startChunkLoop(volumeID, h, layer)
go p.watchChunkFence(volumeID, h, layer)
}
return nil
}
@@ -1,6 +1,11 @@
package durable
import "errors"
import (
"errors"
"time"
"github.com/seaweedfs/seaweed-block/core/storage"
)
// ChunkStartupUpdates wakes the process owner when a startup wait ends. It is
// not an event queue: the owner must read ChunkStartupOutcome for its volume.
@@ -57,3 +62,59 @@ func (p *DurableProvider) ChooseChunkStartupExit(volumeID string, gen uint64, ch
choose()
return true
}
// chunkFenceWatchInterval bounds how long after a runtime fence the backend
// reports not operational and the process owner is woken. I/O is refused
// from the fence itself (readyCheck reads the layer's latched flag).
const chunkFenceWatchInterval = 50 * time.Millisecond
// watchChunkFence waits for the attached layer to fence after startup (its
// publication found HEAD owned by another holder or epoch: the layer latches
// fenced only on supersede or owner change, never on a clean detach), then
// latches the backend not operational with that evidence and marks the
// volume runtime-fenced (INV-FE-PRIMARY-READY-OPERATIONAL-001). It ends when
// the provider closes or the layer is no longer this volume's.
func (p *DurableProvider) watchChunkFence(volumeID string, h *volHandle, layer storage.ChunkLayer) {
t := time.NewTicker(chunkFenceWatchInterval)
defer t.Stop()
for {
select {
case <-p.closeCtx.Done():
return
case <-t.C:
}
p.mu.Lock()
current := !p.closed && p.volumes[volumeID] == h && h.chunk == layer
p.mu.Unlock()
if !current {
return
}
if !layer.Fenced() {
continue
}
h.backend.SetOperational(false, "chunk layer fenced after startup: HEAD has another publication owner")
p.mu.Lock()
if !p.closed && p.volumes[volumeID] == h && h.chunk == layer {
h.runtimeFenced = true
select {
case p.fenceUpdates <- struct{}{}:
default:
}
}
p.mu.Unlock()
return
}
}
// ChunkRuntimeFenceUpdates wakes the process owner when a volume's attached
// layer fenced after startup; read ChunkRuntimeFenced for the volume.
func (p *DurableProvider) ChunkRuntimeFenceUpdates() <-chan struct{} { return p.fenceUpdates }
// ChunkRuntimeFenced reports a latched runtime fence of the volume's
// attached layer (HEAD has another publication owner).
func (p *DurableProvider) ChunkRuntimeFenced(volumeID string) bool {
p.mu.Lock()
defer p.mu.Unlock()
h := p.volumes[volumeID]
return !p.closed && h != nil && h.runtimeFenced
}
@@ -0,0 +1,89 @@
package durable_test
import (
"context"
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
"github.com/seaweedfs/seaweed-block/core/storage"
)
// INV-FE-PRIMARY-READY-OPERATIONAL-001 (condition A): a HEAD fence after
// startup, while the lease would still be valid, refuses I/O from the fence,
// latches the backend not operational with its evidence and marks the volume
// runtime-fenced with a wakeup, so the process owner chooses the no-restart
// exit. Another holder claims HEAD at a newer epoch, or at the same epoch
// under another holder string; this holder's next publication fences.
func TestWALStoreChunk_RuntimeHeadFenceLatchesNotOperational(t *testing.T) {
for _, tc := range []struct {
name string
epoch func(uint64) uint64
holder string
}{
{"newer epoch", func(e uint64) uint64 { return e + 1 }, "s2/r1"},
{"same epoch, other holder", func(e uint64) uint64 { return e }, "s2/r1"},
} {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
remote := storage.NewMemChunkRemote()
p := chunkProvider(t, t.TempDir(), remote, v1View(), 0)
s := openRecovered(t, p)
if _, err := s.Write(1, block(1)); err != nil {
t.Fatal(err)
}
if _, err := p.CaptureVolume(ctx, "v1"); err != nil {
t.Fatal(err)
}
if p.ChunkRuntimeFenced("v1") {
t.Fatal("runtime-fenced while serving")
}
backend, err := p.Open(ctx, "v1")
if err != nil {
t.Fatal(err)
}
head, err := remote.GetHead(ctx)
if err != nil {
t.Fatal(err)
}
next := head
next.Epoch, next.Holder = tc.epoch(head.Epoch), tc.holder
if _, err := remote.CASHead(ctx, storage.ChunkHeadVersion{Gen: head.Gen, Epoch: head.Epoch}, next); err != nil {
t.Fatal(err)
}
if _, err := s.Write(2, block(2)); err != nil {
t.Fatal(err)
}
if _, err := p.CaptureVolume(ctx, "v1"); err == nil {
t.Fatal("a capture over another holder's HEAD succeeded")
}
// From the fence on, no I/O is admitted (before the watcher runs).
if n, err := backend.Write(ctx, 3*4096, block(3)); err == nil || n != 0 {
t.Fatalf("a write after the fence: n=%d err=%v, want refused", n, err)
}
select {
case <-p.ChunkRuntimeFenceUpdates():
case <-time.After(5 * time.Second):
t.Fatal("no runtime-fence wakeup within the cleanup bound")
}
if !p.ChunkRuntimeFenced("v1") {
t.Fatal("woken but not runtime-fenced")
}
var st *durable.VolumeStatus
for _, v := range p.DurableStatuses() {
if v.VolumeID == "v1" {
v := v
st = &v
}
}
if st == nil || st.Operational || st.Evidence != "chunk layer fenced after startup: HEAD has another publication owner" {
t.Fatalf("durable status after a runtime fence: %+v, want not operational with the fence evidence", st)
}
if _, err := backend.Write(ctx, 3*4096, block(3)); err == nil {
t.Fatal("a write after the runtime fence was admitted")
}
})
}
}
@@ -265,10 +265,11 @@ func (g *WorkspaceLeaseGuard) Refresh(ctx context.Context) error {
}
closed := g.fenced
g.mu.Unlock()
if firstGrant {
if firstGrant && !closed {
// Once per guard: the first grant, or the re-grant after refused
// renewals (a restart before the forced-move barrier); unix_ms is the
// request start, which the lease validity is anchored to.
// request start, which the lease validity is anchored to. A first
// reply that revokes (or arrives fenced) grants nothing: no line.
what := "granted"
if refused > 0 {
what = fmt.Sprintf("re-granted after %d refused renewal(s)", refused)
@@ -59,6 +59,37 @@ func TestWorkspaceLeaseGrantIsLoggedOnceAfterRefusedRenewals(t *testing.T) {
}
}
// A first reply that revokes grants nothing: after refused renewals, a valid
// first reply with Revoking set fences the guard, is never held and logs no
// grant line (the line is a readiness timing witness).
func TestWorkspaceLeaseFirstRevokingReplyIsNotLoggedAsAGrant(t *testing.T) {
logs := captureLog(t)
now := time.Unix(1000, 0)
calls := 0
client := workspaceTestClient{
renew: func() (*control.WorkspaceLeaseFact, error) {
calls++
if calls == 1 {
return nil, errors.New("workspace forced move lease expiry plus clock-skew margin has not elapsed")
}
return &control.WorkspaceLeaseFact{VolumeId: "v", ReplicaId: "r", Epoch: 1, ValidForNs: int64(10 * time.Second), Revoking: true}, nil
},
ack: func() error { return nil },
}
g, err := NewWorkspaceLeaseGuard(workspaceTestView{}, client, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r", Epoch: 1}, func(context.Context) (uint64, error) { return 7, nil }, func() time.Time { return now })
if err != nil {
t.Fatal(err)
}
_ = g.Refresh(context.Background())
_ = g.Refresh(context.Background())
if g.Held() || g.Projection().Healthy {
t.Fatal("a revoking first reply left the lease held")
}
if out := logs.String(); strings.Contains(out, "granted") || !strings.Contains(out, "revoked by the master") {
t.Fatalf("want no grant line and the revocation fence; log=%q", out)
}
}
// V1-SPEC r2.37: a workspace primary reports NotReadyReason=lease_not_held,
// first, while its guard is missing or holds no granted lease, even with the
// backend admitting I/O; ready once the lease is held; lease_not_held again
+9 -5
View File
@@ -46,7 +46,8 @@ The local storage engine and the durable backend in front of it. Diagrams in the
stateDiagram-v2
[*] --> Opened: OpenWALStore / CreateWALStore
Opened --> Recovering: RecoverVolume
Recovering --> Serving: Recover ok, backend operational
Recovering --> Serving: Recover ok, backend operational; workspace primary: lease held, then HEAD claim, then frontends listen, then ready
Serving --> Closed: runtime HEAD fence, exit 78 head_fenced
Recovering --> RecoveryFailed: Recover error (typed reason)
Serving --> Serving: map prepare refused (prior root released, no latch, retry)
Serving --> FaultLatched: fsync or WAL append fails
@@ -60,13 +61,14 @@ stateDiagram-v2
|---|---|---|---|---|
| — | Opened | v3 A/B descriptors and owned-map dependencies valid, exclusive file ownership acquired; legacy formats refused; backend starts not operational | `core/storage/walstore.go` `OpenWALStoreWithOptions`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-WAL-OPGATE-001`, `INV-WAL-V3-ACTIVATION-001`, `INV-WAL-V3-DESCRIPTOR-001`, `INV-WAL-V3-MAP-PUBLISH-001` |
| Opened | Recovering | the volume is open in the provider | `core/frontend/durable/provider.go` `RecoverVolume` | `INV-WAL-OPGATE-001` |
| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end; the frontend targets start, and `FrontendPrimaryReady` is reported, only once the backend admits I/O (a chunk volume: after its storage claim; attach-pending or fenced reports not ready with the reason) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `core/host/volume/status_server.go` `statusProjection` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001`, `INV-WAL-V3-W-RECOVERY-001`, `INV-WAL-V3-FENCE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001` |
| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end; the frontend targets start, and `FrontendPrimaryReady` is reported, only once the backend admits I/O (a chunk volume: after its storage claim; attach-pending or fenced reports not ready with the reason); a workspace primary claims HEAD, listens and reports ready only while its lease guard permits now (`WorkspaceLeaseGuard.Held`; without a grant: `NotReadyReason=lease_not_held`, exit 75 after the start-time wait) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `core/host/volume/status_server.go` `statusProjection`; `core/host/volume/workspace_lease.go` `Held` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001`, `INV-WAL-V3-W-RECOVERY-001`, `INV-WAL-V3-FENCE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001` |
| Recovering | RecoveryFailed | a WAL integrity failure or an I/O error; the backend stays not operational and the host blocks local readiness with `wal_corrupt` or `io_error` | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `INV-WAL-TYPED-FAILCLOSED-001`, `INV-WAL-OPGATE-001`, `INV-WAL-V3-W-RECOVERY-001` |
| Serving | Serving | each `Read`, `Write`, `Sync` passes the operational, chunk-fence and lineage checks; write admission samples the active writer's native pressure before waiting; a write is durable only when a covering `Sync` returns | `core/frontend/durable/storage_adapter.go` `gate`; `core/storage/walstore.go` `WALStore.Sync` | `INV-FE-LINEAGE-GATE-001`, `INV-WAL-SYNC-FRONTIER-001`, `INV-FE-FUA-SYNC-001`, `INV-FE-FLUSH-SYNC-001`, `INV-WAL-V3-ADMISSION-001`, `INV-WAL-V3-W-001` |
| Serving | Serving (checkpoint) | the flusher binds its snapshot/materialization to one recovery lifetime; extent and owned COW map are durable before the shared descriptor publisher advances checkpoint/tail; both slot tails pin reuse | `core/storage/flusher.go` `flushOnceInternal`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `INV-WAL-CHECKPOINT-SNAPSHOT-001`, `INV-WAL-REUSE-PERSISTED-TAIL-001`, `INV-WAL-CKPT-META-FAIL-001`, `INV-CUT-BITMAP-001`, `INV-WAL-FLUSH-SYNC-COVERS-WAL-001`, `INV-WAL-V3-RECLAIM-001`, `INV-WAL-V3-PUBLISH-NONCE-FLOOR-001`, `INV-WAL-V3-MAP-PRIOR-LIVE-001` |
| Serving | Serving (map prepare refused) | a map preparer (the flusher's checkpoint, the chunk layer's captured-map publication, BASE complete) captured prior and a publication released it before the prepare's live-set snapshot: the prepare reuses no page, writes nothing, refuses with `prior_released` without latching, counts it, and the caller's next cycle prepares from the current root | `core/storage/chunk_lsn_map_v3.go` `prepareLockedV3`; `core/storage/chunk_map_extents_v3.go` `liveSnapshotWithPriorV3` | `INV-WAL-V3-MAP-PRIOR-LIVE-001` |
| Serving | FaultLatched | the first failed `fsync` of the store file, or a WAL append whose write failed | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`; `core/storage/walstore_v3.go` `appendWriteV3` | `INV-WAL-FSYNC-STICKY-001`, `INV-WAL-APPEND-STICKY-001` |
| FaultLatched | FaultLatched | every later `Sync`, write, checkpoint and `Recover` on the same open store is refused | `core/storage/walstore.go` `stickyIOFault` | `INV-WAL-FSYNC-STICKY-001` |
| Serving | Closed (process exit 78 `head_fenced`) | workspace chunk primary: the attached layer fenced after startup (HEAD has another publication owner); I/O is refused from the fence, the backend latches not operational with the evidence, and the process owner chooses the no-restart exit | `core/frontend/durable/provider_startup.go` `watchChunkFence`; `cmd/blockvolume/process_exit.go` `watchChunkRuntimeFence` | `INV-FE-PRIMARY-READY-OPERATIONAL-001` |
| any | Closed | `Close`; a store with a latched fault does not write the final superblock | `core/storage/walstore.go` `WALStore.Close` | — |
The v2 writer, scanner, checkpoint path, C11 codec/reconciler and in-place converter are retired. Native map and descriptor rules remain enforced; v2 inputs refuse open without mutation. `TestNativeReplacementLegacyBytesRefusedWithoutMutation` and `TestChunkAttachRefusesAnUnmappedNativeStore` cover these admission boundaries. The receiver session bitmap is separate and unchanged.
@@ -447,7 +449,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO
## Part B. Invariant ledger
310 rows: 239 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 295 new.
311 rows: 240 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 296 new.
The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger.
@@ -461,7 +463,8 @@ The "Machine / transition" column refers to Part A. Notes under a table record w
| `INV-FE-NVME-READY-001` | A read or write on a successfully recovered chunk volume awaiting attachment waits for attachment readiness, before storage admission, for at most 3 s or until an earlier caller deadline, on the local monotonic clock. | M1 Opened / Recovering → Serving | `core/frontend/durable/storage_adapter.go` `admitAfterAttachUnqueued`, `awaitAttachAdmission`, `readyCheck` | `TestWALStoreChunk_PendingReadWaitIsBounded`; `TestWALStoreChunk_PendingReadHonoursEarlierDeadline`; `TestWALStoreChunk_TakeoverWriteWaitsForAttach`; `TestReadReadinessWaitDoesNotHoldAdmissionAndCloseWakesIt` (`core/frontend/durable/read_ready_wait_test.go`) | — | ACTIVE |
| `INV-FE-NVME-READY-STATUS-001` | An NVMe read or write whose attachment-readiness wait times out or is refused completes with Namespace Not Ready (SC 0x82), DNR=0, without reading or mutating storage. | M1 Opened / Recovering → Serving | `core/frontend/durable/storage_adapter.go` `attachReadyTimeout`; `core/frontend/nvme/io.go` `mapBackendError` | `TestWALStoreChunk_TakeoverReadBeforeAttachIsRetryable`; `TestSessionReadNotReadyIsRetryable` (`core/frontend/nvme/read_ready_retry_test.go`); `TestWALStoreChunk_PendingAttachBeyondHostRetryBudget` (`core/frontend/durable/takeover_read_ready_test.go`) | — | ACTIVE |
| `INV-FE-NVME-READY-ANA-001` | An I/O that ends during the attachment-readiness wait because the backend closed or its lineage went stale keeps its ANA error, and a physical I/O fault keeps Internal Error. | M1 Opened / Recovering → Serving | `core/frontend/durable/storage_adapter.go` `attachReadyTimeout`; `core/frontend/nvme/io.go` `mapBackendError` | `TestSessionReadNotReadyIsRetryable` (`core/frontend/nvme/read_ready_retry_test.go`); `TestReadReadinessWaitDoesNotHoldAdmissionAndCloseWakesIt` (`core/frontend/durable/read_ready_wait_test.go`) | — | ACTIVE |
| `INV-FE-PRIMARY-READY-OPERATIONAL-001` | FrontendPrimaryReady is reported only while the local durable backend admits I/O, and the frontend target starts listening only after it first does; attach-pending, fenced or no durable status reports not ready with the reason; a fence after the target listens ends the process within 5 s (`INV-WS-STARTUP-RETRY-001`). | M1 Opened / Recovering → Serving; M2 process exit | `core/host/volume/status_server.go` `statusProjection`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart` (the iSCSI, NVMe and ublk targets in `cmd/blockvolume/main.go` `runVolume` start after it); `cmd/blockvolume/process_exit.go` `waitWorkspaceStop` | `TestStatusServer_ReadyOnlyWhileBackendOperational`, `TestStatusServer_NotReadyAlwaysHasAReason` (`core/host/volume/status_server_test.go`); `TestFrontendGateWaitsForTheStorageClaim`, `TestFrontendGateStopsWithoutStartingTheFrontends` (`cmd/blockvolume/frontend_gate_test.go`); `TestDurableProvider_NonChunkVolumeServesRightAfterOpen` (`core/frontend/durable/first_serving_test.go`) | — | ACTIVE |
| `INV-FE-PRIMARY-READY-OPERATIONAL-001` | FrontendPrimaryReady is reported only while the local durable backend admits I/O, and the frontend target listens only after it first does; attach-pending, fenced or no durable status reports not ready with the reason; a fence after the target listens ends the process within 5 s. | M1 Opened / Recovering → Serving; M2 process exit | `core/host/volume/status_server.go` `statusProjection`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart` (the iSCSI, NVMe and ublk targets in `cmd/blockvolume/main.go` `runVolume` start after it); `cmd/blockvolume/process_exit.go` `waitWorkspaceStop`; a runtime HEAD fence: `core/frontend/durable/provider_startup.go` `watchChunkFence` (not operational with the evidence) and `cmd/blockvolume/process_exit.go` `watchChunkRuntimeFence` (exit 78 `head_fenced`) | `TestStatusServer_ReadyOnlyWhileBackendOperational`, `TestStatusServer_NotReadyAlwaysHasAReason` (`core/host/volume/status_server_test.go`); `TestFrontendGateWaitsForTheStorageClaim`, `TestFrontendGateStopsWithoutStartingTheFrontends` (`cmd/blockvolume/frontend_gate_test.go`); `TestDurableProvider_NonChunkVolumeServesRightAfterOpen` (`core/frontend/durable/first_serving_test.go`); `TestWALStoreChunk_RuntimeHeadFenceLatchesNotOperational` (`core/frontend/durable/runtime_fence_test.go`); `TestRuntimeHeadFenceChoosesHeadFencedExit` (`cmd/blockvolume/runtime_fence_exit_test.go`) | — | ACTIVE |
| `INV-WS-SERVE-LEASE-HELD-001` | A workspace primary claims HEAD, listens, reports ready and admits I/O only while its lease guard permits now; without a granted lease it holds at the gate and exits 75 after the start-time wait. | M1 Recovering → Serving; M2 process exit | `core/host/volume/workspace_lease.go` `WorkspaceLeaseGuard.Held` / `permits` (the one deciding function: the guarded projection gates the chunk claim, the per-I/O admit and `FrontendPrimaryReady`); `core/host/volume/status_server.go` `statusProjection` (`NotReadyReason=lease_not_held`); `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart` (frontends start after the claim); `cmd/blockvolume/process_exit.go` (exit 75 `assignment_timeout`) | `TestStatusServer_WorkspacePrimaryNotReadyWithoutHeldLease`, `TestWorkspaceLeaseGrantIsLoggedOnceAfterRefusedRenewals`, `TestWorkspaceLeaseFirstRevokingReplyIsNotLoggedAsAGrant` (`core/host/volume/workspace_lease_held_test.go`); real-binary cases B-late (restart before the forced-move barrier, re-granted inside the wait: no claim, listen or ready before the re-grant), B75 (no grant inside the wait: no claim, listen or ready, exit 75; a restart after the barrier serves) and B0 (restart inside the lease serves at once) | — | ACTIVE |
| `INV-WAL-REPLAY-LWW-001` | Replay of the validated native prefix retains the highest admitted LSN per LBA; invalid cursor, nonce or LSN order is refused. | M1 Recovering | `core/storage/dirty_map.go` `putAtIfNewer` | `TestWALLSNOrderV3_RefusesDuplicateAndLower` (`core/storage/wal_lsn_order_v3_test.go`) | `WALRecovery` `ReplayLastWriter` | ACTIVE |
| `INV-WAL-REUSE-PERSISTED-TAIL-001` | The WAL writer reuses only bytes that the both durable descriptor slots has already released. | M1 write lifecycle: Checkpointed → Reusable | `core/storage/wal_io_v3.go` `append`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `TestWALIOV3_FloorAndPwriteFailureRefuse` (`core/storage/wal_io_v3_test.go`); `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`) | `WALRecovery` `I1` | ACTIVE |
| `INV-WAL-CHECKPOINT-SNAPSHOT-001` | A checkpoint never passes a synced write that is not yet in the extent. | M1 write lifecycle: InExtent → Checkpointed | `core/storage/flusher.go` `flushOnceInternal` | `TestWALStoreV3_FlushMaterializationBoundToRecoveryLifetime` (`core/storage/walstore_map_recovery_lifetime_v3_test.go`); `TestNativeReplacementCheckpointSIGKILL` (`core/storage/legacy_checkpoint_replacement_v3_linux_test.go`) | `WALRecovery` `I1` | ACTIVE |
@@ -981,7 +984,8 @@ One row per wait in the data and control paths. Guest-visible rows on one path m
|---|---|---|---|---|---|---|
| `core/storage/chunk_publish_settled.go` `runPublishSettled` (from `unlockCap`, on the cut or detach caller's goroutine) | the `OnPublishSettled` hook to return | the hook's duration: the hook must return without blocking and without remote calls, enqueueing its work to its own worker | the hook implementer | none: a stalled hook stalls its caller, and later reports queue without a bound (a nil hook queues nothing) | none (`capMu` and `stMu` released) | yes on detach (the detach caller delivers before returning) |
| `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart` (from `runVolume`, before any frontend starts) | the backend's first admitted I/O (`StorageBackend.FirstServing`), or the process's stop waiter returning | none of its own: it ends on the stop waiter, which INV-WS-STARTUP-RETRY-001 bounds (a refused or timed-out claim latches exit 75/78) | `runVolume` (`INV-FE-PRIMARY-READY-OPERATIONAL-001`) | no frontend starts; shutdown as after the frontends | none | no (no target listens yet) |
| `cmd/blockvolume/process_exit.go` `waitWorkspaceStop` (one goroutine from `runVolume`, started with the workspace lease guard before the frontends) | a signal, the lease guard's drain request or end, or the latched startup outcome | the process lifetime | the process exit owner (`superviseProcess`, `INV-WS-STARTUP-RETRY-001`) | the chosen exit status (0 revoked/signal, 75 retry, 78 superseded) | none | no |
| `cmd/blockvolume/process_exit.go` `waitWorkspaceStop` (one goroutine from `runVolume`, started with the workspace lease guard before the frontends) | a signal, the lease guard's drain request or end, or the latched process outcome (startup, or a runtime HEAD fence) | the process lifetime | the process exit owner (`superviseProcess`, `INV-WS-STARTUP-RETRY-001`) | the chosen exit status (0 revoked/signal, 75 retry, 78 superseded or `head_fenced`) | none | no |
| `cmd/blockvolume/main.go` `runVolume`, the receive of `stopWait` after the frontends started (when `awaitFrontendStart` released on first serving) | the one result of the `waitWorkspaceStop` goroutine (its only producer, a 1-slot channel it sends to exactly once) | the process lifetime, as `waitWorkspaceStop` | the process exit owner (`superviseProcess`) | shutdown with the handed-back lease drain request | none | no (the targets serve until the stop) |
Format v3 row 4 runs in production recovery (`WALStore.recoverV3`). Its typed scan result preserves trusted records, absolute end, highest LSN, contiguous frontier, trusted DurableLSN and stop cause separately. The W/BASE/fence owner (`WALStore.recoverV3`) must check R < W*, fence and publish bounds before readiness or append admission; neither codec nor scan success is readiness. The installed scan begins at max(BaseCursor, retainedTail). No ACTIVE v2 machine/guard is replaced by this step.