From 7cc044549fdd13fb8cc55c9cd0d820b5aff74487 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 18:00:50 -0800 Subject: [PATCH] storage: retain the concurrent HEAD oracle across locally refused cut points --- seaweed-block/core/storage/chunk_cut_cow.go | 3 +- .../core/storage/chunk_layer_contract_test.go | 40 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/storage/chunk_cut_cow.go b/seaweed-block/core/storage/chunk_cut_cow.go index 0686927a9e..8844d982e3 100644 --- a/seaweed-block/core/storage/chunk_cut_cow.go +++ b/seaweed-block/core/storage/chunk_cut_cow.go @@ -30,6 +30,7 @@ const ( ) var errCutCOWAborted = errors.New("storage: cut copy window aborted; retry cut") +var errCutLocalFlushBusy = errors.New("storage: local chunk flush in progress") type cutCOWEntry struct { mu sync.Mutex @@ -213,7 +214,7 @@ func (w *cutCOWWindow) claim(idx uint64, saving bool) (*cutCOWEntry, uint8, <-ch gate := w.layer.s.chunkFlushGate(idx) if !gate.TryRLock() { w.terminal = true - w.err = fmt.Errorf("%w: local chunk flush in progress", errCutCOWAborted) + w.err = fmt.Errorf("%w: %w", errCutCOWAborted, errCutLocalFlushBusy) close(w.ended) w.cancel() return nil, cowDone, nil, nil diff --git a/seaweed-block/core/storage/chunk_layer_contract_test.go b/seaweed-block/core/storage/chunk_layer_contract_test.go index 86dd77f065..73b2c1eb5b 100644 --- a/seaweed-block/core/storage/chunk_layer_contract_test.go +++ b/seaweed-block/core/storage/chunk_layer_contract_test.go @@ -176,7 +176,7 @@ func TestChunkLayer_C2_StalledUploadDoesNotGateLocal(t *testing.T) { func TestChunkLayer_C3_EveryHeadIsExactUnderConcurrentWrites(t *testing.T) { s, _ := newChunkTestStore(t) f := newFakeChunkRemote() - layer := mustAttach(t, s, f, ctConfig(1)) + layer := rollingCaptureForTest{mustAttach(t, s, f, ctConfig(1))} w := newWriteLog() for lba := uint32(0); lba < ctChunkBlocks; lba++ { w.write(t, s, lba, byte(0x40+lba)) @@ -1199,3 +1199,41 @@ func TestChunkLayer_C10_LocalRecoveryWinsOverOlderHead(t *testing.T) { t.Fatal("first capture after restart did not publish the recovered local data") } } + +// Rolling callers retry a point refused because the local flusher already +// owns its chunk. No deadline extension and no retry of a joined physical, +// integrity, cancellation or authority error is allowed here. +type rollingCaptureForTest struct{ chunkLayer } + +func (l rollingCaptureForTest) Capture(ctx context.Context) (uint64, error) { + ticker := time.NewTicker(time.Millisecond) + defer ticker.Stop() + for { + h, err := l.chunkLayer.Capture(ctx) + if !errors.Is(err, errCutLocalFlushBusy) || !onlyLocalFlushAbortForTest(err) { + return h, err + } + select { + case <-ctx.Done(): + return 0, ctx.Err() + case <-ticker.C: + } + } +} +func onlyLocalFlushAbortForTest(err error) bool { + if err == nil || err == errCutLocalFlushBusy || err == errCutCOWAborted { + return true + } + if joined, ok := err.(interface{ Unwrap() []error }); ok { + for _, cause := range joined.Unwrap() { + if !onlyLocalFlushAbortForTest(cause) { + return false + } + } + return true + } + if wrapped, ok := err.(interface{ Unwrap() error }); ok { + return onlyLocalFlushAbortForTest(wrapped.Unwrap()) + } + return false +}