mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
feat(storage): report each pre-copy admission attempt outside the barrier
This commit is contained in:
1 parent
1aa87c60d3
commit
0141be5aaf
3 files changed
+81
-19
No files matched your search
@@ -952,6 +952,10 @@ func (p *DurableProvider) DetachVolume(ctx context.Context, volumeID string) (st
|
||||
beginFreeze()
|
||||
return true
|
||||
})
|
||||
// Log only after capture releases its barrier; at most five records.
|
||||
for _, a := range r.Precopy.Rounds {
|
||||
log.Printf("durable: pre-copy attempt volume=%s attempt=%d drain_ms=%.3f barrier_ms=%.3f pause_ms=%.3f reason=%s tail=%d rate_samples=%d estimate_ms=%.3f frozen=%t err=%s", volumeID, a.Attempt, float64(a.Drain)/float64(time.Millisecond), float64(a.Barrier)/float64(time.Millisecond), float64(a.Pause)/float64(time.Millisecond), a.Reason, a.TailBytes, a.RateSamples, float64(a.Estimate)/float64(time.Millisecond), a.Frozen, a.Error)
|
||||
}
|
||||
log.Printf("durable: pre-copy volume=%s attempts=%d tail=%d rate=%.0f sample_age=%s fixed=%s estimate=%s frozen=%t reason=%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, err)
|
||||
if err == nil {
|
||||
if !start.IsZero() {
|
||||
|
||||
@@ -26,26 +26,41 @@ type precopySample struct {
|
||||
rate float64
|
||||
}
|
||||
|
||||
type PrecopyAttempt struct {
|
||||
Attempt int `json:"attempt"`
|
||||
Drain time.Duration `json:"drainNs"`
|
||||
Barrier time.Duration `json:"barrierNs"`
|
||||
Pause time.Duration `json:"pauseNs"`
|
||||
TailBytes uint64 `json:"tailBytes"`
|
||||
RateSamples int `json:"rateSamples"`
|
||||
Estimate time.Duration `json:"estimateNs"`
|
||||
Reason string `json:"reason"`
|
||||
Frozen bool `json:"frozen"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// PrecopyReport records admission estimates, not a worst-case latency proof.
|
||||
type PrecopyReport struct {
|
||||
Drain time.Duration `json:"drainNs"`
|
||||
DrainTimedOut bool `json:"drainTimedOut"`
|
||||
Attempts int `json:"attempts"`
|
||||
TailBytes uint64 `json:"tailBytes"`
|
||||
Fixed time.Duration `json:"fixedNs"`
|
||||
Estimate time.Duration `json:"estimateNs"`
|
||||
SampleAge time.Duration `json:"sampleAgeNs"`
|
||||
BytesPerSecond float64 `json:"bytesPerSecond"`
|
||||
Reason string `json:"reason"`
|
||||
Frozen bool `json:"frozen"`
|
||||
FreezeElapsed time.Duration `json:"freezeElapsedNs"`
|
||||
ExtraCASAttempts uint64 `json:"extraCASAttempts"`
|
||||
CASFailureTimeout time.Duration `json:"casFailureTimeoutNs"`
|
||||
DeclaredWorst time.Duration `json:"declaredWorstNs"`
|
||||
LatencyGateFailed bool `json:"latencyGateFailed"`
|
||||
BarrierBeforeFreeze time.Duration `json:"barrierBeforeFreezeNs"`
|
||||
TentativePauseTotal time.Duration `json:"tentativePauseTotalNs"`
|
||||
LongestTentativePause time.Duration `json:"longestTentativePauseNs"`
|
||||
Rounds []PrecopyAttempt `json:"rounds,omitempty"`
|
||||
Drain time.Duration `json:"drainNs"`
|
||||
DrainTimedOut bool `json:"drainTimedOut"`
|
||||
Attempts int `json:"attempts"`
|
||||
TailBytes uint64 `json:"tailBytes"`
|
||||
Fixed time.Duration `json:"fixedNs"`
|
||||
Estimate time.Duration `json:"estimateNs"`
|
||||
SampleAge time.Duration `json:"sampleAgeNs"`
|
||||
BytesPerSecond float64 `json:"bytesPerSecond"`
|
||||
RateSamples int `json:"rateSamples"`
|
||||
Reason string `json:"reason"`
|
||||
Frozen bool `json:"frozen"`
|
||||
FreezeElapsed time.Duration `json:"freezeElapsedNs"`
|
||||
ExtraCASAttempts uint64 `json:"extraCASAttempts"`
|
||||
CASFailureTimeout time.Duration `json:"casFailureTimeoutNs"`
|
||||
DeclaredWorst time.Duration `json:"declaredWorstNs"`
|
||||
LatencyGateFailed bool `json:"latencyGateFailed"`
|
||||
BarrierBeforeFreeze time.Duration `json:"barrierBeforeFreezeNs"`
|
||||
TentativePauseTotal time.Duration `json:"tentativePauseTotalNs"`
|
||||
LongestTentativePause time.Duration `json:"longestTentativePauseNs"`
|
||||
}
|
||||
|
||||
// Finish records the whole freeze, including any owner-driven settlement.
|
||||
@@ -98,6 +113,7 @@ func (l *chunkLayerImpl) precopyDetach(ctx context.Context, prepare func(context
|
||||
var pauseTotal, longestPause time.Duration
|
||||
var drain time.Duration
|
||||
var drainErr error
|
||||
var rounds []PrecopyAttempt
|
||||
if prepare != nil {
|
||||
l.precopyPrepare = func(ctx context.Context) (func(), error) {
|
||||
dc, cancel := context.WithTimeout(ctx, precopyDrainBound)
|
||||
@@ -148,11 +164,27 @@ 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.Attempts = attempt
|
||||
report = PrecopyReport{Attempts: attempt, Rounds: rounds}
|
||||
drain, drainErr = 0, nil
|
||||
if err := ctx.Err(); err != nil {
|
||||
return ChunkCutResult{Precopy: report}, err
|
||||
}
|
||||
pauseBefore := pauseTotal
|
||||
r, err := l.captureLocked(ctx, false)
|
||||
a := PrecopyAttempt{
|
||||
Attempt: attempt, Drain: drain, Pause: pauseTotal - pauseBefore,
|
||||
TailBytes: report.TailBytes, RateSamples: report.RateSamples,
|
||||
Estimate: report.Estimate, Reason: report.Reason, Frozen: report.Frozen,
|
||||
}
|
||||
a.Barrier = max(time.Duration(0), a.Pause-a.Drain)
|
||||
if a.Reason == "" {
|
||||
a.Reason = "before_barrier"
|
||||
}
|
||||
if err != nil {
|
||||
a.Error = err.Error()
|
||||
}
|
||||
rounds = append(rounds, a)
|
||||
report.Rounds = rounds
|
||||
report.TentativePauseTotal, report.LongestTentativePause = pauseTotal, longestPause
|
||||
r.Precopy = report
|
||||
if errors.Is(err, errChunkLayerDetached) {
|
||||
@@ -209,6 +241,7 @@ func (l *chunkLayerImpl) precopyEstimate(tail uint64, attempts int) PrecopyRepor
|
||||
rates = append(rates, s.rate)
|
||||
}
|
||||
}
|
||||
r.RateSamples = len(rates)
|
||||
if r.Fixed <= 0 {
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -391,3 +391,28 @@ func TestPrecopyDrainLetsAnAdmittedWriterReachTheBarrier(t *testing.T) {
|
||||
t.Fatal("authoritative barrier omitted the drained writer")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrecopyAttemptDiagnosticsSeparateTimeoutFromFit(t *testing.T) {
|
||||
_, _, l, _ := precopyLayer(t, 1024, 0)
|
||||
calls := 0
|
||||
r, err := l.PrecopyDetachWithAdmission(ctTimeout(t), func(ctx context.Context) (func(), error) {
|
||||
calls++
|
||||
if calls == 1 {
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
return func() {}, nil
|
||||
}, func() bool { return true })
|
||||
if err != nil || len(r.Precopy.Rounds) != 2 {
|
||||
t.Fatalf("rounds=%+v err=%v", r.Precopy.Rounds, err)
|
||||
}
|
||||
first, second := r.Precopy.Rounds[0], r.Precopy.Rounds[1]
|
||||
if first.Attempt != 1 || first.Reason != "drain_timeout" || first.Frozen || second.Attempt != 2 || second.Reason != "fit" || !second.Frozen {
|
||||
t.Fatalf("attempt outcomes mixed: first=%+v second=%+v", first, second)
|
||||
}
|
||||
for _, a := range r.Precopy.Rounds {
|
||||
if a.Drain <= 0 || a.Pause < a.Drain || a.Barrier != a.Pause-a.Drain {
|
||||
t.Fatalf("pause accounting: %+v", a)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user