diff --git a/seaweed-block/core/frontend/durable/first_cut_known_zero_test.go b/seaweed-block/core/frontend/durable/first_cut_known_zero_test.go index 610216aa3a..50e535ac3b 100644 --- a/seaweed-block/core/frontend/durable/first_cut_known_zero_test.go +++ b/seaweed-block/core/frontend/durable/first_cut_known_zero_test.go @@ -1,15 +1,16 @@ package durable_test -// The first cut of a volume. A local store created empty against a HEAD -// that was never claimed and holds no segments knows every chunk it has not -// written is zero, so its first cut scans only the chunks written since; a -// store whose relation to HEAD is not known (a claimed HEAD, a restore or -// fork target, a store an earlier release created) keeps scanning every -// chunk it holds locally. +// The first cut of a volume. A fresh local store (its first attach not yet +// committed) knows every chunk its claimed HEAD does not name is zero on both +// sides, so its first cut scans only the chunks written since; a +// store that is not fresh (one an earlier release created, or any store +// after its first attach commit) keeps its chunks' state as persisted. Chunks +// HEAD names stay absent and are hydrated from HEAD. import ( "bytes" "context" + "errors" "testing" "time" @@ -118,10 +119,12 @@ func TestRedFirstCutOfAFreshVolumeScansOnlyWrittenChunks(t *testing.T) { } } -// TestFirstCutAgainstAClaimedHeadScansEveryChunk: a store created empty -// against a HEAD another store already claimed (no segments yet) keeps -// every chunk a candidate. Passes today; pins the fix's scope. -func TestFirstCutAgainstAClaimedHeadScansEveryChunk(t *testing.T) { +// TestFirstCutAgainstAClaimedHeadCertifiesUnnamedChunks: a store created +// empty against a HEAD another store already claimed (no data published) is +// fresh too: every chunk that HEAD does not name starts equal to it (both +// zero), so the first cut has no candidates. General form of the rule: the +// premise is the store's fresh marker, not the HEAD's history. +func TestFirstCutAgainstAClaimedHeadCertifiesUnnamedChunks(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() remote := storage.NewMemChunkRemote() @@ -130,28 +133,28 @@ func TestFirstCutAgainstAClaimedHeadScansEveryChunk(t *testing.T) { if err := first.Close(); err != nil { t.Fatal(err) } - if head, err := remote.GetHead(ctx); err != nil || head.Gen == 0 || len(head.Segments) != 0 { - t.Fatalf("setup: HEAD %+v %v; want a claimed HEAD with no segments", head, err) + if head, err := remote.GetHead(ctx); err != nil || head.Gen == 0 || len(head.Chunks) != 0 { + t.Fatalf("setup: HEAD %+v %v; want a claimed HEAD naming no chunk", head, err) } p := fcutProvider(t, t.TempDir(), remote) fcutOpen(t, ctx, p) - if got := fcutStats(t, p).DirtyChunks; got != fcutChunks { - t.Fatalf("store created against a claimed HEAD: %d candidate chunks; want all %d", got, fcutChunks) + if got := fcutStats(t, p).DirtyChunks; got != 0 { + t.Fatalf("fresh store against a claimed HEAD naming nothing: %d candidate chunks; want 0", got) } } -// TestFirstCutOfARestoreTargetKeepsItsHydrationPath: a store created on a -// new root against a HEAD that names chunks hydrates them (they are -// absent, not candidates) and keeps every other chunk a candidate. Passes -// today; pins the fix's scope. +// TestFirstCutOfARestoreTargetKeepsItsHydrationPath: a fresh store against a +// HEAD that names chunks keeps those chunks absent (hydrated from HEAD; a +// read returns HEAD's data, never zeros) and starts every other chunk equal +// to HEAD (zero), so its first cut has no candidates. func TestFirstCutOfARestoreTargetKeepsItsHydrationPath(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() remote := storage.NewMemChunkRemote() first := fcutProvider(t, t.TempDir(), remote) fcutOpen(t, ctx, first) - fcutWrite(t, ctx, first, pcChunkBlocks*3, 0x33) - fcutWrite(t, ctx, first, pcChunkBlocks*7, 0x37) + a := fcutWrite(t, ctx, first, pcChunkBlocks*3, 0x33) + b := fcutWrite(t, ctx, first, pcChunkBlocks*7, 0x37) if _, err := first.CaptureVolume(ctx, "v1"); err != nil { t.Fatal(err) } @@ -160,8 +163,36 @@ func TestFirstCutOfARestoreTargetKeepsItsHydrationPath(t *testing.T) { } p := fcutProvider(t, t.TempDir(), remote) fcutOpen(t, ctx, p) - s := fcutStats(t, p) - if s.AbsentChunks != 2 || s.DirtyChunks != fcutChunks-2 { - t.Fatalf("restore target: %d absent, %d candidate chunks; want 2 absent and %d candidates", s.AbsentChunks, s.DirtyChunks, fcutChunks-2) + if s := fcutStats(t, p); s.AbsentChunks != 2 || s.DirtyChunks != 0 { + t.Fatalf("restore target: %d absent, %d candidate chunks; want 2 absent and 0 candidates", s.AbsentChunks, s.DirtyChunks) + } + got := make([]byte, 4096) + for lba, want := range map[int][]byte{pcChunkBlocks * 3: a, pcChunkBlocks * 7: b} { + if n, err := p.Backend("v1").Read(ctx, int64(lba)*4096, got); err != nil || n != len(got) || !bytes.Equal(got, want) { + t.Fatalf("restore target read of HEAD-named block %d: %d %v, data equal %v; want HEAD's data, not zeros", lba, n, err, bytes.Equal(got, want)) + } + } +} + +// TestExplicitWALStoreRefusesAFreshChunkRoot: a root carrying chunk metadata +// (here the fresh marker of a store that never attached) is refused by an +// explicitly configured plain walstore as by auto, so no write can reach a +// store whose marker says none ever did. +func TestExplicitWALStoreRefusesAFreshChunkRoot(t *testing.T) { + root := t.TempDir() + p := fcutProvider(t, root, storage.NewMemChunkRemote()) + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } + if err := p.Close(); err != nil { + t.Fatal(err) + } + plain, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStore, StorageRoot: root, BlockSize: 4096, NumBlocks: pcBlocks}, v1View()) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = plain.Close() }) + if _, err := plain.EnsureStorage("v1"); !errors.Is(err, durable.ErrImplKindMismatch) { + t.Fatalf("explicit walstore on a fresh chunk root: %v; want ErrImplKindMismatch", err) } } diff --git a/seaweed-block/core/frontend/durable/known_zero_premise_test.go b/seaweed-block/core/frontend/durable/known_zero_premise_test.go new file mode 100644 index 0000000000..1e6859a450 --- /dev/null +++ b/seaweed-block/core/frontend/durable/known_zero_premise_test.go @@ -0,0 +1,141 @@ +package durable + +import ( + "bytes" + "context" + "errors" + "os" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// kzProvider is a walstore-chunk provider for v1 (256 blocks, 16 per +// chunk: 16 chunks) over root and remote. +func kzProvider(t *testing.T, root string, remote storage.ChunkRemote) *DurableProvider { + t.Helper() + id := frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 3, EndpointVersion: 1} + p, err := NewDurableProvider(ProviderConfig{ + Impl: ImplWALStoreChunk, StorageRoot: root, BlockSize: 4096, NumBlocks: 256, ChunkBlocks: 16, + ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil }, + }, precopyQueueView{id}) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = p.Close() }) + return p +} + +func kzCandidates(t *testing.T, p *DurableProvider) int { + t.Helper() + for _, st := range p.DurableStatuses() { + if st.VolumeID == "v1" && st.Chunk != nil && st.Chunk.Attached { + return st.Chunk.Stats.DirtyChunks + } + } + t.Fatal("v1 has no attached chunk layer") + return -1 +} + +// The premise of RULE-FRESH-KNOWN-ZERO: until the attach commit retires the +// fresh marker, no write reaches the store. Held at that boundary (after the +// claim and the certification, before the commit), a frontend write is not +// admitted (it may wait; here it is bounded) and appends no WAL record. After +// the commit the store has no candidates: nothing was written. +func TestNoWriteReachesAFreshStoreBeforeItsAttachCommit(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + p := kzProvider(t, t.TempDir(), storage.NewMemChunkRemote()) + st, err := p.EnsureStorage("v1") + if err != nil { + t.Fatal(err) + } + ws := st.(*storage.WALStore) + var writeErr error + var nextAtBoundary uint64 + held := false + p.testBeforeChunkFreshRetire = func() error { + held = true + wctx, wcancel := context.WithTimeout(ctx, 300*time.Millisecond) + defer wcancel() + _, writeErr = p.Backend("v1").Write(wctx, 0, bytes.Repeat([]byte{0x5a}, 4096)) + nextAtBoundary = ws.NextLSN() + return nil + } + if _, err := p.RecoverVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + p.testBeforeChunkFreshRetire = nil + if !held { + t.Fatal("the attach did not reach its commit boundary") + } + if writeErr == nil || nextAtBoundary != 1 { + t.Fatalf("at the commit boundary a frontend write returned %v and the WAL's next LSN was %d; want refused, 1", writeErr, nextAtBoundary) + } + if got := kzCandidates(t, p); got != 0 { + t.Fatalf("after the commit: %d candidate chunks; want 0 (nothing was written)", got) + } +} + +// A first start that crashes before its attach commit (the commit fails, the +// process ends) leaves the fresh marker: the next start decides again on its +// own claim. It still has no candidates, and a write after it is published +// by the next cut. +func TestFreshAttachCrashBeforeCommitDecidesAgain(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + root, remote := t.TempDir(), storage.NewMemChunkRemote() + p := kzProvider(t, root, remote) + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } + crash := errors.New("crash before the attach commit") + p.testBeforeChunkFreshRetire = func() error { return crash } + if _, err := p.RecoverVolume(ctx, "v1"); !errors.Is(err, crash) { + t.Fatalf("first start: %v; want the injected crash", err) + } + if err := p.Close(); err != nil { + t.Fatal(err) + } + if _, err := os.Stat(chunkFreshMarker(p.volumePath("v1"))); err != nil { + t.Fatalf("fresh marker after the crash: %v; want it kept", err) + } + + p2 := kzProvider(t, root, remote) + if _, err := p2.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } + if _, err := p2.RecoverVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + if got := kzCandidates(t, p2); got != 0 { + t.Fatalf("second start: %d candidate chunks; want 0", got) + } + want := bytes.Repeat([]byte{0x6b}, 4096) + if _, err := p2.Backend("v1").Write(ctx, 5*16*4096, want); err != nil { + t.Fatal(err) + } + if err := p2.Backend("v1").Sync(ctx); err != nil { + t.Fatal(err) + } + if _, err := p2.CaptureVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + head, err := remote.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + ref, ok := head.Chunks[5] + if !ok { + t.Fatal("the cut after the second start did not publish chunk 5") + } + chunk, err := remote.Get(ctx, ref.Key) + if err != nil || !bytes.Equal(chunk[:4096], want) { + t.Fatalf("published chunk 5: %v, data equal %v", err, err == nil && bytes.Equal(chunk[:4096], want)) + } + if got := kzCandidates(t, p2); got != 0 { + t.Fatalf("after the cut: %d candidate chunks; want 0", got) + } +} diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index a6af566c84..eb631a06a4 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -809,17 +809,19 @@ func (p *DurableProvider) openOrCreate(volumeID string) (*volHandle, error) { if err != nil { return nil, fmt.Errorf("durable: stat %s: %w", path, err) } - if p.cfg.Impl == ImplAuto { + if p.cfg.Impl != ImplWALStoreChunk { // A walstore-chunk volume shares walstore's on-disk format, and its // authoritative bytes may live only in the remote HEAD. Opened as - // plain walstore it would serve local (possibly absent) extents, so - // auto refuses any root carrying chunk metadata; it never deletes - // or converts it. + // plain walstore it would serve local (possibly absent) extents, and + // a write through it would reach a store whose fresh marker still + // says no write ever did (RULE-FRESH-KNOWN-ZERO). So every other + // implementation, auto or explicit, refuses a root carrying chunk + // metadata; it never deletes or converts it. if side, err := chunkSidecars(path); err != nil { return nil, err } else if len(side) > 0 { - return nil, fmt.Errorf("%w: %s is a chunk-managed volume (%s present); auto cannot open it: set --durable-impl=walstore-chunk with its remote configuration", - ErrImplKindMismatch, path, strings.Join(side, ", ")) + return nil, fmt.Errorf("%w: %s is a chunk-managed volume (%s present); %s cannot open it: set --durable-impl=walstore-chunk with its remote configuration", + ErrImplKindMismatch, path, strings.Join(side, ", "), p.cfg.Impl) } } diff --git a/seaweed-block/core/storage/chunk_fresh_known_zero.go b/seaweed-block/core/storage/chunk_fresh_known_zero.go new file mode 100644 index 0000000000..d695f17997 --- /dev/null +++ b/seaweed-block/core/storage/chunk_fresh_known_zero.go @@ -0,0 +1,41 @@ +package storage + +// RULE-FRESH-KNOWN-ZERO (INV-CUT-BITMAP-001). A fresh store (FreshFromHead +// still true at its attach: the .chunkfresh marker is present and no BASE +// is installed) has never had a write or a fill reach it: frontend I/O is +// admitted only after the attach commit retires the marker, a chunk volume +// takes no replication apply, no cut or hydration can resolve the layer +// before that commit, and no other implementation opens a root that carries +// chunk metadata. Its extent therefore holds the creation bytes (zeros) in +// every chunk, and a chunk the claimed HEAD does not name is zero there too: +// the two are equal, so the chunk need not be a cut candidate. +// +// freshKnownZeroCandidates samples, under the attach's capture barrier, the +// mutation token of every chunk the claimed HEAD does not name whose owned +// map entry is still its creation value {LSN 0, Unknown}; the entry test is +// an extra exclusion, not the premise. attachChunkLayer then clears only the +// UNKNOWN bit of those whose token is unchanged, through the cut's own +// persistCapturedMapV3, before the provider's attach commit. A failed map +// publication leaves them UNKNOWN on disk (conservative). +func (l *chunkLayerImpl) freshKnownZeroCandidates(head chunkHead) map[uint64]uint64 { + s := l.s + if s.v3 == nil || s.v3.ownedMap == nil { + return nil + } + s.mu.RLock() + defer s.mu.RUnlock() + out := map[uint64]uint64{} + for idx := uint64(0); idx < l.numChunks && idx < uint64(len(s.v3.mapEntries)); idx++ { + if _, named := head.Chunks[idx]; named { + continue + } + if e := s.v3.mapEntries[idx]; e.LSN != 0 || !e.Unknown { + continue + } + out[idx] = l.chunkVersion(idx) + } + if len(out) == 0 { + return nil + } + return out +} diff --git a/seaweed-block/core/storage/chunk_fresh_known_zero_test.go b/seaweed-block/core/storage/chunk_fresh_known_zero_test.go new file mode 100644 index 0000000000..da243a67b9 --- /dev/null +++ b/seaweed-block/core/storage/chunk_fresh_known_zero_test.go @@ -0,0 +1,68 @@ +package storage + +import ( + "bytes" + "testing" +) + +// fkzConfig is a fresh attach's config (FreshFromHead) or an existing +// store's. +func fkzConfig(fresh bool) chunkLayerConfig { + cfg := ctConfig(1) + cfg.FreshFromHead = fresh + return cfg +} + +func fkzCandidates(l chunkLayer) int { return l.Stats().DirtyChunks } + +// A fresh attach certifies every chunk the claimed HEAD does not name whose +// owned-map entry is still the creation value; a chunk whose entry recorded +// a write (LSN >= 1) is never certified and stays a candidate, even where +// that LSN is not above HEAD's RemoteLSN (so "LSN above HEAD" alone would +// not make it one): here HEAD is at 100 and the write at 1. +func TestFreshKnownZeroNeverCertifiesARecordedWrite(t *testing.T) { + s, _ := newChunkTestStore(t) + if _, err := s.Write(uint32(2*ctChunkBlocks+1), bytes.Repeat([]byte{0x22}, ctBlockSize)); err != nil { + t.Fatal(err) + } + remote := newFakeChunkRemote() + remote.head = chunkHead{Gen: 1, Epoch: 1, RemoteLSN: 100, State: ChunkHeadActive} + l := mustAttach(t, s, remote, fkzConfig(true)) + if got := fkzCandidates(l); got != 1 { + t.Fatalf("fresh attach after a recorded write to chunk 2: %d candidates; want 1 (that chunk only)", got) + } +} + +// Without the fresh premise (an existing store) nothing is certified: every +// chunk keeps its persisted UNKNOWN. +func TestFreshKnownZeroNotWithoutTheFreshPremise(t *testing.T) { + s, _ := newChunkTestStore(t) + l := mustAttach(t, s, newFakeChunkRemote(), fkzConfig(false)) + if got, want := fkzCandidates(l), int(l.(*chunkLayerImpl).numChunks); got != want { + t.Fatalf("existing-store attach: %d candidates; want all %d", got, want) + } +} + +// The certification clears only chunks whose mutation token is unchanged +// since it was sampled under the attach barrier: a write landing between the +// sample and the clear keeps its chunk a candidate. +func TestFreshKnownZeroSkipsAChunkWrittenAfterTheSample(t *testing.T) { + s, _ := newChunkTestStore(t) + raw, err := attachChunkLayerImpl(s, newFakeChunkRemote(), fkzConfig(true)) + if err != nil { + t.Fatal(err) + } + l := raw.(*chunkLayerImpl) + t.Cleanup(func() { _ = l.Close() }) + if len(l.freshKnownZero) == 0 { + t.Fatal("no chunk sampled for certification") + } + if _, err := s.Write(uint32(3*ctChunkBlocks), bytes.Repeat([]byte{0x33}, ctBlockSize)); err != nil { + t.Fatal(err) + } + l.persistCapturedMapV3(l.freshKnownZero) + l.freshKnownZero = nil + if got := fkzCandidates(l); got != 1 { + t.Fatalf("a write between the sample and the clear: %d candidates; want 1 (the written chunk)", got) + } +} diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 02954e75e2..e2a7562eb2 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -62,6 +62,10 @@ type chunkLayerImpl struct { remote chunkRemote cfg chunkLayerConfig + // freshKnownZero: the mutation tokens RULE-FRESH-KNOWN-ZERO sampled at a + // fresh attach; applied and cleared by attachChunkLayer. + freshKnownZero map[uint64]uint64 + blockSize int chunkBlocks uint64 numChunks uint64 @@ -287,6 +291,7 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) l.absentGen[idx]++ } l.presenceVer++ + l.freshKnownZero = l.freshKnownZeroCandidates(head) } else if err := l.loadPresence(); err != nil { l.cancel() return nil, err diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index ae9344d73b..e6e5adee6c 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -653,5 +653,14 @@ var ( // attachChunkLayer attaches a chunk layer to an open store (chunk_layer.go). func attachChunkLayer(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) (chunkLayer, error) { - return attachChunkLayerImpl(s, remote, cfg) + l, err := attachChunkLayerImpl(s, remote, cfg) + if err != nil { + return nil, err + } + // RULE-FRESH-KNOWN-ZERO: outside the capture barrier, as for a cut. + if impl, ok := l.(*chunkLayerImpl); ok && impl.freshKnownZero != nil { + impl.persistCapturedMapV3(impl.freshKnownZero) + impl.freshKnownZero = nil + } + return l, nil } diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 2878cca9bb..fa1c220b56 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -497,7 +497,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -322 rows: 252 ACTIVE, 67 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 307 new. +323 rows: 253 ACTIVE, 67 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 308 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. @@ -822,7 +822,8 @@ Notes: | `INV-CUT-RECONCILING-001` | ARCHIVED: the legacy bitmap/reconciler is retired. Native owned-map validation and fail-closed attach admission replace its dirty-coverage protection; a provided legacy bitmap is ignored. | M5 native map admission | `core/storage/chunk_layer.go` `AttachChunkLayer` | `TestChunkAttachRefusesAnUnmappedNativeStore`; `TestChunkLayerV3_IgnoresProvidedLegacyBitmap` (`core/storage/chunk_layer_map_only_v3_test.go`) | legacy reconciliation transition retired | ARCHIVED | | `INV-CUT-STAGED-REUSE-001` | Completed uploads survive a refused point in-process, under their intents. A chunk pre-copied outside the barrier is used only if HEAD generation is unchanged and no write and no same-open `Recover` touched it after staging; otherwise it is copied again in the native COW window. | M5 Stage → Copy | `core/storage/chunk_layer.go` `captureLocked`, `stage` | `TestChunkStageV3_SpillBudgetTriggersPrecopy` (`core/storage/chunk_cut_progress_test.go`); `TestChunkStageV3_AbortedPointReusesUploads` (`core/storage/chunk_cut_progress_test.go`); `TestChunkPrecopy_RedirtiedStagedChunkIsRecopied` (`core/storage/chunk_layer_precopy_test.go`); `TestNativeReplacementRecoverInvalidatesStagedImage` (`core/storage/legacy_replacement_v3_test.go`); `TestChunkStageV3_MidUploadAbortReducesRetryBytes` (`core/storage/chunk_abort_upload_bytes_test.go`); `TestCutRevokedMidUploadKeepsItsUploads` (`core/storage/chunk_cut_revoke_reuse_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | | `INV-CUT-STAGED-COUNT-001` | `Stats.StagedChunks` counts each chunk staging finished (remembered for reuse) in every cut attempt, an interrupted round included, and only grows; a re-staged chunk counts again; it is in-process. A cut's `PayloadNs` includes its staging rounds whether or not they uploaded. | M5 Stage (before the barrier) | `core/storage/chunk_cut_payload.go` `rememberPayload`, `streamCutPayloads`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkStage_StagedChunksCountsFailedAttempts`, `TestChunkStage_StagedChunksCountsAnInterruptedRound`, `TestChunkStage_PayloadTimeCountsStagingWithoutUploads` (`core/storage/chunk_stage_accounting_test.go`) | — | ACTIVE | -| `INV-CUT-BITMAP-001` | The owned map never under-reports: its checkpoint coverage is durable before WAL recycling; UNKNOWN is cleared only after definite HEAD publication and an unchanged capture token. | M5 CAS → Settled; M1 InExtent → Checkpointed | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `core/storage/chunk_layer_map_v3.go` `persistCapturedMapV3` | `TestWALStoreV3_AutomaticMapCheckpoint` (`core/storage/walstore_map_checkpoint_v3_test.go`); `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN` (`core/storage/chunk_layer_map_v3_test.go`) | `CutCapture` `HeadImage` | ACTIVE | +| `INV-CUT-BITMAP-001` | The owned map never under-reports: its checkpoint coverage is durable before WAL recycling; UNKNOWN is cleared only after definite HEAD publication (a cut, or a fresh store's claim: `INV-CUT-FRESH-KNOWN-ZERO-001`) and an unchanged capture token. | M5 CAS → Settled; M1 InExtent → Checkpointed | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `core/storage/chunk_layer_map_v3.go` `persistCapturedMapV3` | `TestWALStoreV3_AutomaticMapCheckpoint` (`core/storage/walstore_map_checkpoint_v3_test.go`); `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN` (`core/storage/chunk_layer_map_v3_test.go`) | `CutCapture` `HeadImage` | ACTIVE | +| `INV-CUT-FRESH-KNOWN-ZERO-001` | A fresh store's attach (marker present, no BASE) clears UNKNOWN for each chunk its claimed HEAD does not name whose entry is still {LSN 0, UNKNOWN} and whose token is unchanged. Premise: no write, fill or other implementation reaches a store before that attach commits. | M1 Recovering → Serving (fresh attach, before its commit) | `core/storage/chunk_fresh_known_zero.go` `freshKnownZeroCandidates`; `core/storage/chunk_seam.go` `attachChunkLayer`; `core/frontend/durable/provider.go` `openOrCreate` (non-chunk implementations refuse chunk roots) | `TestRedFirstCutOfAFreshVolumeScansOnlyWrittenChunks`, `TestFirstCutAgainstAClaimedHeadCertifiesUnnamedChunks`, `TestFirstCutOfARestoreTargetKeepsItsHydrationPath`, `TestExplicitWALStoreRefusesAFreshChunkRoot` (`core/frontend/durable/first_cut_known_zero_test.go`); `TestNoWriteReachesAFreshStoreBeforeItsAttachCommit`, `TestFreshAttachCrashBeforeCommitDecidesAgain` (`core/frontend/durable/known_zero_premise_test.go`); `TestFreshKnownZeroNeverCertifiesARecordedWrite`, `TestFreshKnownZeroNotWithoutTheFreshPremise`, `TestFreshKnownZeroSkipsAChunkWrittenAfterTheSample` (`core/storage/chunk_fresh_known_zero_test.go`) | `KnownZero` | ACTIVE | | `INV-CUT-RECOVER-BARRIER-001` | Native `Recover` aborts and drains OPEN COW owners before lower locks, with admission held through recovery and a hook snapshot recheck. No recovered record above H can enter a HEAD labelled H. | M5 Quiesce; M1 Recovering | `core/storage/walstore.go` `WALStore.Recover`; `chunk_cut_cow.go` `holdChunkDestructive` | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`) | — | ACTIVE | | `INV-CUT-UPLOAD-FROM-BUFFER` | CopyFinish owns an immutable at-H slot. Every PUT retry sends that slot, without rereading local bytes; transient failures keep the point until the caller deadline, window abort or 30-second object deadline. Guest writes to a copied chunk need no save. | M5 Copy -> Upload | `chunk_cut_cow.go` `copyCOWEntry`; `chunk_upload.go` `putCaptured` | `TestCutUploadRetriesPastThreeAttemptsAtSamePoint`, `TestChunkCutUploadDeadlineBoundRetainsDirt`, `TestCutCOWV3_PutRetryUsesFrozenSlot` (`core/storage/chunk_cut_alignment_test.go`) | CutCOW2 BufFrozen; separate upload action extension pending | ACTIVE | | `INV-CUT-NO-WAL-PIN` | A cut window pins no WAL space and does not defer the flusher. Logical readers validate their resolved record and retry against the dirty map/extent after retirement and reuse. | M1 Checkpoint / M5 Copy | `walstore_v3.go` `readDirtyV3`; `flusher.go` `flushOnceInternal` | `TestCutCOWV3_CaptureDoesNotPinWAL` (`core/storage/chunk_cut_alignment_test.go`) | CutFlush refinement; native real ring-reuse control | ACTIVE |