mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
fix: a cut's payload time counts staging; the layer counts staged chunks
A cut's PayloadNs now counts its staging rounds even when they uploaded nothing (every staged chunk was zero), so a first cut that spent its time reading and hashing shows it. The layer status gains StagedChunks: the chunks staged by every cut attempt, failed ones included, so a cut retried after its deadline shows the progress its earlier attempts made. DirtyChunks is documented as the next cut's candidates, not its progress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1c4870dd65
commit
6d00eb63b4
4 files changed
+80
-7
No files matched your search
@@ -778,9 +778,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
|
||||
if !guestFrozen {
|
||||
staged, intents, err = l.stage(ctx, &st, spill.bytes)
|
||||
}
|
||||
if st.UploadedBytes > 0 {
|
||||
st.PayloadNs += time.Since(stageStart).Nanoseconds()
|
||||
}
|
||||
st.PayloadNs += time.Since(stageStart).Nanoseconds()
|
||||
if err != nil {
|
||||
dropCapturedIntents(ctx, intents)
|
||||
return chunkCutResult{}, err
|
||||
@@ -1631,6 +1629,9 @@ func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats, spillCap
|
||||
staged[idx] = sc
|
||||
}
|
||||
st.StagedChunks += len(batch)
|
||||
l.stMu.Lock()
|
||||
l.stats.StagedChunks += uint64(len(batch))
|
||||
l.stMu.Unlock()
|
||||
if hook := l.testAfterStageHook; hook != nil {
|
||||
hook(round)
|
||||
}
|
||||
|
||||
@@ -489,8 +489,13 @@ type chunkCutStats struct {
|
||||
// results whose outcome stayed unresolved after the HEAD re-read.
|
||||
// - PendingUnresolved: an unresolved proposal is held now.
|
||||
// - DirtyChunks is the number of chunks dirty since the last HEAD now
|
||||
// (the C11 bitmap popcount); the cut scheduler's threshold reads it.
|
||||
// Chunks still awaiting reconciliation are not counted.
|
||||
// (the C11 bitmap popcount): the next cut's candidates, not its
|
||||
// progress (it does not fall while a cut runs or across failed
|
||||
// attempts); the cut scheduler's threshold reads it. Chunks still
|
||||
// awaiting reconciliation are not counted.
|
||||
// - StagedChunks counts the chunks every cut attempt of this layer
|
||||
// staged, failed attempts included (in-process): the progress a cut
|
||||
// retried after its deadline has made.
|
||||
// - Reconciling: the dirty set is being reconciled against HEAD; no cut
|
||||
// publishes until it is done. ReconcileDone of ReconcileTotal chunks
|
||||
// are compared.
|
||||
@@ -508,7 +513,8 @@ type chunkLayerStats struct {
|
||||
CASConflicts uint64 // HEAD CAS precondition failures
|
||||
CASUnknown uint64 // HEAD CAS results still unresolved after the re-read
|
||||
PendingUnresolved bool // an unresolved HEAD proposal is held now
|
||||
DirtyChunks int // chunks dirty since the last HEAD (not counting those awaiting reconciliation)
|
||||
DirtyChunks int // chunks dirty since the last HEAD (not counting those awaiting reconciliation): candidates, not progress
|
||||
StagedChunks uint64 // chunks staged by every cut attempt, failed ones included (in-process)
|
||||
Reconciling bool // the dirty set is being reconciled against HEAD; no cut publishes meanwhile
|
||||
ReconcileDone int // chunks compared so far
|
||||
ReconcileTotal int // chunks to compare
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// zeroStagedLayer is a layer past its zero baseline cut with n chunks
|
||||
// rewritten with zeros: candidates that staging reads and hashes but never
|
||||
// uploads. The spill cap of two chunks makes the cut stage them.
|
||||
func zeroStagedLayer(t *testing.T, n int) (*fakeChunkRemote, *chunkLayerImpl) {
|
||||
t.Helper()
|
||||
s, f, l, w := precopyLayer(t, 1, 0)
|
||||
l.cfg.COWSpillLimit = 2 * ctChunkBytes
|
||||
for c := 0; c < n; c++ {
|
||||
w.write(t, s, uint32(c*ctChunkBlocks+2), 0)
|
||||
}
|
||||
return f, l
|
||||
}
|
||||
|
||||
// The payload time of a cut counts its staging rounds even when they
|
||||
// upload nothing (every staged chunk was zero), so a first cut that spent
|
||||
// its time reading and hashing shows it.
|
||||
func TestChunkStage_PayloadTimeCountsStagingWithoutUploads(t *testing.T) {
|
||||
_, l := zeroStagedLayer(t, 6)
|
||||
// Staging takes measurable time on any clock resolution.
|
||||
l.testAfterStageHook = func(int) { time.Sleep(20 * time.Millisecond) }
|
||||
r, err := l.Cut(ctTimeout(t))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := r.Stats
|
||||
if st.StageRounds == 0 || st.StagedChunks == 0 {
|
||||
t.Fatalf("cut stats %+v; want staging rounds", st)
|
||||
}
|
||||
if st.UploadedBytes != 0 {
|
||||
t.Fatalf("uploaded %d bytes; want none (every staged chunk is zero)", st.UploadedBytes)
|
||||
}
|
||||
if st.PayloadNs < int64(20*time.Millisecond) {
|
||||
t.Fatalf("payload time %d ns with %d chunks staged; want the staging time", st.PayloadNs, st.StagedChunks)
|
||||
}
|
||||
}
|
||||
|
||||
// The layer counts every chunk staged by any cut attempt, a failed one
|
||||
// included, so a first cut retried after its deadline shows the progress
|
||||
// its earlier attempts made; the last successful cut's stats do not move.
|
||||
func TestChunkStage_StagedChunksCountsFailedAttempts(t *testing.T) {
|
||||
_, l := zeroStagedLayer(t, 6)
|
||||
before := l.Stats()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
l.testBeforeBarrierLockHook = cancel
|
||||
if _, err := l.Cut(ctx); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("cut: %v; want it cancelled before the barrier", err)
|
||||
}
|
||||
l.testBeforeBarrierLockHook = nil
|
||||
after := l.Stats()
|
||||
if after.StagedChunks <= before.StagedChunks {
|
||||
t.Fatalf("staged chunks %d before, %d after a failed attempt that staged; want more", before.StagedChunks, after.StagedChunks)
|
||||
}
|
||||
if after.CutSeq != before.CutSeq || after.LastCut.StagedChunks != before.LastCut.StagedChunks {
|
||||
t.Fatal("a failed attempt changed the last successful cut")
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,8 @@ Durable store state of the served volume. Go type `volume.durableStatusBody`.
|
||||
| `Volumes[].Chunk.Stats.CASConflicts` | uint64 | HEAD CAS precondition failures |
|
||||
| `Volumes[].Chunk.Stats.CASUnknown` | uint64 | HEAD CAS results still unresolved after the re-read |
|
||||
| `Volumes[].Chunk.Stats.PendingUnresolved` | bool | an unresolved HEAD proposal is held now |
|
||||
| `Volumes[].Chunk.Stats.DirtyChunks` | int | chunks dirty since the last HEAD (not counting those awaiting reconciliation) |
|
||||
| `Volumes[].Chunk.Stats.DirtyChunks` | int | chunks dirty since the last HEAD (not counting those awaiting reconciliation): candidates, not progress |
|
||||
| `Volumes[].Chunk.Stats.StagedChunks` | uint64 | chunks staged by every cut attempt, failed ones included (in-process) |
|
||||
| `Volumes[].Chunk.Stats.Reconciling` | bool | the dirty set is being reconciled against HEAD; no cut publishes meanwhile |
|
||||
| `Volumes[].Chunk.Stats.ReconcileDone` | int | chunks compared so far |
|
||||
| `Volumes[].Chunk.Stats.ReconcileTotal` | int | chunks to compare |
|
||||
|
||||
Reference in new issue
Block a user