fix: preserve permanent causes across joined backend errors

This commit is contained in:
pingqiu committed 2026-11-22 06:33:38 -08:00
1 parent 5508d581b5
commit 83751bbaef
4 files changed
+47 -3

No files matched your search

@@ -20,6 +20,11 @@ const (
// Call only for a non-nil backend error. A pure expired command deadline is
// transient; a joined physical cause keeps its permanent classification.
func ClassifyBackendError(ctx context.Context, err error) BackendErrorClass {
// M1 I/O error completion: every cause must be transient before any
// sentinel can select retry status (INV-FE-ERROR-RETRY-CLASS-001).
if !backendCausesKnown(ctx, err) {
return BackendErrorPermanent
}
switch {
case IsWriteDeadline(ctx, err):
return BackendErrorNotReady
@@ -35,3 +40,26 @@ func ClassifyBackendError(ctx context.Context, err error) BackendErrorClass {
return BackendErrorPermanent
}
}
// Inspect children before matching sentinels: errors.Is on a joined error can
// match one transient branch while another branch carries a permanent fault.
func backendCausesKnown(ctx context.Context, err error) bool {
if joined, ok := err.(interface{ Unwrap() []error }); ok {
causes := joined.Unwrap()
if len(causes) == 0 {
return false
}
for _, cause := range causes {
if !backendCausesKnown(ctx, cause) {
return false
}
}
return true
}
if cause := errors.Unwrap(err); cause != nil {
return backendCausesKnown(ctx, cause)
}
return errors.Is(err, ErrBackendBusy) || errors.Is(err, ErrStalePrimary) ||
errors.Is(err, ErrBackendClosed) || errors.Is(err, ErrNotReady) ||
(ctx.Err() == context.DeadlineExceeded && err == context.DeadlineExceeded)
}
@@ -38,6 +38,14 @@ func TestBackendErrorClassesAcrossFrontends(t *testing.T) {
{name: "permanent", err: errors.New("media read failure"), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6},
{name: "deadline", err: context.DeadlineExceeded, status: 0x02, key: 0x02, asc: 0x04, ascq: 0x01, sct: 0, sc: 0x82, deadline: true},
{name: "deadline-and-physical", err: errors.Join(context.DeadlineExceeded, errors.New("media sync failure")), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true},
{name: "deadline-and-busy", err: errors.Join(context.DeadlineExceeded, frontend.ErrBackendBusy), status: 0x08, sct: 0, sc: 0x82, deadline: true},
{name: "deadline-busy-physical-last", err: errors.Join(context.DeadlineExceeded, frontend.ErrBackendBusy, errors.New("physical sync failure")), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true},
{name: "deadline-busy-physical-first", err: errors.Join(errors.New("physical sync failure"), frontend.ErrBackendBusy, context.DeadlineExceeded), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true},
{name: "deadline-busy-nested-physical", err: errors.Join(frontend.ErrBackendBusy, fmt.Errorf("durability: %w", errors.Join(context.DeadlineExceeded, errors.New("physical sync failure")))), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true},
{name: "deadline-and-not-ready", err: errors.Join(context.DeadlineExceeded, frontend.ErrNotReady), status: 0x02, key: 0x02, asc: 0x04, ascq: 0x01, sct: 0, sc: 0x82, deadline: true},
{name: "deadline-not-ready-physical-last", err: errors.Join(context.DeadlineExceeded, frontend.ErrNotReady, errors.New("physical sync failure")), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true},
{name: "deadline-not-ready-physical-first", err: errors.Join(errors.New("physical sync failure"), frontend.ErrNotReady, context.DeadlineExceeded), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true},
{name: "deadline-not-ready-nested-physical", err: errors.Join(frontend.ErrNotReady, fmt.Errorf("durability: %w", errors.Join(context.DeadlineExceeded, errors.New("physical sync failure")))), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true},
} {
for _, op := range []string{"read", "write", "sync"} {
t.Run(tc.name+"/"+op, func(t *testing.T) {
@@ -6,6 +6,7 @@ import (
"github.com/seaweedfs/seaweed-block/core/frontend"
"github.com/seaweedfs/seaweed-block/core/frontend/testback"
"testing"
"time"
)
type retryClassBackend struct {
@@ -27,11 +28,17 @@ func TestBackendRetryClassClearsWireDNR(t *testing.T) {
{"not-ready", frontend.ErrNotReady, false},
{"busy", frontend.ErrBackendBusy, false},
{"permanent", errors.New("physical media fault"), true},
{"deadline-busy", errors.Join(context.DeadlineExceeded, frontend.ErrBackendBusy), false},
{"deadline-not-ready", errors.Join(context.DeadlineExceeded, frontend.ErrNotReady), false},
{"deadline-busy-physical", errors.Join(context.DeadlineExceeded, frontend.ErrBackendBusy, errors.New("physical sync failure")), true},
{"deadline-not-ready-physical", errors.Join(context.DeadlineExceeded, frontend.ErrNotReady, errors.New("physical sync failure")), true},
} {
for _, op := range []uint8{ioRead, ioWrite, ioFlush} {
t.Run(tc.name+string(rune('0'+op)), func(t *testing.T) {
h := NewIOHandler(HandlerConfig{Backend: retryClassBackend{Backend: testback.NewRecordingBackend(frontend.Identity{VolumeID: "v"}), err: tc.err}})
result := h.Handle(context.Background(), IOCommand{Opcode: op, NSID: 1, NLB: 1, Data: make([]byte, 512)})
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-time.Second))
defer cancel()
result := h.Handle(ctx, IOCommand{Opcode: op, NSID: 1, NLB: 1, Data: make([]byte, 512)})
if dnr := result.completionStatus()&(1<<15) != 0; dnr != tc.dnr {
t.Fatalf("DNR=%t want %t, result=%+v", dnr, tc.dnr, result)
}
+3 -2
View File
@@ -381,8 +381,9 @@ snapshot lifetime; local persistence does not bypass it.
deadlines map to SCSI NOT READY04/01 or NVMe NamespaceNotReady/DNR0;
local busy maps to SCSI BUSY or NVMe NamespaceNotReady/DNR0. Stale
lineage and closed preserve their distinct path-status meanings.
Permanent errors retain terminal protocol mapping, including a deadline
joined with a physical error. Read, write and sync use the same classifier;
Every leaf of a wrapped or joined error is checked before selecting a
retry class: any physical or unknown cause retains terminal mapping, even
alongside a deadline and busy/not-ready sentinel. Read, write and sync use the same classifier;
no storage/authority state changes on this mapping.
- A flusher cycle sorts native snapshot entries by record offset and reuses at
most one fully validated record (bounded by WALSize). Every block still checks