mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Merge remote pre-copy reporting before takeover fixes
This commit is contained in:
commit
93449232f7
6 files changed
+54
-8
No files matched your search
@@ -130,13 +130,13 @@ func precopyFiftyIOPS(t *testing.T, samples byte, wantUnknown bool) {
|
||||
}()
|
||||
result, _, err := p.DetachVolume(ctx, "v1")
|
||||
stopped.Store(true)
|
||||
t.Logf("attempts=%d drain=%s estimate=%s frozen=%t guest_errors=%d", result.Precopy.Attempts, result.Precopy.Drain, result.Precopy.Estimate, result.Precopy.Frozen, guestErrors.Load())
|
||||
t.Logf("attempts=%d measurement_rounds=%d samples_at_start=%d drain=%s estimate=%s frozen=%t guest_errors=%d", result.Precopy.Attempts, result.Precopy.MeasurementRounds, result.Precopy.SamplesAtStart, result.Precopy.Drain, result.Precopy.Estimate, result.Precopy.Frozen, guestErrors.Load())
|
||||
if wantUnknown {
|
||||
if result.Precopy.Frozen {
|
||||
// Staging or later rounds may leave an empty tail, which needs
|
||||
// only measured fixed cost. A nonempty first tail still needs
|
||||
// three upload samples; the one-sample fixture cannot supply them.
|
||||
if err != nil || (result.Precopy.Attempts == 1 && result.Precopy.TailBytes != 0) || guestErrors.Load() != 0 || !bytes.Equal(headBlock(t, remote, 1), block(0x5b)) {
|
||||
if err != nil || (len(result.Precopy.Rounds) == 1 && result.Precopy.TailBytes != 0) || guestErrors.Load() != 0 || !bytes.Equal(headBlock(t, remote, 1), block(0x5b)) {
|
||||
t.Fatalf("cold samples claimed premature fit: report=%+v guest_errors=%d err=%v", result.Precopy, guestErrors.Load(), err)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -962,7 +962,7 @@ func (p *DurableProvider) DetachVolume(ctx context.Context, volumeID string) (st
|
||||
if !stopIOReturned.IsZero() {
|
||||
stopAt = stopIOReturned.UTC().Format(time.RFC3339Nano)
|
||||
}
|
||||
log.Printf("durable: pre-copy volume=%s attempts=%d tail=%d rate=%.0f sample_age=%s fixed=%s estimate=%s frozen=%t reason=%s stop_io_returned_at=%s err=%v", volumeID, r.Precopy.Attempts, r.Precopy.TailBytes, r.Precopy.BytesPerSecond, r.Precopy.SampleAge, r.Precopy.Fixed, r.Precopy.Estimate, r.Precopy.Frozen, r.Precopy.Reason, stopAt, err)
|
||||
log.Printf("durable: pre-copy volume=%s attempts=%d measurement_rounds=%d samples_at_start=%d tail=%d rate=%.0f sample_age=%s fixed=%s estimate=%s frozen=%t reason=%s stop_io_returned_at=%s err=%v", volumeID, r.Precopy.Attempts, r.Precopy.MeasurementRounds, r.Precopy.SamplesAtStart, r.Precopy.TailBytes, r.Precopy.BytesPerSecond, r.Precopy.SampleAge, r.Precopy.Fixed, r.Precopy.Estimate, r.Precopy.Frozen, r.Precopy.Reason, stopAt, err)
|
||||
if err == nil {
|
||||
if !start.IsZero() {
|
||||
r.Precopy.Finish(time.Since(start)+r.Precopy.BarrierBeforeFreeze, 0, false)
|
||||
|
||||
@@ -215,8 +215,8 @@ func precopyBusyOwnerKeepsServing(t *testing.T, delay time.Duration) {
|
||||
t.Fatalf("incomplete pre-copy attempt diagnostic: %s", line)
|
||||
}
|
||||
}
|
||||
if lines != r.Precopy.Attempts {
|
||||
t.Fatalf("pre-copy attempt diagnostics missing: got %d, want %d", lines, r.Precopy.Attempts)
|
||||
if lines != len(r.Precopy.Rounds) || lines != r.Precopy.Attempts+r.Precopy.MeasurementRounds {
|
||||
t.Fatalf("pre-copy round diagnostics missing: got %d, report=%+v", lines, r.Precopy)
|
||||
}
|
||||
if started, resumed := k.calls(); len(started) != 1 || len(resumed) != 1 {
|
||||
t.Fatalf("nonconverged hooks: started=%v resumed=%v", started, resumed)
|
||||
|
||||
@@ -27,6 +27,7 @@ type precopySample struct {
|
||||
}
|
||||
|
||||
type PrecopyAttempt struct {
|
||||
// Attempt is the physical round ordinal, including measurement rounds.
|
||||
Attempt int `json:"attempt"`
|
||||
Drain time.Duration `json:"drainNs"`
|
||||
Barrier time.Duration `json:"barrierNs"`
|
||||
@@ -45,6 +46,8 @@ type PrecopyReport struct {
|
||||
Drain time.Duration `json:"drainNs"`
|
||||
DrainTimedOut bool `json:"drainTimedOut"`
|
||||
Attempts int `json:"attempts"`
|
||||
MeasurementRounds int `json:"measurementRounds"`
|
||||
SamplesAtStart int `json:"samplesAtStart"`
|
||||
TailBytes uint64 `json:"tailBytes"`
|
||||
Fixed time.Duration `json:"fixedNs"`
|
||||
Estimate time.Duration `json:"estimateNs"`
|
||||
@@ -114,6 +117,8 @@ func (l *chunkLayerImpl) precopyDetach(ctx context.Context, prepare func(context
|
||||
var drain time.Duration
|
||||
var drainErr error
|
||||
var rounds []PrecopyAttempt
|
||||
samplesAtStart := l.precopyEstimate(0, 0).RateSamples
|
||||
warmAttempts, measurementRounds := 0, 0
|
||||
if prepare != nil {
|
||||
l.precopyPrepare = func(ctx context.Context) (func(), error) {
|
||||
dc, cancel := context.WithTimeout(ctx, precopyDrainBound)
|
||||
@@ -164,13 +169,21 @@ func (l *chunkLayerImpl) precopyDetach(ctx context.Context, prepare func(context
|
||||
}
|
||||
defer func() { l.precopyFreeze = nil; l.precopyPause = nil; l.precopyPrepare = nil }()
|
||||
for attempt := 1; attempt <= precopyAttempts; attempt++ {
|
||||
report = PrecopyReport{Attempts: attempt, Rounds: rounds}
|
||||
// Measurement rounds still consume the same five-round/60s budget.
|
||||
// Count an admission attempt only with a warm rate window at entry.
|
||||
if l.precopyEstimate(0, 0).RateSamples >= 3 {
|
||||
warmAttempts++
|
||||
} else {
|
||||
measurementRounds++
|
||||
}
|
||||
report = PrecopyReport{Attempts: warmAttempts, Rounds: rounds, SamplesAtStart: samplesAtStart, MeasurementRounds: measurementRounds}
|
||||
drain, drainErr = 0, nil
|
||||
if err := ctx.Err(); err != nil {
|
||||
return ChunkCutResult{Precopy: report}, err
|
||||
}
|
||||
pauseBefore := pauseTotal
|
||||
r, err := l.captureLocked(ctx, false)
|
||||
report.SamplesAtStart, report.MeasurementRounds = samplesAtStart, measurementRounds
|
||||
a := PrecopyAttempt{
|
||||
Attempt: attempt, Drain: drain, Pause: pauseTotal - pauseBefore,
|
||||
TailBytes: report.TailBytes, RateSamples: report.RateSamples,
|
||||
|
||||
@@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -76,7 +77,7 @@ func TestPrecopyDetachBusyOwnerExhaustsWithoutStopping(t *testing.T) {
|
||||
s, f, l, _ := precopyLayer(t, 1024, 1)
|
||||
calls := 0
|
||||
r, err := l.PrecopyDetach(ctTimeout(t), func() bool { calls++; return false })
|
||||
if !errors.Is(err, ErrPrecopyNotConverged) || r.Precopy.Attempts != 5 || r.Precopy.Frozen || calls == 0 {
|
||||
if !errors.Is(err, ErrPrecopyNotConverged) || len(r.Precopy.Rounds) != 5 || r.Precopy.Frozen || calls == 0 {
|
||||
t.Fatalf("report=%+v calls=%d err=%v", r.Precopy, calls, err)
|
||||
}
|
||||
if f.stats().head.State == ChunkHeadDetached {
|
||||
@@ -416,3 +417,35 @@ func TestPrecopyAttemptDiagnosticsSeparateTimeoutFromFit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrecopyCountsWarmAttemptsSeparatelyFromMeasurementRounds(t *testing.T) {
|
||||
for _, warm := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "cold", true: "warm"}[warm], func(t *testing.T) {
|
||||
_, _, l, _ := precopyLayer(t, 1024, 0)
|
||||
l.precopySamples = nil
|
||||
if warm {
|
||||
for i := 0; i < 3; i++ {
|
||||
l.precopySamples = append(l.precopySamples, precopySample{at: time.Now(), fixed: time.Millisecond, rate: 1 << 30})
|
||||
}
|
||||
}
|
||||
r, _ := l.PrecopyDetachWithAdmission(ctTimeout(t), func(context.Context) (func(), error) {
|
||||
return nil, errors.New("controlled admission refusal")
|
||||
}, func() bool { t.Fatal("refused admission froze"); return false })
|
||||
data, err := json.Marshal(r.Precopy)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var fields map[string]any
|
||||
if err := json.Unmarshal(data, &fields); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantSamples, wantAttempts, wantMeasurement := float64(0), float64(0), float64(5)
|
||||
if warm {
|
||||
wantSamples, wantAttempts, wantMeasurement = 3, 5, 0
|
||||
}
|
||||
if fields["samplesAtStart"] != wantSamples || fields["attempts"] != wantAttempts || fields["measurementRounds"] != wantMeasurement || len(r.Precopy.Rounds) != 5 {
|
||||
t.Fatalf("warm=%t report=%s", warm, data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -465,7 +465,7 @@ Notes:
|
||||
|---|---|---|---|---|---|---|
|
||||
| `INV-CUT-COW-OWNER-001` | Before any read-visible native mutation, a pending candidate has one saving owner; copying/saving collisions wait. The immutable cut buffer is exactly the image at H. | M5 OpenWindow → Copy | `chunk_cut_cow.go` `claim`, `beforeCOWMutation`; Write/WriteBatch/applyEntryV3 pre-publication hooks | `TestCutCOWV3_MutationCompletesWhileEarlierChunkCopyIsHeld`, `TestCutCOWV3_CopyingChunkWaitsButPendingChunkSaves`, `TestCutCOWV3_TwoWritersOneSaveAndCloseJoinsSavedReader`, `TestCutCOWV3_OverlappingRealBatchesPreserveCut` | CutCOW2 BufFrozen/HeadImage; writer/batch multiplicity tested, not modelled | ACTIVE |
|
||||
| `INV-CUT-COW-DRAIN-001` | Terminal invalidation forbids new references; aborting owners release themselves before join. Side cleanup and destructive transitions wait for actual I/O references. Store Close cannot miss first attachment; every Close waits for full shutdown. | M5 Closed/Aborted → Drain; M1 Close/Recover | `chunk_cut_cow.go` `abort`, `join`, `holdChunkDestructive`; `WALStore.Close`; attach capture admission | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner`, `TestCutCOWV3_CloseJoinsHeldLiveCopy`, `TestCutCOWV3_CloseSnapshotRejectsFirstAttachAndSharesCompletion`, `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment`, `TestCutCOWV3_SpillIsEphemeralAndCleanupIsPrefixScoped`, `TestCutCOWV3_ProcessCrashDropsSideAndRestoresSyncedImage` | CutCOW2 SideOnlyInCut, abortNoJoin RED; real lifecycle races tested separately | ACTIVE |
|
||||
| `INV-CUT-PRECOPY-001` | Opt-in final-tail admission closes frontend admission, drains registered I/O before the store lock within a 100 ms caller context, then uses authoritative barrier candidates and measured costs. Refusal reopens tentative admission before rolling uploads. Final freeze queues without completion for up to five seconds; safe resume is FIFO, host drain preserves the active queue, and transport teardown cancels commands before joining; no queued storage work is issued. Only settled detached publication permits handoff; aborted rounds retain dirty bytes. | M5 tentative admission -> ordinary COW or FinalFreeze | `chunk_precopy.go`; `precopy_admission.go`; `storage_adapter.go`; `provider_chunk.go` | `TestPrecopyProviderBusyOwnerKeepsServing`, `TestPrecopyProviderBusyOwnerRetryRetainsSlowFixedSample`, `TestPrecopyFiftyIOPSSyncConvergesFirstAttempt`, `TestPrecopyFiftyIOPSColdCostsKeepAdmissionHonest`, `TestPrecopyHostDrainDoesNotCompleteHeldGuestIO`, `TestPrecopyTargetCloseDropsHeldCommandWithoutCompletion`, `TestPrecopyDrainLetsAnAdmittedWriterReachTheBarrier`, `TestPrecopyDrainReceives100MillisecondBound`, `TestPrecopyDrainTimeoutReopensWithoutWaitingUnderCapture`, `TestPrecopyLateGateCallerCannotCrossFreeze`, `TestPrecopyQueueResumesInFIFOOrder`, `TestPrecopyQueueUsesFiveSecondCutoverBudget`, `TestPrecopyRollingUploadReopensTentativeAdmission`, `TestPrecopyDetachRefusedFinalCutKeepsChangedBytes`, `TestPrecopyDetachSustainedWrapFlushAndFreshRestore` | Controlled callers; measured latency is not a model proof | ACTIVE |
|
||||
| `INV-CUT-PRECOPY-001` | Opt-in final-tail admission closes frontend admission, drains registered I/O before the store lock within a 100 ms caller context, then uses authoritative barrier candidates and measured costs. Refusal reopens tentative admission before rolling uploads. Final freeze queues without completion for up to five seconds; safe resume is FIFO, host drain preserves the active queue, and transport teardown cancels commands before joining; no queued storage work is issued. Only settled detached publication permits handoff; aborted rounds retain dirty bytes. Warm attempts and measurement rounds are reported separately, with samples at start; both consume the same five-round budget. | M5 tentative admission -> ordinary COW or FinalFreeze | `chunk_precopy.go`; `precopy_admission.go`; `storage_adapter.go`; `provider_chunk.go` | `TestPrecopyProviderBusyOwnerKeepsServing`, `TestPrecopyProviderBusyOwnerRetryRetainsSlowFixedSample`, `TestPrecopyCountsWarmAttemptsSeparatelyFromMeasurementRounds`, `TestPrecopyFiftyIOPSSyncConvergesFirstAttempt`, `TestPrecopyFiftyIOPSColdCostsKeepAdmissionHonest`, `TestPrecopyHostDrainDoesNotCompleteHeldGuestIO`, `TestPrecopyTargetCloseDropsHeldCommandWithoutCompletion`, `TestPrecopyDrainLetsAnAdmittedWriterReachTheBarrier`, `TestPrecopyDrainReceives100MillisecondBound`, `TestPrecopyDrainTimeoutReopensWithoutWaitingUnderCapture`, `TestPrecopyLateGateCallerCannotCrossFreeze`, `TestPrecopyQueueResumesInFIFOOrder`, `TestPrecopyQueueUsesFiveSecondCutoverBudget`, `TestPrecopyRollingUploadReopensTentativeAdmission`, `TestPrecopyDetachRefusedFinalCutKeepsChangedBytes`, `TestPrecopyDetachSustainedWrapFlushAndFreshRestore` | Controlled callers; measured latency is not a model proof | ACTIVE |
|
||||
| `INV-CUT-QUIESCED-001` | HEAD is exactly the image at a quiesced cut H, and H is a synced LSN. | M5 Quiesce → Copy → CAS | `core/storage/chunk_layer.go` `captureLocked` | `TestChunkLayer_C1_HeadIsQuiescedCutImage`, `TestChunkLayer_C3_EveryHeadIsExactUnderConcurrentWrites` (`core/storage/chunk_layer_contract_test.go`) | `CutPipeline` `HeadImage`; `CutCapture` `HeadImage` | ACTIVE |
|
||||
| `INV-CUT-BIRTH-001` | A captured chunk birth is bounded by the same-barrier cut frontier: native capture uses min(conservative owned-map maximum, H), retaining lower inherited births. A dropped unacked suffix and reused LSN cannot emit BirthLSN > HEAD.RemoteLSN; the manifest validator still refuses future births. | M5 Quiesce -> Copy -> Manifest | `core/storage/chunk_birth.go` `captureBirths`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestChunkBirthDroppedSuffixPublishesWithRealManifest` (`core/storage/chunk_birth_manifest_test.go`), `TestChunkBirthCOWDoesNotObservePostBarrierWrite`, `TestChunkBirthBASEUsesInheritedFrontierIncludingZero` | Cut image at H; real recovery/manifest regression, not a new model claim | ACTIVE |
|
||||
| `INV-CUT-RECONCILING-001` | While the dirty set is being reconciled, no cut or `MakeRemoteDurable` moves HEAD or makes a remote call. | M5 Admit → Refused (reconciling) | `core/storage/chunk_layer.go` `captureLocked`, `startReconcile` | `TestChunkReconcile_NoHeadMovesWhileReconciling` (`core/storage/chunk_layer_reconcile_test.go`) | `CutPipeline` `HeadImage` | ACTIVE |
|
||||
|
||||
Reference in new issue
Block a user