diff --git a/seaweed-block/core/storage/chunk_cut_candidate_set_test.go b/seaweed-block/core/storage/chunk_cut_candidate_set_test.go index a12d04ffdd..e165179685 100644 --- a/seaweed-block/core/storage/chunk_cut_candidate_set_test.go +++ b/seaweed-block/core/storage/chunk_cut_candidate_set_test.go @@ -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 diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 172d471a17..231632af8d 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -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