From 3073d4e134b61f32f52bfd580278bfaeeb67cb1b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 21:56:02 -0800 Subject: [PATCH] storage, chunkstore: #324 fold: periodic cut reports through unlockCap; failure-safe joins and a causal Close witness; Begin and Finish refusal controls; ledger rows, wait-site row and hook contract docs Co-Authored-By: Claude Opus 5.5 --- .../frontend/chunkstore/share_guard_test.go | 40 ++++ .../core/frontend/durable/provider.go | 10 +- .../host/volume/chunk_control_order_test.go | 20 ++ seaweed-block/core/storage/chunk_layer.go | 6 + .../core/storage/chunk_periodic_cut.go | 2 +- .../core/storage/chunk_publish_settled.go | 8 + .../storage/chunk_publish_settled_test.go | 189 +++++++++++------- seaweed-block/core/storage/chunk_seam.go | 19 +- seaweed-block/docs/design/invariants.md | 13 +- 9 files changed, 225 insertions(+), 82 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/share_guard_test.go b/seaweed-block/core/frontend/chunkstore/share_guard_test.go index 42b839a9d1..a0f7661520 100644 --- a/seaweed-block/core/frontend/chunkstore/share_guard_test.go +++ b/seaweed-block/core/frontend/chunkstore/share_guard_test.go @@ -17,6 +17,7 @@ type recGuard struct { events []string n int finishErr error + beginErr error onFinish func() } @@ -25,6 +26,9 @@ func (g *recGuard) Begin(_ context.Context, vol string) (string, error) { defer g.mu.Unlock() g.n++ g.events = append(g.events, "begin:"+vol) + if g.beginErr != nil { + return "", g.beginErr + } return fmt.Sprintf("tok-%d", g.n), nil } @@ -161,4 +165,40 @@ func TestShareGuard_Fork(t *testing.T) { if countUnder(f, catBase+"/v3/HEAD") != 0 { t.Fatal("child HEAD written after a refused Finish") } + if n := countUnder(f, catBase+"/v3/intents/"); n != 0 { + t.Fatalf("%d intents left for the refused fork; want its new intent dropped", n) + } +} + +// A refused Begin stops the snapshot and the fork before anything is +// written: no Finish, no snapshot entry, no child HEAD, no intent left. +func TestShareGuard_BeginRefused(t *testing.T) { + f, _, c, h := catalogFixture(t) + ctx := context.Background() + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s0", RequestID: "r0"}, h); err != nil { + t.Fatal(err) + } + intents := countUnder(f, catBase+"/v1/intents/") + g := &recGuard{beginErr: errors.New("share refused")} + c.SetShareGuard(g) + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r"}, h); err == nil { + t.Fatal("snapshot after a refused Begin") + } + if n := countUnder(f, catBase+"/v1/snaps/s1/"); n != 0 { + t.Fatalf("%d snapshot entries after a refused Begin", n) + } + if n := countUnder(f, catBase+"/v1/intents/"); n != intents { + t.Fatalf("intents %d -> %d after a refused Begin", intents, n) + } + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s0", Target: "v4", RequestID: "fork-b"}); err == nil { + t.Fatal("fork after a refused Begin") + } + if countUnder(f, catBase+"/v4/HEAD") != 0 || countUnder(f, catBase+"/v4/intents/") != 0 { + t.Fatal("a fork refused at Begin wrote a child HEAD or an intent") + } + for _, e := range g.list() { + if strings.HasPrefix(e, "finish:") { + t.Fatalf("Finish after a refused Begin: %v", g.list()) + } + } } diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index af6a417c34..6d6e5c0b70 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -194,9 +194,13 @@ type ProviderConfig struct { OnChunkDetachResumed func(volumeID string, attempt uint64) // ChunkOnPublishSettled, optional, is called once per confirmed // publication of a chunk volume's HEAD, with the HEAD before and after it - // (storage.ChunkLayerConfig.OnPublishSettled). It runs on the publishing - // caller after the capture lock is released; ctx ends when the volume's - // layer closes. + // (storage.ChunkLayerConfig.OnPublishSettled): serialized, in publication + // order, outside the capture lock, by the volume's one registered drainer + // (whichever publishing caller is draining; a publisher may return before + // its own report is delivered). ctx ends when the volume's layer closes; + // after that no report is dequeued, though one already dequeued may still + // be delivered. It must return without blocking and without remote calls: + // enqueue work to your own worker (it is a guest-visible wait on detach). ChunkOnPublishSettled func(ctx context.Context, volumeID string, prev, next storage.ChunkHead) // ChunkDirtyThreshold is the number of candidate chunks above which // a cut pre-copies (stages) chunks before its barrier, in rounds of diff --git a/seaweed-block/core/host/volume/chunk_control_order_test.go b/seaweed-block/core/host/volume/chunk_control_order_test.go index 46d9c288fd..71a16b3e89 100644 --- a/seaweed-block/core/host/volume/chunk_control_order_test.go +++ b/seaweed-block/core/host/volume/chunk_control_order_test.go @@ -6,6 +6,7 @@ package volume import ( "context" + "errors" "testing" "github.com/seaweedfs/seaweed-block/core/frontend" @@ -102,10 +103,14 @@ type ownerGuard struct { cutsAtBegin []int finishes []string fp *fakeChunkProvider + beginErr error } func (g *ownerGuard) Begin(context.Context, string) (string, error) { g.cutsAtBegin = append(g.cutsAtBegin, g.fp.cuts) + if g.beginErr != nil { + return "", g.beginErr + } return "owner", nil } @@ -131,3 +136,18 @@ func TestChunkControl_SnapshotBeginsShareBeforeTheCut(t *testing.T) { t.Fatalf("finishes %v; want one Finish with the owner's token", g.finishes) } } + +// A refused Begin stops the owner's seal before its cut: no cut, no Finish, +// no snapshot. +func TestChunkControl_SnapshotBeginRefusedCutsNothing(t *testing.T) { + ctx := context.Background() + fp, ctl := adapterFixture(t) + g := &ownerGuard{fp: fp, beginErr: errors.New("share refused")} + ctl.(*chunkControl).cat.SetShareGuard(g) + if _, err := ctl.Snapshot(ctx, "v1", ChunkSnapshotRequest{Name: "s1", RequestID: "r"}); err == nil { + t.Fatal("snapshot after a refused Begin") + } + if fp.cuts != 0 || len(g.finishes) != 0 { + t.Fatalf("cuts %d finishes %v after a refused Begin; want none", fp.cuts, g.finishes) + } +} diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 6b87408ad3..ad4f45955a 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -1864,7 +1864,13 @@ func (l *chunkLayerImpl) Close() error { if w != nil { w.join() } + if h := testCloseJoinHook; h != nil { + h() // tests: Close has cancelled the layer and now joins its owners, the drainer among them + } l.wg.Wait() + if h := testCloseJoinedHook; h != nil { + h() // tests: the join returned + } l.stMu.Lock() protected := make(map[string]bool, len(l.pendingIntents)) for _, id := range l.pendingIntents { diff --git a/seaweed-block/core/storage/chunk_periodic_cut.go b/seaweed-block/core/storage/chunk_periodic_cut.go index 49822ee959..7803020e59 100644 --- a/seaweed-block/core/storage/chunk_periodic_cut.go +++ b/seaweed-block/core/storage/chunk_periodic_cut.go @@ -17,7 +17,7 @@ var _ ChunkPeriodicCutter = (*chunkLayerImpl)(nil) func (l *chunkLayerImpl) CutUnlessCutSince(ctx context.Context, lastCutNs int64) (chunkCutResult, bool, error) { l.capMu.Lock() - defer l.capMu.Unlock() + defer l.unlockCap() // delivers the cut's OnPublishSettled report after the lock l.stMu.Lock() last := l.stats.LastCutNs l.stMu.Unlock() diff --git a/seaweed-block/core/storage/chunk_publish_settled.go b/seaweed-block/core/storage/chunk_publish_settled.go index fe41e34512..2f2c0b905a 100644 --- a/seaweed-block/core/storage/chunk_publish_settled.go +++ b/seaweed-block/core/storage/chunk_publish_settled.go @@ -61,3 +61,11 @@ func (l *chunkLayerImpl) runPublishSettled() { hook(l.ctx, t.prev, t.next) } } + +// testCloseJoinHook, set only by tests, runs in Close after the layer is +// cancelled and before it joins its owners (the active drainer among them). +var testCloseJoinHook func() + +// testCloseJoinedHook, set only by tests, runs in Close when that join has +// returned. +var testCloseJoinedHook func() diff --git a/seaweed-block/core/storage/chunk_publish_settled_test.go b/seaweed-block/core/storage/chunk_publish_settled_test.go index 2e03073d42..51171e81e2 100644 --- a/seaweed-block/core/storage/chunk_publish_settled_test.go +++ b/seaweed-block/core/storage/chunk_publish_settled_test.go @@ -141,6 +141,58 @@ func waitClosed(t *testing.T, ch <-chan struct{}, what string) { } } +// worker is a goroutine a test launches. Its bounded join (after release, +// if given) is registered as cleanup before it starts, so a failing test +// never leaves it running; the result is read once and kept. +type worker struct { + name string + done chan error + once sync.Once + err error + ok bool +} + +func launch(t *testing.T, name string, release func(), f func() error) *worker { + t.Helper() + w := &worker{name: name, done: make(chan error, 1)} + t.Cleanup(func() { + if release != nil { + release() + } + if _, ok := w.result(10 * time.Second); !ok { + t.Errorf("%s never returned", name) + } + }) + go func() { w.done <- f() }() + return w +} + +// result waits up to d for the worker; ok is false on timeout. +func (w *worker) result(d time.Duration) (error, bool) { + w.once.Do(func() { + select { + case w.err = <-w.done: + w.ok = true + case <-time.After(d): + } + }) + if !w.ok { + w.once = sync.Once{} // a timed-out wait may be retried + } + return w.err, w.ok +} + +func (w *worker) mustReturn(t *testing.T) { + t.Helper() + err, ok := w.result(10 * time.Second) + if !ok { + t.Fatalf("%s did not return", w.name) + } + if err != nil { + t.Fatalf("%s: %v", w.name, err) + } +} + // Overlapping publishers: while the first report's hook is held, a second // publisher's cut completes and returns; its report is delivered after the // first, never concurrently with it. @@ -150,7 +202,7 @@ func TestChunkPublishSettled_OverlappingPublishersStayOrdered(t *testing.T) { layer := mustAttach(t, s, f, ctConfig(1)).(*chunkLayerImpl) entered, release := make(chan struct{}), make(chan struct{}) var once, rel sync.Once - t.Cleanup(func() { rel.Do(func() { close(release) }) }) + releaseHook := func() { rel.Do(func() { close(release) }) } var mu sync.Mutex var got [][2]uint64 active, maxActive := 0, 0 @@ -171,27 +223,14 @@ func TestChunkPublishSettled_OverlappingPublishersStayOrdered(t *testing.T) { } w := newWriteLog() w.write(t, s, 2, 0x22) - aDone := make(chan error, 1) - go func() { _, err := layer.Cut(context.Background()); aDone <- err }() - t.Cleanup(func() { - rel.Do(func() { close(release) }) - select { - case <-aDone: - case <-time.After(10 * time.Second): - t.Error("the first publisher never returned") - } - }) + a := launch(t, "the first publisher", releaseHook, func() error { _, err := layer.Cut(context.Background()); return err }) waitClosed(t, entered, "the first report") w.write(t, s, 9, 0x29) - bDone := make(chan error, 1) - go func() { _, err := layer.Cut(context.Background()); bDone <- err }() - select { - case err := <-bDone: - if err != nil { - t.Fatal(err) - } - case <-time.After(10 * time.Second): + b := launch(t, "the second publisher", releaseHook, func() error { _, err := layer.Cut(context.Background()); return err }) + if err, ok := b.result(10 * time.Second); !ok { t.Fatal("the second publisher waited on the first report's hook") + } else if err != nil { + t.Fatal(err) } mu.Lock() n := len(got) @@ -199,16 +238,8 @@ func TestChunkPublishSettled_OverlappingPublishersStayOrdered(t *testing.T) { if n != 1 { t.Fatalf("%d reports delivered while the first was held; want 1", n) } - rel.Do(func() { close(release) }) - select { - case err := <-aDone: - aDone <- err - if err != nil { - t.Fatal(err) - } - case <-time.After(10 * time.Second): - t.Fatal("the first publisher did not finish") - } + releaseHook() + a.mustReturn(t) mu.Lock() defer mu.Unlock() if len(got) != 2 || got[0] != [2]uint64{0, 1} || got[1] != [2]uint64{1, 2} || maxActive != 1 { @@ -217,14 +248,23 @@ func TestChunkPublishSettled_OverlappingPublishersStayOrdered(t *testing.T) { } // Close during the first of two queued reports: the first hook sees its -// context end, Close waits for it, and the second report is never delivered. +// context end, Close reaches its join of the active drainer and waits there +// (witnessed, not timed), and the second report is never delivered. func TestChunkPublishSettled_CloseDropsUnstartedReports(t *testing.T) { f := newFakeChunkRemote() s, _ := newChunkTestStore(t) layer := mustAttach(t, s, f, ctConfig(1)).(*chunkLayerImpl) entered, release := make(chan struct{}), make(chan struct{}) var rel sync.Once - t.Cleanup(func() { rel.Do(func() { close(release) }) }) + releaseHook := func() { rel.Do(func() { close(release) }) } + joining := make(chan struct{}) + var joinOnce sync.Once + var order []string // "hook returned" and "Close joined", in the order they happened + var orderMu sync.Mutex + note := func(e string) { orderMu.Lock(); order = append(order, e); orderMu.Unlock() } + testCloseJoinHook = func() { joinOnce.Do(func() { close(joining) }) } + testCloseJoinedHook = func() { note("Close joined") } + t.Cleanup(func() { testCloseJoinHook, testCloseJoinedHook = nil, nil }) var hookCtx context.Context var mu sync.Mutex calls := 0 @@ -232,46 +272,35 @@ func TestChunkPublishSettled_CloseDropsUnstartedReports(t *testing.T) { mu.Lock() calls++ n := calls - mu.Unlock() if n == 1 { hookCtx = ctx + } + mu.Unlock() + if n == 1 { close(entered) <-release + note("hook returned") } } layer.stMu.Lock() layer.settled = append(layer.settled, headTransition{prev: chunkHead{Gen: 0}, next: chunkHead{Gen: 1}}, headTransition{prev: chunkHead{Gen: 1}, next: chunkHead{Gen: 2}}) layer.stMu.Unlock() - drained := make(chan struct{}) - go func() { layer.runPublishSettled(); close(drained) }() + drainer := launch(t, "the drainer", releaseHook, func() error { layer.runPublishSettled(); return nil }) waitClosed(t, entered, "the first report") - closeDone := make(chan error, 1) - go func() { closeDone <- layer.Close() }() - t.Cleanup(func() { - rel.Do(func() { close(release) }) - select { - case <-closeDone: - case <-time.After(10 * time.Second): - t.Error("Close never returned") - } - }) - waitClosed(t, hookCtx.Done(), "Close cancelling the hook's context") - select { - case err := <-closeDone: - closeDone <- err - t.Fatal("Close returned while a report hook was running") - case <-time.After(200 * time.Millisecond): - } - rel.Do(func() { close(release) }) - waitClosed(t, drained, "the drain to end") - select { - case err := <-closeDone: - closeDone <- err - if err != nil { - t.Fatal(err) - } - case <-time.After(10 * time.Second): - t.Fatal("Close did not return") + closer := launch(t, "Close", releaseHook, layer.Close) + mu.Lock() + ctx := hookCtx + mu.Unlock() + waitClosed(t, ctx.Done(), "Close cancelling the hook's context") + waitClosed(t, joining, "Close reaching its join of the drainer") + releaseHook() + drainer.mustReturn(t) + closer.mustReturn(t) + orderMu.Lock() + seq := append([]string(nil), order...) + orderMu.Unlock() + if len(seq) != 2 || seq[0] != "hook returned" || seq[1] != "Close joined" { + t.Fatalf("order %v; want the running hook to return before Close's join does", seq) } mu.Lock() defer mu.Unlock() @@ -287,12 +316,16 @@ func TestChunkPublishSettled_HookThatPublishes(t *testing.T) { s, _ := newChunkTestStore(t) layer := mustAttach(t, s, f, ctConfig(1)).(*chunkLayerImpl) w := newWriteLog() + var mu sync.Mutex var got [][2]uint64 nested := false layer.cfg.OnPublishSettled = func(ctx context.Context, prev, next ChunkHead) { + mu.Lock() got = append(got, [2]uint64{prev.Gen, next.Gen}) - if !nested { - nested = true + again := !nested + nested = true + mu.Unlock() + if again { w.write(t, s, 9, 0x29) if _, err := layer.Cut(ctx); err != nil { t.Errorf("cut from the hook: %v", err) @@ -300,17 +333,31 @@ func TestChunkPublishSettled_HookThatPublishes(t *testing.T) { } } w.write(t, s, 2, 0x22) - done := make(chan error, 1) - go func() { _, err := layer.Cut(context.Background()); done <- err }() - select { - case err := <-done: - if err != nil { - t.Fatal(err) - } - case <-time.After(10 * time.Second): + cut := launch(t, "a cut whose hook publishes", nil, func() error { _, err := layer.Cut(context.Background()); return err }) + if err, ok := cut.result(10 * time.Second); !ok { t.Fatal("a hook that publishes deadlocked") + } else if err != nil { + t.Fatal(err) } + mu.Lock() + defer mu.Unlock() if len(got) != 2 || got[0] != [2]uint64{0, 1} || got[1] != [2]uint64{1, 2} { t.Fatalf("reports %v; want [0->1 1->2]", got) } } + +// A periodic cut (CutUnlessCutSince) reports its publication like any other +// cut, after the capture lock is released, before it returns. +func TestChunkPublishSettled_PeriodicCutReports(t *testing.T) { + f := newFakeChunkRemote() + s, layer, log := attachWithSettled(t, f) + w := newWriteLog() + w.write(t, s, 3, 0x33) + if _, skipped, err := layer.CutUnlessCutSince(ctTimeout(t), 0); err != nil || skipped { + t.Fatalf("periodic cut: skipped=%v err=%v", skipped, err) + } + got, free := log.snapshot() + if len(got) != 1 || got[0] != [2]uint64{0, 1} || !free[0] { + t.Fatalf("periodic cut reports %v (capture lock free %v); want one report 0->1 with the lock free", got, free) + } +} diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index 9706888146..7be66e2e10 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -312,12 +312,19 @@ func validChunkIntentID(id string) bool { type chunkLayerConfig struct { // OnPublishSettled, when set, is called once per confirmed publication // (a cut, a detach, or an earlier unresolved CAS found applied), with the - // HEAD before and after it. Calls are serialized and in publication - // order, outside the capture lock, on whichever publishing caller is - // draining the reports (a publisher may return before its own report is - // delivered by the drainer). The drainer is registered with Close; ctx - // ends with Close, and once Close has begun no further report is - // delivered. A hook may publish again (its report is delivered after). + // HEAD before and after it (INV-PUBLISH-SETTLED-001). Calls are + // serialized and in publication order, outside the capture lock, on + // whichever publishing caller is draining the reports (a publisher may + // return before its own report is delivered by the drainer). The drainer + // is registered with Close; ctx ends with Close. Once Close has begun no + // further report is dequeued; a report already dequeued may still reach + // the hook after Close began (Close then waits for it). + // + // The hook MUST return without blocking and without remote calls; enqueue + // work to your own worker. It runs on the cut or detach caller's + // goroutine, before a detach returns: its duration is a guest-visible wait + // (Part C wait sites). While a hook stalls, later reports queue without a + // bound. A hook may publish again (its report is delivered after). OnPublishSettled func(ctx context.Context, prev, next ChunkHead) // ChunkBlocks is the number of consecutive blocks per chunk (1024 for // 4 KiB blocks and 4 MiB chunks). diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index aa90753dcb..b6ed420d15 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -347,7 +347,7 @@ snapshot lifetime; local persistence does not bypass it. ## Part B. Invariant ledger -118 rows: 99 ACTIVE, 19 STUB; 15 kept from the internal ledger, 103 new. +120 rows: 101 ACTIVE, 19 STUB; 15 kept from the internal ledger, 105 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. @@ -527,10 +527,13 @@ Notes: | `INV-VOLDEL-COMMIT-001` | A volume delete commits only when no snapshot name record exists, and after its commit point no concurrent delete can roll it back. | M6 HEAD: deleting → purging | `core/frontend/chunkstore/volume_delete.go` `DeleteVolume`, `snapshotsBlock`, `commitHeadPurging` | `TestCatalog_DeleteVolumeRefusesWhileSnapshotsExist`, `TestCatalog_ConcurrentDeleteCannotRollBackACommittedOne` (`core/frontend/chunkstore/volume_delete_test.go`) | `ChunkLifecycleFixed` `CommitClean` | ACTIVE | | `INV-VOLDEL-HELD-HEAD-001` | A delete marks HEAD `deleting` only while no holder holds it; an attach that reaches HEAD first wins. | M6 HEAD: detached → deleting | `core/frontend/chunkstore/volume_delete.go` `markHeadDeleting`, `headHeld` | `TestCatalog_DeleteVolumeLosesToAnAttachAtTheMark` (`core/frontend/chunkstore/volume_delete_test.go`) | — | ACTIVE | | `INV-HEAD-DELETE-FROZEN-001` | Once HEAD is `deleting`, `purging` or `deleted`, `CASHead` refuses every claim or cut; only the delete's own transitions move it. | M6 HEAD: deleting \| purging \| deleted | `core/frontend/chunkstore/chunk_remote.go` `CASHead` | `TestCatalog_DeletedHeadCannotBeRevivedByAClaim` (`core/frontend/chunkstore/volume_delete_test.go`) | `ChunkLifecycleFixed` `NoPublishAfterCommit` | ACTIVE | +| `INV-SHARE-ACTIVATION-001` | With a `ShareGuard` installed, a snapshot activates (writes its snapshot entry) and a fork activates (writes the child HEAD) only after `Finish` accepted the share for that HEAD; a refused `Begin` or `Finish` aborts before activation and drops the new intent, and the owner's seal calls `Begin` before the cut that produces the sealed HEAD (a refused `Begin` cuts nothing). With no guard, no call and no check is added. | M6 snapshot: Pending → Published; fork: child HEAD create | `core/frontend/chunkstore/share_guard.go` `beginShare`, `finishShare`; `core/frontend/chunkstore/catalog.go` `CreateSnapshot`, `Fork`; `core/host/volume/chunk_control.go` `chunkControl.Snapshot` | `TestShareGuard_SnapshotFinishesBeforeActivation`, `TestShareGuard_RefusedFinishAbortsTheSnapshot`, `TestShareGuard_StaleHeadIsRefused`, `TestShareGuard_CallerToken`, `TestShareGuard_Fork`, `TestShareGuard_BeginRefused` (`core/frontend/chunkstore/share_guard_test.go`); `TestChunkControl_SnapshotBeginsShareBeforeTheCut`, `TestChunkControl_SnapshotBeginRefusedCutsNothing` (`core/host/volume/chunk_control_order_test.go`) | — (the enterprise policy's protocol is modelled in `ShareMarker`) | ACTIVE | +| `INV-PUBLISH-SETTLED-001` | With `OnPublishSettled` set, each confirmed publication (HEAD prev → next with a new generation: a cut, a detach, or an earlier unresolved CAS found applied) is delivered once, in publication order, one at a time, outside the capture and state locks, by one registered drainer. Once Close has begun no report is dequeued; a report already dequeued may still reach the hook. A no-op cut reports nothing; with no hook nothing is queued. | M5 CAS → Settled; M6 HEAD: published | `core/storage/chunk_publish_settled.go` `noteSettled`, `unlockCap`, `runPublishSettled`; `core/storage/chunk_periodic_cut.go` `CutUnlessCutSince` | `TestChunkPublishSettled_ReportsEachPublication`, `TestChunkPublishSettled_ReportsALatePublication`, `TestChunkPublishSettled_ClosedAndUnset`, `TestChunkPublishSettled_OverlappingPublishersStayOrdered`, `TestChunkPublishSettled_CloseDropsUnstartedReports`, `TestChunkPublishSettled_HookThatPublishes`, `TestChunkPublishSettled_PeriodicCutReports` (`core/storage/chunk_publish_settled_test.go`); `TestWALStoreChunk_PublishSettledHook` (`core/frontend/durable/provider_chunk_sched_test.go`) | — | ACTIVE | Notes: - `INV-GC-GRACE-DEADLINE-001`: The check is in `NewCollector`; no Go test constructs a collector with a too-short grace. +- `ChunkRemote.ReclaimKey` is the Collector's per-key step (`reclaimBinding`) exported, not a new admission: `INV-GC-REACHABLE-001` (reachability and the two-mark grace) stays the Collector's, and a `ReclaimKey` caller must itself know nothing references the key. The step keeps `INV-CHUNK-WRITE-ONCE-001`: the binding is tombstoned, its exact fid deleted, and the binding kept for ever, never rebound; owner-qualified keys are refused. ### B.7 Rows kept from the internal ledger: Kubernetes line and replica fencing @@ -593,6 +596,14 @@ How a fix or a feature is calibrated against this model: 5. **Rows are stable.** IDs are never reused or renumbered. A retired row stays with status `ARCHIVED` and a reason. A narrowed statement says what was dropped in a note. 6. **STUB rows block claims.** A release note or a design document must not claim a property backed only by a `STUB` row. Turning a `STUB` into `ACTIVE` is the test plus the status change. +### C.W Wait sites (SYSTEM-MATH Part C) + +One row per wait in the data and control paths. Guest-visible rows on one path must sum to at most 5 s. + +| Site | Waits for | Bound | Owner that ends it | On expiry | Lock held while waiting | Guest-visible | +|---|---|---|---|---|---|---| +| `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) | + Format v3 row 4 remains dark. Its typed scan result preserves trusted records, absolute end, highest LSN, contiguous frontier, trusted DurableLSN and stop cause separately. The later W/BASE/fence owner 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. ### Dark v3 offline reader (row12a)