diff --git a/seaweed-block/core/storage/checkpoint_append_progress_v3_test.go b/seaweed-block/core/storage/checkpoint_append_progress_v3_test.go index 4ddf562718..246dbcd8ab 100644 --- a/seaweed-block/core/storage/checkpoint_append_progress_v3_test.go +++ b/seaweed-block/core/storage/checkpoint_append_progress_v3_test.go @@ -459,6 +459,11 @@ func TestCheckpointV3_AppendRolloverFaultRefusesHeldCandidate(t *testing.T) { // Max-LSN map entries may include unsynced writes above both cp and W. A // reused LSN can then set UNKNOWN without changing the prefix proof token. func TestCheckpointV3_SpeculativeMaximumAfterDroppedSuffix(t *testing.T) { + // v1.0 format: the test tears records 2 and 3 after a clean layer stop. On + // v1.1 the stop writes the chunk record's page that shows them, and a page + // is written only after the WAL is synced through what it shows, so they + // are durable and cannot tear. + v10Only(t) s, path := newMappedCheckpointStoreV3(t) remote := newFakeChunkRemote() layer := mustAttach(t, s, remote, ctConfig(1)) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index a356cb65d0..b75c09ffea 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -2389,14 +2389,11 @@ func (l *chunkLayerImpl) Close() error { unresolved := l.pending != nil l.stMu.Unlock() // A clean stop writes the record's dirty pages and its header: work in - // the pages changed, never in the volume's size. The WAL is synced first, - // so the final pages carry the final position (a page never claims more - // than the durable WAL). A failure is the stop's result, not a log line. + // the pages changed, never in the volume's size. Each page syncs the WAL + // through what it shows before it is written; the header claims no more + // than the WAL's last sync. A failure is the stop's result, not a log line. var finalErr error if sh := l.shadow; sh != nil && sh.v11 { - if _, err := l.s.Sync(); err != nil { - finalErr = errors.Join(finalErr, fmt.Errorf("storage: chunk record: sync before the final pages: %w", err)) - } if err := l.markFills(sh); err != nil { finalErr = errors.Join(finalErr, fmt.Errorf("storage: chunk record: final fill marks: %w", err)) } diff --git a/seaweed-block/core/storage/chunk_record_open.go b/seaweed-block/core/storage/chunk_record_open.go index 80bab31680..a4343deb98 100644 --- a/seaweed-block/core/storage/chunk_record_open.go +++ b/seaweed-block/core/storage/chunk_record_open.go @@ -181,6 +181,7 @@ func (l *chunkLayerImpl) loadChunkRecordV11(dir string, epoch uint64) (*chunkRec // A page is stamped with the position its content includes, and the WAL // is made durable through it before the page is written: a crash cannot // drop a write (or reuse its LSN) under a page that shows it. + rec.durable = s.v3.wack.Load rec.syncThrough = func(pos uint64) error { if s.v3.wack.Load() >= pos { return nil diff --git a/seaweed-block/core/storage/chunk_record_runtime.go b/seaweed-block/core/storage/chunk_record_runtime.go index 43d5134224..2515bcc789 100644 --- a/seaweed-block/core/storage/chunk_record_runtime.go +++ b/seaweed-block/core/storage/chunk_record_runtime.go @@ -114,6 +114,10 @@ type chunkRecordRuntime struct { // WAL is synced through it first, so a crash cannot drop a write a page // already shows. Called with pubMu held, outside mu. syncThrough func(pos uint64) error + // durable is the WAL's last completed sync (nil: no bound). The header's + // G claims no more than it: G carries no content to back, so it is + // lowered rather than synced for. + durable func() uint64 testBeforePageWrite func(seg uint64) // tests only: runs outside mu, under pubMu, before a page write testPageWriteErr func(seg uint64) error // tests only: a page write that fails @@ -363,16 +367,14 @@ func (r *chunkRecordRuntime) writeHeaderLocked() error { g = min(g, r.since[seg]) } } + if d := r.durable; d != nil { + g = min(g, d()) + } if g <= r.headerG { r.mu.Unlock() return nil } r.mu.Unlock() - if f := r.syncThrough; f != nil { - if err := f(g); err != nil { - return err - } - } if err := writeChunkRecordFile(r.dir, chunkRecordHeaderName, encodeChunkRecordHeader(chunkRecordHeader{Epoch: r.epoch, Chunks: r.chunks, G: g})); err != nil { return err }