From fdbac0f4630bd180e643a59ef5788ced020e26fa Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 14:42:06 -0800 Subject: [PATCH] fix(storage): classify ceiling refusals and measure recovery read-backs --- seaweed-block/core/storage/chunk_layer.go | 10 ++++++++-- seaweed-block/core/storage/chunk_precopy.go | 15 +++++++++------ .../storage/chunk_precopy_fixed_commit_test.go | 11 +++++++++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 342aeccff8..5c32d22aeb 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -663,6 +663,12 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch l.persistCapturedMapV3(versions) st.MapPersistNs += time.Since(start).Nanoseconds() } + readCapturedHead := func() (chunkHead, error) { + start := time.Now() + head, err := readChunkHead(ctx, l.remote) + st.HeadReadbackNs += time.Since(start).Nanoseconds() + return head, err + } var pauseStart time.Time var payloadBeforeBarrier int64 defer func() { @@ -1000,7 +1006,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch if !upgrade && !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) { // A no-op cut still observes authority: a fresh host may have // claimed HEAD without uploading a single chunk since our last cut. - cur, err := readChunkHead(ctx, l.remote) + cur, err := readCapturedHead() if err != nil { l.abortCut(all) l.dropIntents(ctx, intents) @@ -1066,7 +1072,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch l.fencePublication(chunkHead{}) // confirmChunkHead already logged the observed root. return chunkCutResult{}, casErr } - cur, gerr := readChunkHead(ctx, l.remote) + cur, gerr := readCapturedHead() if gerr != nil { keepPending() return chunkCutResult{}, fmt.Errorf("storage: capture CAS outcome unresolved (%v): %w: %w", casErr, errChunkCASOutcomeUnknown, gerr) diff --git a/seaweed-block/core/storage/chunk_precopy.go b/seaweed-block/core/storage/chunk_precopy.go index 1c921d0705..54d5ac8689 100644 --- a/seaweed-block/core/storage/chunk_precopy.go +++ b/seaweed-block/core/storage/chunk_precopy.go @@ -337,18 +337,21 @@ func (r *PrecopyReport) admitPrecopy(previous *PrecopyAttempt) bool { if r.Reason == "fit" && r.Estimate <= precopyAllowance { return true } - if previous == nil || previous.Estimate <= 0 || r.Reason == "samples_unknown" { + if r.Reason == "samples_unknown" { + return false + } + // Preserve and name the existing frontend ceiling even on the first round. + if r.TailEstimate <= precopyAllowance/4 && r.Estimate > precopyFreezeLimit { + r.Reason = "fixed_cost_exceeds_freeze_budget" + return false + } + if previous == nil || previous.Estimate <= 0 { return false } r.PreviousEstimate = previous.Estimate if r.TailEstimate > precopyAllowance/4 || r.Estimate < previous.Estimate { return false } - // Preserve the frontend's existing five-second held-command ceiling. - if r.Estimate > precopyFreezeLimit { - r.Reason = "fixed_cost_exceeds_freeze_budget" - return false - } r.Reason = "fixed_cost_over_allowance" return true } diff --git a/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go b/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go index 6e5e863bb2..be6cdccf54 100644 --- a/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go +++ b/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go @@ -11,15 +11,15 @@ import ( func TestPrecopyFixedCostSmallTailCommitsBySecondAttempt(t *testing.T) { s, f, l, w := precopyLayer(t, 1024, 0) fixed := 1300 * time.Millisecond - f.beforeCAS = func(*fakeChunkRemote) { time.Sleep(fixed) } rounds := 0 l.testBeforeBarrierLockHook = func() { rounds++ w.write(t, s, 1, byte(rounds)) + f.beforeCAS = func(*fakeChunkRemote) { time.Sleep(fixed) } // Keep the same known small tail and fixed envelope in each attempt. l.precopySamples = nil for i := 0; i < 3; i++ { - l.precopySamples = append(l.precopySamples, precopySample{at: time.Now(), fixed: fixed, rate: 20 * float64(ctChunkBytes)}) + l.precopySamples = append(l.precopySamples, precopySample{at: time.Now(), fixed: fixed, parts: PrecopyFixedParts{HeadCAS: fixed}, rate: 20 * float64(ctChunkBytes)}) } } ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) @@ -28,6 +28,9 @@ func TestPrecopyFixedCostSmallTailCommitsBySecondAttempt(t *testing.T) { if err != nil || !r.Precopy.Frozen || len(r.Precopy.Rounds) > 2 || r.Precopy.Reason != "fixed_cost_over_allowance" || r.Precopy.Fixed < fixed || r.Precopy.DeclaredWorst < fixed { t.Fatalf("fixed cost cannot converge by recopying the same small tail: report=%+v err=%v", r.Precopy, err) } + if r.Precopy.FreezeElapsed < fixed || r.Precopy.LatencyGateFailed || time.Duration(r.Stats.CASWriteNs) < fixed { + t.Fatalf("final fixed-cost operation was not witnessed within its declaration: %+v", r) + } if r.Head.State != ChunkHeadDetached || !bytes.Equal(f.imageOf(t, r.Head)[ctBlockSize:2*ctBlockSize], makeBlock(ctBlockSize, byte(rounds))) { t.Fatal("amended commit lost the exact point") } @@ -77,6 +80,7 @@ func TestPrecopyFixedCommitRuleKeepsProgressAndFreezeBounds(t *testing.T) { {"large-tail", 300*time.Millisecond + 1, 1500 * time.Millisecond, 1500 * time.Millisecond, true, false}, {"unknown", 0, 1500 * time.Millisecond, 1500 * time.Millisecond, false, false}, {"freeze-ceiling", 0, 5*time.Second + 1, 5*time.Second + 1, true, false}, + {"first-freeze-ceiling", 0, 5*time.Second + 1, 0, true, false}, } { t.Run(tc.name, func(t *testing.T) { reason := "tail_too_large" @@ -91,6 +95,9 @@ func TestPrecopyFixedCommitRuleKeepsProgressAndFreezeBounds(t *testing.T) { if got := r.admitPrecopy(previous); got != tc.want { t.Fatalf("admit=%t report=%+v", got, r) } + if tc.known && tc.estimate > 5*time.Second && r.Reason != "fixed_cost_exceeds_freeze_budget" { + t.Fatalf("mislabelled fixed ceiling: %+v", r) + } if tc.want && r.Reason != "fixed_cost_over_allowance" { t.Fatalf("missing exception reason: %+v", r) }