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 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-27 17:43:51 -08:00
1 parent 6ba69c56c0
commit 33a331ffb9
3 files changed
+112 -2

No files matched your search

@@ -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])
})
}
}
@@ -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()))
}
@@ -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)
}
}
}
}