mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
storage: the pause accounting is the capture's own
resolveTouchFilled and the touched set's allocation also run on readers (status, pre-copy, the shadow: peekTouched) without the capture lock; they counted into the capture's paused/pauseOps whenever a cut happened to be paused, a data race and a misattribution. They count only on the capturing goroutine now (byCapture); readers never touch those fields. TestAReaderBesideCutsAndRecoveriesIsNotChargedToThePause runs a reader beside cuts and recoveries (one just before the barrier); under -race it reports 2 data races on the previous code and none now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1add3afcd0
commit
da217ed376
2 files changed
+70
-17
No files matched your search
@@ -93,6 +93,50 @@ func TestARecoveryJustBeforeTheBarrierIsJudgedAfterThePause(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A reader of the candidates (status, pre-copy, the shadow) running beside
|
||||
// cuts and recoveries never charges its work to a cut's pause nor touches the
|
||||
// capture's pause accounting: run with -race, the schedule (a reader that
|
||||
// can consume a recovery's request while a cut enters its barrier) has no
|
||||
// race, and every cut's pause does no per-candidate work.
|
||||
func TestAReaderBesideCutsAndRecoveriesIsNotChargedToThePause(t *testing.T) {
|
||||
_, l, _ := filledFreshVolume(t)
|
||||
stop := make(chan struct{})
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
default:
|
||||
}
|
||||
_ = l.captureCandidates() // the readers' path: peekTouched, resolveTouchFilled
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
close(stop)
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(ctLocalBound):
|
||||
t.Error("the reader did not stop")
|
||||
}
|
||||
}()
|
||||
for i := 0; i < 20; i++ {
|
||||
l.noteAllMutated() // a recovery the reader may consume first
|
||||
if i%2 == 1 {
|
||||
l.testBeforeBarrierLockHook = func() { l.noteAllMutated() } // or one just before the barrier
|
||||
}
|
||||
r, err := l.Cut(ctTimeout(t))
|
||||
l.testBeforeBarrierLockHook = nil
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.Stats.PauseCandidateOps != 0 {
|
||||
t.Fatalf("cut %d: %d per-candidate operations charged to the pause beside a reader", i, r.Stats.PauseCandidateOps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -513,8 +513,11 @@ func (l *chunkLayerImpl) touchRefChangedLocked() {
|
||||
}
|
||||
|
||||
// resolveTouchFilled touches every clean fill if a recovery asked for it.
|
||||
// The caller holds neither stMu nor WALStore.mu.
|
||||
func (l *chunkLayerImpl) resolveTouchFilled() {
|
||||
// The caller holds neither stMu nor WALStore.mu. byCapture is true only on
|
||||
// the capturing goroutine: the pause accounting (paused, pauseOps) is its
|
||||
// own, so a reader's work (status, pre-copy, the shadow) is never charged to
|
||||
// a cut nor touches those fields.
|
||||
func (l *chunkLayerImpl) resolveTouchFilled(byCapture bool) {
|
||||
if !l.touchFilled.Swap(false) {
|
||||
return
|
||||
}
|
||||
@@ -524,14 +527,19 @@ func (l *chunkLayerImpl) resolveTouchFilled() {
|
||||
filled = append(filled, idx)
|
||||
}
|
||||
l.stMu.Unlock()
|
||||
l.pauseOp(len(filled))
|
||||
if byCapture {
|
||||
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)
|
||||
// dependent, counted as pause work when the capturing goroutine allocates it
|
||||
// while the guest is paused).
|
||||
func (l *chunkLayerImpl) newTouchedSet(byCapture bool) *candidateSet {
|
||||
if byCapture {
|
||||
l.pauseOp(int(l.numChunks/64) + 1)
|
||||
}
|
||||
return newCandidateSet(l.numChunks)
|
||||
}
|
||||
|
||||
@@ -628,7 +636,7 @@ func (l *chunkLayerImpl) touch(chunks ...uint64) {
|
||||
return
|
||||
}
|
||||
l.unkMu.Lock()
|
||||
set := l.touchedLocked()
|
||||
set := l.touchedLocked(false) // any goroutine
|
||||
for _, c := range chunks {
|
||||
if c < l.numChunks {
|
||||
set.set(c)
|
||||
@@ -637,10 +645,11 @@ func (l *chunkLayerImpl) touch(chunks ...uint64) {
|
||||
l.unkMu.Unlock()
|
||||
}
|
||||
|
||||
// touchedLocked is the live touched set, made on first use. Caller holds unkMu.
|
||||
func (l *chunkLayerImpl) touchedLocked() *candidateSet {
|
||||
// touchedLocked is the live touched set, made on first use. Caller holds
|
||||
// unkMu; byCapture as in resolveTouchFilled.
|
||||
func (l *chunkLayerImpl) touchedLocked(byCapture bool) *candidateSet {
|
||||
if l.touched == nil {
|
||||
l.touched = l.newTouchedSet()
|
||||
l.touched = l.newTouchedSet(byCapture)
|
||||
}
|
||||
return l.touched
|
||||
}
|
||||
@@ -780,10 +789,10 @@ func (l *chunkLayerImpl) seedTouched() {
|
||||
// peekTouched lists the touched set's members, for a reader.
|
||||
func (l *chunkLayerImpl) peekTouched() []uint64 {
|
||||
l.touchedSeed.Do(l.seedTouched)
|
||||
l.resolveTouchFilled()
|
||||
l.resolveTouchFilled(false)
|
||||
l.unkMu.Lock()
|
||||
defer l.unkMu.Unlock()
|
||||
set := l.touchedLocked()
|
||||
set := l.touchedLocked(false)
|
||||
out := make([]uint64, 0, set.Len())
|
||||
set.each(func(c uint64) { out = append(out, c) })
|
||||
return out
|
||||
@@ -795,9 +804,9 @@ func (l *chunkLayerImpl) peekTouched() []uint64 {
|
||||
func (l *chunkLayerImpl) takeTouched() *candidateSet {
|
||||
l.unkMu.Lock()
|
||||
defer l.unkMu.Unlock()
|
||||
taken := l.touchedLocked()
|
||||
taken := l.touchedLocked(true)
|
||||
if l.touchedSpare == nil {
|
||||
l.touchedSpare = l.newTouchedSet() // only if prepareTouched was skipped
|
||||
l.touchedSpare = l.newTouchedSet(true) // only if prepareTouched was skipped
|
||||
}
|
||||
l.touched, l.touchedSpare = l.touchedSpare, nil
|
||||
return taken
|
||||
@@ -808,11 +817,11 @@ func (l *chunkLayerImpl) takeTouched() *candidateSet {
|
||||
// and the cleared spare the barrier swaps in. The barrier then only swaps.
|
||||
func (l *chunkLayerImpl) prepareTouched() {
|
||||
l.touchedSeed.Do(l.seedTouched)
|
||||
l.resolveTouchFilled()
|
||||
l.resolveTouchFilled(true)
|
||||
l.unkMu.Lock()
|
||||
l.touchedLocked()
|
||||
l.touchedLocked(true)
|
||||
if l.touchedSpare == nil {
|
||||
l.touchedSpare = l.newTouchedSet()
|
||||
l.touchedSpare = l.newTouchedSet(true)
|
||||
}
|
||||
l.unkMu.Unlock()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user