seaweed-block: a held write is not answered stalled while its space is already free

A flush cycle persists its checkpoint (the WAL drops below the hard
mark) before it records its reclaimed bytes, so a held writer whose
reclaim window ended in between saw no progress and answered
wal_reclaim_stalled for space that was already free.

At the stall boundary the hold now takes one fresh look at the space it
waits for: a WAL already below the hard mark counts as progress. The
store's pressure sample reads the space before its budget check, the
hard-mark loop and the FIFO wait pass that look, and a fault or the
command cap still answers first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-05 22:52:36 -08:00
1 parent 0aa174b4c7
commit dd26e8a48e
4 files changed
+57 -21

No files matched your search

+11 -1
View File
@@ -166,7 +166,7 @@ retry:
continue retry
}
if hold != nil {
if err := hold.check(); err != nil {
if err := hold.checkFreed(a.belowHard(sample)); err != nil {
return err
}
}
@@ -248,6 +248,16 @@ retry:
}
}
// belowHard reports, from a fresh sample, whether the WAL is below the hard
// mark: the space a held command waits for is free even while the flush cycle
// that freed it has not yet recorded its reclaim.
func (a *walAdmission) belowHard(sample func() (float64, error)) func() bool {
return func() bool {
pressure, err := sample()
return err == nil && pressure < a.hardMark
}
}
// Release returns a write slot to the semaphore.
func (a *walAdmission) Release() {
<-a.sem
@@ -117,7 +117,7 @@ func (a *walAdmission) waitForTicket(ctx context.Context, deadline *time.Timer,
} else {
hold.endWait()
}
if err := hold.check(); err != nil {
if err := hold.checkFreed(a.belowHard(func() (float64, error) { return a.walUsed(), nil })); err != nil {
return err
}
}
+12 -1
View File
@@ -183,7 +183,14 @@ func (h *walWriteHold) endWait() {
h.store.walHold.active.Add(-1)
}
func (h *walWriteHold) check() error {
func (h *walWriteHold) check() error { return h.checkFreed(nil) }
// checkFreed is check with one last look at the space a waiting command waits
// for. At the stall boundary, freed (a fresh WAL sample below the hard mark)
// counts as progress: a flush cycle publishes the freed space before it records
// its reclaimed bytes, so the counters can lag the space by the rest of that
// cycle. A fault or the command cap still answers first.
func (h *walWriteHold) checkFreed(freed func() bool) error {
if fault := h.store.stickyIOFault(); fault != nil {
return fault
}
@@ -211,6 +218,10 @@ func (h *walWriteHold) check() error {
return ErrWALHoldCap
case walReclaimStalled:
if h.waiting {
if freed != nil && freed() {
h.window.observeProgress(now)
return nil
}
h.reason = walReclaimStalled
return ErrWALReclaimStalled
}
@@ -32,6 +32,12 @@ func (s *WALStore) writeAdmissionDeadline(ctx context.Context) time.Time {
}
func (s *WALStore) writeBudgetError(ctx context.Context, deadline time.Time) error {
return s.writeBudgetErrorFreed(ctx, deadline, nil)
}
// writeBudgetErrorFreed is writeBudgetError with the hold's last look at the
// freed space (walWriteHold.checkFreed).
func (s *WALStore) writeBudgetErrorFreed(ctx context.Context, deadline time.Time, freed func() bool) error {
if err := s.stickyIOFault(); err != nil {
return err
}
@@ -39,7 +45,7 @@ func (s *WALStore) writeBudgetError(ctx context.Context, deadline time.Time) err
return context.Canceled
}
if h := holdFor(ctx, s); h != nil {
if err := h.check(); err != nil {
if err := h.checkFreed(freed); err != nil {
return err
}
}
@@ -95,27 +101,36 @@ func (s *WALStore) writePressureSample(ctx context.Context, deadline time.Time)
// checked once they are held.
s.mu.RLock()
defer s.mu.RUnlock()
if err := s.writeBudgetError(ctx, deadline); err != nil {
// The space is read before the budget answers: a stall is not answered
// while the WAL is already below the hard mark (walWriteHold.checkFreed).
freed := func() bool { return s.admission != nil && s.walPressureRLocked() < s.admission.hardMark }
if err := s.writeBudgetErrorFreed(ctx, deadline, freed); err != nil {
return 0, err
}
if s.closed {
return 0, errVolumeClosed
}
v := s.v3
w := v.w
if w == nil {
return 0, nil
} // append still refuses the missing binding
p := v.pub
p.descMu.Lock()
floor, valid := p.reuseFloorLocked()
d := p.cur
p.descMu.Unlock() // preserve snapshot ordering: no descriptor -> writer edge
w.mu.Lock()
defer w.mu.Unlock()
if !valid || d.WALSize == 0 || d.Nonce != w.nonce || w.head < floor || w.head-floor > d.WALSize {
return 0, nil
}
return float64(w.head-floor) / float64(d.WALSize), nil
return s.walPressureRLocked(), nil
}
}
// walPressureRLocked is the V3 WAL fill fraction; s.mu is read-locked. A
// missing binding or an inconsistent snapshot reads 0 (append still refuses it).
func (s *WALStore) walPressureRLocked() float64 {
v := s.v3
w := v.w
if w == nil {
return 0
}
p := v.pub
p.descMu.Lock()
floor, valid := p.reuseFloorLocked()
d := p.cur
p.descMu.Unlock() // preserve snapshot ordering: no descriptor -> writer edge
w.mu.Lock()
defer w.mu.Unlock()
if !valid || d.WALSize == 0 || d.Nonce != w.nonce || w.head < floor || w.head-floor > d.WALSize {
return 0
}
return float64(w.head-floor) / float64(d.WALSize)
}