storage: v1.1 chunk record: the header's G is bounded by the WAL's last sync; no extra sync at a clean stop

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-30 20:07:43 -08:00
1 parent e9ad1ce991
commit 5e6eb7c79e
4 files changed
+16 -11

No files matched your search

@@ -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))
+3 -6
View File
@@ -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))
}
@@ -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
@@ -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
}