From 6ee693c3c242a2594676c0b2e8db05b1a3fee055 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 2 Dec 2026 11:50:04 -0800 Subject: [PATCH] Replacement-path test: the store's own file is fenced (seeded bytes read back zero) Co-Authored-By: Claude Opus 5.5 --- .../storage/walstore_fence_direct_v3_test.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/storage/walstore_fence_direct_v3_test.go b/seaweed-block/core/storage/walstore_fence_direct_v3_test.go index 3f9478c2e5..437d32c1b3 100644 --- a/seaweed-block/core/storage/walstore_fence_direct_v3_test.go +++ b/seaweed-block/core/storage/walstore_fence_direct_v3_test.go @@ -132,8 +132,9 @@ func TestWALStoreV3FenceSliceFlushFaultAfterADirectWriteIsNotCounted(t *testing. // 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 and the other file is -// never touched. The control is the test above (same file: O_DIRECT used). +// 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") @@ -153,6 +154,15 @@ func TestWALStoreV3FenceNeverWritesAFileThatReplacedTheStorePath(t *testing.T) { 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) } @@ -177,4 +187,11 @@ func TestWALStoreV3FenceNeverWritesAFileThatReplacedTheStorePath(t *testing.T) { 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") + } }