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) + } +}