From 33a331ffb91ae63edb1d2dc70fe2d7f163594e16 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 27 Nov 2026 17:43:51 -0800 Subject: [PATCH] fix(durable): a capture refused as PendingUnresolved says so in the log A scheduled snapshot or periodic cut refused because an earlier HEAD commit's outcome is unresolved logged only the raw error. Every later cut, snapshot and detach of the volume is refused until that settles, so the line now names the state (PendingUnresolved), its cause and the cure, once per attempt, never per write. Co-Authored-By: Claude Opus 5.5 --- .../chunk_pending_unresolved_log_test.go | 89 +++++++++++++++++++ .../durable/chunk_snapshot_schedule.go | 19 +++- .../core/frontend/durable/provider_chunk.go | 6 +- 3 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 seaweed-block/core/frontend/durable/chunk_pending_unresolved_log_test.go diff --git a/seaweed-block/core/frontend/durable/chunk_pending_unresolved_log_test.go b/seaweed-block/core/frontend/durable/chunk_pending_unresolved_log_test.go new file mode 100644 index 0000000000..41d7a35fdd --- /dev/null +++ b/seaweed-block/core/frontend/durable/chunk_pending_unresolved_log_test.go @@ -0,0 +1,89 @@ +package durable + +import ( + "bytes" + "context" + "errors" + "fmt" + "log" + "strings" + "sync" + "testing" + "testing/synctest" + "time" + + "github.com/seaweedfs/seaweed-block/core/storage" +) + +type syncBuffer struct { + mu sync.Mutex + b bytes.Buffer +} + +func (s *syncBuffer) Write(p []byte) (int, error) { + s.mu.Lock() + defer s.mu.Unlock() + return s.b.Write(p) +} + +func (s *syncBuffer) String() string { + s.mu.Lock() + defer s.mu.Unlock() + return s.b.String() +} + +// A scheduled snapshot refused because an earlier HEAD commit's outcome is +// unresolved says so in the log, by name, with the cause and the cure, once +// per attempt. Any other failure keeps its ordinary line. +func TestAScheduledSnapshotRefusedAsPendingUnresolvedIsLoud(t *testing.T) { + stuck := fmt.Errorf("storage: capture: earlier CAS outcome still unresolved (layout: look up pool/24/247664-ab: rpc error: code = DeadlineExceeded): HEAD unchanged: %w", storage.ErrChunkCASOutcomeUnknown) + for _, tc := range []struct { + name string + err error + loud bool + cause string + }{ + {"pending unresolved", stuck, true, "pool/24/247664-ab"}, + {"ordinary failure", &SnapshotFailure{Code: "remote_unavailable"}, false, "remote_unavailable"}, + } { + t.Run(tc.name, func(t *testing.T) { + var out syncBuffer + prior := log.Writer() + log.SetOutput(&out) + t.Cleanup(func() { log.SetOutput(prior) }) + synctest.Test(t, func(t *testing.T) { + _, start, stop := snapLoop(func(context.Context) error { return tc.err }) + start() + defer func() { + if !stop() { + t.Error("the loop was not joined") + } + }() + time.Sleep(24 * time.Hour) // the first attempt, at the volume's offset, and its first retry + synctest.Wait() + }) + var lines []string + for _, l := range strings.Split(out.String(), "\n") { + if strings.Contains(l, "scheduled snapshot volume=v1") { + lines = append(lines, l) + } + } + if len(lines) == 0 { + t.Fatalf("no scheduled-snapshot line logged; log:\n%s", out.String()) + } + for _, l := range lines { + if !strings.Contains(l, tc.cause) { + t.Fatalf("line %q does not carry the cause %q", l, tc.cause) + } + loud := strings.Contains(l, "REFUSED: PendingUnresolved") && strings.Contains(l, "every cut, snapshot and detach") && strings.Contains(l, "restart the volume") + if loud != tc.loud { + t.Fatalf("line %q: loud=%t, want %t", l, loud, tc.loud) + } + } + if !errors.Is(tc.err, storage.ErrChunkCASOutcomeUnknown) && strings.Contains(out.String(), "PendingUnresolved") { + t.Fatal("an ordinary failure was reported as PendingUnresolved") + } + t.Logf("%d attempt line(s), e.g. %s", len(lines), lines[0]) + }) + } +} diff --git a/seaweed-block/core/frontend/durable/chunk_snapshot_schedule.go b/seaweed-block/core/frontend/durable/chunk_snapshot_schedule.go index c75494a707..824d3696c8 100644 --- a/seaweed-block/core/frontend/durable/chunk_snapshot_schedule.go +++ b/seaweed-block/core/frontend/durable/chunk_snapshot_schedule.go @@ -3,6 +3,7 @@ package durable import ( "context" "errors" + "fmt" "log" "sync" "time" @@ -11,6 +12,17 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" ) +// capturePendingNote names a capture refused because an earlier HEAD commit's +// outcome is unresolved (Stats.PendingUnresolved): until it settles every +// cut, snapshot and detach of the volume is refused, so the logs say so, with +// the cause and the cure, once per attempt (never per write). +func capturePendingNote(err error) (string, bool) { + if !errors.Is(err, storage.ErrChunkCASOutcomeUnknown) { + return "", false + } + return fmt.Sprintf("PendingUnresolved: an earlier HEAD commit's outcome is unresolved, so every cut, snapshot and detach of this volume is refused until it settles; cause: %v; it is retried at every capture; if it persists, check the filer, then restart the volume (the next holder settles it)", err), true +} + const ( // snapshotRetryMin and snapshotRetryMax bound the backoff after a // failed scheduled snapshot: it doubles from the minimum up to the cap. @@ -241,7 +253,12 @@ func (p *DurableProvider) chunkSnapshotLoop(ctx context.Context, volumeID string } slot.record(time.Now(), err) if err != nil { - log.Printf("durable: scheduled snapshot volume=%s: %v (next attempt in %s)", volumeID, err, time.Until(slot.due()).Round(time.Second)) + next := time.Until(slot.due()).Round(time.Second) + if note, stuck := capturePendingNote(err); stuck { + log.Printf("durable: scheduled snapshot volume=%s REFUSED: %s (next attempt in %s)", volumeID, note, next) + } else { + log.Printf("durable: scheduled snapshot volume=%s: %v (next attempt in %s)", volumeID, err, next) + } } timer.Reset(time.Until(slot.due())) } diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index 0ea280da83..5bda51d763 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -884,7 +884,11 @@ func (p *DurableProvider) chunkLoop(ctx context.Context, volumeID string, layer s = pol.after(s, start, time.Now(), err, layer.Stats().CutSeq) wait.record(s) if err != nil && !errors.Is(err, storage.ErrChunkCaptureRefused) && ctx.Err() == nil { - log.Printf("durable: %s chunk cut for volume=%s: %v (retry in %s)", reason, volumeID, err, s.backoff) + if note, stuck := capturePendingNote(err); stuck { + log.Printf("durable: %s chunk cut for volume=%s REFUSED: %s (retry in %s)", reason, volumeID, note, s.backoff) + } else { + log.Printf("durable: %s chunk cut for volume=%s: %v (retry in %s)", reason, volumeID, err, s.backoff) + } } } }