retry automatic cuts while staging makes progress

This commit is contained in:
pingqiu committed 2026-11-28 18:26:20 -08:00
1 parent 0aeed517fd
commit acfafb4aca
2 files changed
+45 -27

No files matched your search

@@ -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)}
})
}
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)
}
})
}
@@ -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 {