fix: persist native WAL under local pressure without guest Flush

This commit is contained in:
pingqiu committed 2026-11-18 19:02:18 -08:00
1 parent d75dbd51c6
commit 44116eece6
3 files changed
+37 -4

No files matched your search

+7
View File
@@ -162,6 +162,13 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) {
if err := store.stickyIOFault(); err != nil {
return err // no checkpoint advance after a failed fsync
}
// Do not acquire lifecycleMu here: Close holds it while joining Stop.
// The pressure leader is released before snapshot/materialization/checkpoint.
if store.v3 != nil {
if err := store.syncWALPressureV3(); err != nil {
return fmt.Errorf("flusher: pressure WAL sync: %w", err)
}
}
store.mu.RLock()
if store.closed && !allowClosed {
store.mu.RUnlock()
+5
View File
@@ -379,6 +379,11 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B
// flusher via NotifyUrgent — same seam V2 wires for pressure-
// driven flushes.
s.admissionTimeout = 30 * time.Second
if s.v3 != nil {
// WAL pressure gets a budget below the host's I/O timeout. This bounds
// cooperative admission waits, not a blocking callback or physical I/O.
s.admissionTimeout = 4 * time.Second
}
s.admission = newWALAdmission(walAdmissionConfig{
MaxConcurrent: 64,
SoftWatermark: 0.70,
+25 -4
View File
@@ -774,13 +774,20 @@ func (s *WALStore) replayRecordV3(r walScannedRecordV3, walSize uint64, blockSiz
// syncWALBatchV3 is the committer leader's batch for a v3 store (DESIGN 6.2,
// 6.3). The cut H is every record pwritten before the leader starts.
func (s *WALStore) syncWALBatchV3() error {
return s.syncWALBatchV3Internal(false)
}
// Called only by the flusher, without capture/lifecycle/store locks. Pressure
// cannot depend on a guest Flush: persist locally before checkpointing, using
// the same physical sync and final fault gate as an ordinary sync batch.
func (s *WALStore) syncWALPressureV3() error {
return s.syncWALBatchV3Internal(true)
}
func (s *WALStore) syncWALBatchV3Internal(pressureOnly bool) error {
if err := s.stickyIOFault(); err != nil {
return err
}
cut := s.walMutation.Load()
if !s.bypassSyncDedup.Load() && s.chunk.Load() == nil && cut <= s.durableMutation.Load() {
return nil
}
v := s.v3
// The leader role: SetWMode holds it while it changes the mode, so no
// batch acknowledges under a stale mode selection (the mode is read
@@ -790,6 +797,20 @@ func (s *WALStore) syncWALBatchV3() error {
}
v.syncMu.Lock()
defer v.syncMu.Unlock()
if pressureOnly {
// Recheck under the same leader interval as the mutation/frontier cut.
// Installing uses receiver-owned SyncInstallLog, never this normal path.
s.mu.RLock()
closed := s.closed
s.mu.RUnlock()
if closed || v.pub.current().BaseState == BaseInstalling || s.walUsedFraction() < 0.70 || v.appended.Load() <= v.wack.Load() {
return nil
}
}
cut := s.walMutation.Load()
if !s.bypassSyncDedup.Load() && s.chunk.Load() == nil && cut <= s.durableMutation.Load() {
return nil
}
H, prev := v.appended.Load(), v.wack.Load()
// One sample per covering WAL batch, as on v2. In mode C the slot
// publication is the physical sync; mode A also settles its W slot.