diff --git a/seaweed-block/core/storage/wal_io_v3.go b/seaweed-block/core/storage/wal_io_v3.go index ff3edb4c5d..c0d1f6bced 100644 --- a/seaweed-block/core/storage/wal_io_v3.go +++ b/seaweed-block/core/storage/wal_io_v3.go @@ -39,8 +39,13 @@ type walWriterV3 struct { highestLSN uint64 // includes the last LSN consumed by a batch failed error writeAt func([]byte, int64) (int, error) + // Volatile record boundaries, never payloads. Recovery reconstructs + // only the trusted kept prefix; a batch is one indivisible point. + reclaim []walReclaimPointV3 } +type walReclaimPointV3 struct{ lastLSN, end uint64 } + func newWALWriterV3(fd *os.File, pub *descriptorPublisherV3) (*walWriterV3, error) { d, _, ok := pub.walSnapshotV3() if err := d.validate(pub.accept); err != nil { @@ -70,6 +75,15 @@ func (w *walWriterV3) append(e walEntryV3, durableLSN uint64) (uint64, error) { if !ok || d.Nonce != w.nonce || w.head < floor || w.head-floor > d.WALSize { return 0, errWALBindingV3 } + // Only both-slot-released points may leave the bounded index. + nReleased := 0 + for nReleased < len(w.reclaim) && w.reclaim[nReleased].end <= floor { + nReleased++ + } + if nReleased > 0 { + copy(w.reclaim, w.reclaim[nReleased:]) + w.reclaim = w.reclaim[:len(w.reclaim)-nReleased] + } if e.LSN <= w.highestLSN { return 0, fmt.Errorf("%w: first %d after %d", ErrWALLSNOrder, e.LSN, w.highestLSN) } @@ -138,9 +152,26 @@ func (w *walWriterV3) append(e walEntryV3, durableLSN uint64) (uint64, error) { if e.Type == walEntryWriteBatch { w.highestLSN += e.BatchCount - 1 } + w.reclaim = append(w.reclaim, walReclaimPointV3{w.highestLSN, w.head}) return start % d.WALSize, nil } +// reclaimThroughV3 returns only a complete, validated record boundary. +// Caller serializes recovery/reset with syncMu; appends can only extend +// the index with higher LSNs. No descriptor lock or I/O is taken here. +func (w *walWriterV3) reclaimThroughV3(lsn uint64) uint64 { + w.mu.Lock() + defer w.mu.Unlock() + var end uint64 + for _, point := range w.reclaim { + if point.lastLSN > lsn { + break + } + end = point.end + } + return end +} + func (w *walWriterV3) logicalHeadV3() uint64 { w.mu.Lock(); defer w.mu.Unlock(); return w.head } // advanceHeadV3 moves the writer forward to p, never back. Plan row 11: a @@ -177,9 +208,42 @@ func (w *walWriterV3) restoreScanV3(r walScanResultV3) error { // The owner fences any dropped suffix first. Its raw HighestLSN must not // pin the allocator after that suffix has been discarded. w.highestLSN = r.Frontier + w.indexReclaimScanLockedV3(r) return nil } +// rememberReclaimScanV3 is physical-recovery bookkeeping only. It does +// NOT restore or rewind the writer position/LSN, including on an +// installing reopen whose suffix cannot be admitted until resume. +func (w *walWriterV3) rememberReclaimScanV3(r walScanResultV3) error { + w.mu.Lock() + defer w.mu.Unlock() + if r.Nonce != w.nonce { + return errWALBindingV3 + } + w.indexReclaimScanLockedV3(r) + return nil +} + +func (w *walWriterV3) indexReclaimScanLockedV3(r walScanResultV3) { + w.reclaim = w.reclaim[:0] + for _, rec := range r.Records { + if rec.End > r.End { + break + } + last := rec.Entry.LSN + if rec.Entry.Type == walEntryWriteBatch { + last += rec.Entry.BatchCount - 1 + } + if last > r.Frontier { + break + } + if rec.Entry.Type == walEntryWrite || rec.Entry.Type == walEntryWriteBatch { + w.reclaim = append(w.reclaim, walReclaimPointV3{last, rec.End}) + } + } +} + type walScannedRecordV3 struct { Entry walEntryV3 End uint64 diff --git a/seaweed-block/core/storage/walstore_map_checkpoint_v3.go b/seaweed-block/core/storage/walstore_map_checkpoint_v3.go index 093a01ec52..7bbc72d014 100644 --- a/seaweed-block/core/storage/walstore_map_checkpoint_v3.go +++ b/seaweed-block/core/storage/walstore_map_checkpoint_v3.go @@ -118,14 +118,35 @@ func (s *WALStore) publishCheckpointV3(cp uint64, seed bool, recoveryGen uint64) if wack < cp { return descriptorV3{}, ErrMapCoverageStale } + s.mu.RLock() + retention := s.recoveryRetentionLSNs + s.mu.RUnlock() + releaseLSN := uint64(0) + if cp > retention { + releaseLSN = cp - retention + } + tail := v.w.reclaimThroughV3(releaseLSN) + current := v.pub.current() + if current.BaseState == BaseInstalling { + // An incomplete BASE still needs its entire install-lane suffix. + tail = min(tail, current.BaseCursor) + } d, err := v.pub.publishMapV3(&s.mu, nil, prepared, func(n *descriptorV3) error { n.W = max(n.W, wack) n.CheckpointLSN = cp + n.RetainedTail = max(n.RetainedTail, tail) + n.RetainedHead = max(n.RetainedHead, n.RetainedTail) return nil }) if err != nil { return descriptorV3{}, err } + // Reuse still waits for BOTH valid slots. This uses the same sole + // publisher and existing immutable map; failure keeps the old slot pin + // and latches the store before the flusher retires dirty entries. + if _, err := v.pub.rolloverIfPinned(); err != nil { + return descriptorV3{}, err + } if seed { v.appended.Store(max(v.appended.Load(), cp)) v.wack.Store(wack) diff --git a/seaweed-block/core/storage/walstore_readonly_v3_test.go b/seaweed-block/core/storage/walstore_readonly_v3_test.go index 949901bbcd..998edc01e2 100644 --- a/seaweed-block/core/storage/walstore_readonly_v3_test.go +++ b/seaweed-block/core/storage/walstore_readonly_v3_test.go @@ -81,6 +81,11 @@ func TestWALStoreV3_ReadOnlyRefusesIncompleteOrCorruptDependencies(t *testing.T) for _, fault := range []string{"installing", "acknowledged_wal", "missing_map", "fallback_page", "presence", "fresh"} { t.Run(fault, func(t *testing.T) { s, path := newMappedCheckpointStoreV3(t) + if fault == "fallback_page" { + // Keep a genuinely referenced prior map in the fallback slot. + // Otherwise tail advance immediately rolls both slots forward. + s.SetRecoveryRetentionLSNs(1) + } oldPage := s.v3.pub.mapCurrent.refs[0].Offset writeSynced(t, s, 1, 1) if err := s.flusher.flushOnce(); err != nil { diff --git a/seaweed-block/core/storage/walstore_reclaim_v3_test.go b/seaweed-block/core/storage/walstore_reclaim_v3_test.go new file mode 100644 index 0000000000..e33368885a --- /dev/null +++ b/seaweed-block/core/storage/walstore_reclaim_v3_test.go @@ -0,0 +1,197 @@ +package storage + +import ( + "bytes" + "errors" + "path/filepath" + "testing" +) + +func TestWALStoreV3CheckpointReclaimsAcrossRingLaps(t *testing.T) { + path := filepath.Join(t.TempDir(), "volume") + s, err := createMappedWALStoreV3ForTest(path, 16, 4096, 64*1024, WModeStrict, 4) + if err != nil { + t.Fatal(err) + } + s.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = s.Close() }) + for i := 1; i <= 40; i++ { + if _, err := s.Write(0, blk(byte(i))); err != nil { + t.Fatalf("cycle %d after prior synced checkpoints: %v", i, err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + } + if floor, valid := s.v3.pub.reuseFloor(); !valid || floor <= 64*1024 { + t.Fatalf("both-slot reuse floor did not cross a ring lap: floor=%d valid=%v", floor, valid) + } + if err := s.Close(); err != nil { + t.Fatal(err) + } + r, err := openWALStoreV3ForTest(path) + if err != nil { + t.Fatal(err) + } + defer r.Close() + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if got, err := r.Read(0); err != nil || !bytes.Equal(got, blk(40)) { + t.Fatalf("latest acknowledged bytes after ring reuse/reopen: %v", err) + } +} + +func TestWALStoreV3ReclaimKeepsPartialBatchAndRetention(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + if _, err := s.WriteBatch(0, [][]byte{blk(1), blk(2)}); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + s.SetRecycleFloorSource(&fakeRecycleFloorSource{floor: 1, anyActive: true}) + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if d := s.v3.pub.current(); d.CheckpointLSN != 1 || d.RetainedTail != 0 { + t.Fatalf("partial batch released before checkpoint covered its last LSN: %+v", d) + } + s.SetRecycleFloorSource(nil) + s.SetRecoveryRetentionLSNs(1) + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if d := s.v3.pub.current(); d.CheckpointLSN != 2 || d.RetainedTail != 0 { + t.Fatalf("retention split and released a retained batch: %+v", d) + } + var got []RecoveryEntry + if err := s.ScanLBAs(2, func(e RecoveryEntry) error { got = append(got, e); return nil }); err != nil || len(got) != 1 || !bytes.Equal(got[0].Data, blk(2)) { + t.Fatalf("retained batch suffix is not available to catch-up: entries=%d err=%v", len(got), err) + } + s.SetRecoveryRetentionLSNs(0) + if _, err := s.Write(3, blk(3)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + d := s.v3.pub.current() + if floor, ok := s.v3.pub.reuseFloor(); !ok || floor != d.RetainedTail || floor == 0 { + t.Fatalf("idle post-flush fallback still pins the released prefix: %d %v", floor, ok) + } +} + +func TestWALStoreV3ReclaimRebuildsIndexAfterPhysicalRecovery(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + writeSynced(t, s, 0, 1) + writeSynced(t, s, 1, 2) + crashReadOnlyStoreV3(t, s) + r, err := openWALStoreV3ForTest(path) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = r.Close() }) + r.DisableAutoFlushForRecoveryTest() + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if err := r.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + d := r.v3.pub.current() + if floor, ok := r.v3.pub.reuseFloor(); !ok || floor == 0 || floor != d.RetainedTail { + t.Fatalf("physical recovery did not restore reclaimable record boundaries: %d %v", floor, ok) + } +} + +func TestWALStoreV3ReclaimSecondSlotFailureKeepsOldPin(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + writeSynced(t, s, 0, 1) + writeSlot := s.v3.pub.io.writeSlot + writes := 0 + s.v3.pub.io.writeSlot = func(off int64, data []byte) error { + writes++ + if writes == 2 { + return errors.New("held fallback rollover write failed") + } + return writeSlot(off, data) + } + if err := s.flusher.flushOnce(); !errors.Is(err, ErrDescriptorPublishUncertain) || writes != 2 { + t.Fatalf("rollover failure was not surfaced: writes=%d err=%v", writes, err) + } + if floor, valid := s.v3.pub.reuseFloor(); valid && floor != 0 { + t.Fatalf("failed rollover granted reuse over the old slot: floor=%d", floor) + } + head := s.v3.w.logicalHeadV3() + if _, err := s.Write(1, blk(2)); err == nil || s.v3.w.logicalHeadV3() != head { + t.Fatalf("failed rollover allowed another append: %v", err) + } + crashReadOnlyStoreV3(t, s) + r, err := openWALStoreV3ForTest(path) + if err != nil { + t.Fatal(err) + } + defer r.Close() + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if got, err := r.Read(1); err != nil || !bytes.Equal(got, blk(1)) { + t.Fatalf("acknowledged bytes lost at the fallback failure window: %v", err) + } +} + +func TestWALStoreV3ReclaimAfterInstallingPhysicalReopen(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + h, err := s.BeginBaseInstall(0, idA) + if err != nil { + t.Fatal(err) + } + for i := uint64(1); i <= 3; i++ { + if err := h.ApplyInstallEntry(uint32(i), blk(byte(i)), i); err != nil { + t.Fatal(err) + } + } + if _, err := s.SyncInstallLog(idA); err != nil { + t.Fatal(err) + } + crashReadOnlyStoreV3(t, s) + r, err := openWALStoreV3ForTest(path) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = r.Close() }) + r.DisableAutoFlushForRecoveryTest() + initialHead := r.v3.w.logicalHeadV3() + if _, err := r.Recover(); !errors.Is(err, ErrBaseIncomplete) { + t.Fatalf("installing reopen: %v", err) + } + if r.v3.w.logicalHeadV3() != initialHead { + t.Fatal("reclaim bookkeeping changed the not-yet-resumed writer cursor") + } + h, err = r.resumeBaseInstallV3(idA) + if err != nil { + t.Fatal(err) + } + if err := h.MarkBaseComplete(); err != nil { + t.Fatal(err) + } + if _, err := r.Sync(); err != nil { + t.Fatal(err) + } + if err := r.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if floor, ok := r.v3.pub.reuseFloor(); !ok || floor == 0 { + t.Fatalf("completed recovered install suffix cannot be reclaimed: floor=%d valid=%v", floor, ok) + } + if got, err := r.Read(3); err != nil || !bytes.Equal(got, blk(3)) { + t.Fatalf("recovered install bytes: %v", err) + } +} diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index 6df64ced15..048796495e 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -418,6 +418,13 @@ func (s *WALStore) recoverV3() (uint64, error) { } } v.installReopen = ro + if v.w != nil { + kept := scan + kept.End, kept.Frontier = o.E, o.R + if err := v.w.rememberReclaimScanV3(kept); err != nil { + return 0, err + } + } } else if o.Damaged || v.w == nil || o.E != v.w.logicalHeadV3() { // A same-open Recover of this open's live install that finds the // WAL cut short of the live writer (damage under a live install): diff --git a/seaweed-block/core/transport/catchup_format_v3_test.go b/seaweed-block/core/transport/catchup_format_v3_test.go index e3313bae82..60d8efe88c 100644 --- a/seaweed-block/core/transport/catchup_format_v3_test.go +++ b/seaweed-block/core/transport/catchup_format_v3_test.go @@ -16,6 +16,51 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" ) +func TestCatchUpV3AfterCheckpointRingReuse(t *testing.T) { + primary, err := storage.CreateMappedWALStoreV3Test(filepath.Join(t.TempDir(), "primary.v3"), 64, v3RepBlock, 4) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = primary.Close() }) + primary.DisableAutoFlushForRecoveryTest() + primary.SetRecoveryRetentionLSNs(1) + const last = 270 // more than one lap of the real 1MiB test WAL + for i := 1; i <= last; i++ { + if _, err := primary.Write(0, v3RepBlk(byte(i))); err != nil { + t.Fatalf("cycle %d: %v", i, err) + } + if _, err := primary.Sync(); err != nil { + t.Fatal(err) + } + if err := storage.FlushMappedWALStoreV3Test(primary); err != nil { + t.Fatal(err) + } + } + replica := v3Rep(t) + h, err := replica.BeginBaseInstall(last-1, [16]byte{1}) + if err != nil { + t.Fatal(err) + } + if err := h.WriteBase(0, v3RepBlk(byte((last-1)%256))); err != nil { + t.Fatal(err) + } + if err := h.MarkBaseComplete(); err != nil { + t.Fatal(err) + } + l := v3Listen(t, replica) + r := runCatchUpFrom(t, NewBlockExecutor(primary, l.Addr()), last, last+1) + if !r.Success || r.AchievedLSN != last { + t.Fatalf("retained post-wrap record did not catch up: %+v", r) + } + if got := v3Read(t, replica, 0); !bytes.Equal(got, v3RepBlk(byte(last%256))) { + t.Fatal("catch-up after physical reuse returned wrong bytes") + } + r = runCatchUpFrom(t, NewBlockExecutor(primary, l.Addr()), last-1, last+1) + if r.Success || r.FailureKind != engine.RecoveryFailureWALRecycled { + t.Fatalf("released prefix must route to rebuild: %+v", r) + } +} + func TestCatchUpV3InstallRetireABARefusesOldScan(t *testing.T) { primary, err := storage.CreateMappedWALStoreV3Test(filepath.Join(t.TempDir(), "primary.v3"), 64, v3RepBlock, 4) if err != nil { diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index cade4a610c..0dd431221b 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -63,7 +63,7 @@ stateDiagram-v2 | 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` | | any | Closed | `Close`; a store with a latched fault does not write the final superblock | `core/storage/walstore.go` `WALStore.Close` | — | -The format-v3 record codec (plan row 2) is dark: no production M1 transition selects it yet. Its framing/validation boundary is tested separately (`INV-WAL-V3-RECORD-001`); writer/cursor/lap admission and production activation land in later ordered rows. Existing machine diagrams and ACTIVE recovery guards are unchanged. Before reading v3 slots, both read/write and offline read-only open acquire an exclusive nonblocking file lock; the offline migration CLI acquires the same lock before any descriptor read or mutation (`INV-WAL-V3-OWNER-001`). Contention refuses open/migration without changing bytes; descriptor close or process exit releases ownership. This implements the existing offline-migration precondition, not a new serving state. +The format-v3 record codec (plan row 2) is dark: no production M1 transition selects it yet. Its framing/validation boundary is tested separately (`INV-WAL-V3-RECORD-001`); writer/cursor/lap admission and production activation land in later ordered rows. Existing machine diagrams and ACTIVE recovery guards are unchanged. Before reading v3 slots, both read/write and offline read-only open acquire an exclusive nonblocking file lock; the offline migration CLI acquires the same lock before any descriptor read or mutation (`INV-WAL-V3-OWNER-001`). Contention refuses open/migration without changing bytes; descriptor close or process exit releases ownership. This implements the existing offline-migration precondition, not a new serving state. The mapped v3 checkpoint also carries a complete-record physical tail through the covered LSN minus the configured retention window; partial batches remain retained. The existing sole publisher then performs metadata-only rollover when the fallback still pins that prefix. Reuse still requires both valid same-nonce slot tails; a failed rollover latches and grants no reuse (`INV-WAL-V3-RECLAIM-001`). Recovery warnings such as `wal_hole_suspected` are recorded in Serving without changing health (`INV-WAL-WARN-NO-HEALTH-001`). The open gaps of this machine (a corrupted synced record mid-history only warns; forged records in user data) are listed in the [core known issues](block-design.md#24-known-issues-and-work-in-progress) and are not ledger rows. @@ -281,6 +281,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-WAL-V3-DESCRIPTOR-001` | A v3 descriptor slot is used only if it is valid. It needs a matching CRC32C (Castagnoli), every reserved byte zero, an accepted impl, a nonzero slotGen at most 2^64-2 and a nonzero nonce. Its geometry must be consistent with checked arithmetic, its BASE fields must follow their per-state rules, and CheckpointLSN ≤ mapCoveredCheckpoint ≤ W must hold. Of the two slots, the valid selectable one with the higher slotGen wins. A prepared migration slot is never selected. Equal generations with different bytes, or slots that disagree on identity or geometry, are refused. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `decodeSlotV3`, `selectSlotV3`, `nextSlotGenV3` | `TestSlotV3VectorsDecodeAsExpected`, `TestSlotV3Selection`, `TestSlotV3CounterExhaustion`, `TestSlotV3InstalledMayHaveCursorBelowTail` (`core/storage/superblock_v3_test.go`) | — | STUB | | `INV-WAL-V3-RECORD-001` | A dark impl-3 record codec uses the fixed 62-byte prefix and 70-byte overhead, CRC32C and an explicit EntrySize. It refuses unknown types/flags, a zero nonce, invalid per-type geometry, overflowing count/LSN/cursor or LBA spans, nonzero padding, bad CRC/footer and truncation before allocating a payload. Codec success alone is not nonce/cursor/lap replay admission. | M1 (v3 codec only; no production transition yet) | `core/storage/wal_entry_v3.go` `payloadSizeV3`, `encodeWALEntryV3`, `decodeWALEntryV3` | `TestWALEntryV3_CanonicalBarrierBytes`, `TestWALEntryV3_TypeFootprints`, `TestWALEntryV3_RefusesInvalidEncode`, `TestWALEntryV3_RefusesMalformedWire`, `FuzzWALEntryV3_DecodeNeverPanics` | `WALRecovery` abstract record validity; physical byte rules are code-test obligations | STUB | | `INV-WAL-V3-LSN-ORDER-001` | A dark v3 writer accepts only a first LSN above its highest consumed LSN; a batch consumes its whole validated range. Equal/lower requests return ErrWALLSNOrder before any pwrite or cursor change. Constructor coverage and a recovered kept frontier count as consumed; a fenced-away suffix does not. | M1 (dark append only) | `core/storage/wal_io_v3.go` `append`, `newWALWriterV3`, `restoreScanV3` | `TestWALLSNOrderV3_RefusesDuplicateAndLower`, `TestWALLSNOrderV3_BatchConsumesFullRange`, `TestWALLSNOrderV3_RestoreUsesKeptNotDroppedFrontier`, `TestWALLSNOrderV3_DescriptorFloorIsAlreadyConsumed`, `TestWALIOV3_ValidatedFrontierIntervals`, `TestWALIOV3_ConcurrentAppendsHaveUniqueCursors` | Physical LSN-strict prefix is a contract constraint; r16 model correspondence is pending | STUB | +| `INV-WAL-V3-RECLAIM-001` | A mapped v3 checkpoint releases only complete validated record ends covered by the checkpoint and outside the retention window; an installing BASE retains its install suffix. Physical recovery rebuilds the volatile boundary index only from the trusted kept scan, without restoring a disconnect cursor. Tail/head/map/checkpoint/W publish together, followed by metadata-only rollover; both slot tails still pin reuse. Failure grants no reuse and retains retry work. | M1 checkpoint / existing two-slot retirement | `wal_io_v3.go` `reclaimThroughV3`, `rememberReclaimScanV3`; `walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `descriptor_v3.go` `rolloverIfPinned` | `TestWALStoreV3CheckpointReclaimsAcrossRingLaps`, `TestWALStoreV3ReclaimKeepsPartialBatchAndRetention`, `TestWALStoreV3ReclaimRebuildsIndexAfterPhysicalRecovery`, `TestWALStoreV3ReclaimAfterInstallingPhysicalReopen`, `TestWALStoreV3ReclaimSecondSlotFailureKeepsOldPin`, tagged `TestCatchUpV3AfterCheckpointRingReuse` | Existing dual-slot retirement and nonce/cursor contract; concrete index/recovery/caller wiring is a code-test obligation | STUB | | `INV-WAL-V3-OWNER-001` | v3 read/write open, offline readonly open and migrate-v3 acquire the same exclusive nonblocking OS file lock before reading slots or changing bytes. Contention refuses with volume locked; descriptor close releases it, allowing retry. | M1 open admission / offline migration precondition | `core/storage/volume_lock*.go`; `walstore_v3.go`; `walstore_readonly_v3.go`; `cmd/sw-block/migrate.go` | `TestMigrateV3RefusesAnOpenV3Volume`, `TestMigrateV3ExcludesOpenUntilCommitFinishes` (tag `swblock_format_v3_test`), `TestWALStoreV3OwnerExcludesOpenAndReadOnly` | OS mutual exclusion is a caller obligation, outside the abstract crash model; existing open states unchanged | STUB | | `INV-WAL-V3-CATCHUP-001` | A dark v3 catch-up source refuses while installing, including an empty at-head request. Requests covered by an installed BASE require rebuild (typed WALRecycled); damage in retained WAL remains an integrity failure. Before emitting any entries the scan revalidates recovery generation, nonce, BASE state/ID and install epoch, so begin/complete/retire ABA cannot publish a superseded prefix. | M1 BASE lifecycle / M3 CatchingUp (dark callers) | `core/storage/walstore_recovery.go` `ScanLBAs`, `scanLBAsV3`, `v3CatchUpEntries` | `TestCatchUpV3InstallingAtHeadRefuses`, `TestCatchUpV3CompletedBASEUsesRebuild`, `TestCatchUpV3InstallRetireABARefusesOldScan`, `TestCatchUpV3CorruptFirstRecordFails`, `TestCatchUpV3CorruptMiddleRecordFails`, `TestCatchUpV3CompletedBASESuffix` (tag `swblock_format_v3_test`, actual catch-up sender) | Existing BASE and catch-up transitions unchanged; this physical scan/source-lifetime obligation is covered by deterministic caller tests | STUB | | `INV-WAL-V3-BINDING-001` | The dark v3 writer stamps the selected nonce and absolute cursor, fits each append/padding inside the dual-slot reuse floor, and refuses later I/O after a pwrite failure. A dark scanner checks nonce and exact expected cursor before using Length/count, checks the full record again, skips only geometric end slack, and stops at the first untrusted record without payload resynchronization. It returns a typed scan result, never ACK or serving permission. | M1 Recovering (dark muscles only) | `core/storage/wal_io_v3.go` `append`, `scanWALV3`, `walSnapshotV3` | `TestWALIOV3_RealWriterReopenScan`, `TestWALIOV3_WrapPaddingAndSlack`, `TestWALIOV3_StopsAtBindingBeforeEmbeddedRecord`, `TestWALIOV3_EmbeddedRecordInPayloadIsNotScanned`, `TestWALIOV3_InstalledScanBeginsAtMaxTail`, `TestWALIOV3_FloorAndPwriteFailureRefuse` | Record/lap admission is abstracted in composed WALFormatR5; physical framing/wrap boundaries remain code-test obligations | STUB |