feat: distinguish final-error device WAL hold windows

This commit is contained in:
pingqiu committed 2026-12-02 04:12:10 -08:00
1 parent cf98b6928c
commit 56289b4fdb
3 files changed
+63 -4

No files matched your search

+19 -3
View File
@@ -17,10 +17,26 @@ const (
type walHoldWindow struct {
capAt time.Time
progressAt time.Time
stallAfter time.Duration
}
func newWALHoldWindow(arrival, holdStarted time.Time, maxHold time.Duration) walHoldWindow {
return walHoldWindow{capAt: arrival.Add(maxHold), progressAt: holdStarted}
return walHoldWindow{capAt: arrival.Add(maxHold), progressAt: holdStarted, stallAfter: walReclaimWindow}
}
// newWALNoRetryHoldWindow is for protocols whose error completion is final.
// A zero device cap means no device timeout; it does not inherit a network
// frontend's cap. Diagnostic degradation still starts at five seconds.
func newWALNoRetryHoldWindow(arrival, holdStarted time.Time, deviceCap time.Duration) walHoldWindow {
w := walHoldWindow{progressAt: holdStarted, stallAfter: 30 * time.Second}
if deviceCap > 0 {
w.capAt = arrival.Add(deviceCap)
}
return w
}
func (w *walHoldWindow) degraded(now time.Time) bool {
return !now.Before(w.progressAt.Add(walReclaimWindow))
}
// observeProgress is called only when a same-scope checkpoint advanced or
@@ -33,10 +49,10 @@ func (w *walHoldWindow) observeProgress(at time.Time) {
}
func (w *walHoldWindow) expired(now time.Time) walHoldReason {
if !now.Before(w.capAt) {
if !w.capAt.IsZero() && !now.Before(w.capAt) {
return walHoldCap
}
if !now.Before(w.progressAt.Add(walReclaimWindow)) {
if !now.Before(w.progressAt.Add(w.stallAfter)) {
return walReclaimStalled
}
return ""
@@ -65,3 +65,44 @@ func TestWALHoldWindowOlderObservationCannotMoveWindowBack(t *testing.T) {
t.Fatalf("no-progress window: %s", got)
}
}
func TestWALHoldWindowNoRetrySeparatesDegradedFromError(t *testing.T) {
now := time.Now()
w := newWALNoRetryHoldWindow(now, now, 0)
if w.degraded(now.Add(5*time.Second - time.Nanosecond)) {
t.Fatal("premature degraded")
}
if !w.degraded(now.Add(5 * time.Second)) {
t.Fatal("stall not visible at5s")
}
if got := w.expired(now.Add(30*time.Second - time.Nanosecond)); got != "" {
t.Fatalf("final answer before30s: %s", got)
}
if got := w.expired(now.Add(30 * time.Second)); got != walReclaimStalled {
t.Fatalf("stall answer at30s: %s", got)
}
}
func TestWALHoldWindowNoDeviceTimeoutHasNoCapWhileProgressMoves(t *testing.T) {
now := time.Now()
w := newWALNoRetryHoldWindow(now, now, 0)
for sec := 4; sec <= 120; sec += 4 {
at := now.Add(time.Duration(sec) * time.Second)
if got := w.expired(at); got != "" {
t.Fatalf("progressing uncapped hold expired at%ds: %s", sec, got)
}
w.observeProgress(at)
if w.degraded(at) {
t.Fatal("successful progress left degraded window")
}
}
}
func TestWALHoldWindowDeviceCapStillBoundsProgress(t *testing.T) {
now := time.Now()
w := newWALNoRetryHoldWindow(now, now, 10*time.Second)
w.observeProgress(now.Add(9 * time.Second))
if got := w.expired(now.Add(10 * time.Second)); got != walHoldCap {
t.Fatalf("device cap renewed: %s", got)
}
}
+3 -1
View File
@@ -679,4 +679,6 @@ Every command on the pages above, and the test that runs it.
The holder cannot discover an initiator's I/O timeout. Set `blockvolume --host-io-timeout` (`host_io_timeout`) to match the hosts using the volume; the default is `30s`. If you raise or lower the hosts' `io_timeout`, change this setting to match. For hosts with different timeouts, use the shortest timeout.
The per-command WAL-pressure hold limit, `--wal-hold-timeout`, defaults to `25s`. Startup refuses a non-positive hold or a hold that leaves less than five seconds before `--host-io-timeout`: `hold + 5s <= host_io_timeout`. Thus the default `25s` hold and `30s` host timeout are valid. For a `15s` host timeout, set the hold to at most `10s`. The five-second margin allows for network and queueing delay; it does not configure the host.
For NVMe and iSCSI, the per-command WAL-pressure hold limit, `--wal-hold-timeout`, defaults to `25s`. Startup refuses a non-positive hold or a hold that leaves less than five seconds before `--host-io-timeout`: `hold + 5s <= host_io_timeout`. Thus the default `25s` hold and `30s` host timeout are valid. For a `15s` host timeout, set the hold to at most `10s`. The five-second margin allows for network and queueing delay; it does not configure the host.
ublk and NBD errors are final; they do not have NVMe or SCSI retryable completion semantics. They use the same FIFO capacity ordering and reclaim-progress definition. After five seconds without progress the volume is degraded; after thirty seconds without progress a held write returns `EIO` with reason `wal_reclaim_stalled`. If the device has an I/O timeout, its hold cap must leave at least five seconds before that timeout and returns `EIO` with reason `wal_hold_cap` at the cap. With no device timeout, there is no total cap while reclaim continues to make progress. This policy does not extend the release's frontend support list.