From 5e4f2f3d45e018e85e39d131128c62ee97002f44 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 07:12:20 -0800 Subject: [PATCH] storage, durable: cuts are ordered by an in-process CutSeq, never by wall stamps; the periodic decision skips once CutSeq moved Co-Authored-By: Claude Opus 5.5 --- .../durable/chunk_snapshot_loop_test.go | 57 ++++++++++++------- .../core/frontend/durable/cut_policy_test.go | 44 +++++++------- .../core/frontend/durable/provider_chunk.go | 55 +++++++++--------- seaweed-block/core/storage/chunk_layer.go | 1 + .../core/storage/chunk_periodic_cut.go | 14 +++-- .../core/storage/chunk_periodic_cut_test.go | 41 ++++++++++++- seaweed-block/core/storage/chunk_seam.go | 5 +- seaweed-block/docs/design/invariants.md | 14 ++++- seaweed-block/docs/status-schema.md | 1 + 9 files changed, 147 insertions(+), 85 deletions(-) diff --git a/seaweed-block/core/frontend/durable/chunk_snapshot_loop_test.go b/seaweed-block/core/frontend/durable/chunk_snapshot_loop_test.go index a21cdbc878..cdfd91df56 100644 --- a/seaweed-block/core/frontend/durable/chunk_snapshot_loop_test.go +++ b/seaweed-block/core/frontend/durable/chunk_snapshot_loop_test.go @@ -52,6 +52,16 @@ func snapLoop(take func(context.Context) error) (h *volHandle, start func(), sto return h, start, stop } +// recv waits for ch for at most an hour of virtual time. +func recv(t *testing.T, ch <-chan struct{}, what string) { + t.Helper() + select { + case <-ch: + case <-time.After(time.Hour): + t.Fatalf("%s did not happen", what) + } +} + // The first attempt is at the start plus the volume's offset and the next // one a period later, both on the monotonic clock. func TestScheduledSnapshotLoop_TakesEachSlotOnMonotonicTime(t *testing.T) { @@ -101,21 +111,24 @@ func TestScheduledSnapshotLoop_RearmKeepsTheSchedule(t *testing.T) { return &SnapshotFailure{Code: "remote_unavailable"} }) start() + running := true + defer func() { // registered before any check: whichever loop runs is joined + if running && !stop() { + t.Error("the loop was not joined") + } + }() time.Sleep(time.Until(h.snapshots.due()) + time.Second) synctest.Wait() slot, retry := h.snapshots, h.snapshots.due() if st := slot.status(time.Now()); st.Attempts != 1 || st.LastFailure == nil { t.Fatalf("after the first attempt: %+v; want one failure", st) } + running = false if !stop() { t.Fatal("the loop was not joined") } start() - defer func() { - if !stop() { - t.Error("the re-armed loop was not joined") - } - }() + running = true if h.snapshots != slot || h.snapshots.due() != retry || slot.status(time.Now()).Attempts != 1 { t.Fatalf("after re-arm: same schedule %v, due %v (want %v), %+v", h.snapshots == slot, h.snapshots.due(), retry, slot.status(time.Now())) } @@ -143,9 +156,18 @@ func TestScheduledSnapshotLoop_StopJoinsTheAttempt(t *testing.T) { }) start() joined := make(chan bool, 1) - stopping := false - defer func() { // runs after the release below: join the stop, bounded - if !stopping { + stopStarted := false + var released atomic.Bool + free := func() { + if released.CompareAndSwap(false, true) { + close(release) + } + } + // Registered before any check, run last: release the attempt, then + // join the stop (bounded), starting it if the test never did. + defer func() { + free() + if !stopStarted { joined <- stop() } select { @@ -157,26 +179,19 @@ func TestScheduledSnapshotLoop_StopJoinsTheAttempt(t *testing.T) { t.Error("stop did not return") } }() - var released atomic.Bool - defer func() { - if released.CompareAndSwap(false, true) { - close(release) - } - }() time.Sleep(time.Until(h.snapshots.due()) + time.Second) - <-entered - stopping = true + recv(t, entered, "the attempt") + stopStarted = true go func() { joined <- stop() }() - <-cancelled // the attempt saw the cancellation + recv(t, cancelled, "the attempt seeing the cancellation") synctest.Wait() select { - case <-joined: + case ok := <-joined: + joined <- ok // leave it for the deferred join t.Fatal("stop returned while the attempt was still running") default: } - if released.CompareAndSwap(false, true) { - close(release) - } + free() }) } diff --git a/seaweed-block/core/frontend/durable/cut_policy_test.go b/seaweed-block/core/frontend/durable/cut_policy_test.go index 51bc38ab3f..415a178d1e 100644 --- a/seaweed-block/core/frontend/durable/cut_policy_test.go +++ b/seaweed-block/core/frontend/durable/cut_policy_test.go @@ -130,7 +130,7 @@ func TestCutPolicy_ExplicitSuccessClearsFailedAutoBackoff(t *testing.T) { } // The cut the failure already saw (it completed before the failure) // leaves the backoff in force. - s2 := cutSchedule{lastSuccess: t0, seenNs: 90} + s2 := cutSchedule{lastSuccess: t0, seenSeq: 90} s2 = pol.after(s2, at(10*time.Second), at(10*time.Second), fail, 100) s2 = s2.observe(100, at(11*time.Second)) if s2.retryAt.IsZero() { @@ -183,30 +183,26 @@ func TestCutPolicy_StaggerPreservesExplicitTimerReset(t *testing.T) { } } -// The timer runs on this process's monotonic time: the layer's LastCutNs -// is only the identity of the latest cut. A stamp from a wall clock that -// lags or leaps (a step, another host) is taken in at the moment it is -// observed, so the next timer cut is one interval after the observation; -// and at start the layer's existing cut (from before a restart) is not -// new, so the startup phase stands. -func TestCutPolicy_TimerIgnoresTheWallClockOfLastCutNs(t *testing.T) { +// The timer runs on this process's monotonic time and keys on the layer's +// CutSeq, never on a cut's wall stamp: a cut seen for the first time is a +// success at the moment it is observed, so the next timer cut is one +// interval after the observation; at start the layer's existing CutSeq is +// not new, so the startup phase stands. +func TestCutPolicy_TimerRunsOnObservationTime(t *testing.T) { pol := testPolicy() - s := cutSchedule{lastSuccess: t0} - for _, stamp := range []time.Time{t0.Add(-3 * time.Hour), t0.Add(48 * time.Hour)} { - seen := at(20 * time.Second) - s = cutSchedule{lastSuccess: t0}.observe(stamp.UnixNano(), seen) - if !s.lastSuccess.Equal(seen) { - t.Fatalf("stamp %v: last success %v; want the observation time %v", stamp, s.lastSuccess, seen) - } - if _, ok := pol.dueNR(s, seen.Add(pol.interval-time.Nanosecond)); ok { - t.Fatalf("stamp %v: due before one interval after the observation", stamp) - } - if _, ok := pol.dueNR(s, seen.Add(pol.interval)); !ok { - t.Fatalf("stamp %v: not due one interval after the observation", stamp) - } + seen := at(20 * time.Second) + s := cutSchedule{lastSuccess: t0}.observe(1, seen) + if !s.lastSuccess.Equal(seen) { + t.Fatalf("last success %v; want the observation time %v", s.lastSuccess, seen) } - restart := initialCutSchedule("v1", pol.interval, t0, true, 777) - if got := restart.observe(777, at(time.Second)); got.firstDue.IsZero() || !got.lastSuccess.Equal(t0) { - t.Fatalf("after a restart the existing cut was taken in as new: %+v", got) + if _, ok := pol.dueNR(s, seen.Add(pol.interval-time.Nanosecond)); ok { + t.Fatal("due before one interval after the observation") + } + if _, ok := pol.dueNR(s, seen.Add(pol.interval)); !ok { + t.Fatal("not due one interval after the observation") + } + restart := initialCutSchedule("v1", pol.interval, t0, true, 7) + if got := restart.observe(7, at(time.Second)); got.firstDue.IsZero() || !got.lastSuccess.Equal(t0) { + t.Fatalf("the cut existing at start was taken in as new: %+v", got) } } diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index 614e05b2ae..5660441c98 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -666,32 +666,32 @@ type cutPolicy struct { // cutSchedule runs on in-process monotonic time: every time in it is a // time.Now() reading of this process (or derived from one), never the // layer's persisted LastCutNs, so wall-clock steps move nothing and a -// restart starts a fresh schedule. LastCutNs is used only as the identity -// of the latest cut: a value not seen before is a new successful cut. +// restart starts a fresh schedule. The layer's CutSeq identifies the +// latest cut: a value not seen before is a new successful cut. type cutSchedule struct { - lastSuccess time.Time // last successful cut of any kind, as observed here - lastAuto time.Time // start of the last automatic cut - failedAt time.Time // end of the last failed automatic cut - retryAt time.Time // a failed automatic cut's backoff ends here - backoff time.Duration - firstDue time.Time // startup phase only; never a fabricated success - seenNs int64 // the layer's LastCutNs last taken in - failedSeenNs int64 // the layer's LastCutNs when the last automatic cut failed + lastSuccess time.Time // last successful cut of any kind, as observed here + lastAuto time.Time // start of the last automatic cut + failedAt time.Time // end of the last failed automatic cut + retryAt time.Time // a failed automatic cut's backoff ends here + backoff time.Duration + firstDue time.Time // startup phase only; never a fabricated success + seenSeq uint64 // the layer's CutSeq last taken in + failedSeenSeq uint64 // the layer's CutSeq when the last automatic cut failed } // observe takes in, at now, the latest cut the layer reports (any -// trigger): a LastCutNs not seen before is a success at now. A cut other +// trigger): a CutSeq not seen before is a success at now. A cut other // than the one the last failure saw makes that failure's backoff obsolete. -func (s cutSchedule) observe(lastCutNs int64, now time.Time) cutSchedule { - if lastCutNs == 0 || lastCutNs == s.seenNs { +func (s cutSchedule) observe(seq uint64, now time.Time) cutSchedule { + if seq == 0 || seq == s.seenSeq { return s } - s.seenNs = lastCutNs + s.seenSeq = seq if now.After(s.lastSuccess) { s.lastSuccess = now } s.firstDue = time.Time{} - if !s.failedAt.IsZero() && lastCutNs != s.failedSeenNs { + if !s.failedAt.IsZero() && seq != s.failedSeenSeq { s.backoff, s.retryAt, s.failedAt = 0, time.Time{}, time.Time{} } return s @@ -718,11 +718,11 @@ func (pol cutPolicy) due(s cutSchedule, now time.Time, reconciling bool) (string } // after records the outcome of an automatic cut started at start, with -// the layer's LastCutNs read after it. -func (pol cutPolicy) after(s cutSchedule, start, end time.Time, err error, lastCutNs int64) cutSchedule { +// the layer's CutSeq read after it. +func (pol cutPolicy) after(s cutSchedule, start, end time.Time, err error, seq uint64) cutSchedule { s.lastAuto = start if err == nil { - s.seenNs = lastCutNs + s.seenSeq = seq s.firstDue = time.Time{} s.backoff, s.retryAt, s.failedAt = 0, time.Time{}, time.Time{} if end.After(s.lastSuccess) { @@ -738,15 +738,14 @@ func (pol cutPolicy) after(s cutSchedule, start, end time.Time, err error, lastC default: s.backoff *= 2 } - s.failedAt, s.retryAt, s.failedSeenNs = end, end.Add(s.backoff), lastCutNs + s.failedAt, s.retryAt, s.failedSeenSeq = end, end.Add(s.backoff), seq return s } -// initialCutSchedule starts a fresh schedule at now; lastCutNs is the -// layer's latest cut at start, so a cut from before (another process -// lifetime) is not taken in as new. -func initialCutSchedule(volumeID string, interval time.Duration, now time.Time, stagger bool, lastCutNs int64) cutSchedule { - s := cutSchedule{lastSuccess: now, seenNs: lastCutNs} +// initialCutSchedule starts a fresh schedule at now; seq is the layer's +// CutSeq at start, so a cut already made is not taken in as new. +func initialCutSchedule(volumeID string, interval time.Duration, now time.Time, stagger bool, seq uint64) cutSchedule { + s := cutSchedule{lastSuccess: now, seenSeq: seq} if stagger && interval > 0 { phase := hostlimit.Phase(volumeID, interval) startup := hostlimit.Phase(volumeID+":startup", min(interval, 10*time.Second)) @@ -767,7 +766,7 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer backoffMin: chunkCutBackoffMin, backoffMax: chunkCutBackoffMax, } - s := initialCutSchedule(volumeID, pol.interval, time.Now(), p.cfg.ChunkStagger, layer.Stats().LastCutNs) + s := initialCutSchedule(volumeID, pol.interval, time.Now(), p.cfg.ChunkStagger, layer.Stats().CutSeq) t := time.NewTicker(chunkSchedulePoll) defer t.Stop() for { @@ -781,7 +780,7 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer } ls := layer.Stats() start := time.Now() - s = s.observe(ls.LastCutNs, start) + s = s.observe(ls.CutSeq, start) reason, ok := pol.due(s, start, ls.Reconciling) if !ok { continue @@ -796,7 +795,7 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer // A cut that completed after this decision (an explicit one // running meanwhile) restarted the timer: no cut now. var skipped bool - _, skipped, err = pc.CutUnlessCutSince(cutCtx, ls.LastCutNs) + _, skipped, err = pc.CutUnlessCutSince(cutCtx, ls.CutSeq) if trace != nil { trace("cut", ls.LastCutNs, skipped) } @@ -811,7 +810,7 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer } } cancel() - s = pol.after(s, start, time.Now(), err, layer.Stats().LastCutNs) + s = pol.after(s, start, time.Now(), err, layer.Stats().CutSeq) if err != nil && !errors.Is(err, storage.ErrChunkCaptureRefused) && ctx.Err() == nil { log.Printf("durable: %s chunk cut for volume=%s: %v (retry in %s)", reason, volumeID, err, s.backoff) } diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 3ed9ec97b5..39e9b7a5a9 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -1443,6 +1443,7 @@ func (l *chunkLayerImpl) recordCut(r chunkCutResult, st chunkCutStats, err error } if err == nil { l.stats.LastCut, l.stats.LastCutH, l.stats.LastCutNs = st, r.H, time.Now().UnixNano() + l.stats.CutSeq++ } if st.BarrierOverBound { l.stats.BarrierOverBound++ diff --git a/seaweed-block/core/storage/chunk_periodic_cut.go b/seaweed-block/core/storage/chunk_periodic_cut.go index 49822ee959..72522b7994 100644 --- a/seaweed-block/core/storage/chunk_periodic_cut.go +++ b/seaweed-block/core/storage/chunk_periodic_cut.go @@ -8,20 +8,22 @@ import "context" // complete before this one gets the capture lock. That cut restarted the // timer, so the due cut is not taken. type ChunkPeriodicCutter interface { - // CutUnlessCutSince cuts unless a cut succeeded after lastCutNs (the - // LastCutNs the timer decided on); skipped reports that it did not cut. - CutUnlessCutSince(ctx context.Context, lastCutNs int64) (r ChunkCutResult, skipped bool, err error) + // CutUnlessCutSince cuts unless a cut succeeded since the timer decided + // (CutSeq is no longer seq, the CutSeq it decided on); skipped reports + // that it did not cut. Cuts are ordered by CutSeq, never by their wall + // stamps. + CutUnlessCutSince(ctx context.Context, seq uint64) (r ChunkCutResult, skipped bool, err error) } var _ ChunkPeriodicCutter = (*chunkLayerImpl)(nil) -func (l *chunkLayerImpl) CutUnlessCutSince(ctx context.Context, lastCutNs int64) (chunkCutResult, bool, error) { +func (l *chunkLayerImpl) CutUnlessCutSince(ctx context.Context, seq uint64) (chunkCutResult, bool, error) { l.capMu.Lock() defer l.capMu.Unlock() l.stMu.Lock() - last := l.stats.LastCutNs + cur := l.stats.CutSeq l.stMu.Unlock() - if last > lastCutNs { + if cur != seq { return chunkCutResult{}, true, nil } r, err := l.captureLocked(ctx, false) diff --git a/seaweed-block/core/storage/chunk_periodic_cut_test.go b/seaweed-block/core/storage/chunk_periodic_cut_test.go index 5289cb8b9a..8ec256b21a 100644 --- a/seaweed-block/core/storage/chunk_periodic_cut_test.go +++ b/seaweed-block/core/storage/chunk_periodic_cut_test.go @@ -1,6 +1,9 @@ package storage -import "testing" +import ( + "testing" + "time" +) // A periodic cut decided before another cut completed is skipped; decided // after the last cut, it cuts. @@ -14,7 +17,7 @@ func TestChunkPeriodicCut_SkipsAfterANewerCut(t *testing.T) { } w := newWriteLog() w.write(t, s, 2, 0x22) - decided := layer.Stats().LastCutNs // the timer decides here... + decided := layer.Stats().CutSeq // the timer decides here... if _, err := layer.Cut(ctTimeout(t)); err != nil { // ...then another cut completes first t.Fatal(err) } @@ -26,7 +29,7 @@ func TestChunkPeriodicCut_SkipsAfterANewerCut(t *testing.T) { if f.stats().cas != casBefore { t.Fatal("a skipped periodic cut published") } - r, skipped, err := pc.CutUnlessCutSince(ctTimeout(t), layer.Stats().LastCutNs) + r, skipped, err := pc.CutUnlessCutSince(ctTimeout(t), layer.Stats().CutSeq) if err != nil || skipped || r.Noop { t.Fatalf("periodic cut decided after the last cut: skipped=%v noop=%v err=%v; want a cut", skipped, r.Noop, err) } @@ -34,3 +37,35 @@ func TestChunkPeriodicCut_SkipsAfterANewerCut(t *testing.T) { t.Fatalf("CAS calls %d -> %d; want one", casBefore, f.stats().cas) } } + +// Cuts are ordered by CutSeq, not by their wall stamps: a newer cut whose +// stamp reads earlier than the one the timer decided on (a backward clock +// step between them) still makes the stale periodic decision skip. +func TestChunkPeriodicCut_SkipsANewerCutWithAnOlderStamp(t *testing.T) { + s, _ := newChunkTestStore(t) + f := newFakeChunkRemote() + layer := mustAttach(t, s, f, ctConfig(1)) + pc := layer.(ChunkPeriodicCutter) + impl := layer.(*chunkLayerImpl) + w := newWriteLog() + w.write(t, s, 2, 0x22) + if _, err := layer.Cut(ctTimeout(t)); err != nil { + t.Fatal(err) + } + decided, decidedNs := layer.Stats().CutSeq, layer.Stats().LastCutNs + w.write(t, s, 5, 0x25) + if _, err := layer.Cut(ctTimeout(t)); err != nil { // a newer cut completes... + t.Fatal(err) + } + impl.stMu.Lock() + impl.stats.LastCutNs = decidedNs - int64(time.Hour) // ...stamped by a clock stepped back an hour + impl.stMu.Unlock() + w.write(t, s, 9, 0x29) + casBefore := f.stats().cas + if _, skipped, err := pc.CutUnlessCutSince(ctTimeout(t), decided); err != nil || !skipped { + t.Fatalf("stale periodic decision after a newer cut with an older stamp: skipped=%v err=%v; want skipped", skipped, err) + } + if f.stats().cas != casBefore { + t.Fatal("the stale periodic decision published") + } +} diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index c8461ba69a..293d0aebdd 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -474,7 +474,9 @@ type chunkCutStats struct { // publishes until it is done. ReconcileDone of ReconcileTotal chunks // are compared. // - LastCut, LastCutH and LastCutNs (wall clock, Unix ns) describe the -// last successful cut, whatever triggered it. +// last successful cut, whatever triggered it. CutSeq counts the +// successful cuts of this layer (in-process): it identifies the latest +// cut and orders cuts without any clock. type chunkLayerStats struct { Hydration ChunkHydrationStats // lazy fetches of absent chunks from the remote CutsOK uint64 // cuts that installed a HEAD @@ -492,6 +494,7 @@ type chunkLayerStats struct { LastCut chunkCutStats // the last successful cut's measurements LastCutH uint64 // the LSN the last successful cut published LastCutNs int64 // when it completed (wall clock, Unix ns) + CutSeq uint64 // successful cuts of this layer so far (in-process); the latest cut's identity // BarrierOverBound counts cuts whose barrier copied more than the // bound after the staging rounds. BarrierOverBound uint64 diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index a8403a48ae..3256f64fe6 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -381,6 +381,16 @@ A pass has one minute for retention and optional GC; retention failure skips GC. A scoped GC pass traces the whole catalog but mutates only its target volume, with a separate scope/config-bound mark. Incomplete marks carry no coverage. +The scheduled-snapshot worker runs beside it under the same owner and join, on +in-process monotonic time: `Armed -> Due -> Running -> Armed`. A success sets the +next slot (loop start + the volume's offset + whole periods); a failure keeps +its typed code and retries after a backoff doubling from 1 min to 1 h; a +restoring volume (absent chunks) is skipped, counted, and retried within 1 h. +A re-armed loop on the same handle keeps this state; a restart starts fresh. +Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksOff`, +`_RestoringIsSkippedAndCounted`, `TestScheduledSnapshotLoop_TakesEachSlotOnMonotonicTime`, +`_RearmKeepsTheSchedule`. + ## Part B. Invariant ledger 136 rows: 116 ACTIVE, 17 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 121 new. @@ -549,13 +559,13 @@ Notes: | `INV-CUT-SEGMENT-REUSE-001` | A cut rewrites only manifest segments whose chunk references changed, and an uploaded but unpublished segment leaves the published root unchanged. | M5 Manifest | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestManifest_ReusesUnchangedRangeAndCrashKeepsOldRoot` (`core/frontend/chunkstore/manifest_test.go`) | `CutPipeline` `SegConsistent` | ACTIVE | | `INV-CUT-HYDRATION-WAIT-001` | A read command shares its arrival deadline across chunks. A timed-out waiter returns typed pending without cancelling a shared fill. Per-layer worker and distinct-flight limits bound remote work; Close wakes waiters and joins issued fills before storage release. Physical/hash errors remain terminal. | M4 Holder (hydration wait) | `core/storage/chunk_hydration.go`; `core/storage/walstore.go` `ReadContext`; `core/frontend/durable/storage_adapter.go` `readStorageBlock`; `core/frontend/nvme/session.go` `handleRead` | `TestDurableHydration_MultipleChunksShareOneDeadline`, `TestDurableHydration_NVMePreservesPhysicalAndHashErrors`, `TestSessionReadBudgetIncludesQueueResidence`, `TestChunkHydration_QueueAndWorkerLimitsAreBounded`, `TestChunkHydration_CloseWakesCallerAndJoinsUninterruptibleGet`, `TestChunkHydration_ContextlessReadAllowsSlowFill`, `TestChunkHydration_NewGenerationDoesNotJoinStaleGet`, `TestChunkHydration_StaleCompletionKeepsReplacement`, `TestDurableHydration_RMWFenceWinsCallerExpiry` | — | ACTIVE | | `INV-CUT-READMISS-001` | A block fetched from HEAD after a move is installed only if it does not overwrite a newer local extent version; a newer WAL-only write still wins on reads, and HEAD's value may be installed beneath it as the backing value, which is correct if a crash loses that unsynced write. | M4 Holder (lazy restore) | `core/storage/chunk_layer.go` `OnReadMiss`, `installFetchedBlock`; `core/storage/walstore.go` `readFromExtent` | `TestChunkLayer_WALOnlyOverlapReadNeverReturnsUntouchedZero` (`core/storage/chunk_layer_races_test.go`); `TestWALStore_PostReadMissRechecksWALFormat` (`core/storage/walstore_read_miss_v3_test.go`; real-store v2/v3 dispatch, v3 remains dark) | — | ACTIVE | -| `INV-CUT-TIMER-RESTART-001` | A successful cut of any kind restarts the periodic timer, which runs on in-process monotonic time (a restart starts a fresh schedule; wall-clock steps move nothing). A periodic cut decided from an older last cut is skipped under the capture lock: no automatic cut follows another within the interval. | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `chunkLoop`; `core/storage/chunk_periodic_cut.go` `CutUnlessCutSince` | `TestWALStoreChunk_ExplicitCutRestartsTheTimer`, `TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt` (`core/frontend/durable/provider_chunk_sched_test.go`); `TestChunkPeriodicCut_SkipsAfterANewerCut` (`core/storage/chunk_periodic_cut_test.go`); `TestCutPolicy_TimerIgnoresTheWallClockOfLastCutNs` (`core/frontend/durable/cut_policy_test.go`) | — | ACTIVE | +| `INV-CUT-TIMER-RESTART-001` | A successful cut of any kind restarts the periodic timer, which runs on in-process monotonic time (a restart starts a fresh schedule; wall-clock steps move nothing). A periodic cut decided from an older last cut is skipped under the capture lock: no automatic cut follows another within the interval. | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `chunkLoop`; `core/storage/chunk_periodic_cut.go` `CutUnlessCutSince` | `TestWALStoreChunk_ExplicitCutRestartsTheTimer`, `TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt` (`core/frontend/durable/provider_chunk_sched_test.go`); `TestChunkPeriodicCut_SkipsAfterANewerCut` (`core/storage/chunk_periodic_cut_test.go`); `TestCutPolicy_TimerRunsOnObservationTime` (`core/frontend/durable/cut_policy_test.go`); `TestChunkPeriodicCut_SkipsANewerCutWithAnOlderStamp` (`core/storage/chunk_periodic_cut_test.go`) | — | ACTIVE | A guest read has a cooperative arrival budget; internal contextless readers keep the owned fill timeout (default 30 s). With five immediate host retries, cold fills slower than roughly 20–24 s can still end in guest EIO despite shared work; retry-delay advertisement remains separate. A changed generation replaces its promise without abandoning the old worker. `AllBlocks` returns an error and no partial image on a failed read; the rebuild sender propagates it before sending blocks. Notes: -- `INV-CUT-TIMER-RESTART-001`: the layer's persisted `LastCutNs` is only the identity of the latest cut: a value not seen before is a success at the moment it is observed; at start the existing value is not new, so a restart keeps the startup phase. The scheduled-snapshot worker (`INV-SNAP-SCHEDULED-KEEP-001`) runs on the same monotonic time: slots are the loop start plus the volume's offset plus whole periods; a re-armed loop on the same handle keeps its schedule (failures, retry time); a restart starts a fresh one. Tests: `TestScheduledSnapshotLoop_TakesEachSlotOnMonotonicTime`, `_RearmKeepsTheSchedule`, `_OverdueWithNoSuccess`, `TestSnapshotSchedule_SlotsAreOffsetPerVolume`. +- `INV-CUT-TIMER-RESTART-001`: cuts are identified and ordered by the layer's in-process `CutSeq`, never by the `LastCutNs` wall stamp: a `CutSeq` not seen before is a success at the moment it is observed, and a periodic decision is skipped once `CutSeq` has moved; at start the existing value is not new, so a restart keeps the startup phase. The scheduled-snapshot worker (`INV-SNAP-SCHEDULED-KEEP-001`) runs on the same monotonic time: slots are the loop start plus the volume's offset plus whole periods; a re-armed loop on the same handle keeps its schedule (failures, retry time); a restart starts a fresh one. Tests: `TestScheduledSnapshotLoop_TakesEachSlotOnMonotonicTime`, `_RearmKeepsTheSchedule`, `_OverdueWithNoSuccess`, `TestSnapshotSchedule_SlotsAreOffsetPerVolume`. - `INV-CUT-PRECOPY-001`: Opt-in final-tail admission closes frontend admission, drains registered I/O before the store lock within a 100 ms caller context, then uses authoritative barrier candidates and measured costs. Ordinary refusal reopens tentative admission before rolling uploads; guest-frozen refusal instead sends no payload. A contended freeze fallback never replaces an existing pause or its queue clock. Final freeze queues without completion for up to five seconds; on resume every queued waiter is granted in arrival order under one lock hold; each then passes the normal gate; completion is unordered. The ended pause is cleared before those normal gate checks; queue deadlines are measured once from each command arrival and capped by five seconds or its earlier caller deadline, so independent I/O is concurrent and later arrivals cannot inherit an expired pause; host drain preserves the active queue, and transport teardown cancels commands before joining; no queued storage work is issued. Only settled detached publication permits handoff; aborted rounds retain dirty bytes. Warm attempts and measurement rounds are reported separately, with samples at start; both consume the same five-round budget. Admission fits the allowance, or declares an estimate within five seconds when it is at least 90% of the previous comparable known estimate, or on the final physical round. The fixed input is the maximum of up to the latest five observations younger than fifteen minutes (at least one required); disjoint parts come from the same selected observation. Ordinary admission never uses unknown samples. A guest-frozen attempt skips staging, forecasts and rechecks against five seconds minus guest elapsed, and refuses without uploading if it cannot fit. Only an explicit final override can bypass that estimate guard, with over_budget recorded; authority and publication settlement remain mandatory. Checkpoint tails are advisory same-window measurements. Nested Sync phases and live barrier-prefix spans explain fixed cost without double counting. - `INV-CUT-STAGED-REUSE-001`: `captureLocked` also requires HEAD's generation to be the one the stage was compared against (code reading; not asserted by these tests). diff --git a/seaweed-block/docs/status-schema.md b/seaweed-block/docs/status-schema.md index 33559866a3..a5d5b4f682 100644 --- a/seaweed-block/docs/status-schema.md +++ b/seaweed-block/docs/status-schema.md @@ -273,6 +273,7 @@ Durable store state of the served volume. Go type `volume.durableStatusBody`. | `Volumes[].Chunk.Stats.LastCut.BarrierOverBound` | bool | (group of `StageRounds`) Pre-copy (staging by the copy-on-write side budget, M5 Stage): StageRounds staging rounds staged StagedChunks chunks outside the barrier; StagedChunksUsed of the uploads in HEAD came from staging. BarrierCopyChunks were copied under the barrier. BarrierOverBound: more than the legacy fixture BarrierBound; always false in production, where that bound is zero. | | `Volumes[].Chunk.Stats.LastCutH` | uint64 | the LSN the last successful cut published | | `Volumes[].Chunk.Stats.LastCutNs` | int64 | when it completed (wall clock, Unix ns) | +| `Volumes[].Chunk.Stats.CutSeq` | uint64 | successful cuts of this layer so far (in-process); the latest cut's identity | | `Volumes[].Chunk.Stats.BarrierOverBound` | uint64 | BarrierOverBound counts cuts whose barrier copied more than the bound after the staging rounds. | | `Volumes[].Chunk.Stats.AbsentChunks` | int | AbsentChunks is the number of HEAD-named chunks still absent with a block not local (what HydrateAll would still fetch); 0 = fully local. | | `Volumes[].Chunk.HostBudget` | interface | the host background-cut budget state, with --host-limit-dir (omitted when empty) |