From acfafb4aca60be04202061fb2cc7c8cdcb3bce50 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 06:13:55 -0800 Subject: [PATCH] retry automatic cuts while staging makes progress --- .../frontend/durable/cut_progress_test.go | 57 ++++++++++--------- .../core/frontend/durable/provider_chunk.go | 15 ++++- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/seaweed-block/core/frontend/durable/cut_progress_test.go b/seaweed-block/core/frontend/durable/cut_progress_test.go index b1ae5606a9..a0a8efa20c 100644 --- a/seaweed-block/core/frontend/durable/cut_progress_test.go +++ b/seaweed-block/core/frontend/durable/cut_progress_test.go @@ -1,39 +1,44 @@ package durable import ( - "context" - "sync/atomic" - "testing" - "testing/synctest" - "time" + "context" + "sync/atomic" + "testing" + "testing/synctest" + "time" - "github.com/seaweedfs/seaweed-block/core/storage" + "github.com/seaweedfs/seaweed-block/core/storage" ) // The public layer counters report completed staging even when its cut times out. type progressLoopLayer struct { - storage.ChunkLayer - staged atomic.Uint64 - calls atomic.Int32 + storage.ChunkLayer + staged atomic.Uint64 + calls atomic.Int32 } + func (l *progressLoopLayer) Fenced() bool { return false } -func (l *progressLoopLayer) Stats() storage.ChunkLayerStats { return storage.ChunkLayerStats{StagedChunks:l.staged.Load()} } -func (l *progressLoopLayer) Cut(context.Context) (storage.ChunkCutResult,error) { - l.calls.Add(1) - l.staged.Add(1) - return storage.ChunkCutResult{},context.DeadlineExceeded +func (l *progressLoopLayer) Stats() storage.ChunkLayerStats { + return storage.ChunkLayerStats{StagedChunks: l.staged.Load()} +} +func (l *progressLoopLayer) Cut(context.Context) (storage.ChunkCutResult, error) { + l.calls.Add(1) + l.staged.Add(1) + return storage.ChunkCutResult{}, context.DeadlineExceeded } func TestCutLoopProgressRetriesWithoutBackoff(t *testing.T) { - synctest.Test(t,func(t *testing.T){ - layer:=&progressLoopLayer{} - p:=&DurableProvider{cfg:ProviderConfig{ChunkCaptureInterval:time.Millisecond}} - ctx,cancel:=context.WithCancel(context.Background()) - done:=make(chan struct{}) - go p.chunkLoop(ctx,"progress",layer,done,nil) - defer func(){cancel(); <-done}() - time.Sleep(500*time.Millisecond) - synctest.Wait() - if n:=layer.calls.Load();n<3 {t.Fatalf("only %d attempts despite new staged chunks; progress must retry at the next poll, without backoff or minimum spacing",n)} - }) -} \ No newline at end of file + synctest.Test(t, func(t *testing.T) { + layer := &progressLoopLayer{} + p := &DurableProvider{cfg: ProviderConfig{ChunkCaptureInterval: time.Millisecond}} + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan struct{}) + go p.chunkLoop(ctx, "progress", layer, done, nil) + defer func() { cancel(); <-done }() + time.Sleep(500 * time.Millisecond) + synctest.Wait() + if n := layer.calls.Load(); n < 3 { + t.Fatalf("only %d attempts despite new staged chunks; progress must retry at the next poll, without backoff or minimum spacing", n) + } + }) +} diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index e275e2ac4e..7a67a2757a 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -837,6 +837,18 @@ func (pol cutPolicy) after(s cutSchedule, start, end time.Time, err error, seq u return s } +// afterStaging retries at the next poll when a failed attempt completed new +// staging. Minimum spacing and exponential backoff apply only without progress. +func (pol cutPolicy) afterStaging(s cutSchedule, start, end time.Time, err error, seq, staged uint64) cutSchedule { + s = pol.after(s, start, end, err, seq) + if err != nil && staged > 0 { + s.lastAuto = time.Time{} + s.backoff = 0 + s.retryAt = end + } + return s +} + // 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 { @@ -910,7 +922,8 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer } } cancel() - s = pol.after(s, start, time.Now(), err, layer.Stats().CutSeq) + after := layer.Stats() + s = pol.afterStaging(s, start, time.Now(), err, after.CutSeq, after.StagedChunks-ls.StagedChunks) wait.record(s) if err != nil && !errors.Is(err, storage.ErrChunkCaptureRefused) && ctx.Err() == nil { if note, stuck := capturePendingNote(err); stuck {