mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
storage, chunkstore: a cut reports its manifest work
ManifestNs was never set (always 0): it is now the time of the manifest read and the segment writes, which run inside the commit check outside every other measured part, so the pre-copy fixed parts gain it from their remainder without counting it twice. Typed counts join it: HEAD's roots and segments read, the roots and segments written, and their bytes, counted by the layout remote (CountCutWork) on both the full commit and the commit by change. They are in the cut stats, the /chunk/cut body (and the status schema) and the cut log line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c4edc98eb0
commit
ba146134e2
7 files changed
+215
-34
No files matched your search
@@ -419,14 +419,22 @@ func (l *LayoutRemote) manifest(ctx context.Context, rn layout.RootName) (map[ui
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
m := map[uint64]layout.Ref{}
|
||||
err := l.r.EachRef(ctx, rn, layout.AllShards, func(idx uint64, ref layout.Ref) bool {
|
||||
m[idx] = ref
|
||||
return true
|
||||
})
|
||||
img, err := l.r.Open(ctx, rn)
|
||||
if err != nil {
|
||||
return nil, layoutRemoteErr(err)
|
||||
}
|
||||
storage.CountCutWork(ctx, storage.CountRootReads, 1)
|
||||
m := map[uint64]layout.Ref{}
|
||||
for _, sh := range img.Shards() {
|
||||
seg, _, err := img.Segment(ctx, sh)
|
||||
if err != nil {
|
||||
return nil, layoutRemoteErr(err)
|
||||
}
|
||||
storage.CountCutWork(ctx, storage.CountSegmentReads, 1)
|
||||
for idx, ref := range seg.Chunks {
|
||||
m[idx] = ref
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -853,6 +861,7 @@ func (l *LayoutRemote) deltaLocked(ctx context.Context, h layout.Head, changes m
|
||||
if err != nil {
|
||||
return layout.CommitDelta{}, layoutRemoteErr(err)
|
||||
}
|
||||
storage.CountCutWork(ctx, storage.CountRootReads, 1)
|
||||
base := *h.Current
|
||||
d.Base, d.BaseRoot = &base, img.Root()
|
||||
shards, _ := layout.ChangesByShard(d.Changes)
|
||||
@@ -862,6 +871,7 @@ func (l *LayoutRemote) deltaLocked(ctx context.Context, h layout.Head, changes m
|
||||
return layout.CommitDelta{}, layoutRemoteErr(err)
|
||||
}
|
||||
if ok {
|
||||
storage.CountCutWork(ctx, storage.CountSegmentReads, 1)
|
||||
d.Prev[sh] = seg
|
||||
}
|
||||
}
|
||||
@@ -873,6 +883,9 @@ func (l *LayoutRemote) deltaLocked(ctx context.Context, h layout.Head, changes m
|
||||
func (l *LayoutRemote) writeDeltaRootLocked(ctx context.Context, plan layout.CommitPlan) error {
|
||||
defer storage.MeasureCutWork(ctx, storage.CutSegmentWrites)()
|
||||
_, err := layout.PrepareRootDelta(ctx, l.st, plan.RootObject(), plan.Segments(), l.session)
|
||||
if err == nil {
|
||||
countManifestWrites(ctx, plan.RootObject(), plan.Segments())
|
||||
}
|
||||
return layoutRemoteErr(err)
|
||||
}
|
||||
|
||||
@@ -885,9 +898,29 @@ func (l *LayoutRemote) writeRootLocked(ctx context.Context, next map[uint64]layo
|
||||
return err
|
||||
}
|
||||
_, err = layout.PrepareRoot(ctx, l.st, root, segs, l.session)
|
||||
if err == nil {
|
||||
countManifestWrites(ctx, root, segs)
|
||||
}
|
||||
return layoutRemoteErr(err)
|
||||
}
|
||||
|
||||
// countManifestWrites counts a commit's prepared manifest objects: each
|
||||
// segment it ensured (written, or found already written by this volume) and
|
||||
// the root, with their bytes. A full commit ensures every segment; a commit
|
||||
// by change only the changed shards' new ones.
|
||||
func countManifestWrites(ctx context.Context, root layout.Root, segs map[layout.SegName][]byte) {
|
||||
var bytes int64
|
||||
for _, b := range segs {
|
||||
bytes += int64(len(b))
|
||||
}
|
||||
if rb, err := root.Encode(); err == nil {
|
||||
bytes += int64(len(rb))
|
||||
}
|
||||
storage.CountCutWork(ctx, storage.CountSegmentWrites, int64(len(segs)))
|
||||
storage.CountCutWork(ctx, storage.CountRootWrites, 1)
|
||||
storage.CountCutWork(ctx, storage.CountManifestBytesWritten, bytes)
|
||||
}
|
||||
|
||||
// Begin opens the cut's session on HEAD (the kernel's Begin), or replays
|
||||
// the open one, and returns it.
|
||||
func (l *LayoutRemote) Begin(ctx context.Context) (string, error) {
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package durable
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log"
|
||||
"path"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
)
|
||||
|
||||
// slowManifestFiler takes 5 ms over each root or segment lookup while
|
||||
// armed, so the manifest time is measurable on any clock.
|
||||
type slowManifestFiler struct {
|
||||
*chunkstore.MemFiler
|
||||
armed atomic.Bool
|
||||
}
|
||||
|
||||
func (f *slowManifestFiler) LookupEntry(ctx context.Context, dir, name string) (*filerpb.Entry, error) {
|
||||
if p := path.Join(dir, name); f.armed.Load() && (strings.Contains(p, "/root/") || strings.Contains(p, "/seg/")) {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
return f.MemFiler.LookupEntry(ctx, dir, name)
|
||||
}
|
||||
|
||||
// A cut through the layout remote reports its manifest work, where the
|
||||
// counters were always zero before: the time of the manifest read and the
|
||||
// segment writes (ManifestNs), HEAD's root and segments read, the root and
|
||||
// segments written, and their bytes, in the cut's stats and in its log line.
|
||||
// The commit is the full one (the engine's): it reads every segment of HEAD
|
||||
// and ensures every segment of the new root.
|
||||
func TestCutReportsItsManifestWork(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
b := &kzLayoutBlobs{b: map[string][]byte{}}
|
||||
f := &slowManifestFiler{MemFiler: chunkstore.NewMemFiler()}
|
||||
cat, err := chunkstore.NewBCatalog(f, b, "/cut-work")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id, err := layout.NewVolumeID()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ref := chunkstore.VolumeRef{Name: "v1", ID: id}
|
||||
if _, err := cat.CreateVolume(ctx, ref, layout.Geometry{SizeBytes: 256 * 4096, BlockSize: 4096, ChunkBytes: 16 * 4096}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := kzProvider(t, t.TempDir(), &kzLayout{cat: cat, ref: ref, blobs: b})
|
||||
if _, err := p.EnsureStorage("v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.RecoverVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.Backend("v1").Write(ctx, 0, bytes.Repeat([]byte{0x11}, 4096)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.CaptureVolume(ctx, "v1"); err != nil { // HEAD now names a root with one segment
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := p.Backend("v1").Write(ctx, 16*4096, bytes.Repeat([]byte{0x22}, 4096)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.armed.Store(true)
|
||||
old := log.Writer()
|
||||
var out bytes.Buffer
|
||||
log.SetOutput(&out)
|
||||
defer log.SetOutput(old)
|
||||
res, err := p.CutVolume(ctx, "v1", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := res.Stats
|
||||
if st.ManifestNs < int64(5*time.Millisecond) || st.ManifestRootReads != 1 || st.ManifestSegmentReads != 1 || st.ManifestRootWrites != 1 || st.ManifestSegmentWrites != 1 || st.ManifestBytesWritten <= 0 {
|
||||
t.Fatalf("manifest work of a one-segment cut: ns=%d root reads=%d segment reads=%d root writes=%d segment writes=%d bytes=%d; want >=5ms, 1, 1, 1, 1, >0",
|
||||
st.ManifestNs, st.ManifestRootReads, st.ManifestSegmentReads, st.ManifestRootWrites, st.ManifestSegmentWrites, st.ManifestBytesWritten)
|
||||
}
|
||||
line := out.String()
|
||||
for _, field := range []string{"root_reads=1", "segment_reads=1", "root_writes=1", "segment_writes=1", "manifest_bytes_written="} {
|
||||
if !strings.Contains(line, field) {
|
||||
t.Fatalf("the cut log line lacks %s: %s", field, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,14 @@ type ChunkCutStatsBody struct {
|
||||
StagedChunksUsed int `json:"stagedChunksUsed"`
|
||||
BarrierCopyChunks int `json:"barrierCopyChunks"`
|
||||
BarrierOverBound bool `json:"barrierOverBound"` // always false in production: its bound is set only by legacy test fixtures
|
||||
|
||||
// The commit's manifest work (ManifestNs is its time): HEAD's roots and
|
||||
// segments read, the roots and segments written, and their bytes.
|
||||
ManifestRootReads int64 `json:"manifestRootReads"`
|
||||
ManifestSegmentReads int64 `json:"manifestSegmentReads"`
|
||||
ManifestRootWrites int64 `json:"manifestRootWrites"`
|
||||
ManifestSegmentWrites int64 `json:"manifestSegmentWrites"`
|
||||
ManifestBytesWritten int64 `json:"manifestBytesWritten"`
|
||||
}
|
||||
|
||||
func cutStatsBody(s storage.ChunkCutStats) ChunkCutStatsBody {
|
||||
@@ -109,34 +117,39 @@ func cutStatsBody(s storage.ChunkCutStats) ChunkCutStatsBody {
|
||||
CommitStateNs: s.CommitStateNs,
|
||||
NonPayloadCopyNs: s.NonPayloadCopyNs,
|
||||
|
||||
PayloadNs: s.PayloadNs,
|
||||
COWWALReadAttempts: s.COWWALReadAttempts,
|
||||
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,
|
||||
COWSaveNs: s.COWSaveNs,
|
||||
COWWaitNs: s.COWWaitNs,
|
||||
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,
|
||||
PayloadNs: s.PayloadNs,
|
||||
COWWALReadAttempts: s.COWWALReadAttempts,
|
||||
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,
|
||||
COWSaveNs: s.COWSaveNs,
|
||||
COWWaitNs: s.COWWaitNs,
|
||||
CandidateChunks: s.CandidateChunks,
|
||||
UploadedChunks: s.UploadedChunks,
|
||||
UploadedBytes: s.UploadedBytes,
|
||||
ZeroedChunks: s.ZeroedChunks,
|
||||
ManifestRootReads: s.ManifestRootReads,
|
||||
ManifestSegmentReads: s.ManifestSegmentReads,
|
||||
ManifestRootWrites: s.ManifestRootWrites,
|
||||
ManifestSegmentWrites: s.ManifestSegmentWrites,
|
||||
ManifestBytesWritten: s.ManifestBytesWritten,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ const (
|
||||
type cutAttemptObservation struct {
|
||||
compared, staged, uploaded atomic.Int64
|
||||
spans [cutWorkSpanCount]atomic.Int64
|
||||
counts [cutWorkCountCount]atomic.Int64
|
||||
}
|
||||
type cutObservationKey struct{}
|
||||
|
||||
@@ -38,3 +39,25 @@ func MeasureCutWork(ctx context.Context, span CutWorkSpan) func() {
|
||||
start := time.Now()
|
||||
return func() { w.spans[span].Add(time.Since(start).Nanoseconds()) }
|
||||
}
|
||||
|
||||
// CutWorkCount identifies a counted unit of a cut's manifest work: the
|
||||
// objects the commit read or wrote, and the bytes it wrote. Like the spans,
|
||||
// counts include work repeated by a retry within one attempt.
|
||||
type CutWorkCount uint8
|
||||
|
||||
const (
|
||||
CountRootReads CutWorkCount = iota
|
||||
CountSegmentReads
|
||||
CountRootWrites
|
||||
CountSegmentWrites
|
||||
CountManifestBytesWritten
|
||||
cutWorkCountCount
|
||||
)
|
||||
|
||||
// CountCutWork adds n to a count of this cut attempt. Outside a cut attempt
|
||||
// it is a no-op.
|
||||
func CountCutWork(ctx context.Context, c CutWorkCount, n int64) {
|
||||
if w := cutObservation(ctx); w != nil && c < cutWorkCountCount {
|
||||
w.counts[c].Add(n)
|
||||
}
|
||||
}
|
||||
@@ -847,6 +847,12 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
|
||||
st.CandidateNs += time.Since(scanStart).Nanoseconds()
|
||||
}
|
||||
st.TotalNs = time.Since(start).Nanoseconds()
|
||||
// The manifest read and the segment writes run inside the commit
|
||||
// check, outside every other measured part: their time is ManifestNs.
|
||||
st.ManifestNs = work.spans[CutManifestRead].Load() + work.spans[CutSegmentWrites].Load()
|
||||
st.ManifestRootReads, st.ManifestSegmentReads = work.counts[CountRootReads].Load(), work.counts[CountSegmentReads].Load()
|
||||
st.ManifestRootWrites, st.ManifestSegmentWrites = work.counts[CountRootWrites].Load(), work.counts[CountSegmentWrites].Load()
|
||||
st.ManifestBytesWritten = work.counts[CountManifestBytesWritten].Load()
|
||||
if err == nil {
|
||||
res.Stats = st
|
||||
if !pauseStart.IsZero() {
|
||||
@@ -873,9 +879,10 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
|
||||
if err == nil && res.Noop && !recoveredPublication && st.CandidateChunks == 0 && st.UploadedChunks == 0 && work.compared.Load() == 0 && work.staged.Load() == 0 && work.uploaded.Load() == 0 {
|
||||
emit = logging.Debugf
|
||||
}
|
||||
emit("storage: cut phases phase_scope=publication work_scope=attempt volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d compared=%d staged=%d uploaded=%d manifest_read_ms=%.3f segment_writes_ms=%.3f commit_check_ms=%.3f candidates_ms=%.3f compare_prepare_ms=%.3f upload_ms=%.3f commit_ms=%.3f head_write_ms=%.3f settle_ms=%.3f total_ms=%.3f err=%q",
|
||||
emit("storage: cut phases phase_scope=publication work_scope=attempt volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d compared=%d staged=%d uploaded=%d manifest_read_ms=%.3f segment_writes_ms=%.3f commit_check_ms=%.3f root_reads=%d segment_reads=%d root_writes=%d segment_writes=%d manifest_bytes_written=%d candidates_ms=%.3f compare_prepare_ms=%.3f upload_ms=%.3f commit_ms=%.3f head_write_ms=%.3f settle_ms=%.3f total_ms=%.3f err=%q",
|
||||
l.cfg.VolumeID, l.cfg.Holder, l.cfg.Epoch, res.H, res.Noop, st.CandidateChunks, work.compared.Load(), work.staged.Load(), work.uploaded.Load(),
|
||||
float64(work.spans[CutManifestRead].Load())/1e6, float64(work.spans[CutSegmentWrites].Load())/1e6, float64(work.spans[CutCommitCheck].Load())/1e6,
|
||||
st.ManifestRootReads, st.ManifestSegmentReads, st.ManifestRootWrites, st.ManifestSegmentWrites, st.ManifestBytesWritten,
|
||||
float64(st.CandidateNs)/1e6, float64(st.PublishPrepareNs)/1e6, float64(st.UploadNs)/1e6,
|
||||
float64(st.CASNs)/1e6, float64(st.CASWriteNs)/1e6,
|
||||
float64(st.HeadReadbackNs+st.CommitStateNs+st.MapPersistNs)/1e6, float64(st.TotalNs)/1e6, errorText)
|
||||
|
||||
@@ -455,6 +455,15 @@ type chunkCutStats struct {
|
||||
StagedChunksUsed int
|
||||
BarrierCopyChunks int
|
||||
BarrierOverBound bool
|
||||
|
||||
// The commit's manifest work, as the remote counts it: HEAD's roots and
|
||||
// segments read, and the roots and segments written with their bytes
|
||||
// (ManifestNs is its time: the manifest read and the segment writes).
|
||||
ManifestRootReads int64
|
||||
ManifestSegmentReads int64
|
||||
ManifestRootWrites int64
|
||||
ManifestSegmentWrites int64
|
||||
ManifestBytesWritten int64
|
||||
}
|
||||
|
||||
// chunkLayerStats are a layer's cumulative cut counters and its last
|
||||
|
||||
@@ -305,6 +305,11 @@ Durable store state of the served volume. Go type `volume.durableStatusBody`.
|
||||
| `Volumes[].Chunk.Stats.LastCut.StagedChunksUsed` | int | (group of `StageRounds`) Pre-copy (staging by the copy-on-write side budget, M5 Stage): StageRounds staging rounds staged StagedChunks chunks outside the barrier; StagedChunksUsed of the uploads in HEAD came from staging. BarrierCopyChunks were copied under the barrier. BarrierOverBound: more than the legacy fixture BarrierBound; always false in production, where that bound is zero. |
|
||||
| `Volumes[].Chunk.Stats.LastCut.BarrierCopyChunks` | int | (group of `StageRounds`) Pre-copy (staging by the copy-on-write side budget, M5 Stage): StageRounds staging rounds staged StagedChunks chunks outside the barrier; StagedChunksUsed of the uploads in HEAD came from staging. BarrierCopyChunks were copied under the barrier. BarrierOverBound: more than the legacy fixture BarrierBound; always false in production, where that bound is zero. |
|
||||
| `Volumes[].Chunk.Stats.LastCut.BarrierOverBound` | bool | (group of `StageRounds`) Pre-copy (staging by the copy-on-write side budget, M5 Stage): StageRounds staging rounds staged StagedChunks chunks outside the barrier; StagedChunksUsed of the uploads in HEAD came from staging. BarrierCopyChunks were copied under the barrier. BarrierOverBound: more than the legacy fixture BarrierBound; always false in production, where that bound is zero. |
|
||||
| `Volumes[].Chunk.Stats.LastCut.ManifestRootReads` | int64 | The commit's manifest work, as the remote counts it: HEAD's roots and segments read, and the roots and segments written with their bytes (ManifestNs is its time: the manifest read and the segment writes). |
|
||||
| `Volumes[].Chunk.Stats.LastCut.ManifestSegmentReads` | int64 | (group of `ManifestRootReads`) The commit's manifest work, as the remote counts it: HEAD's roots and segments read, and the roots and segments written with their bytes (ManifestNs is its time: the manifest read and the segment writes). |
|
||||
| `Volumes[].Chunk.Stats.LastCut.ManifestRootWrites` | int64 | (group of `ManifestRootReads`) The commit's manifest work, as the remote counts it: HEAD's roots and segments read, and the roots and segments written with their bytes (ManifestNs is its time: the manifest read and the segment writes). |
|
||||
| `Volumes[].Chunk.Stats.LastCut.ManifestSegmentWrites` | int64 | (group of `ManifestRootReads`) The commit's manifest work, as the remote counts it: HEAD's roots and segments read, and the roots and segments written with their bytes (ManifestNs is its time: the manifest read and the segment writes). |
|
||||
| `Volumes[].Chunk.Stats.LastCut.ManifestBytesWritten` | int64 | (group of `ManifestRootReads`) The commit's manifest work, as the remote counts it: HEAD's roots and segments read, and the roots and segments written with their bytes (ManifestNs is its time: the manifest read and the segment writes). |
|
||||
| `Volumes[].Chunk.Stats.LastCutH` | uint64 | the LSN the last successful cut published |
|
||||
| `Volumes[].Chunk.Stats.LastCutNs` | int64 | when it completed (wall clock, Unix ns) |
|
||||
| `Volumes[].Chunk.Stats.CutSeq` | uint64 | successful cuts of this layer so far (in-process); the latest cut's identity |
|
||||
|
||||
Reference in new issue
Block a user