From 38077535e7730299b2bca1d91c64fcc0f9ee5794 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 03:22:46 -0800 Subject: [PATCH] test(storage): the record's header is not written ahead of the synced store Co-Authored-By: Claude Opus 5.5 --- .../core/storage/chunk_record_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/seaweed-block/core/storage/chunk_record_test.go b/seaweed-block/core/storage/chunk_record_test.go index c8bdc38c8e..069c226b09 100644 --- a/seaweed-block/core/storage/chunk_record_test.go +++ b/seaweed-block/core/storage/chunk_record_test.go @@ -314,3 +314,21 @@ func TestCompleteRecordPagePositions(t *testing.T) { t.Fatalf("page fields: %+v", p) } } + +// A write assigned but not synced is not durable: pages written through it +// are ahead of the synced store, and the header is refused. +func TestRecordHeaderIsNotWrittenAheadOfTheSyncedStore(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + writeSynced(t, s, 1, 2) + if _, err := s.Write(3, blk(3)); err != nil { // assigned, not synced + t.Fatal(err) + } + dir := chunkRecordDir(path) + chunks := recordPagesAt(t, s, dir, s.NextLSN()-1) + if err := completeChunkRecord(s, dir, 7, chunks); err == nil { + t.Fatal("a header was written through a write that is not durable") + } + if _, err := os.Stat(filepath.Join(dir, chunkRecordHeaderName)); !errors.Is(err, os.ErrNotExist) { + t.Fatalf("header exists ahead of the synced store: %v", err) + } +}