From d866004634bc46d41fb7f152911bf23fab27435c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 14:21:35 -0800 Subject: [PATCH 1/6] feat, storage: report existing cut phase timings at debug --- .../core/storage/chunk_cut_logging_test.go | 49 +++++++++++++++++++ seaweed-block/core/storage/chunk_layer.go | 9 ++++ seaweed-block/docs/operator-guide.md | 9 ++++ 3 files changed, 67 insertions(+) create mode 100644 seaweed-block/core/storage/chunk_cut_logging_test.go diff --git a/seaweed-block/core/storage/chunk_cut_logging_test.go b/seaweed-block/core/storage/chunk_cut_logging_test.go new file mode 100644 index 0000000000..d1de8aa0e1 --- /dev/null +++ b/seaweed-block/core/storage/chunk_cut_logging_test.go @@ -0,0 +1,49 @@ +package storage + +import ( + "bytes" + "log" + "strings" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/internal/logging" +) + +func TestCutPhaseTimingIsDebugOnlyAndKeepsTheMeasuredHeadTime(t *testing.T) { + old, flags := log.Writer(), log.Flags() + t.Cleanup(func() { _ = logging.Configure("info"); log.SetOutput(old); log.SetFlags(flags) }) + var out bytes.Buffer + log.SetOutput(&out) + s, remote, layer, writes := precopyLayer(t, 1024, 0) + layer.remote = &fixedSpanRemote{fakeChunkRemote: remote, delay: 20 * time.Millisecond} + writes.write(t, s, 1, 0x32) + if err := logging.Configure("info"); err != nil { + t.Fatal(err) + } + if _, err := layer.Cut(ctTimeout(t)); err != nil { + t.Fatal(err) + } + if strings.Contains(out.String(), "cut phases") { + t.Fatalf("timing at INFO: %s", out.String()) + } + out.Reset() + writes.write(t, s, 2, 0x41) + if err := logging.Configure("debug"); err != nil { + t.Fatal(err) + } + r, err := layer.Cut(ctTimeout(t)) + if err != nil { + t.Fatal(err) + } + line := out.String() + for _, field := range []string{"level=DEBUG", "cut phases", "candidates_ms=", "compare_prepare_ms=", "upload_ms=", "commit_ms=", "head_write_ms=", "settle_ms=", "total_ms="} { + if !strings.Contains(line, field) { + t.Fatalf("missing %s: %q", field, line) + } + } + if strings.Count(line, "cut phases") != 1 || r.Stats.CASWriteNs < int64(20*time.Millisecond) { + t.Fatalf("one cut with measured HEAD time: stats=%+v log=%s", r.Stats, line) + } + assertEveryHeadIsPrefixImage(t, remote, writes) +} diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 277becf626..f0341863c9 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -30,6 +30,8 @@ import ( "sync" "sync/atomic" "time" + + "github.com/seaweedfs/seaweed-block/internal/logging" ) // chunkHooks is what the WALStore holds for an attached layer. @@ -767,6 +769,13 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch observe(time.Duration(st.BarrierPauseNs)) } l.recordCut(res, st, err) + // Existing spans overlap (upload includes copy, commit includes its + // HEAD exchange); report observations, never add them into a new total. + logging.Debugf("storage: cut phases holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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.Holder, l.cfg.Epoch, res.H, res.Noop, st.CandidateChunks, st.UploadedChunks, + 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, fmt.Sprint(err)) }() if err := l.admit(); err != nil { return chunkCutResult{}, err diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 3731241556..744308b512 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -34,6 +34,15 @@ commit are separate lines with the same session; errors do not claim a successful write. Log timestamps are observations, not authority or ordering proofs: use the generation and session fields to correlate writes. +At debug, each cut attempt reports `storage: cut phases`: `candidates_ms` +is the existing candidate-scan span; `compare_prepare_ms` includes comparison, +proposal preparation and session admission; `upload_ms` includes copy/upload; +`commit_ms` includes the HEAD exchange, also shown as `head_write_ms`; +`settle_ms` groups HEAD readback, local commit state and map persistence. +These are existing diagnostic spans and can overlap: do not sum them. +`total_ms` is the independently measured attempt duration. A zero span means +that phase recorded no work; `noop` and `err` distinguish outcomes. + ## Clock safety requirement While volumes are served, blockmaster's host must keep its wall clock **slewed, not stepped**. Configure chrony to From ba933ec0c815cd9e3b48a9fa5be3bb5faec2f667 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 14:29:16 -0800 Subject: [PATCH 2/6] docs, logging: describe the enabled cut diagnostics and unknown outcomes --- seaweed-block/docs/operator-guide.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 744308b512..446ac7f585 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -21,9 +21,9 @@ that runs it. `blockmaster` and `blockvolume` accept `--log-level info|debug` (default `info`). For the CLI, put the global flag before the subcommand: -`sw-block --log-level debug ops workspace show ...`. This switch configures the -DEBUG filter; additional cut diagnostics follow separately. Ordinary logs and -every acknowledged HEAD write remain visible at INFO. +`sw-block --log-level debug ops workspace show ...`. DEBUG adds per-cut phase +diagnostics. Ordinary logs and every acknowledged HEAD write remain visible +at INFO. An unsupported level is refused before the command runs. Standard log timestamps are UTC with six fractional digits, for example @@ -31,7 +31,9 @@ Standard log timestamps are UTC with six fractional digits, for example their existing formats. A HEAD-write line identifies `head_write`, volume, generation, session, resulting HEAD facts and elapsed milliseconds. Begin and commit are separate lines with the same session; errors do not claim a -successful write. Log timestamps are observations, not authority or ordering +successful write. An ambiguous store answer emits WARN `outcome=unknown` with +the expected generation: it describes an attempt, never proof of persistence. +Log timestamps are observations, not authority or ordering proofs: use the generation and session fields to correlate writes. At debug, each cut attempt reports `storage: cut phases`: `candidates_ms` From 35bab9be86707b4a2b235571e6619b6b1a236157 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 14:36:57 -0800 Subject: [PATCH 3/6] fix, logging: label cut timings by volume and leave successful errors empty --- seaweed-block/core/frontend/durable/provider_chunk.go | 1 + seaweed-block/core/storage/chunk_cut_logging_test.go | 3 ++- seaweed-block/core/storage/chunk_layer.go | 10 +++++++--- seaweed-block/core/storage/chunk_seam.go | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index fb836d1f92..8b40e2f64a 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -517,6 +517,7 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h } var remote storage.ChunkRemote = &layoutBoundRemote{closeBoundRemote: bound, keyer: keyer} cfg := storage.ChunkLayerConfig{ + VolumeID: volumeID, OnPublishSettled: p.publishSettledHook(volumeID), ChunkBlocks: p.cfg.ChunkBlocks, RestoreChunkBytes: uint64(ws.BlockSize()) * uint64(p.cfg.ChunkBlocks), diff --git a/seaweed-block/core/storage/chunk_cut_logging_test.go b/seaweed-block/core/storage/chunk_cut_logging_test.go index d1de8aa0e1..5bbc7f5e12 100644 --- a/seaweed-block/core/storage/chunk_cut_logging_test.go +++ b/seaweed-block/core/storage/chunk_cut_logging_test.go @@ -16,6 +16,7 @@ func TestCutPhaseTimingIsDebugOnlyAndKeepsTheMeasuredHeadTime(t *testing.T) { var out bytes.Buffer log.SetOutput(&out) s, remote, layer, writes := precopyLayer(t, 1024, 0) + layer.cfg.VolumeID = "cut-log-volume" layer.remote = &fixedSpanRemote{fakeChunkRemote: remote, delay: 20 * time.Millisecond} writes.write(t, s, 1, 0x32) if err := logging.Configure("info"); err != nil { @@ -37,7 +38,7 @@ func TestCutPhaseTimingIsDebugOnlyAndKeepsTheMeasuredHeadTime(t *testing.T) { t.Fatal(err) } line := out.String() - for _, field := range []string{"level=DEBUG", "cut phases", "candidates_ms=", "compare_prepare_ms=", "upload_ms=", "commit_ms=", "head_write_ms=", "settle_ms=", "total_ms="} { + for _, field := range []string{"level=DEBUG", "cut phases", `volume="cut-log-volume"`, `err=""`, "candidates_ms=", "compare_prepare_ms=", "upload_ms=", "commit_ms=", "head_write_ms=", "settle_ms=", "total_ms="} { if !strings.Contains(line, field) { t.Fatalf("missing %s: %q", field, line) } diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index f0341863c9..2fb4085036 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -769,13 +769,17 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch observe(time.Duration(st.BarrierPauseNs)) } l.recordCut(res, st, err) + errorText := "" + if err != nil { + errorText = err.Error() + } // Existing spans overlap (upload includes copy, commit includes its // HEAD exchange); report observations, never add them into a new total. - logging.Debugf("storage: cut phases holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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.Holder, l.cfg.Epoch, res.H, res.Noop, st.CandidateChunks, st.UploadedChunks, + logging.Debugf("storage: cut phases volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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, st.UploadedChunks, 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, fmt.Sprint(err)) + float64(st.HeadReadbackNs+st.CommitStateNs+st.MapPersistNs)/1e6, float64(st.TotalNs)/1e6, errorText) }() if err := l.admit(); err != nil { return chunkCutResult{}, err diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index 54f15338c5..3395a0881e 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -265,6 +265,8 @@ func validChunkKey(key string) error { // chunkLayerConfig configures one attachment. type chunkLayerConfig struct { + // VolumeID labels diagnostics only; it never decides identity or admission. + VolumeID string // OnPublishSettled, when set, is called once per confirmed publication // (a cut, a detach, or an earlier unresolved CAS found applied), with the // HEAD before and after it (INV-PUBLISH-SETTLED-001). Calls are From 9915ca8d61fcc6e1e8522668ede724a05188c80e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 14:40:02 -0800 Subject: [PATCH 4/6] test, logging: qualify failed and recovered cut timing spans --- .../core/storage/chunk_cut_logging_test.go | 76 +++++++++++++++++++ seaweed-block/core/storage/chunk_layer.go | 2 +- seaweed-block/docs/operator-guide.md | 16 +++- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/seaweed-block/core/storage/chunk_cut_logging_test.go b/seaweed-block/core/storage/chunk_cut_logging_test.go index 5bbc7f5e12..e622f891b2 100644 --- a/seaweed-block/core/storage/chunk_cut_logging_test.go +++ b/seaweed-block/core/storage/chunk_cut_logging_test.go @@ -2,7 +2,11 @@ package storage import ( "bytes" + "context" + "errors" "log" + "regexp" + "strconv" "strings" "testing" "time" @@ -46,5 +50,77 @@ func TestCutPhaseTimingIsDebugOnlyAndKeepsTheMeasuredHeadTime(t *testing.T) { if strings.Count(line, "cut phases") != 1 || r.Stats.CASWriteNs < int64(20*time.Millisecond) { t.Fatalf("one cut with measured HEAD time: stats=%+v log=%s", r.Stats, line) } + if cutLogMilliseconds(t, line, "head_write_ms") < 20 { + t.Fatalf("log omitted the delayed HEAD exchange: %s", line) + } + assertEveryHeadIsPrefixImage(t, remote, writes) +} + +func cutLogMilliseconds(t *testing.T, line, field string) float64 { + t.Helper() + m := regexp.MustCompile(regexp.QuoteMeta(field) + `=([0-9.]+)`).FindStringSubmatch(line) + if len(m) != 2 { + t.Fatalf("missing numeric %s: %s", field, line) + } + v, err := strconv.ParseFloat(m[1], 64) + if err != nil { + t.Fatal(err) + } + return v +} + +type cutLogFailedBegin struct { + *fakeChunkRemote + fault error +} + +func (r cutLogFailedBegin) Begin(context.Context) (string, error) { + time.Sleep(20 * time.Millisecond) + return "", r.fault +} + +func TestCutTimingFailedPhaseCanHaveIncompleteSpans(t *testing.T) { + old, flags := log.Writer(), log.Flags() + t.Cleanup(func() { _ = logging.Configure("info"); log.SetOutput(old); log.SetFlags(flags) }) + s, remote, layer, writes := precopyLayer(t, 1024, 0) + fault := errors.New("begin unavailable") + layer.remote = cutLogFailedBegin{remote, fault} + writes.write(t, s, 1, 0x31) + var out bytes.Buffer + log.SetOutput(&out) + _ = logging.Configure("debug") + if _, err := layer.Cut(ctTimeout(t)); !errors.Is(err, fault) { + t.Fatalf("error=%v", err) + } + line := out.String() + if !strings.Contains(line, "begin unavailable") || !strings.Contains(line, "phase_scope=publication") || cutLogMilliseconds(t, line, "total_ms") < 20 || cutLogMilliseconds(t, line, "compare_prepare_ms") != 0 { + t.Fatalf("failed Begin duration was misrepresented: %s", line) + } +} + +func TestCutTimingPendingRecoveryIsOnlyInTheAttemptTotal(t *testing.T) { + old, flags := log.Writer(), log.Flags() + t.Cleanup(func() { _ = logging.Configure("info"); log.SetOutput(old); log.SetFlags(flags) }) + s, remote, layer, writes := precopyLayer(t, 1024, 0) + layer.remote = &fixedSpanRemote{remote, 20 * time.Millisecond} + writes.write(t, s, 1, 0x31) + remote.mu.Lock() + remote.casModes = []fakeCASMode{casUnknownNotApplied} + remote.mu.Unlock() + if _, err := layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkCASOutcomeUnknown) { + t.Fatalf("first cut=%v", err) + } + before := remote.stats().cas + var out bytes.Buffer + log.SetOutput(&out) + _ = logging.Configure("debug") + r, err := layer.Cut(ctTimeout(t)) + if err != nil || !r.Noop || remote.stats().cas != before+1 { + t.Fatalf("pending replay/no-op: %+v %v", r, err) + } + line := out.String() + if !strings.Contains(line, "phase_scope=publication") || cutLogMilliseconds(t, line, "head_write_ms") != 0 || cutLogMilliseconds(t, line, "total_ms") < 20 { + t.Fatalf("recovery HEAD exchange was not distinguished: %s", line) + } assertEveryHeadIsPrefixImage(t, remote, writes) } diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 2fb4085036..3d26ac42e2 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -775,7 +775,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch } // Existing spans overlap (upload includes copy, commit includes its // HEAD exchange); report observations, never add them into a new total. - logging.Debugf("storage: cut phases volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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", + logging.Debugf("storage: cut phases phase_scope=publication volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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, st.UploadedChunks, float64(st.CandidateNs)/1e6, float64(st.PublishPrepareNs)/1e6, float64(st.UploadNs)/1e6, float64(st.CASNs)/1e6, float64(st.CASWriteNs)/1e6, diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 446ac7f585..6840e4a264 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -42,8 +42,20 @@ proposal preparation and session admission; `upload_ms` includes copy/upload; `commit_ms` includes the HEAD exchange, also shown as `head_write_ms`; `settle_ms` groups HEAD readback, local commit state and map persistence. These are existing diagnostic spans and can overlap: do not sum them. -`total_ms` is the independently measured attempt duration. A zero span means -that phase recorded no work; `noop` and `err` distinguish outcomes. +`phase_scope=publication` means the phase spans describe the normal publication +path. Recovery of an earlier unresolved publication can exchange HEAD before +this path, then finish as a no-op: that recovery cost appears in `total_ms`, +not necessarily in `commit_ms` or `head_write_ms`. `noop` does not mean the +invocation made no remote call. + +Spans are completion-dependent and rounded to three decimal places in +milliseconds: zero can mean +unfinished or unmeasured work, or rounding, rather than no work. A failed +session begin or upload can consume time without its completion span being +recorded. `noop` and `err` distinguish outcomes. `total_ms` is the independent +attempt measurement up to logging; synchronous log output and subsequent +cleanup can extend caller latency beyond it. Logging releases the statistics +mutex first but remains within the cut's capture lock and in-flight lifetime. ## Clock safety requirement From 619f1de421bf5e38e36bb8f7218ef9463b54adc6 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 15:02:36 -0800 Subject: [PATCH 5/6] feat, logging: retain every cut attempt at INFO --- .../core/storage/chunk_cut_logging_test.go | 25 +++++++++++++------ seaweed-block/core/storage/chunk_layer.go | 5 ++-- seaweed-block/docs/operator-guide.md | 9 ++++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/seaweed-block/core/storage/chunk_cut_logging_test.go b/seaweed-block/core/storage/chunk_cut_logging_test.go index e622f891b2..9ee5bb5678 100644 --- a/seaweed-block/core/storage/chunk_cut_logging_test.go +++ b/seaweed-block/core/storage/chunk_cut_logging_test.go @@ -14,7 +14,7 @@ import ( "github.com/seaweedfs/seaweed-block/internal/logging" ) -func TestCutPhaseTimingIsDebugOnlyAndKeepsTheMeasuredHeadTime(t *testing.T) { +func TestCutPhaseTimingAtDefaultInfoKeepsTheMeasuredHeadTime(t *testing.T) { old, flags := log.Writer(), log.Flags() t.Cleanup(func() { _ = logging.Configure("info"); log.SetOutput(old); log.SetFlags(flags) }) var out bytes.Buffer @@ -23,14 +23,23 @@ func TestCutPhaseTimingIsDebugOnlyAndKeepsTheMeasuredHeadTime(t *testing.T) { layer.cfg.VolumeID = "cut-log-volume" layer.remote = &fixedSpanRemote{fakeChunkRemote: remote, delay: 20 * time.Millisecond} writes.write(t, s, 1, 0x32) + out.Reset() // The fixture itself publishes an initial empty image. if err := logging.Configure("info"); err != nil { t.Fatal(err) } if _, err := layer.Cut(ctTimeout(t)); err != nil { t.Fatal(err) } - if strings.Contains(out.String(), "cut phases") { - t.Fatalf("timing at INFO: %s", out.String()) + first := out.String() + if strings.Count(first, "cut phases") != 1 || !strings.Contains(first, "level=INFO") || cutLogMilliseconds(t, first, "head_write_ms") < 20 { + t.Fatalf("default INFO omitted the measured cut: %s", first) + } + out.Reset() + if r, err := layer.Cut(ctTimeout(t)); err != nil || !r.Noop { + t.Fatalf("no-op control: %+v %v", r, err) + } + if strings.Count(out.String(), "cut phases") != 1 || !strings.Contains(out.String(), "level=INFO") || !strings.Contains(out.String(), "noop=true") { + t.Fatalf("default INFO omitted a no-op attempt: %s", out.String()) } out.Reset() writes.write(t, s, 2, 0x41) @@ -42,7 +51,7 @@ func TestCutPhaseTimingIsDebugOnlyAndKeepsTheMeasuredHeadTime(t *testing.T) { t.Fatal(err) } line := out.String() - for _, field := range []string{"level=DEBUG", "cut phases", `volume="cut-log-volume"`, `err=""`, "candidates_ms=", "compare_prepare_ms=", "upload_ms=", "commit_ms=", "head_write_ms=", "settle_ms=", "total_ms="} { + for _, field := range []string{"level=INFO", "cut phases", `volume="cut-log-volume"`, `err=""`, "candidates_ms=", "compare_prepare_ms=", "upload_ms=", "commit_ms=", "head_write_ms=", "settle_ms=", "total_ms="} { if !strings.Contains(line, field) { t.Fatalf("missing %s: %q", field, line) } @@ -88,12 +97,12 @@ func TestCutTimingFailedPhaseCanHaveIncompleteSpans(t *testing.T) { writes.write(t, s, 1, 0x31) var out bytes.Buffer log.SetOutput(&out) - _ = logging.Configure("debug") + _ = logging.Configure("info") if _, err := layer.Cut(ctTimeout(t)); !errors.Is(err, fault) { t.Fatalf("error=%v", err) } line := out.String() - if !strings.Contains(line, "begin unavailable") || !strings.Contains(line, "phase_scope=publication") || cutLogMilliseconds(t, line, "total_ms") < 20 || cutLogMilliseconds(t, line, "compare_prepare_ms") != 0 { + if !strings.Contains(line, "level=INFO") || !strings.Contains(line, "begin unavailable") || !strings.Contains(line, "phase_scope=publication") || cutLogMilliseconds(t, line, "total_ms") < 20 || cutLogMilliseconds(t, line, "compare_prepare_ms") != 0 { t.Fatalf("failed Begin duration was misrepresented: %s", line) } } @@ -113,13 +122,13 @@ func TestCutTimingPendingRecoveryIsOnlyInTheAttemptTotal(t *testing.T) { before := remote.stats().cas var out bytes.Buffer log.SetOutput(&out) - _ = logging.Configure("debug") + _ = logging.Configure("info") r, err := layer.Cut(ctTimeout(t)) if err != nil || !r.Noop || remote.stats().cas != before+1 { t.Fatalf("pending replay/no-op: %+v %v", r, err) } line := out.String() - if !strings.Contains(line, "phase_scope=publication") || cutLogMilliseconds(t, line, "head_write_ms") != 0 || cutLogMilliseconds(t, line, "total_ms") < 20 { + if !strings.Contains(line, "level=INFO") || !strings.Contains(line, "phase_scope=publication") || cutLogMilliseconds(t, line, "head_write_ms") != 0 || cutLogMilliseconds(t, line, "total_ms") < 20 { t.Fatalf("recovery HEAD exchange was not distinguished: %s", line) } assertEveryHeadIsPrefixImage(t, remote, writes) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 3d26ac42e2..934be2485f 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -20,6 +20,7 @@ import ( "encoding/hex" "errors" "fmt" + "log" "math" "os" "path/filepath" @@ -30,8 +31,6 @@ import ( "sync" "sync/atomic" "time" - - "github.com/seaweedfs/seaweed-block/internal/logging" ) // chunkHooks is what the WALStore holds for an attached layer. @@ -775,7 +774,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch } // Existing spans overlap (upload includes copy, commit includes its // HEAD exchange); report observations, never add them into a new total. - logging.Debugf("storage: cut phases phase_scope=publication volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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", + log.Printf("level=INFO storage: cut phases phase_scope=publication volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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, st.UploadedChunks, float64(st.CandidateNs)/1e6, float64(st.PublishPrepareNs)/1e6, float64(st.UploadNs)/1e6, float64(st.CASNs)/1e6, float64(st.CASWriteNs)/1e6, diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 6840e4a264..3495963e67 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -21,9 +21,9 @@ that runs it. `blockmaster` and `blockvolume` accept `--log-level info|debug` (default `info`). For the CLI, put the global flag before the subcommand: -`sw-block --log-level debug ops workspace show ...`. DEBUG adds per-cut phase -diagnostics. Ordinary logs and every acknowledged HEAD write remain visible -at INFO. +`sw-block --log-level debug ops workspace show ...`. This configures the DEBUG +filter. HEAD writes and cut-phase diagnostics remain INFO at both settings; +the current logging update adds no debug-only diagnostics. An unsupported level is refused before the command runs. Standard log timestamps are UTC with six fractional digits, for example @@ -36,7 +36,8 @@ the expected generation: it describes an attempt, never proof of persistence. Log timestamps are observations, not authority or ordering proofs: use the generation and session fields to correlate writes. -At debug, each cut attempt reports `storage: cut phases`: `candidates_ms` +At the default INFO level, every cut attempt (including failures and no-ops) +reports `storage: cut phases`: `candidates_ms` is the existing candidate-scan span; `compare_prepare_ms` includes comparison, proposal preparation and session admission; `upload_ms` includes copy/upload; `commit_ms` includes the HEAD exchange, also shown as `head_write_ms`; From a5515a9be58f7d3cd5c26561f3c225a53c36bcf3 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 15:09:48 -0800 Subject: [PATCH 6/6] fix, logging: keep idle cut attempts at DEBUG --- seaweed-block/core/storage/chunk_cut_logging_test.go | 11 +++++++++-- seaweed-block/core/storage/chunk_layer.go | 10 +++++++++- seaweed-block/docs/operator-guide.md | 8 ++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/storage/chunk_cut_logging_test.go b/seaweed-block/core/storage/chunk_cut_logging_test.go index 9ee5bb5678..ab9a3558ec 100644 --- a/seaweed-block/core/storage/chunk_cut_logging_test.go +++ b/seaweed-block/core/storage/chunk_cut_logging_test.go @@ -38,8 +38,15 @@ func TestCutPhaseTimingAtDefaultInfoKeepsTheMeasuredHeadTime(t *testing.T) { if r, err := layer.Cut(ctTimeout(t)); err != nil || !r.Noop { t.Fatalf("no-op control: %+v %v", r, err) } - if strings.Count(out.String(), "cut phases") != 1 || !strings.Contains(out.String(), "level=INFO") || !strings.Contains(out.String(), "noop=true") { - t.Fatalf("default INFO omitted a no-op attempt: %s", out.String()) + if strings.Contains(out.String(), "cut phases") { + t.Fatalf("default INFO exposed a successful no-op: %s", out.String()) + } + _ = logging.Configure("debug") + if r, err := layer.Cut(ctTimeout(t)); err != nil || !r.Noop { + t.Fatalf("debug no-op control: %+v %v", r, err) + } + if strings.Count(out.String(), "cut phases") != 1 || !strings.Contains(out.String(), "level=DEBUG") || !strings.Contains(out.String(), "noop=true") || !strings.Contains(out.String(), `err=""`) { + t.Fatalf("debug omitted the successful no-op: %s", out.String()) } out.Reset() writes.write(t, s, 2, 0x41) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 934be2485f..558e20d4fa 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -31,6 +31,8 @@ import ( "sync" "sync/atomic" "time" + + "github.com/seaweedfs/seaweed-block/internal/logging" ) // chunkHooks is what the WALStore holds for an attached layer. @@ -726,6 +728,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch } defer done() start := time.Now() + recoveredPublication := l.pending != nil var st chunkCutStats persistCapturedMap := func(versions map[uint64]uint64) { start := time.Now() @@ -774,7 +777,12 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch } // Existing spans overlap (upload includes copy, commit includes its // HEAD exchange); report observations, never add them into a new total. - log.Printf("level=INFO storage: cut phases phase_scope=publication volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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", + // Pending recovery can write HEAD even when normal publication is a no-op. + emit := func(format string, args ...any) { log.Printf("level=INFO "+format, args...) } + if err == nil && res.Noop && !recoveredPublication && st.CandidateChunks == 0 && st.UploadedChunks == 0 { + emit = logging.Debugf + } + emit("storage: cut phases phase_scope=publication volume=%q holder=%q epoch=%d h=%d noop=%t candidates=%d uploaded=%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, st.UploadedChunks, float64(st.CandidateNs)/1e6, float64(st.PublishPrepareNs)/1e6, float64(st.UploadNs)/1e6, float64(st.CASNs)/1e6, float64(st.CASWriteNs)/1e6, diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 3495963e67..d608a3183a 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -22,8 +22,8 @@ that runs it. `blockmaster` and `blockvolume` accept `--log-level info|debug` (default `info`). For the CLI, put the global flag before the subcommand: `sw-block --log-level debug ops workspace show ...`. This configures the DEBUG -filter. HEAD writes and cut-phase diagnostics remain INFO at both settings; -the current logging update adds no debug-only diagnostics. +filter. HEAD writes and failed or working cut attempts remain INFO at both settings; +successful cut no-ops without pending recovery or candidate/upload work appear only at DEBUG. An unsupported level is refused before the command runs. Standard log timestamps are UTC with six fractional digits, for example @@ -36,8 +36,8 @@ the expected generation: it describes an attempt, never proof of persistence. Log timestamps are observations, not authority or ordering proofs: use the generation and session fields to correlate writes. -At the default INFO level, every cut attempt (including failures and no-ops) -reports `storage: cut phases`: `candidates_ms` +At the default INFO level, failed cut attempts and attempts that do work +report `storage: cut phases`: `candidates_ms` is the existing candidate-scan span; `compare_prepare_ms` includes comparison, proposal preparation and session admission; `upload_ms` includes copy/upload; `commit_ms` includes the HEAD exchange, also shown as `head_write_ms`;