storage: red tests, no touched-set allocation or fill scan in the pause

- The touched set's allocation and the recovery's clean-fill enumeration
  now count themselves in PauseCandidateOps when the guest is paused.
- TestAColdFirstCutAllocatesNoSetInThePause: a layer's first cut at the
  1 TiB shape (fails: 4,097, the spare set allocated at the take).
- TestARecoveryJustBeforeTheBarrierIsJudgedAfterThePause: a recovery
  between the pre-barrier work and the barrier (fails: 9, the clean fills
  enumerated at the take); the cut must still judge every clean fill.
- TestTheFirstCutAfterWritesDoesNoPerCandidateWorkInThePause now fails
  too (the spare allocation).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-01 20:06:08 -08:00
1 parent 72e429830c
commit d8f828275a
2 files changed
+52 -2

No files matched your search

@@ -51,6 +51,48 @@ func TestTheFirstCutAfterWritesDoesNoPerCandidateWorkInThePause(t *testing.T) {
})
}
// A layer's first cut finds its touched sets ready: the barrier only swaps
// them; no set is allocated in the pause (size-dependent work).
func TestAColdFirstCutAllocatesNoSetInThePause(t *testing.T) {
const n = 262144
s, l := freshShape(t, n)
if _, err := s.Write(3, []byte(fmt.Sprintf("%-512s", "cold"))); err != nil {
t.Fatal(err)
}
r, err := l.Cut(ctTimeout(t))
if err != nil {
t.Fatal(err)
}
if r.Stats.PauseCandidateOps != 0 {
t.Fatalf("a layer's first cut over %d chunks did %d size-dependent operations in the pause, want 0", n, r.Stats.PauseCandidateOps)
}
}
// A recovery that lands between a cut's pre-barrier work and its barrier
// moves every clean fill's version: the cut still judges those fills (their
// proofs are gone), after the pause, and the pause does no per-fill work.
func TestARecoveryJustBeforeTheBarrierIsJudgedAfterThePause(t *testing.T) {
_, l, _ := filledFreshVolume(t)
l.stMu.Lock()
fills := len(l.filledClean)
l.stMu.Unlock()
if fills == 0 {
t.Fatal("setup: no clean fills")
}
l.testBeforeBarrierLockHook = func() { l.noteAllMutated() }
r, err := l.Cut(ctTimeout(t))
l.testBeforeBarrierLockHook = nil
if err != nil {
t.Fatal(err)
}
if r.Stats.PauseCandidateOps != 0 {
t.Fatalf("a recovery just before the barrier cost %d per-fill operations in the pause, want 0", r.Stats.PauseCandidateOps)
}
if r.Stats.CandidateChunks < fills {
t.Fatalf("the cut after the recovery judged %d candidates, want all %d clean fills (their proofs are gone)", r.Stats.CandidateChunks, fills)
}
}
// A fill whose fetch outlives a same-open recovery installs HEAD's bytes but
// no clean mark (the recovery moved the chunk's version), so the chunk is a
// candidate again, as the full scan says; the absent-to-present install
+10 -2
View File
@@ -524,9 +524,17 @@ func (l *chunkLayerImpl) resolveTouchFilled() {
filled = append(filled, idx)
}
l.stMu.Unlock()
l.pauseOp(len(filled))
l.touch(filled...)
}
// newTouchedSet allocates a touched set (its words and summary: size
// dependent, counted if the guest is paused).
func (l *chunkLayerImpl) newTouchedSet() *candidateSet {
l.pauseOp(int(l.numChunks/64) + 1)
return newCandidateSet(l.numChunks)
}
// candidateOracle, when set (by this package's tests), receives every chunk
// the full predicate scan finds that a barrier's touched-set candidate step
// missed. Production leaves it nil: the scan is O(chunks).
@@ -632,7 +640,7 @@ func (l *chunkLayerImpl) touch(chunks ...uint64) {
// touchedLocked is the live touched set, made on first use. Caller holds unkMu.
func (l *chunkLayerImpl) touchedLocked() *candidateSet {
if l.touched == nil {
l.touched = newCandidateSet(l.numChunks)
l.touched = l.newTouchedSet()
}
return l.touched
}
@@ -791,7 +799,7 @@ func (l *chunkLayerImpl) takeTouched() *candidateSet {
defer l.unkMu.Unlock()
taken := l.touchedLocked()
if l.touchedSpare == nil {
l.touchedSpare = newCandidateSet(l.numChunks)
l.touchedSpare = l.newTouchedSet()
}
l.touched, l.touchedSpare = l.touchedSpare, nil
return taken