diff --git a/seaweed-block/core/frontend/durable/precopy_fifty_iops_test.go b/seaweed-block/core/frontend/durable/precopy_fifty_iops_test.go index 4ba4423a44..14470678b4 100644 --- a/seaweed-block/core/frontend/durable/precopy_fifty_iops_test.go +++ b/seaweed-block/core/frontend/durable/precopy_fifty_iops_test.go @@ -167,11 +167,10 @@ func precopyFiftyIOPS(t *testing.T, samples byte, wantUnknown bool, fixedDelay t } // A loaded host may correctly refuse an expensive tail. Preserve the // first-attempt oracle whenever it fits: EVERY earlier attempt must have - // been refused by both the ordinary allowance and the small-tail plateau rule. + // been refused by frontend drain admission or both cost-admission rules. if fixedDelay > 0 && result.Precopy.Fixed < fixedDelay { t.Fatalf("lost slow fixed sample: %+v", result.Precopy) } - const allowance = 1200 * time.Millisecond if len(result.Precopy.Rounds) == 0 { t.Fatal("no admission attempts") } @@ -179,20 +178,15 @@ func precopyFiftyIOPS(t *testing.T, samples byte, wantUnknown bool, fixedDelay t t.Fatal("final freeze disagrees with attempt report") } for i, round := range result.Precopy.Rounds { - eligible := round.Estimate <= allowance - reason := "fit" - if !eligible && i > 0 && round.TailEstimate <= allowance/4 && round.Estimate >= result.Precopy.Rounds[i-1].Estimate && round.Estimate <= 5*time.Second { - eligible = true - reason = "fixed_cost_over_allowance" + var previous *storage.PrecopyAttempt + if i > 0 { + previous = &result.Precopy.Rounds[i-1] } - if round.Frozen { - if !eligible || i != len(result.Precopy.Rounds)-1 || round.Reason != reason || round.DeclaredFreeze != round.Estimate || round.Error != "" { - t.Fatalf("invalid fitting attempt: %+v", round) - } - } else if eligible || (round.Reason != "tail_too_large" && round.Reason != "barrier_over_budget" && round.Reason != "fixed_cost_exceeds_freeze_budget") || round.Error != "" { - t.Fatalf("refused an eligible attempt or hid a failure: %+v", round) + if admissionErr := precopyFiftyAttemptError(round, previous, i == len(result.Precopy.Rounds)-1); admissionErr != nil { + t.Fatal(admissionErr) } } + if !result.Precopy.Frozen { if !errors.Is(err, storage.ErrPrecopyNotConverged) || len(result.Precopy.Rounds) != 5 || result.Precopy.Attempts != 5 || guestErrors.Load() != 0 { t.Fatalf("wrong over-budget outcome: report=%+v err=%v", result.Precopy, err) @@ -301,3 +295,56 @@ func TestPrecopyFiftyIOPSRoundAccounting(t *testing.T) { } }) } + +func precopyFiftyAttemptError(round storage.PrecopyAttempt, previous *storage.PrecopyAttempt, last bool) error { + // Drain admission precedes cost admission. A still-draining FIFO pause + // can refuse even a cheap round; it must not freeze or declare admission. + if !round.Frozen && (round.Reason == "drain_refused" || round.Reason == "drain_timeout") { + if round.Error != "" || round.DeclaredFreeze != 0 { + return fmt.Errorf("drain refusal hid a failure or declared admission: %+v", round) + } + return nil + } + const allowance = 1200 * time.Millisecond + eligible := round.Estimate <= allowance + reason := "fit" + if !eligible && previous != nil && round.TailEstimate <= allowance/4 && round.Estimate >= previous.Estimate && round.Estimate <= 5*time.Second { + eligible, reason = true, "fixed_cost_over_allowance" + } + if round.Frozen { + if !eligible || !last || round.Reason != reason || round.DeclaredFreeze != round.Estimate || round.Error != "" { + return fmt.Errorf("invalid fitting attempt: %+v", round) + } + } else if eligible || (round.Reason != "tail_too_large" && round.Reason != "barrier_over_budget" && round.Reason != "fixed_cost_exceeds_freeze_budget") || round.Error != "" { + return fmt.Errorf("refused an eligible attempt or hid a failure: %+v", round) + } + return nil +} + +func TestPrecopyFiftyIOPSDrainRefusalDoesNotClaimAdmission(t *testing.T) { + previous := storage.PrecopyAttempt{Estimate: 1740 * time.Millisecond} + for _, reason := range []string{"drain_refused", "drain_timeout"} { + for _, estimate := range []time.Duration{500 * time.Millisecond, 1740 * time.Millisecond} { + t.Run(fmt.Sprintf("%s_%d", reason, estimate), func(t *testing.T) { + round := storage.PrecopyAttempt{Reason: reason, Estimate: estimate} + if err := precopyFiftyAttemptError(round, &previous, false); err != nil { + t.Fatal(err) + } + round.Error = "physical read failure" + if err := precopyFiftyAttemptError(round, &previous, false); err == nil { + t.Fatal("drain refusal hid a physical failure") + } + round.Error = "" + round.Frozen = true + if err := precopyFiftyAttemptError(round, &previous, true); err == nil { + t.Fatal("drain refusal claimed a frozen command") + } + round.Frozen = false + round.DeclaredFreeze = round.Estimate + if err := precopyFiftyAttemptError(round, &previous, false); err == nil { + t.Fatal("drain refusal claimed a freeze declaration") + } + }) + } + } +} diff --git a/seaweed-block/core/host/volume/chunk_control.go b/seaweed-block/core/host/volume/chunk_control.go index 392e12a380..1a52a4270a 100644 --- a/seaweed-block/core/host/volume/chunk_control.go +++ b/seaweed-block/core/host/volume/chunk_control.go @@ -64,6 +64,10 @@ type ChunkCutStatsBody struct { COWWaitNs int64 `json:"cowWaitNs"` BarrierPauseNs int64 `json:"barrierPauseNs"` LockWaitNs int64 `json:"lockWaitNs"` + DrainNs int64 `json:"drainNs"` + CASWriteNs int64 `json:"casWriteNs"` + MapPersistNs int64 `json:"mapPersistNs"` + HeadReadbackNs int64 `json:"headReadbackNs"` SyncNs int64 `json:"syncNs"` CopyNs int64 `json:"copyNs"` CandidateChunks int `json:"candidateChunks"` @@ -89,6 +93,10 @@ func cutStatsBody(s storage.ChunkCutStats) ChunkCutStatsBody { COWLocalReadNs: s.COWLocalReadNs, BarrierPauseNs: s.BarrierPauseNs, LockWaitNs: s.LockWaitNs, + DrainNs: s.DrainNs, + CASWriteNs: s.CASWriteNs, + MapPersistNs: s.MapPersistNs, + HeadReadbackNs: s.HeadReadbackNs, SyncNs: s.SyncNs, CopyNs: s.CopyNs, COWSavedChunks: s.COWSavedChunks,