mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
volume: return the cut's statistics in POST /chunk/cut
The chunk layer fills chunkCutStats for every cut, but the /chunk/cut body dropped them (the W2 placeholder said "added when W3 fills them"). The body now carries a "stats" object that mirrors storage.ChunkCutStats field for field: barrier pause, sync, copy, candidate/uploaded/zeroed/unchanged chunks, uploaded bytes, upload and CAS time and result, total time, and the staging counters. A reflection test keeps the body in step with the layer's struct, so a new layer statistic cannot be dropped silently. This lets a caller (the CLI, a test harness) see what one cut cost without reading logs: the barrier pause against the chunks it copied, and the bytes each cut uploaded to the store. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0e70bd2d2e
commit
0b8ea2f2e6
2 files changed
+88
-3
No files matched your search
@@ -45,8 +45,55 @@ type ChunkCutResponse struct {
|
||||
Holder string `json:"holder"`
|
||||
Noop bool `json:"noop"`
|
||||
FullHash bool `json:"fullHash"`
|
||||
// The cut statistics (§3.1) are added when W3 fills them; until then
|
||||
// the body omits them rather than report zeros (B9 W2 appendix).
|
||||
// Stats are the statistics the chunk layer measured for this cut
|
||||
// (§3.1). A zero field is "not measured" or "none" (a Noop cut
|
||||
// uploads nothing).
|
||||
Stats ChunkCutStatsBody `json:"stats"`
|
||||
}
|
||||
|
||||
// ChunkCutStatsBody is one cut's statistics in the /chunk/cut body. It
|
||||
// mirrors storage.ChunkCutStats field for field (a test keeps the two in
|
||||
// step); every duration is in nanoseconds.
|
||||
type ChunkCutStatsBody struct {
|
||||
BarrierPauseNs int64 `json:"barrierPauseNs"`
|
||||
SyncNs int64 `json:"syncNs"`
|
||||
CopyNs int64 `json:"copyNs"`
|
||||
CandidateChunks int `json:"candidateChunks"`
|
||||
UploadedChunks int `json:"uploadedChunks"`
|
||||
UploadedBytes int64 `json:"uploadedBytes"`
|
||||
ZeroedChunks int `json:"zeroedChunks"`
|
||||
UnchangedChunks int `json:"unchangedChunks"`
|
||||
UploadNs int64 `json:"uploadNs"`
|
||||
CASNs int64 `json:"casNs"`
|
||||
CASResult string `json:"casResult"`
|
||||
TotalNs int64 `json:"totalNs"`
|
||||
StageRounds int `json:"stageRounds"`
|
||||
StagedChunks int `json:"stagedChunks"`
|
||||
StagedChunksUsed int `json:"stagedChunksUsed"`
|
||||
BarrierCopyChunks int `json:"barrierCopyChunks"`
|
||||
BarrierOverBound bool `json:"barrierOverBound"`
|
||||
}
|
||||
|
||||
func cutStatsBody(s storage.ChunkCutStats) ChunkCutStatsBody {
|
||||
return ChunkCutStatsBody{
|
||||
BarrierPauseNs: s.BarrierPauseNs,
|
||||
SyncNs: s.SyncNs,
|
||||
CopyNs: s.CopyNs,
|
||||
CandidateChunks: s.CandidateChunks,
|
||||
UploadedChunks: s.UploadedChunks,
|
||||
UploadedBytes: s.UploadedBytes,
|
||||
ZeroedChunks: s.ZeroedChunks,
|
||||
UnchangedChunks: s.UnchangedChunks,
|
||||
UploadNs: s.UploadNs,
|
||||
CASNs: s.CASNs,
|
||||
CASResult: s.CASResult,
|
||||
TotalNs: s.TotalNs,
|
||||
StageRounds: s.StageRounds,
|
||||
StagedChunks: s.StagedChunks,
|
||||
StagedChunksUsed: s.StagedChunksUsed,
|
||||
BarrierCopyChunks: s.BarrierCopyChunks,
|
||||
BarrierOverBound: s.BarrierOverBound,
|
||||
}
|
||||
}
|
||||
|
||||
// ChunkSnapshotRequest is POST /chunk/snapshot's request (§3.2), without
|
||||
@@ -455,7 +502,7 @@ func (c *chunkControl) Cut(ctx context.Context, volumeID string, minLSN uint64)
|
||||
return ChunkCutResponse{}, err
|
||||
}
|
||||
return ChunkCutResponse{VolumeID: volumeID, CutLSN: r.H, HeadGen: r.Head.Gen, HeadEpoch: r.Head.Epoch, Holder: r.Head.Holder,
|
||||
Noop: r.Noop, FullHash: r.FullHash}, nil
|
||||
Noop: r.Noop, FullHash: r.FullHash, Stats: cutStatsBody(r.Stats)}, nil
|
||||
}
|
||||
|
||||
// Snapshot resolves the request against the catalog first (§3.2 step 1):
|
||||
|
||||
@@ -3,6 +3,7 @@ package volume
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
@@ -112,6 +113,43 @@ func TestChunkControl_CutReturnsTheLayerStats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// ChunkCutStatsBody mirrors storage.ChunkCutStats: a field added to the
|
||||
// layer's statistics must also reach the body.
|
||||
func TestChunkCutStatsBody_MirrorsTheLayerStats(t *testing.T) {
|
||||
layer, body := reflect.TypeOf(storage.ChunkCutStats{}), reflect.TypeOf(ChunkCutStatsBody{})
|
||||
if layer.NumField() != body.NumField() {
|
||||
t.Fatalf("storage.ChunkCutStats has %d fields, ChunkCutStatsBody %d", layer.NumField(), body.NumField())
|
||||
}
|
||||
for i := 0; i < layer.NumField(); i++ {
|
||||
lf, ok := body.FieldByName(layer.Field(i).Name)
|
||||
if !ok || lf.Type != layer.Field(i).Type {
|
||||
t.Fatalf("ChunkCutStatsBody lacks %s %s", layer.Field(i).Name, layer.Field(i).Type)
|
||||
}
|
||||
}
|
||||
// Every field is copied: set each one to a distinct value and compare.
|
||||
var s storage.ChunkCutStats
|
||||
v := reflect.ValueOf(&s).Elem()
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
switch f := v.Field(i); f.Kind() {
|
||||
case reflect.Int, reflect.Int64:
|
||||
f.SetInt(int64(i + 1))
|
||||
case reflect.String:
|
||||
f.SetString("s")
|
||||
case reflect.Bool:
|
||||
f.SetBool(true)
|
||||
default:
|
||||
t.Fatalf("field %s: unhandled kind %s", v.Type().Field(i).Name, f.Kind())
|
||||
}
|
||||
}
|
||||
got := reflect.ValueOf(cutStatsBody(s))
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
name := v.Type().Field(i).Name
|
||||
if !reflect.DeepEqual(got.FieldByName(name).Interface(), v.Field(i).Interface()) {
|
||||
t.Fatalf("cutStatsBody drops %s: got %v, want %v", name, got.FieldByName(name).Interface(), v.Field(i).Interface())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkControl_CutMinLSNAndDetach(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fp, ctl := adapterFixture(t)
|
||||
|
||||
Reference in new issue
Block a user