storage: retain the concurrent HEAD oracle across locally refused cut points

This commit is contained in:
pingqiu committed 2026-11-19 20:16:35 -08:00
1 parent 67a18b151b
commit 7cc044549f
2 files changed
+41 -2

No files matched your search

+2 -1
View File
@@ -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
@@ -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
}