diff --git a/seaweed-block/core/storage/checkpoint_diagnostics.go b/seaweed-block/core/storage/checkpoint_diagnostics.go index 6aae6678ba..e3c28d5839 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics.go @@ -34,8 +34,7 @@ type CheckpointPersistenceStatus struct { CycleExtentBytes uint64 // extent bytes the cycle in progress (or the latest) has written LastExtentWrite time.Time // when the flusher last wrote extent bytes; zero if never in this open CheckpointSteps CheckpointStepStatus // the checkpoint's step in progress and its per-step time, count and bytes - FencePunched uint64 // WAL fence bytes deallocated by hole punching in this open, counted after the fsync - FenceZeroed uint64 // WAL fence bytes written as zeros in this open (no hole punching), counted after the fsync + FenceZeroed uint64 // WAL fence bytes written as zeros in this open, counted per 4 MiB slice after its fsync FenceSkips uint64 // recovery fences skipped: the same range was fenced in this open with no WAL write since } @@ -80,7 +79,6 @@ func (s *WALStore) CheckpointPersistence() CheckpointPersistenceStatus { FlusherPhase: i.phaseName(), CycleExtentBytes: i.cycleExtentBytes.Load(), CheckpointSteps: s.ckpt.status(), - FencePunched: s.fencePunchedBytes.Load(), FenceZeroed: s.fenceZeroBytes.Load(), FenceSkips: s.fenceSkips.Load(), } diff --git a/seaweed-block/core/storage/fence_punch_linux.go b/seaweed-block/core/storage/fence_punch_linux.go deleted file mode 100644 index f6d2f3d2db..0000000000 --- a/seaweed-block/core/storage/fence_punch_linux.go +++ /dev/null @@ -1,21 +0,0 @@ -//go:build linux - -package storage - -import ( - "errors" - "os" - - "golang.org/x/sys/unix" -) - -// punchHole deallocates [off, off+n) of f, keeping its size: the range reads -// zeros afterwards. The caller fsyncs. -func punchHole(f *os.File, off, n int64) error { - return unix.Fallocate(int(f.Fd()), unix.FALLOC_FL_PUNCH_HOLE|unix.FALLOC_FL_KEEP_SIZE, off, n) -} - -// punchUnsupported reports a filesystem or kernel without hole punching. -func punchUnsupported(err error) bool { - return errors.Is(err, errFencePunchUnsupported) || errors.Is(err, unix.EOPNOTSUPP) || errors.Is(err, unix.ENOSYS) -} diff --git a/seaweed-block/core/storage/fence_punch_other.go b/seaweed-block/core/storage/fence_punch_other.go deleted file mode 100644 index bf7e1a013a..0000000000 --- a/seaweed-block/core/storage/fence_punch_other.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build !linux - -package storage - -import ( - "errors" - "os" -) - -// punchHole is unsupported off Linux: the fence writes zeros instead. -func punchHole(*os.File, int64, int64) error { return errFencePunchUnsupported } - -func punchUnsupported(err error) bool { return errors.Is(err, errFencePunchUnsupported) } diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index d41ccd601c..2f859fe2d8 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -90,7 +90,6 @@ type WALStore struct { lastStop atomic.Pointer[StoreStopPhases] closedCheckpoint atomic.Pointer[MapCheckpointPhases] ckpt checkpointSteps // the flusher checkpoint's per-step timing - fencePunchedBytes atomic.Uint64 // WAL fence bytes deallocated (hole punch), counted after the fsync fenceZeroBytes atomic.Uint64 // WAL fence bytes written as zeros, counted after the fsync fenceSkips atomic.Uint64 // fences skipped: the same range was fenced in this open with no WAL write since testDestructiveSnapshot func() // nil scheduling control, before any capture lock @@ -166,7 +165,8 @@ type WALStore struct { testAfterAdmit func() // testBeforeFileSync, when set, runs in syncFile just before fileSyncMu // is taken. Tests only. - testBeforeFileSync func() + testBeforeFileSync func() + testAfterFenceFsync func() // after each fence slice's fsync returns; tests only // Generations cover completed append attempts and recovery publication. walMutation atomic.Uint64 durableMutation atomic.Uint64 diff --git a/seaweed-block/core/storage/walstore_fence_punch_v3_test.go b/seaweed-block/core/storage/walstore_fence_punch_v3_test.go deleted file mode 100644 index 15af17293a..0000000000 --- a/seaweed-block/core/storage/walstore_fence_punch_v3_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package storage - -import ( - "bytes" - "os" - "path/filepath" - "runtime" - "testing" -) - -// The fence on both of its paths: hole punching (Linux, sparse) and zero -// writes (no punching). On each, records dropped by one recovery do not -// resurface after a second crash. -func TestWALStoreV3FenceBothPathsReplayNoStaleRecord(t *testing.T) { - for _, path := range []string{"punch", "zero"} { - t.Run(path, func(t *testing.T) { - if path == "zero" { - punchHoleFn = func(*os.File, int64, int64) error { return errFencePunchUnsupported } - t.Cleanup(func() { punchHoleFn = punchHole }) - } - for _, mode := range []WMode{WModeLagged, WModeStrict} { - if resurrectionSchedule(t, mode, false) { - t.Fatalf("%s fence, mode %d: a record dropped by recovery resurfaced after the second crash", path, mode) - } - } - }) - } -} - -// The fence counts its bytes after the fsync, by path; a repeated recovery -// with no WAL write since skips the fence (a new volume's second recovery), -// and one after a write fences again. -func TestWALStoreV3FenceCountsAndSkipsARepeat(t *testing.T) { - for _, path := range []string{"punch", "zero"} { - t.Run(path, func(t *testing.T) { - if path == "zero" { - punchHoleFn = func(*os.File, int64, int64) error { return errFencePunchUnsupported } - t.Cleanup(func() { punchHoleFn = punchHole }) - } - const walSize = 256 * 1024 - s, err := createMappedWALStoreV3ForTest(filepath.Join(t.TempDir(), "volume"), 64, 4096, walSize, WModeLagged, 4) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Recover(); err != nil { - t.Fatal(err) - } - first := s.CheckpointPersistence() // creation recovers once, then this Recover - fenced := first.FencePunched + first.FenceZeroed - if fenced != walSize { - t.Fatalf("a new store's first recovery fenced %d bytes, want the whole WAL %d: %+v", fenced, walSize, first) - } - punchExpected := path == "punch" && runtime.GOOS == "linux" - if punchExpected != (first.FencePunched == walSize) || (!punchExpected && first.FenceZeroed != walSize) { - t.Fatalf("%s path on %s: punched=%d zeroed=%d", path, runtime.GOOS, first.FencePunched, first.FenceZeroed) - } - if _, err := s.Recover(); err != nil { - t.Fatal(err) - } - second := s.CheckpointPersistence() - if second.FenceSkips != first.FenceSkips+1 || second.FencePunched+second.FenceZeroed != fenced { - t.Fatalf("a repeated recovery with no WAL write: skips=%d fenced %d -> %d", second.FenceSkips, fenced, second.FencePunched+second.FenceZeroed) - } - if _, err := s.Write(1, blk(1)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if _, err := s.Recover(); err != nil { - t.Fatal(err) - } - third := s.CheckpointPersistence() - if third.FenceSkips != second.FenceSkips || third.FencePunched+third.FenceZeroed <= fenced { - t.Fatalf("a recovery after a WAL write must fence again: %+v", third) - } - }) - } -} - -// A same-open recovery whose head did not move still fences when the WAL -// region was written since the last fence: here records 4 and 5 were -// appended and 4 is torn, so the head stays at 3 while 5 still sits behind -// it. Skipping that fence (the same range key) would let 5 resurface once a -// new record of 4's size refills its place and the store crashes. -func TestWALStoreV3SameOpenRecoveryAfterWritesStillFences(t *testing.T) { - s, path := newStoreV3(t, WModeLagged) - writeSynced(t, s, 1, 3) - if _, err := s.Recover(); err != nil { // fences at head 3 - t.Fatal(err) - } - for _, lba := range []uint32{4, 5} { - if _, err := s.Write(lba, blk(byte(lba))); err != nil { - t.Fatal(err) - } - } - damageOpenRecord(t, s, 4) - skips := s.CheckpointPersistence().FenceSkips - if _, err := s.Recover(); err != nil { // head 3 again: the same range key - t.Fatal(err) - } - skipped := s.CheckpointPersistence().FenceSkips != skips - if bytes.Equal(readV3(t, s, 5), blk(5)) { - t.Fatal("the recovery kept LSN 5 above the torn 4") - } - if _, err := s.Write(9, blk(0x99)); err != nil { // refills 4's place, same size - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - crashRecoveryHardeningStore(t, s) - r := mustReopenV3(t, path) - defer r.Close() - if bytes.Equal(readV3(t, r, 5), blk(5)) { - t.Fatalf("a record dropped by a same-open recovery resurfaced after the crash (its fence skipped: %v)", skipped) - } - if skipped { - t.Fatal("a recovery after WAL writes skipped its fence") - } -} - -// damageOpenRecord flips one payload byte of the WAL record carrying lsn -// through the open store's own file (no second handle, which a locked file -// refuses on Windows). -func damageOpenRecord(t *testing.T, s *WALStore, lsn uint64) { - t.Helper() - d := s.v3.pub.current() - r, err := scanWALV3(s.fd, d) - if err != nil { - t.Fatal(err) - } - for _, rec := range r.Records { - if rec.Entry.LSN != lsn { - continue - } - size := uint64(walEntryHeaderSizeV3 + len(rec.Entry.Data)) - off := int64(d.WALOffset+(rec.End-size)%d.WALSize) + walEntryPrefixSizeV3 + 100 - x := []byte{0} - if _, err := s.fd.ReadAt(x, off); err != nil { - t.Fatal(err) - } - x[0] ^= 0xFF - if _, err := s.fd.WriteAt(x, off); err != nil { - t.Fatal(err) - } - return - } - t.Fatalf("no WAL record with LSN %d", lsn) -} diff --git a/seaweed-block/core/storage/walstore_fence_slice_v3_test.go b/seaweed-block/core/storage/walstore_fence_slice_v3_test.go new file mode 100644 index 0000000000..674da839e3 --- /dev/null +++ b/seaweed-block/core/storage/walstore_fence_slice_v3_test.go @@ -0,0 +1,195 @@ +package storage + +import ( + "bytes" + "errors" + "path/filepath" + "testing" +) + +// The fence counts its bytes after the fsync; a repeated recovery with no +// WAL write since skips the fence (a new volume's second recovery), and one +// after a write fences again. +func TestWALStoreV3FenceCountsAndSkipsARepeat(t *testing.T) { + const walSize = 256 * 1024 + s, err := createMappedWALStoreV3ForTest(filepath.Join(t.TempDir(), "volume"), 64, 4096, walSize, WModeLagged, 4) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = s.Close() }) + s.DisableAutoFlushForRecoveryTest() + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + first := s.CheckpointPersistence() // creation recovers once, then this Recover + if first.FenceZeroed != walSize { + t.Fatalf("a new store fenced %d bytes, want the whole WAL %d once: %+v", first.FenceZeroed, walSize, first) + } + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + second := s.CheckpointPersistence() + if second.FenceSkips != first.FenceSkips+1 || second.FenceZeroed != first.FenceZeroed { + t.Fatalf("a repeated recovery with no WAL write: skips %d -> %d, zeroed %d -> %d", first.FenceSkips, second.FenceSkips, first.FenceZeroed, second.FenceZeroed) + } + if _, err := s.Write(1, blk(1)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + third := s.CheckpointPersistence() + if third.FenceSkips != second.FenceSkips || third.FenceZeroed <= second.FenceZeroed { + t.Fatalf("a recovery after a WAL write must fence again: %+v", third) + } +} + +// A same-open recovery whose head did not move still fences when the WAL +// region was written since the last fence: here records 4 and 5 were +// appended and 4 is torn, so the head stays at 3 while 5 still sits behind +// it. Skipping that fence (the same range key) would let 5 resurface once a +// new record of 4's size refills its place and the store crashes. +func TestWALStoreV3SameOpenRecoveryAfterWritesStillFences(t *testing.T) { + s, path := newStoreV3(t, WModeLagged) + writeSynced(t, s, 1, 3) + if _, err := s.Recover(); err != nil { // fences at head 3 + t.Fatal(err) + } + for _, lba := range []uint32{4, 5} { + if _, err := s.Write(lba, blk(byte(lba))); err != nil { + t.Fatal(err) + } + } + damageOpenRecord(t, s, 4) + skips := s.CheckpointPersistence().FenceSkips + if _, err := s.Recover(); err != nil { // head 3 again: the same range key + t.Fatal(err) + } + skipped := s.CheckpointPersistence().FenceSkips != skips + if bytes.Equal(readV3(t, s, 5), blk(5)) { + t.Fatal("the recovery kept LSN 5 above the torn 4") + } + if _, err := s.Write(9, blk(0x99)); err != nil { // refills 4's place, same size + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + crashRecoveryHardeningStore(t, s) + r := mustReopenV3(t, path) + defer r.Close() + if bytes.Equal(readV3(t, r, 5), blk(5)) { + t.Fatalf("a record dropped by a same-open recovery resurfaced after the crash (its fence skipped: %v)", skipped) + } + if skipped { + t.Fatal("a recovery after WAL writes skipped its fence") + } +} + +// The fence runs in 4 MiB slices: each is zero-written, fsynced, and only +// then counted and reported to the slice hook, in order. +func TestWALStoreV3FenceSlicesCountAfterEachSync(t *testing.T) { + const walSize = 2*fenceSliceBytes + 1<<20 + s, err := createMappedWALStoreV3ForTest(filepath.Join(t.TempDir(), "volume"), 4096, 4096, walSize, WModeLagged, 64) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = s.Close() }) + s.DisableAutoFlushForRecoveryTest() + writeSynced(t, s, 1, 1) // moves the head: the next recovery fences again + syncs := 0 // the fence's fsyncs that returned + s.testAfterFenceFsync = func() { syncs++ } + t.Cleanup(func() { s.testAfterFenceFsync = nil }) + var slices []uint64 + var syncsAt []int + before := s.CheckpointPersistence() + s.v3.fenceSliceHook = func(n uint64) { + counted := s.fenceZeroBytes.Load() - before.FenceZeroed // atomics: the hook runs under the store lock + var reported uint64 + for _, b := range slices { + reported += b + } + if counted != reported+n { + t.Errorf("slice %d reached the hook before it was counted: counted %d, reported %d + %d", len(slices), counted, reported, n) + } + slices = append(slices, n) + syncsAt = append(syncsAt, syncs) + } + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + fenced := s.CheckpointPersistence().FenceZeroed - before.FenceZeroed + var sum uint64 + for i, n := range slices { + if n == 0 || n > fenceSliceBytes { + t.Fatalf("slice %d is %d bytes", i, n) + } + if syncsAt[i] != i+1 { + t.Fatalf("slice %d reached the hook after %d fence fsyncs, want %d (one per slice; syncs %v)", i, syncsAt[i], i+1, syncsAt) + } + sum += n + } + if len(slices) < 3 || sum != fenced || fenced == 0 { + t.Fatalf("slices %v (sum %d), fenced %d: want at least 3 slices of at most 4 MiB covering the fence", slices, sum, fenced) + } +} + +// A slice that fails mid-fence (the store latched a fault after the first +// slice) stops the fence: only the slices whose fsync returned are counted, +// and the hook saw exactly those. +func TestWALStoreV3FenceSliceFailureCountsOnlyCompletedSlices(t *testing.T) { + const walSize = 2*fenceSliceBytes + 1<<20 + s, err := createMappedWALStoreV3ForTest(filepath.Join(t.TempDir(), "volume"), 4096, 4096, walSize, WModeLagged, 64) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = s.Close() }) + s.DisableAutoFlushForRecoveryTest() + writeSynced(t, s, 1, 1) + ioErr := errors.New("injected fence I/O fault") + hooked := 0 + s.v3.fenceSliceHook = func(uint64) { + if hooked++; hooked == 1 { + s.latchV3(ioErr) // the next slice's write/fsync step refuses + } + } + before := s.CheckpointPersistence() + if _, err := s.Recover(); !errors.Is(err, ioErr) { + t.Fatalf("recovery over a failing slice: %v", err) + } + if got := s.CheckpointPersistence().FenceZeroed - before.FenceZeroed; got != fenceSliceBytes || hooked != 1 { + t.Fatalf("after the 2nd slice failed: zeroed %d (want one slice, %d), hook calls %d", got, fenceSliceBytes, hooked) + } +} + +// damageOpenRecord flips one payload byte of the WAL record carrying lsn +// through the open store's own file (no second handle, which a locked file +// refuses on Windows). +func damageOpenRecord(t *testing.T, s *WALStore, lsn uint64) { + t.Helper() + d := s.v3.pub.current() + r, err := scanWALV3(s.fd, d) + if err != nil { + t.Fatal(err) + } + for _, rec := range r.Records { + if rec.Entry.LSN != lsn { + continue + } + size := uint64(walEntryHeaderSizeV3 + len(rec.Entry.Data)) + off := int64(d.WALOffset+(rec.End-size)%d.WALSize) + walEntryPrefixSizeV3 + 100 + x := []byte{0} + if _, err := s.fd.ReadAt(x, off); err != nil { + t.Fatal(err) + } + x[0] ^= 0xFF + if _, err := s.fd.WriteAt(x, off); err != nil { + t.Fatal(err) + } + return + } + t.Fatalf("no WAL record with LSN %d", lsn) +} diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index f49bfb0e87..81363682e4 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -28,6 +28,11 @@ import ( // install handles; raw extent writes and frontier jumps remain refused. type walStoreV3State struct { lastFence *fenceRecordV3 // the last completed fence in this open (recovery only) + // fenceSliceHook, when set, is told the bytes of each fence slice once + // that slice's fsync has returned (recovery progress); nil: none. It runs + // on the recovering goroutine, which holds the store lock: it must not + // take a store lock (or call anything that does, such as CheckpointLSN). + fenceSliceHook func(bytes uint64) // layoutFresh mirrors the descriptor's layout identity: set while the // local root is fresh, when no guest write may be acknowledged. layoutFresh atomic.Bool @@ -192,12 +197,10 @@ func probeWALStoreV3At(r io.ReaderAt) error { // tests. var testSkipFenceOnRecoverV3 bool -// punchHoleFn is punchHole; tests replace it to force the zero-write path. -var punchHoleFn = punchHole - -// errFencePunchUnsupported is a hole punch the platform cannot do: the -// fence writes zeros instead. -var errFencePunchUnsupported = errors.New("storage: hole punching unsupported") +// fenceSliceBytes is one fence slice: its zero writes and their fsync, so a +// recovery over a slow disk reports progress every slice and the journal +// never takes the whole WAL as one burst. +const fenceSliceBytes = 4 << 20 // fenceRecordV3 is the last completed fence: its range key, and the writer // and that writer's WAL write count when it completed. A fence with the same @@ -783,7 +786,11 @@ func (s *WALStore) recoverV3(ctx context.Context) (uint64, error) { } // fenceV3 zeroes exactly the fence ranges and fsyncs them through the leaf -// before any admission (DESIGN 6.6). A write error latches inside the leaf. +// before any admission (DESIGN 6.6), in slices of fenceSliceBytes: each is +// zero writes, then its own fsync, and only then counts and reaches +// fenceSliceHook. The WAL stays allocated (zero-filled, not punched), so the +// next lap's appends are overwrites. A write or fsync error latches inside +// the leaf. func (s *WALStore) fenceV3(E, floor, walSize uint64, sameNonce bool, walOffset uint64) error { ranges, err := fenceRangesV3(E, floor, walSize, sameNonce) if err != nil { @@ -809,51 +816,42 @@ func (s *WALStore) fenceV3(E, floor, walSize uint64, sameNonce bool, walOffset u rec.writesAtFence = rec.writer.writeCountV3() } } - mode, err := configuredAllocationMode() - if err != nil { - return err - } - punch := mode == "sparse" // a prezeroed store stays allocated: zero writes - var punched, zeroed uint64 - err = s.syncFile(func() error { - const chunk = 64 * 1024 - var zero []byte - for _, r := range ranges { - if punch { - perr := punchHoleFn(s.fd, int64(walOffset+r.Off), int64(r.Len)) - if perr == nil { - punched += r.Len - continue + zero := make([]byte, 64*1024) + for _, r := range ranges { + for done := uint64(0); done < r.Len; { + n := min(r.Len-done, fenceSliceBytes) + off := int64(walOffset + r.Off + done) + err := s.syncFile(func() error { + for w := uint64(0); w < n; { + k := min(n-w, uint64(len(zero))) + if _, err := s.fd.WriteAt(zero[:k], off+int64(w)); err != nil { + err = fmt.Errorf("storage: v3 drop fence: %w", err) + s.latchV3(err) + return err + } + w += k } - if !punchUnsupported(perr) { - perr = fmt.Errorf("storage: v3 drop fence: %w", perr) - s.latchV3(perr) - return perr - } - punch = false // the filesystem cannot punch: zeros from here on - } - if zero == nil { - zero = make([]byte, chunk) - } - for done := uint64(0); done < r.Len; { - n := min(r.Len-done, chunk) - if _, err := s.fd.WriteAt(zero[:n], int64(walOffset+r.Off+done)); err != nil { - err = fmt.Errorf("storage: v3 drop fence: %w", err) - s.latchV3(err) + return nil + }, func() error { + if err := s.fd.Sync(); err != nil { return err } - done += n + if h := s.testAfterFenceFsync; h != nil { + h() + } + return nil + }) + if err != nil { + return err } - zeroed += r.Len + // A slice counts only after its fsync. + s.fenceZeroBytes.Add(n) + if v != nil && v.fenceSliceHook != nil { + v.fenceSliceHook(n) + } + done += n } - return nil - }, s.fd.Sync) - if err != nil { - return err } - // The fence counts only after its fsync. - s.fencePunchedBytes.Add(punched) - s.fenceZeroBytes.Add(zeroed) if rec != nil { v.lastFence = rec } diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 9e17dd9ddd..15cc8d2c62 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -79,7 +79,7 @@ stateDiagram-v2 | — | CreateRefused | a chunk volume in create mode (no local store yet): before the provider is built, the geometry flags are compared with the volume record; they disagree, or the record is there but does not decode: exit 78; the filer failed the read: exit 75; nothing is created; an absent record keeps the create path; an existing store is never rechecked against the flags | `cmd/blockvolume/main.go` (create-mode check); `cmd/blockvolume/chunk_remote.go` `geometryFlagsRefusal` | `INV-VOL-GEOMETRY-FLAGS-RECORD-001` | | — | OpenRefused | the file's header carries a removed experimental engine's magic (smartwal, parallel-walstore): refused typed under every selector, read-only, never modified | `core/frontend/durable/provider.go` `verifyImplOnDisk` | `INV-OPEN-REMOVED-ENGINE-REFUSED-001` | | Opened | Recovering | the volume is open in the provider | `core/frontend/durable/provider.go` `RecoverVolume` | `INV-WAL-OPGATE-001`, `INV-RECOVERY-PROGRESS-WINDOW-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); a primary of a replicated line serves only when its own `--replication-ack` is the profile its assignment names (otherwise not Healthy, `NotReadyReason` naming both profiles, ahead of the backend's own refusal) | `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`; `core/host/volume/workspace_startup.go` `noteAckProfile` | `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-FENCE-PUNCH-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001`, `INV-PRIMARY-ACK-PROFILE-001`, `INV-ATTACH-ASSIGNMENT-BOUND-001`, `INV-LAYOUT-REMOTE-CAPABILITIES-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); a primary of a replicated line serves only when its own `--replication-ack` is the profile its assignment names (otherwise not Healthy, `NotReadyReason` naming both profiles, ahead of the backend's own refusal) | `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`; `core/host/volume/workspace_startup.go` `noteAckProfile` | `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-FENCE-SLICE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001`, `INV-PRIMARY-ACK-PROFILE-001`, `INV-ATTACH-ASSIGNMENT-BOUND-001`, `INV-LAYOUT-REMOTE-CAPABILITIES-001` | | Recovering | Serving (v1.1 upgrade, clean-stop seed) | the chunk layer attaches an unmarked store on the draft v1.1 format (lab builds only), after Recover and the storage claim: each whole local chunk is written Rebuilt all → U, Hash → HU, Commit → HP with HEAD's hash (a chunk HEAD does not name: the zero chunk's) only when all hold: a clean-stop proof (the HEAD the claim was built on was a committed, idle detach, `DetachedBy`), its claim id is the store's layout claim id, and its position is the store's synced position the pages are valid through; otherwise each whole local chunk is U (left to the compare pass); partial and absent chunks are classified alike in both; a marked store never seeds | `core/frontend/chunkstore/layout/start.go` `Start` (`ReportCleanStop`); `core/frontend/durable/provider_layout.go` `startLayoutRoot`; `core/storage/chunk_record_upgrade.go` `upgradeChunkRecordSeeded`, `seedsLineage`, `cleanStopHashes` | `INV-CHUNK-RECORD-SEED-001`, `INV-CHUNK-RECORD-UPGRADE-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` | @@ -722,8 +722,8 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-WAL-V3-W-CHECKPOINT-CLAMP-001` | A v3 checkpoint never exceeds the acknowledged W; entries the flusher wrote to the extent above the published checkpoint stay retry work, so a later Sync and flusher cycle advance the checkpoint and map coverage together. | M1 write lifecycle: InExtent → Checkpointed (v3) | `core/storage/walstore_v3.go` `WALStore.persistCheckpointV3`; `core/storage/walstore_map_checkpoint_v3.go` `WALStore.persistOwnedMapCheckpointV3`; `core/storage/flusher.go` `flushOnceInternal` | `TestWALStoreV3FlusherCheckpointIsClampedToTheAcknowledgedW`, `TestWALStoreV3FlusherWritesTheExtentButHoldsTheCheckpointUntilTheMap` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3_FlushedProgressRetriesAfterLaterSync` (`core/storage/walstore_flushed_progress_v3_test.go`) | — | STUB | | `INV-WAL-V3-W-SETWMODE-001` | `SetWMode` first syncs every write admitted before it under the old mode, then publishes the new mode while holding the v3 leader role, so no Sync batch acknowledges under a mode other than the descriptor's. | M1 write lifecycle: Appended → Synced (v3) | `core/storage/walstore_v3.go` `WALStore.SetWMode`, `WALStore.syncWALBatchV3Internal` | `TestWALStoreV3SetWModeWaitsForAHeldBatch`, `TestWALStoreV3NoBatchAcksUnderAStaleModeAfterSetWMode`, `TestWALStoreV3SetWModeCrashCases` (`core/storage/walstore_v3_test.go`) | — | DORMANT | | `INV-WAL-V3-W-RECOVER-STRADDLE-001` | No v3 W publication or Sync acknowledgement straddles a recovery: a Sync whose completion sees a changed recovery generation is refused, and recovery sets the acknowledged W to its recovered prefix R. | M1 Recovering → Serving | `core/storage/walstore_v3.go` `WALStore.recoverV3`, `WALStore.refreshW`, `WALStore.syncWALBatchV3Internal`; `core/storage/walstore.go` `WALStore.syncWithPhases` | `TestWALStoreV3SameOpenRecoverResetsTheAcknowledgedFrontier`, `TestWALStoreV3RecoverWaitsForABatchAckAndNothingRevivesTheCut`, `TestWALStoreV3OuterSyncCompletionIsRefusedAcrossARecovery`, `TestWALStoreV3RefreshDuringRecoverWaitsAndPublishesNothing` (`core/storage/walstore_v3_test.go`) | — | STUB | -| `INV-WAL-V3-FENCE-PUNCH-001` | The fence deallocates its range (a hole punch, which reads zeros) on a sparse store where the filesystem can, else writes zeros; a recovery skips the fence only when the same range was fenced and fsynced in this open with no WAL write since. | M1 Recovering → Serving (v3) | `core/storage/walstore_v3.go` `WALStore.fenceV3`; `core/storage/fence_punch_linux.go` `punchHole`; `core/storage/wal_io_v3.go` `writeCountV3` | `TestWALStoreV3FenceBothPathsReplayNoStaleRecord`, `TestWALStoreV3FenceCountsAndSkipsARepeat`, `TestWALStoreV3SameOpenRecoveryAfterWritesStillFences` (`core/storage/walstore_fence_punch_v3_test.go`) | `WALFormat` `NoResurrection` | ACTIVE | -| `INV-WAL-V3-FENCE-001` | Before any append after a v3 recovery, the store zeroes the logical WAL interval [E, floor + WALSize), floor being the both-slot same-nonce reuse floor, fsyncs it through the leaf, and only then publishes retainedHead = E. | M1 Recovering → Serving (v3) | `core/storage/walstore_v3.go` `WALStore.recoverV3`, `WALStore.fenceV3`; `core/storage/recovery_v3.go` `fenceRangesV3` | `TestWALStoreV3DroppedRecordsNeverResurfaceAfterASecondCrash`, `TestWALStoreV3NoFenceResurrectsInBothModes` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3FenceBothPathsReplayNoStaleRecord` (`core/storage/walstore_fence_punch_v3_test.go`) | `WALFormat` `NoResurrection` | STUB | +| `INV-WAL-V3-FENCE-SLICE-001` | The fence zero-writes its range in 4 MiB slices, each fsynced and only then counted as progress; a recovery skips the fence only when the same range was fenced and fsynced in this open by the same writer with no WAL write since. | M1 Recovering → Serving (v3) | `core/storage/walstore_v3.go` `WALStore.fenceV3`; `core/storage/wal_io_v3.go` `writeCountV3` | `TestWALStoreV3FenceCountsAndSkipsARepeat`, `TestWALStoreV3SameOpenRecoveryAfterWritesStillFences`, `TestWALStoreV3FenceSlicesCountAfterEachSync`, `TestWALStoreV3FenceSliceFailureCountsOnlyCompletedSlices` (`core/storage/walstore_fence_slice_v3_test.go`) | `WALFormat` `NoResurrection` | ACTIVE | +| `INV-WAL-V3-FENCE-001` | Before any append after a v3 recovery, the store zeroes the logical WAL interval [E, floor + WALSize), floor being the both-slot same-nonce reuse floor, fsyncs it through the leaf, and only then publishes retainedHead = E. | M1 Recovering → Serving (v3) | `core/storage/walstore_v3.go` `WALStore.recoverV3`, `WALStore.fenceV3`; `core/storage/recovery_v3.go` `fenceRangesV3` | `TestWALStoreV3DroppedRecordsNeverResurfaceAfterASecondCrash`, `TestWALStoreV3NoFenceResurrectsInBothModes` (`core/storage/walstore_v3_test.go`) | `WALFormat` `NoResurrection` | STUB | | `INV-WAL-V3-FENCE-EXACT-001` | The v3 drop fence changes only the bytes of [E, floor + WALSize) mapped modulo WALSize, in at most two ranges split at the physical wrap; no byte before E or outside the interval changes. | M1 Recovering → Serving (v3) | `core/storage/recovery_v3.go` `fenceRangesV3`; `core/storage/walstore_v3.go` `WALStore.fenceV3` | `TestWALStoreV3FenceTouchesNoByteBeforeTheHead`, `TestWALStoreV3RecoversAHistoryEndingAtTheLastRepresentableCursor` (`core/storage/walstore_v3_test.go`); `TestRecoveryV3FenceRangesAreExact` (`core/storage/recovery_v3_test.go`) | — | STUB | | `INV-WAL-V3-NO-RESURRECTION-001` | A WAL record dropped by one v3 recovery is never replayed by a later recovery, also after a second crash. | M1 Recovering → Serving (v3) | `core/storage/walstore_v3.go` `WALStore.recoverV3`, `WALStore.fenceV3`; `core/storage/wal_io_v3.go` `scanWALV3Accepted` | `TestWALStoreV3DroppedRecordsNeverResurfaceAfterASecondCrash`, `TestWALStoreV3NoFenceResurrectsInBothModes` (`core/storage/walstore_v3_test.go`) | `WALFormat` `NoResurrection` | STUB | | `INV-WAL-V3-RESET-001` | A v3 nonce/position reset is refused with `ErrResetNotPreserved`, writing nothing, unless the dirty map is empty and CheckpointLSN is at least every appended LSN (and so equals the acknowledged W). | M1 Serving → Serving (reset: no production caller; tests only) | `core/storage/reset_v3.go` `WALStore.resetIncarnationV3`, `descriptorPublisherV3.resetIncarnationV3` | `TestResetV3RefusesWhileUncheckpointed`, `TestResetV3RetainedButCheckpointedBytesDoNotBlock` (`core/storage/reset_v3_test.go`); `TestWALStoreV3ResetRefusesUncheckpointedOrUnacknowledgedData` (`core/storage/reset_store_v3_test.go`) | `WALFormat` reset (r4.5, pending) | DORMANT | diff --git a/seaweed-block/docs/releases/v1.1.md b/seaweed-block/docs/releases/v1.1.md index a7adccc05e..0a7e002f4c 100644 --- a/seaweed-block/docs/releases/v1.1.md +++ b/seaweed-block/docs/releases/v1.1.md @@ -29,10 +29,9 @@ These notes collect v1.1's changes as they land; v1.1 is not released. write waiting for WAL space now sees space freed every step rather than once per whole-WAL cycle. Status reports the reclaim progress in `CheckpointPersistence`: `ReclaimedBytes`, `BoundedCycles`, `FlusherPhase`, `CycleStarted`, `CycleExtentBytes` and `LastExtentWrite`. -- Recovery's WAL fence no longer writes the whole WAL as zeros on every open: on Linux, with the default sparse - allocation, it deallocates the range (a hole punch, which reads as zeros), falling back to zero writes where the - filesystem cannot; a new volume's second recovery skips the fence its first one just made. Status counts the bytes - in `CheckpointPersistence.FencePunched`, `FenceZeroed` and `FenceSkips`. +- Recovery's WAL fence writes its zeros in 4 MiB slices, each fsynced and counted as progress, instead of the whole + WAL as one burst; a new volume's second recovery skips the fence its first one just made (64 MiB at creation instead + of 128). Status counts the bytes in `CheckpointPersistence.FenceZeroed` and `FenceSkips`. ## Upgrade - With `--host-limit-dir` set, the limiter's `configuration.json` in that directory records the flags it was diff --git a/seaweed-block/docs/status-schema.md b/seaweed-block/docs/status-schema.md index 758823f346..bbe3579072 100644 --- a/seaweed-block/docs/status-schema.md +++ b/seaweed-block/docs/status-schema.md @@ -225,8 +225,7 @@ Durable store state of the served volume. Go type `volume.durableStatusBody`. | `Volumes[].CheckpointPersistence.CheckpointSteps.Nanos` | object | cumulative nanoseconds per step name | | `Volumes[].CheckpointPersistence.CheckpointSteps.Count` | object | how many times each step ran | | `Volumes[].CheckpointPersistence.CheckpointSteps.Bytes` | object | bytes each writing step wrote (map_write, slot_write) | -| `Volumes[].CheckpointPersistence.FencePunched` | uint64 | WAL fence bytes deallocated by hole punching in this open, counted after the fsync | -| `Volumes[].CheckpointPersistence.FenceZeroed` | uint64 | WAL fence bytes written as zeros in this open (no hole punching), counted after the fsync | +| `Volumes[].CheckpointPersistence.FenceZeroed` | uint64 | WAL fence bytes written as zeros in this open, counted per 4 MiB slice after its fsync | | `Volumes[].CheckpointPersistence.FenceSkips` | uint64 | recovery fences skipped: the same range was fenced in this open with no WAL write since | | `Volumes[].Chunk` | object | Chunk is the chunk layer's state and cut counters; walstore-chunk volumes only. | | `Volumes[].Chunk.CurrentCut` | object | active cut phase; absent when idle (omitted when empty) |