fix: a flusher cycle with no synced entry is idle; test the pressure path

The flusher keeps only the snapshot's synced entries before its empty
check, so a cycle over unsynced writes alone writes no extent and makes
no fsync (it fsynced an empty batch before). A new test drives a guest
that never flushes: below the WAL pressure threshold nothing reaches the
extent; past it, the flusher's pressure sync makes the writes durable and
the same cycle writes every block's newest bytes and advances the
checkpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-23 21:26:23 -08:00
1 parent c921de54e0
commit 9ffae70bf9
3 files changed
+76 -5

No files matched your search

+9 -4
View File
@@ -187,9 +187,17 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) {
// record is durable reach the extent. An entry above the synced WAL
// frontier stays dirty for a later cycle: written now, a power loss
// could keep its extent page and lose its record, leaving extent bytes
// that no recovered record or map entry accounts for.
// that no recovered record or map entry accounts for. A cycle with no
// synced entry is idle: no extent write and no fsync.
synced := store.v3.wack.Load()
store.mu.RUnlock()
kept := entries[:0]
for _, e := range entries {
if e.LSN <= synced {
kept = append(kept, e)
}
}
entries = kept
if len(entries) == 0 {
return store.refreshW() // the mode-C idle refresh (DESIGN 6.2)
@@ -224,9 +232,6 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) {
recordCache := &flushRecordCacheV3{recoveryGen: recoveryGen}
for _, e := range entries {
if e.LSN > synced {
continue
}
data, _, err := f.readDirtyRecordV3Cached(e, recordCache)
if err != nil {
return err
@@ -0,0 +1,66 @@
package storage
import (
"bytes"
"path/filepath"
"testing"
)
// A guest that never flushes: below the WAL pressure threshold its writes
// are not synced, so the flusher writes none of their extents
// (INV-WAL-V3-WRITE-AHEAD-001) and the checkpoint stays; once the WAL is
// past the threshold, the flusher's pressure sync makes them durable and the
// same cycle writes every block's newest bytes to the extent and advances
// the checkpoint. The data never waits for a guest flush that does not come.
func TestFlusherWriteAheadNeverFlushingGuestReachesExtentAtPressure(t *testing.T) {
for _, mode := range []WMode{WModeStrict, WModeLagged} {
t.Run(map[WMode]string{WModeStrict: "A", WModeLagged: "C"}[mode], func(t *testing.T) {
s, err := createMappedWALStoreV3ForTest(filepath.Join(t.TempDir(), "pressure"), 64, 4096, 64*1024, mode, 4)
if err != nil {
t.Fatal(err)
}
s.DisableAutoFlushForRecoveryTest()
t.Cleanup(func() { _ = s.Close() })
expected := map[uint32][]byte{}
write := func(lba uint32) {
t.Helper()
data := bytes.Repeat([]byte{byte(s.NextLSN())}, 4096)
if _, err := s.Write(lba, data); err != nil {
t.Fatal(err)
}
expected[lba] = data
}
extent := func(lba uint32) []byte {
t.Helper()
b, err := s.readFromExtent(lba)
if err != nil {
t.Fatal(err)
}
return b
}
write(0)
if err := s.flusher.flushOnce(); err != nil {
t.Fatal(err)
}
if bytes.Equal(extent(0), expected[0]) || s.CheckpointLSN() != 0 {
t.Fatalf("below pressure: an unsynced write reached the extent (checkpoint %d)", s.CheckpointLSN())
}
for lba := uint32(1); s.walUsedFraction() < 0.72; lba = (lba + 1) % 64 {
write(lba)
}
if err := s.flusher.flushOnce(); err != nil {
t.Fatal(err)
}
for lba, want := range expected {
if !bytes.Equal(extent(lba), want) {
t.Fatalf("after the pressure sync: block %d's extent does not hold its newest write", lba)
}
}
if s.CheckpointLSN() == 0 {
t.Fatal("after the pressure sync: the checkpoint did not advance")
}
})
}
}
+1 -1
View File
@@ -529,7 +529,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w
| `INV-WAL-V3-ACTIVATION-PROVIDER-001` | The durable provider's capture, HEAD restore and status paths probe, open and create volumes through the public v3 selectors (`ProbeWALStoreV3`, `OpenWALStore`, `CreateWALStoreWithOptions`). | M1 open/create/readonly | `core/frontend/durable/provider.go` `openOrCreate` | `TestDurableProviderV3_HEADRestorePreservesRemoteImageAndNextLSN`, `TestDurableProviderV3_StatusTracksRecoverSyncAndCapture` (`core/frontend/durable/provider_format_v3_test.go`) | — | ACTIVE |
| `INV-WAL-V3-LEGACY-FIXTURE-ISOLATION-001` | No default-build production code calls a legacy fixture constructor, and no legacy fixture is in the transitive import closure of the production storage packages. | M1 open/create/readonly | build layout: legacy fixtures outside the default production import closure | `TestLegacyFixtureIsolation` (`core/storage/legacy_fixture_isolation_test.go`) | — | ACTIVE |
| `INV-WAL-V3-FLUSH-PROFILE-001` | Native flusher header/full-record/decode counters describe actual reads and validation; I/O failure is distinct from validation failure and only successfully materialized blocks count validated. | M1 checkpoint instrumentation | `walstore_v3.go` `readWholeRecordProfiledV3`, `readDirtyRecordV3` | `TestFlusherV3ProfileCountsRealRecordStages` | Observability; no durability transition change | ACTIVE |
| `INV-WAL-V3-WRITE-AHEAD-001` | No extent byte reaches the disk before its WAL record is durable: the flusher writes an extent only from dirty entries at or below the synced (acknowledged) WAL frontier; Recover and the install log fsync their records before raising it. | M1 Serving (flusher extent write) | `core/storage/flusher.go` `flushOnceInternal`; `walstore_v3.go` `recoverV3` (descriptor publish fsync before `wack`); `install_log_v3.go` | `TestRedCrashKeepingAnUnsyncedExtentWriteLeavesLocalAndHEADApart` (`core/storage/chunk_u1_reorder_test.go`) | — | ACTIVE |
| `INV-WAL-V3-WRITE-AHEAD-001` | No extent byte reaches the disk before its WAL record is durable: the flusher writes an extent only from dirty entries at or below the synced (acknowledged) WAL frontier; Recover and the install log fsync their records before raising it. | M1 Serving (flusher extent write) | `core/storage/flusher.go` `flushOnceInternal`; `walstore_v3.go` `recoverV3` (descriptor publish fsync before `wack`); `install_log_v3.go` | `TestRedCrashKeepingAnUnsyncedExtentWriteLeavesLocalAndHEADApart` (`core/storage/chunk_u1_reorder_test.go`); `TestFlusherWriteAheadNeverFlushingGuestReachesExtentAtPressure` (`core/storage/flusher_write_ahead_test.go`) | — | ACTIVE |
| `INV-WAL-V3-CAPTURE-CANDIDATES-001` | A retained WAL entry already covered by HEAD is not dirt since HEAD. New post-HEAD WAL entries, UNKNOWN map chunks and map max-LSN above HEAD remain capture candidates. | M5 candidate selection | `chunk_layer.go` `captureCandidates` | `TestChunkLayerV3CapturedUncheckpointedWALIsCleanUntilRewritten`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, `TestBaseInstallV3CompletePersistsTheMapUnknownOfBaseWrites` | Conservative reachability unchanged; narrower redundant work | ACTIVE |
| `INV-WAL-V3-DESCRIPTOR-001` | A v3 descriptor slot is used only if it is valid: a matching CRC32C (Castagnoli), every reserved byte zero, an accepted impl, a nonzero slotGen at most 2^64-2, a nonzero nonce, and geometry consistent under checked arithmetic. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `decodeSlotV3`, `descriptorV3.validate`, `checkedAddV3` | `TestSlotV3VectorsDecodeAsExpected`, `TestSlotV3CounterExhaustion` (`core/storage/superblock_v3_test.go`) | — | STUB |
| `INV-WAL-V3-DESCRIPTOR-BASE-001` | A valid v3 descriptor slot has CheckpointLSN ≤ mapCoveredCheckpoint ≤ W, and BASE fields that follow the rules of its BASE state. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `descriptorV3.validate` | `TestSlotV3VectorsDecodeAsExpected`, `TestSlotV3InstalledMayHaveCursorBelowTail` (`core/storage/superblock_v3_test.go`) | — | STUB |