diff --git a/seaweed-block/core/storage/checkpoint_diagnostics.go b/seaweed-block/core/storage/checkpoint_diagnostics.go index e3c28d5839..f957232fc4 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics.go @@ -34,7 +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 - FenceZeroed uint64 // WAL fence bytes written as zeros in this open, counted per 4 MiB slice after its fsync + FenceZeroed uint64 // WAL fence bytes written as zeros in this open, counted per 1 MiB slice after its data sync FenceSkips uint64 // recovery fences skipped: the same range was fenced in this open with no WAL write since } diff --git a/seaweed-block/core/storage/fence_direct_linux.go b/seaweed-block/core/storage/fence_direct_linux.go new file mode 100644 index 0000000000..2a022ce8a5 --- /dev/null +++ b/seaweed-block/core/storage/fence_direct_linux.go @@ -0,0 +1,34 @@ +//go:build linux + +package storage + +import ( + "os" + "unsafe" + + "golang.org/x/sys/unix" +) + +// fenceDirectAlign is the offset, length and buffer alignment of a fence +// write through the page-cache-bypassing descriptor (4 KiB covers 512-byte +// and 4 KiB logical blocks). +const fenceDirectAlign = 4096 + +// openFenceDirect opens path for fence writes that bypass the page cache +// (O_DIRECT), so a fence slice never waits behind other writers' writeback. +// A filesystem that refuses O_DIRECT returns an error: the fence then writes +// through the page cache as before. +func openFenceDirect(path string) (*os.File, error) { + return os.OpenFile(path, os.O_WRONLY|unix.O_DIRECT, 0) +} + +// alignedZeros is n zero bytes whose start is fenceDirectAlign-aligned. +func alignedZeros(n int) []byte { + b := make([]byte, n+fenceDirectAlign) + skip := (fenceDirectAlign - int(uintptr(unsafe.Pointer(&b[0]))%fenceDirectAlign)) % fenceDirectAlign + return b[skip : skip+n] +} + +// fenceDataSync makes a fence slice durable: its data and the device cache +// (fdatasync; the WAL is preallocated, so no size metadata is due). +func fenceDataSync(f *os.File) error { return fdatasyncFile(f) } diff --git a/seaweed-block/core/storage/fence_direct_other.go b/seaweed-block/core/storage/fence_direct_other.go new file mode 100644 index 0000000000..aee50d1554 --- /dev/null +++ b/seaweed-block/core/storage/fence_direct_other.go @@ -0,0 +1,22 @@ +//go:build !linux + +package storage + +import ( + "errors" + "os" +) + +const fenceDirectAlign = 4096 + +// openFenceDirect is Linux only; elsewhere the fence writes through the page +// cache. +func openFenceDirect(string) (*os.File, error) { + return nil, errors.New("storage: O_DIRECT fence writes require Linux") +} + +func alignedZeros(n int) []byte { return make([]byte, n) } + +// fenceDataSync makes a fence slice durable (fsync where fdatasync is not +// available). +func fenceDataSync(f *os.File) error { return f.Sync() } diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index 6b24288997..8d215e5f7e 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -92,7 +92,8 @@ type WALStore struct { lastStop atomic.Pointer[StoreStopPhases] closedCheckpoint atomic.Pointer[MapCheckpointPhases] ckpt checkpointSteps // the flusher checkpoint's per-step timing - fenceZeroBytes atomic.Uint64 // WAL fence bytes written as zeros, counted after the fsync + fenceZeroBytes atomic.Uint64 // WAL fence bytes written as zeros, counted after the data sync + fenceDirectBytes atomic.Uint64 // of those, bytes written O_DIRECT (page cache bypassed) 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 testCloseSnapshot func() // nil in production; called without captureMu diff --git a/seaweed-block/core/storage/walstore_fence_direct_v3_test.go b/seaweed-block/core/storage/walstore_fence_direct_v3_test.go new file mode 100644 index 0000000000..437d32c1b3 --- /dev/null +++ b/seaweed-block/core/storage/walstore_fence_direct_v3_test.go @@ -0,0 +1,197 @@ +package storage + +import ( + "bytes" + "errors" + "os" + "path/filepath" + "runtime" + "testing" +) + +// directEligible says whether the filesystem holding dir takes an aligned +// O_DIRECT write (not only the open: some filesystems refuse at write +// time). On Linux an ineligible test directory fails the test, so the +// O_DIRECT path cannot pass by falling back unnoticed, unless +// SWBLOCK_TEST_NO_ODIRECT=1 names a filesystem known to refuse it. +func directEligible(t *testing.T, dir string) bool { + t.Helper() + if runtime.GOOS != "linux" { + return false + } + probe := filepath.Join(dir, "odirect-probe") + if err := os.WriteFile(probe, make([]byte, 64<<10), 0o644); err != nil { + t.Fatal(err) + } + defer os.Remove(probe) + ok := false + if f, err := openFenceDirect(probe); err == nil { + _, werr := f.WriteAt(alignedZeros(fenceDirectAlign), 0) + ok = werr == nil + _ = f.Close() + } + if !ok && os.Getenv("SWBLOCK_TEST_NO_ODIRECT") != "1" { + t.Fatalf("the test directory %s refuses an aligned O_DIRECT write: run on a filesystem that takes it, or set SWBLOCK_TEST_NO_ODIRECT=1", dir) + } + return ok +} + +// The fence runs in 1 MiB slices, and where the filesystem allows it each +// slice's aligned bytes bypass the page cache (O_DIRECT), so a slice never +// waits behind other writers' writeback. +func TestWALStoreV3FenceSlicesAreSmallAndBypassThePageCache(t *testing.T) { + dir := t.TempDir() + eligible := directEligible(t, dir) + path := filepath.Join(dir, "volume") + const walSize = 3<<20 + 1<<19 + s, err := createMappedWALStoreV3ForTest(path, 4096, 4096, walSize, WModeLagged, 64) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = s.Close() }) + s.DisableAutoFlushForRecoveryTest() + writeSynced(t, s, 1, 1) + var slices []uint64 + s.v3.fenceSliceHook = func(n uint64) { slices = append(slices, n) } + zeroed, direct := s.fenceZeroBytes.Load(), s.fenceDirectBytes.Load() + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + if len(slices) < 2 { + t.Fatalf("fence slices %v: want the WAL fenced in several 1 MiB slices", slices) + } + for i, n := range slices { + if n == 0 || n > 1<<20 { + t.Fatalf("slice %d is %d bytes, want at most 1 MiB", i, n) + } + } + gotZeroed, gotDirect := s.fenceZeroBytes.Load()-zeroed, s.fenceDirectBytes.Load()-direct + if eligible && (gotDirect == 0 || gotDirect > gotZeroed) { + t.Fatalf("fenced %d bytes, %d of them O_DIRECT: want the aligned bytes written O_DIRECT", gotZeroed, gotDirect) + } + if !eligible && gotDirect != 0 { + t.Fatalf("%d bytes written O_DIRECT where the filesystem refuses it", gotDirect) + } +} + +// A slice counts only once it is durable: a fault of the device flush after +// a slice's O_DIRECT write leaves it uncounted (no counter, no hook, no +// completed fence), latches the store, and the next open's recovery fences +// it again. +func TestWALStoreV3FenceSliceFlushFaultAfterADirectWriteIsNotCounted(t *testing.T) { + dir := t.TempDir() + eligible := directEligible(t, dir) + path := filepath.Join(dir, "volume") + const walSize = 3<<20 + 1<<19 + s, err := createMappedWALStoreV3ForTest(path, 4096, 4096, walSize, WModeLagged, 64) + if err != nil { + t.Fatal(err) + } + closed := false + t.Cleanup(func() { + if !closed { + _ = s.Close() + } + }) + s.DisableAutoFlushForRecoveryTest() + writeSynced(t, s, 1, 1) + flushErr := errors.New("injected device flush failure") + zeroed, direct := s.fenceZeroBytes.Load(), s.fenceDirectBytes.Load() + var writtenDirect uint64 + s.testBeforeFenceFsync = func() error { + writtenDirect = s.fenceDirectBytes.Load() - direct // the slice is written, not yet flushed + return flushErr + } + hooked := 0 + s.v3.fenceSliceHook = func(uint64) { hooked++ } + lastBefore := s.v3.lastFence + if _, err := s.Recover(); !errors.Is(err, flushErr) { + t.Fatalf("recovery over a failing slice flush: %v", err) + } + if eligible && writtenDirect == 0 { + t.Fatal("the faulted slice was not written O_DIRECT") + } + if got := s.fenceZeroBytes.Load() - zeroed; got != 0 || hooked != 0 { + t.Fatalf("a slice whose flush failed was counted: zeroed %d, hook calls %d", got, hooked) + } + if s.v3.lastFence != lastBefore { + t.Fatal("a fence whose slice flush failed was recorded as completed") + } + if s.stickyIOFault() == nil { + t.Fatal("a failed slice flush did not latch the store") + } + s.testBeforeFenceFsync = nil + closed = true + _ = s.Close() // latched: the close may report the fault + r := mustReopenV3(t, path) + defer r.Close() + if got := r.CheckpointPersistence().FenceZeroed; got < 1<<20 { + t.Fatalf("the reopened store's recovery fenced %d bytes, want the unflushed slice fenced again", got) + } +} + +// The O_DIRECT descriptor is used only on the very file the store holds: if +// the store's path now names another file (replaced after the open), the +// fence writes through the store's own descriptor (bytes seeded in the +// fence interval read back as zeros there) and the other file is never +// touched. The control is the test above (same file: O_DIRECT used). +func TestWALStoreV3FenceNeverWritesAFileThatReplacedTheStorePath(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("the O_DIRECT path is Linux only; elsewhere the fence never reopens the path") + } + dir := t.TempDir() + directEligible(t, dir) + path := filepath.Join(dir, "volume") + const walSize = 3<<20 + 1<<19 + s, err := createMappedWALStoreV3ForTest(path, 4096, 4096, walSize, WModeLagged, 64) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = s.Close() }) + s.DisableAutoFlushForRecoveryTest() + writeSynced(t, s, 1, 1) + info, err := s.fd.Stat() + if err != nil { + t.Fatal(err) + } + // Seed non-zero bytes in the WAL's last 64 KiB, inside the fence interval + // [E, floor + WALSize): the fence must zero them in the store's own file. + seedOff := int64(walOffsetV3 + walSize - 64<<10) + if _, err := s.fd.WriteAt(bytes.Repeat([]byte{0xCD}, 64<<10), seedOff); err != nil { + t.Fatal(err) + } + if err := s.fd.Sync(); err != nil { + t.Fatal(err) + } + if err := os.Rename(path, path+".held"); err != nil { // the store keeps its descriptor + t.Fatal(err) + } + foreign := bytes.Repeat([]byte{0xAB}, int(info.Size())) + if err := os.WriteFile(path, foreign, 0o644); err != nil { + t.Fatal(err) + } + zeroed, direct := s.fenceZeroBytes.Load(), s.fenceDirectBytes.Load() + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + if got := s.fenceDirectBytes.Load() - direct; got != 0 { + t.Fatalf("%d fence bytes written O_DIRECT through a path that names another file", got) + } + if s.fenceZeroBytes.Load()-zeroed == 0 { + t.Fatal("the fence did not run on the store's own descriptor") + } + after, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(after, foreign) { + t.Fatal("the fence wrote the file that replaced the store's path") + } + held, err := os.ReadFile(path + ".held") // the store's own file, renamed + if err != nil { + t.Fatal(err) + } + if got := held[seedOff : seedOff+64<<10]; !bytes.Equal(got, make([]byte, 64<<10)) { + t.Fatal("the store's own file was not fenced: the seeded bytes in the fence interval are not zero") + } +} diff --git a/seaweed-block/core/storage/walstore_fence_slice_v3_test.go b/seaweed-block/core/storage/walstore_fence_slice_v3_test.go index bee0a2a436..d3077a2dbc 100644 --- a/seaweed-block/core/storage/walstore_fence_slice_v3_test.go +++ b/seaweed-block/core/storage/walstore_fence_slice_v3_test.go @@ -89,7 +89,7 @@ func TestWALStoreV3SameOpenRecoveryAfterWritesStillFences(t *testing.T) { } } -// The fence runs in 4 MiB slices: each is zero-written, fsynced, and only +// The fence runs in 1 MiB slices: each is zero-written, synced, and only // then counted and reported to the slice hook, in order. func TestWALStoreV3FenceSlicesCountAfterEachSync(t *testing.T) { const walSize = 2*fenceSliceBytes + 1<<20 diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index 5b933025c6..ef1d4ca250 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -11,6 +11,7 @@ import ( "os" "sync" "sync/atomic" + "syscall" "time" "unicode/utf8" ) @@ -197,10 +198,10 @@ func probeWALStoreV3At(r io.ReaderAt) error { // tests. var testSkipFenceOnRecoverV3 bool -// 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 +// fenceSliceBytes is one fence slice: its zero writes and their data sync, +// so a recovery over a slow disk reports progress every slice and the +// journal never takes the whole WAL as one burst. +const fenceSliceBytes = 1 << 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 @@ -801,12 +802,15 @@ func (s *WALStore) recoverV3(ctx context.Context) (uint64, error) { return s.syncedLSN, nil } -// fenceV3 zeroes exactly the fence ranges and fsyncs them through the leaf +// fenceV3 zeroes exactly the fence ranges and syncs them through 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. +// zero writes, then its own data sync (fdatasync: data and device cache), +// and only then counts and reaches fenceSliceHook. The aligned part of each +// slice is written O_DIRECT where the filesystem allows it, so the slice +// never waits behind other writers' page writeback; the rest, and every +// slice where O_DIRECT is refused, goes through the page cache. The WAL +// stays allocated (zero-filled, not punched), so the next lap's appends are +// overwrites. A write or sync 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 { @@ -832,36 +836,24 @@ func (s *WALStore) fenceV3(E, floor, walSize uint64, sameNonce bool, walOffset u rec.writesAtFence = rec.writer.writeCountV3() } } - zero := make([]byte, 64*1024) + zero := alignedZeros(64 * 1024) + direct := s.openFenceDirectV3() // nil: every fence write goes through the page cache + if direct != nil { + defer func() { _ = direct.Close() }() + } 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))) - var err error - if h := s.testBeforeFenceWrite; h != nil && w == 0 { - err = h() // an injected write error takes the real one's path - } - if err == nil { - _, err = s.fd.WriteAt(zero[:k], off+int64(w)) - } - if err != nil { - err = fmt.Errorf("storage: v3 drop fence: %w", err) - s.latchV3(err) - return err - } - w += k - } - return nil + return s.writeFenceSliceV3(direct, zero, off, int64(n)) }, func() error { if h := s.testBeforeFenceFsync; h != nil { if err := h(); err != nil { return err } } - if err := s.fd.Sync(); err != nil { + if err := fenceDataSync(s.fd); err != nil { return err } if h := s.testAfterFenceFsync; h != nil { @@ -872,7 +864,7 @@ func (s *WALStore) fenceV3(E, floor, walSize uint64, sameNonce bool, walOffset u if err != nil { return err } - // A slice counts only after its fsync. + // A slice counts only after its data sync. s.fenceZeroBytes.Add(n) if v != nil && v.fenceSliceHook != nil { v.fenceSliceHook(n) @@ -886,6 +878,76 @@ func (s *WALStore) fenceV3(E, floor, walSize uint64, sameNonce bool, walOffset u return nil } +// openFenceDirectV3 opens the store's file again for O_DIRECT fence writes, +// or returns nil (the page-cache path). The descriptor is used only when it +// is the very file the store holds open (same device and inode as s.fd): a +// path that was replaced or that resolves elsewhere is never written. +func (s *WALStore) openFenceDirectV3() *os.File { + if s.path == "" || s.fd == nil { + return nil + } + f, err := openFenceDirect(s.path) + if err != nil { + return nil + } + owned, err1 := s.fd.Stat() + opened, err2 := f.Stat() + if err1 != nil || err2 != nil || !os.SameFile(owned, opened) { + _ = f.Close() + return nil + } + return f +} + +// writeFenceSliceV3 writes zeros over [off, off+n): the fenceDirectAlign- +// aligned middle through direct (O_DIRECT) when it is open, the unaligned +// edges, or all of it without direct, through the page cache. A direct +// write the filesystem refuses (EINVAL) is redone through the page cache. +// Any other write error latches the store. +func (s *WALStore) writeFenceSliceV3(direct *os.File, zero []byte, off, n int64) error { + end := off + n + lo, hi := end, end // [lo, hi) goes direct; empty without direct + if direct != nil { + a := int64(fenceDirectAlign) + if l, h := (off+a-1)/a*a, end/a*a; l < h { + lo, hi = l, h + } + } + first := true + write := func(f *os.File, from, to int64) error { + for p := from; p < to; { + k := min(to-p, int64(len(zero))) + var err error + if h := s.testBeforeFenceWrite; h != nil && first { + err = h() // an injected write error takes the real one's path + } + first = false + if err == nil { + _, err = f.WriteAt(zero[:k], p) + } + if err != nil && f != s.fd && errors.Is(err, syscall.EINVAL) { + _, err = s.fd.WriteAt(zero[:k], p) // O_DIRECT refused here + } else if err == nil && f != s.fd { + s.fenceDirectBytes.Add(uint64(k)) + } + if err != nil { + err = fmt.Errorf("storage: v3 drop fence: %w", err) + s.latchV3(err) + return err + } + p += k + } + return nil + } + if err := write(s.fd, off, lo); err != nil { + return err + } + if err := write(direct, lo, hi); err != nil { + return err + } + return write(s.fd, hi, end) +} + // appendWriteV3 is the v3 body of Write's append, under s.mu. DurableLSN is // the acknowledged W at append time; a pwrite failure latches the store. // budget (nil = none) is the guest command's budget: checked after a diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 1705c356d2..322ac00519 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -699,7 +699,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-REBUILD-SNAPSHOT-COMPLETE-001` | A rebuild snapshot returns all readable nonzero blocks or an error, never a partial success. The sender propagates snapshot failure before shipping blocks or RebuildDone. | M3 NeedsRebuild (base enumeration) | `core/storage/logical_storage.go` `AllBlocks`; storage implementations; `core/transport/rebuild_sender.go` `doRebuild` | `TestChunkHydration_SnapshotFailsOnReadError`, `TestRebuildSnapshotErrorNeverShipsPartialImage` | Existing fail-closed recovery contract; error propagation only | ACTIVE | | `INV-WAL-SYNCED-RECOVERED-001` | After a crash without media corruption, `Recover` returns every write that a `Sync` acknowledged. | M1 Recovering → Serving | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover` | `TestNativeReplacementTornWrapKeepsAcknowledgedSuffix` (`core/storage/legacy_replacement_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | | `INV-RECOVERY-PROGRESS-WINDOW-001` | Startup reports recovery_stalled only after a window without a new fixed-order phase/count frontier; repeated preparation cannot renew it. Progress never grants readiness or ownership. | M1 Recovering | `core/host/volume/recovery_watchdog.go`; `cmd/blockvolume/durable_startup.go`; `core/storage/recovery_progress.go` | `TestDurableStartup_LocalRecoveryWorkIsOutsideFixedDeadline` (`cmd/blockvolume/durable_startup_budget_test.go`); `TestRecoveryProgress_CountingEntriesOutliveTheTotalWindow`, `TestRecoveryProgress_RepeatedAttachPreparationDoesNotRenew` (`core/host/volume/recovery_progress_test.go`); attach: `TestAttachReportsItsVolumeSizedLocalWork`, `TestAttachReportsTheCreatedThisStartScan`, `TestAttachProgressFlushesSlowWorkAboutEverySecond` (`core/storage/chunk_attach_progress_test.go`), `TestAttachProgressCountsEachAttemptFromZero`, `TestAttachRemoteCallsCarryTheirOwnBound`, `TestAttachManifestReadCarriesThePerFetchRule` (`core/frontend/durable/attach_progress_test.go`), `TestAttachManifestReadBoundsEachFetch` (`core/frontend/chunkstore/layout_attach_fetch_test.go`) | — (joint recovery+attach Linux qualification: 7495 PASS, 0 FAIL, race x5 including the attach tests); C.L | ACTIVE | -| `INV-RECOVERY-SIZED-STEP-SLICES-001` | A sized startup step (a new store's prezero, the WAL fence) reports its bytes as recovery progress only after their sync, prezero one 4 MiB slice at a time. | M1 Recovering | `core/storage/recovery_progress.go` `syncedSlices`; `core/storage/data_sync.go` `prezeroNewStore`; `core/storage/walstore_v3.go` `fenceV3` | `TestSyncedSlicesCountOnlySyncedSlices`, `TestPrezeroReportsEachSyncedSlice`, `TestRecoveryReportsTheSyncedFence`, `TestRecoveryFenceHeldSyncReportsAfterRelease`, `TestPrezeroReportsAfterEachSyncAndStopsAtAFailedOne`, `TestCreateRecoveryReportsTheFenceThroughTheOptions` (`core/storage/recovery_create_progress_test.go`); `TestRecoveryStalled_CreateSlicesRenewTheWindow` (`core/host/volume/recovery_authority_wait_test.go`) | — | ACTIVE | +| `INV-RECOVERY-SIZED-STEP-SLICES-001` | A sized startup step (a new store's prezero, the WAL fence) reports its bytes as recovery progress only after their sync, prezero one 1 MiB slice at a time. | M1 Recovering | `core/storage/recovery_progress.go` `syncedSlices`; `core/storage/data_sync.go` `prezeroNewStore`; `core/storage/walstore_v3.go` `fenceV3` | `TestSyncedSlicesCountOnlySyncedSlices`, `TestPrezeroReportsEachSyncedSlice`, `TestRecoveryReportsTheSyncedFence`, `TestRecoveryFenceHeldSyncReportsAfterRelease`, `TestPrezeroReportsAfterEachSyncAndStopsAtAFailedOne`, `TestCreateRecoveryReportsTheFenceThroughTheOptions` (`core/storage/recovery_create_progress_test.go`); `TestRecoveryStalled_CreateSlicesRenewTheWindow` (`core/host/volume/recovery_authority_wait_test.go`) | — | ACTIVE | | `INV-RECOVERY-AUTHORITY-WAIT-PAUSE-001` | The recovery_stalled window pauses while a recovered volume awaits master authority and restarts at the grant, before local attach work; silence that filled the window before the wait is latched at its start. The master bounds the wait. | M1 Recovering | `core/host/volume/recovery_watchdog.go` `ReportAuthorityWait`; `core/frontend/durable/provider_chunk.go` `chunkAuthorityWait` | `TestRecoveryStalled_FullAuthorityWaitDoesNotStall`, `TestRecoveryStalled_SilentStepBeyondTheWindowIsCaught`, `TestRecoveryStalled_SilenceBeforeTheWaitIsLatchedAtItsStart`, `TestRecoveryStalled_HeldAttachAfterTheGrantStalls` (`core/host/volume/recovery_authority_wait_test.go`); `TestAuthorityWaitIsReportedAndShowsItsGap`, `TestAuthorityWaitEndsAtTheGrantBeforeTheAttach`, `TestAuthorityLostAfterAGrantPausesAgain` (`core/frontend/durable/authority_wait_hook_test.go`) | — | ACTIVE | | `INV-OPEN-REMOVED-ENGINE-REFUSED-001` | A volume whose header carries a removed experimental engine's magic (smartwal `SWAW`; parallel-walstore `SWPW` at offset 0 or 4096) is refused typed (copy the data to a walstore volume with v1.0.x first) under every selector, read-only and never modified. | M1 [*] → OpenRefused | `core/frontend/durable/provider.go` `verifyImplOnDisk` | `TestDurableProvider_RefusesRemovedEngineVolumes` (byte-identical file after each refusal; `core/frontend/durable/provider_auto_impl_test.go`); `TestWALStoreChunk_SelectorRules` (`core/frontend/durable/provider_chunk_test.go`) | — | ACTIVE | | `INV-OPEN-REMOVED-ENGINE-NAME-REFUSED-001` | A selector naming a removed experimental engine (`smartwal`, `parallel-walstore`) is refused typed, with the same advice, by blockvolume, the provider and the Kubernetes launcher before any volume is touched. | M1 [*] → OpenRefused | `core/frontend/durable/provider.go` `RemovedEngineName`, `NewDurableProvider`; `cmd/blockvolume/main.go` `parseFlags`; `core/launcher/k8s_renderer.go` | `TestDurableProvider_RefusesRemovedEngineNames` (`core/frontend/durable/provider_auto_impl_test.go`); `TestBlockvolumeRefusesRemovedEngineNames` (`cmd/blockvolume/durable_impl_default_test.go`); `TestK8sRendererRefusesRemovedEngines` (`core/launcher/k8s_renderer_test.go`) | — | ACTIVE | @@ -825,7 +825,7 @@ 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-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-SLICE-001` | The fence zero-writes its range in 1 MiB slices, aligned bytes O_DIRECT where allowed, each fdatasynced 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`); `TestWALStoreV3FenceSlicesAreSmallAndBypassThePageCache`, `TestWALStoreV3FenceSliceFlushFaultAfterADirectWriteIsNotCounted`, `TestWALStoreV3FenceNeverWritesAFileThatReplacedTheStorePath` (`core/storage/walstore_fence_direct_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 | diff --git a/seaweed-block/docs/releases/v1.1.md b/seaweed-block/docs/releases/v1.1.md index 113a7718ae..ebc27d3d5b 100644 --- a/seaweed-block/docs/releases/v1.1.md +++ b/seaweed-block/docs/releases/v1.1.md @@ -33,8 +33,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 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 +- Recovery's WAL fence writes its zeros in 1 MiB slices, each made durable (fdatasync) before it counts as progress, + instead of the whole WAL as one burst; on Linux each slice bypasses the page cache (O_DIRECT, where the filesystem + allows it), so a slice does not wait behind other writers' writeback on a shared disk; 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 diff --git a/seaweed-block/docs/status-schema.md b/seaweed-block/docs/status-schema.md index 8c99afccc3..febb82e8b5 100644 --- a/seaweed-block/docs/status-schema.md +++ b/seaweed-block/docs/status-schema.md @@ -244,7 +244,7 @@ Durable store state of the served volume. Go type `volume.durableStatusBody`. | `Volumes[].CheckpointPersistence.CheckpointSteps.Nanos{}` | uint64 | cumulative nanoseconds per step name (omitted when empty) | | `Volumes[].CheckpointPersistence.CheckpointSteps.Count{}` | uint64 | how many times each step ran (omitted when empty) | | `Volumes[].CheckpointPersistence.CheckpointSteps.Bytes{}` | uint64 | bytes each writing step wrote (map_write: the owned map file; slot_write: the store file's descriptor slots) (omitted when empty) | -| `Volumes[].CheckpointPersistence.FenceZeroed` | uint64 | WAL fence bytes written as zeros in this open, counted per 4 MiB slice after its fsync | +| `Volumes[].CheckpointPersistence.FenceZeroed` | uint64 | WAL fence bytes written as zeros in this open, counted per 1 MiB slice after its data sync | | `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) | diff --git a/seaweed-block/docs/volume-lifecycle.md b/seaweed-block/docs/volume-lifecycle.md index 331d3c970a..c2e3777b1b 100644 --- a/seaweed-block/docs/volume-lifecycle.md +++ b/seaweed-block/docs/volume-lifecycle.md @@ -341,7 +341,7 @@ without the move does not serve: a sealed HEAD stays sealed for its own epoch. At startup, `--recover-timeout` (default `30s`) is an inactivity window shared by local recovery and attachment, not a total startup deadline. Newly completed WAL records and chunk-map entries advance its progress frontier, and so does -each synced 4 MiB slice of a WAL fence or a new store's prezero. Repeating the +each synced 1 MiB slice of a WAL fence or a new store's prezero. Repeating the same preparation during a retry does not renew it. The window pauses while the recovered volume waits for master authority (`AwaitingAuthority` and `AuthorityGap` in the durable status): the master bounds that wait. A full window without new