mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
filer: end a subscriber's stall when memory serves its cursor (#13310)
* filer: end a subscriber's stall when memory serves its cursor
A metadata subscriber that finds nothing in the ring yet parks until data
arrives ("no readable in-memory entries yet"), which starts its stall
clock. When data arrives the ring serves the cursor and the read goes on,
but nothing stopped the clock: only the paths that leave a gap do.
The clock is what bounds the wait on a gap. With it still running from
that first park, the first real gap the subscriber meets, hours later,
looks older than maxGapStall the moment it parks: the park gives up at
once and skips to the eviction watermark, and the events a peer would have
flushed within the flush interval are never delivered. The log shows a
subscriber "parked" for hours at a cursor a few seconds old, and the gap
skipped in the same millisecond. A mount keeps the stale listing it has
for those events, and filer.sync loses them.
resolve now ends the stall when it sends the read to memory.
* filer: age the first stall in the memory-serves test instead of shrinking maxGapStall
With maxGapStall at 50ms, a scheduler pause between the fresh park and its
give-up check expired the new stall and failed the test against the fixed
code. Keep the real bound and backdate the first park's clock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* filer: shorten the comment on ending the stall in resolve
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: MapleWhiteZZZ <18653045+MapleWhiteZZZ@users.noreply.github.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+76
No files matched your search
@@ -656,6 +656,9 @@ func (p *gapPass) resolve(ctx context.Context, cursor *log_buffer.MessagePositio
|
||||
}
|
||||
return p.park(ctx, cursor, latch, p.dataChan, "no readable in-memory entries yet")
|
||||
}
|
||||
// Memory serves the cursor: a park for entries the ring lacked ends only
|
||||
// here, and its clock left running gives up the next gap at once.
|
||||
p.gapStall.resumed()
|
||||
return gapProceed
|
||||
}
|
||||
|
||||
|
||||
@@ -672,3 +672,76 @@ func TestRingServesCursor(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestGapPassEndsTheStallWhenMemoryServesTheCursor: a subscriber that parked
|
||||
// for entries the ring did not have yet, and then went on reading the ring,
|
||||
// is no longer stalled. Left running, its stall clock makes the first real gap
|
||||
// it meets, however much later, look older than maxGapStall: the park gives up
|
||||
// at once and skips events a peer would have flushed within the minute.
|
||||
func TestGapPassEndsTheStallWhenMemoryServesTheCursor(t *testing.T) {
|
||||
crossings := func() float64 {
|
||||
m := &dto.Metric{}
|
||||
if err := stats.FilerSubscribeUnprovenGapCrossings.WithLabelValues("aggregated").Write(m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return m.GetCounter().GetValue()
|
||||
}
|
||||
signalled := func() chan struct{} {
|
||||
ch := make(chan struct{}, 1)
|
||||
ch <- struct{}{}
|
||||
return ch
|
||||
}
|
||||
|
||||
now := time.Now().UnixNano()
|
||||
var earliest time.Time // the ring is empty
|
||||
var evicted, flushed int64
|
||||
p := &gapPass{
|
||||
fs: &FilerServer{knownListeners: map[int32]int32{7: 3}},
|
||||
req: &filer_pb.SubscribeMetadataRequest{ClientId: 7, ClientEpoch: 3},
|
||||
gapStall: &gapStallReporter{scope: "aggregated", clientName: "c", pathPrefix: "/"},
|
||||
earliest: func() time.Time { return earliest },
|
||||
evicted: func() int64 { return evicted },
|
||||
flushed: func() int64 { return flushed },
|
||||
gapReason: func(time.Time, int64) string { return "test gap" },
|
||||
}
|
||||
defer p.gapStall.close()
|
||||
|
||||
// 1. Nothing in the ring yet: the subscriber parks until data arrives.
|
||||
p.dataChan = signalled()
|
||||
cursor := log_buffer.NewMessagePosition(now, gapResumeCursorOffset)
|
||||
latch := error(log_buffer.ResumeFromDiskError)
|
||||
if got := p.resolve(context.Background(), &cursor, &latch, false); got != gapContinue {
|
||||
t.Fatalf("with an empty ring: outcome %v, want gapContinue after the park", got)
|
||||
}
|
||||
if p.gapStall.stalledFor() == 0 {
|
||||
t.Fatal("precondition: the park did not start the stall clock")
|
||||
}
|
||||
p.gapStall.since = time.Now().Add(-2 * maxGapStall)
|
||||
|
||||
// 2. Data arrived and the ring serves the cursor: the read goes on.
|
||||
earliest = time.Unix(0, now-int64(time.Second))
|
||||
latch = nil
|
||||
if got := p.resolve(context.Background(), &cursor, &latch, false); got != gapProceed {
|
||||
t.Fatalf("with the ring serving the cursor: outcome %v, want gapProceed", got)
|
||||
}
|
||||
if stalled := p.gapStall.stalledFor(); stalled != 0 {
|
||||
t.Errorf("the subscriber reads from memory, yet counts as stalled for %v", stalled)
|
||||
}
|
||||
|
||||
// 3. Much later the ring evicts past the cursor, into a range no peer has
|
||||
// flushed yet. That gap has only just opened: the subscriber must wait for
|
||||
// it, not skip it.
|
||||
evicted = now + int64(3*time.Second)
|
||||
earliest = time.Unix(0, evicted+1)
|
||||
p.gapChan = signalled()
|
||||
before := crossings()
|
||||
if got := p.resolve(context.Background(), &cursor, &latch, false); got != gapContinue {
|
||||
t.Fatalf("on a fresh gap: outcome %v, want gapContinue after the park", got)
|
||||
}
|
||||
if got := cursor.Time.UnixNano(); got != now {
|
||||
t.Fatalf("the cursor skipped a gap it had waited %v for: moved from %v to %v", p.gapStall.stalledFor(), time.Unix(0, now), time.Unix(0, got))
|
||||
}
|
||||
if got := crossings(); got != before {
|
||||
t.Fatalf("a gap that had just opened was given up on: the loss counter moved by %v", got-before)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user