diff --git a/seaweed-block/core/frontend/durable/storage_adapter.go b/seaweed-block/core/frontend/durable/storage_adapter.go index 98c7023841..1766a99f43 100644 --- a/seaweed-block/core/frontend/durable/storage_adapter.go +++ b/seaweed-block/core/frontend/durable/storage_adapter.go @@ -71,7 +71,7 @@ const ( // ErrReplicationAckUnavailable is returned when WriteAckRequireObserverAck // cannot obtain the configured replication acknowledgement. -var ErrReplicationAckUnavailable = errors.New("durable: replication ack unavailable") +var ErrReplicationAckUnavailable = frontend.ErrReplicationAckUnavailable // WriteObserver is the narrow seam StorageBackend uses to notify the // replication layer of each successfully-applied local write and to diff --git a/seaweed-block/core/frontend/error_class.go b/seaweed-block/core/frontend/error_class.go index 2fedcc060a..51e11a0237 100644 --- a/seaweed-block/core/frontend/error_class.go +++ b/seaweed-block/core/frontend/error_class.go @@ -3,6 +3,12 @@ package frontend import ( "context" "errors" + "io" + "log" + "sync/atomic" + "syscall" + + "github.com/seaweedfs/seaweed-block/core/storage" ) // BackendErrorClass is independent of transport status (INV-FE-ERROR-RETRY-CLASS-001). @@ -16,50 +22,48 @@ const ( BackendErrorClosed ) -// ClassifyBackendError implements INV-FE-ERROR-RETRY-CLASS-001. -// Call only for a non-nil backend error. A pure expired command deadline is -// transient; a joined physical cause keeps its permanent classification. +var unclassifiedBackendErrors atomic.Uint64 + +// UnclassifiedBackendErrorCount reports completions using the unknown-cause +// fallback in V1-SPEC r2.42. It is cumulative for this process. +func UnclassifiedBackendErrorCount() uint64 { return unclassifiedBackendErrors.Load() } + +// ClassifyBackendError implements INV-FE-ERROR-RETRY-CLASS-001 and V1-SPEC r2.42. +// Call only for a non-nil backend error. Known permanent causes win across the +// entire wrapped/joined tree; unknown causes are counted and retryable. 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) { + // M1 I/O error completion: inspect permanent causes before any retry marker. + if hasPermanentBackendCause(err) { return BackendErrorPermanent } switch { - case IsWriteDeadline(ctx, err): - return BackendErrorNotReady - case errors.Is(err, ErrBackendBusy): + case errors.Is(err, ErrBackendBusy), errors.Is(err, storage.ErrWALPressureTimeout), + errors.Is(err, storage.ErrChunkHydrationPending), + errors.Is(err, ErrReplicationAckUnavailable) && errors.Is(err, context.DeadlineExceeded): return BackendErrorBusy case errors.Is(err, ErrStalePrimary): return BackendErrorStale case errors.Is(err, ErrBackendClosed): return BackendErrorClosed - case errors.Is(err, ErrNotReady): + case errors.Is(err, ErrNotReady), IsWriteDeadline(ctx, err): return BackendErrorNotReady default: - return BackendErrorPermanent + // M1 unknown completion: V1-SPEC r2.42 bounds retry at the initiator. + count := unclassifiedBackendErrors.Add(1) + log.Printf("frontend: unclassified backend error count=%d: %v", count, err) + return BackendErrorNotReady } } -// 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 +func hasPermanentBackendCause(err error) bool { + // errors.Is traverses every child of joins, so neither an outer transient + // wrapper nor a sibling deadline can hide a typed storage/media failure. + for _, cause := range []error{syscall.EIO, syscall.ENOSPC, syscall.EROFS, + io.ErrUnexpectedEOF, storage.ErrWALIntegrityFault, storage.ErrFsyncFailed, + storage.ErrAppendFailed, storage.ErrMapInvalid} { + if errors.Is(err, cause) { + return true } - 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) + return false } diff --git a/seaweed-block/core/frontend/errors.go b/seaweed-block/core/frontend/errors.go index 84691012a8..c62078bed8 100644 --- a/seaweed-block/core/frontend/errors.go +++ b/seaweed-block/core/frontend/errors.go @@ -20,3 +20,7 @@ var ErrBackendClosed = errors.New("frontend: backend closed") // ErrBackendBusy is a transient local admission timeout. Retry may succeed; // it must not be used for a sticky persistence or integrity fault. var ErrBackendBusy = errors.New("frontend: backend temporarily busy") + +// ErrReplicationAckUnavailable means the configured replication acknowledgement +// was unavailable. It is retryable busy only together with a deadline cause. +var ErrReplicationAckUnavailable = errors.New("durable: replication ack unavailable") diff --git a/seaweed-block/core/frontend/iscsi/backend_error_class_test.go b/seaweed-block/core/frontend/iscsi/backend_error_class_test.go index 3bbff22607..a58e3264c2 100644 --- a/seaweed-block/core/frontend/iscsi/backend_error_class_test.go +++ b/seaweed-block/core/frontend/iscsi/backend_error_class_test.go @@ -1,16 +1,23 @@ package iscsi_test import ( + "bytes" "context" "errors" "fmt" + "io" + "log" + "strings" + "syscall" "testing" "time" "github.com/seaweedfs/seaweed-block/core/frontend" + "github.com/seaweedfs/seaweed-block/core/frontend/durable" "github.com/seaweedfs/seaweed-block/core/frontend/iscsi" "github.com/seaweedfs/seaweed-block/core/frontend/nvme" "github.com/seaweedfs/seaweed-block/core/frontend/testback" + "github.com/seaweedfs/seaweed-block/core/storage" ) type classifiedErrorBackend struct { @@ -31,21 +38,37 @@ func TestBackendErrorClassesAcrossFrontends(t *testing.T) { status, key, asc, ascq, sct, sc uint8 deadline bool }{ + {name: "wal-pressure", err: fmt.Errorf("%w: %w", frontend.ErrBackendBusy, storage.ErrWALPressureTimeout), status: 0x08, sct: 0, sc: 0x82}, + {name: "hydration-pending", err: fmt.Errorf("%w: %w", frontend.ErrBackendBusy, storage.ErrChunkHydrationPending), status: 0x08, sct: 0, sc: 0x82}, + {name: "observer-deadline", err: fmt.Errorf("%w: %w: %w", frontend.ErrBackendBusy, durable.ErrReplicationAckUnavailable, context.DeadlineExceeded), status: 0x08, sct: 0, sc: 0x82, deadline: true}, + {name: "unknown", err: errors.New("unrecognized backend cause"), status: 0x02, key: 0x02, asc: 0x04, ascq: 0x01, sct: 0, sc: 0x82}, + {name: "pressure-without-busy-marker", err: storage.ErrWALPressureTimeout, status: 0x08, sct: 0, sc: 0x82}, + {name: "hydration-without-busy-marker", err: storage.ErrChunkHydrationPending, status: 0x08, sct: 0, sc: 0x82}, + {name: "observer-deadline-without-busy-marker", err: errors.Join(durable.ErrReplicationAckUnavailable, context.DeadlineExceeded), status: 0x08, sct: 0, sc: 0x82, deadline: true}, + {name: "unknown-with-busy", err: errors.Join(errors.New("unrecognized backend cause"), frontend.ErrBackendBusy), status: 0x08, sct: 0, sc: 0x82}, + {name: "unknown-with-physical", err: errors.Join(errors.New("unrecognized backend cause"), syscall.EIO), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "fsync-fault", err: errors.Join(frontend.ErrBackendBusy, storage.ErrFsyncFailed), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "append-fault", err: errors.Join(frontend.ErrBackendBusy, storage.ErrAppendFailed), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "integrity-fault", err: errors.Join(frontend.ErrBackendBusy, storage.ErrWALIntegrityFault), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "invalid-map", err: errors.Join(frontend.ErrBackendBusy, storage.ErrMapInvalid), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "no-space", err: errors.Join(frontend.ErrBackendBusy, syscall.ENOSPC), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "read-only", err: errors.Join(frontend.ErrBackendBusy, syscall.EROFS), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "truncated-io", err: errors.Join(frontend.ErrBackendBusy, io.ErrUnexpectedEOF), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, {name: "not-ready", err: frontend.ErrNotReady, status: 0x02, key: 0x02, asc: 0x04, ascq: 0x01, sct: 0, sc: 0x82}, {name: "busy", err: frontend.ErrBackendBusy, status: 0x08, sct: 0, sc: 0x82}, {name: "stale", err: frontend.ErrStalePrimary, status: 0x02, key: 0x02, asc: 0x04, ascq: 0x0a, sct: 3, sc: 3}, {name: "closed", err: frontend.ErrBackendClosed, status: 0x02, key: 0x02, asc: 0x04, ascq: 0x03, sct: 3, sc: 2}, - {name: "permanent", err: errors.New("media read failure"), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6}, + {name: "permanent", err: syscall.EIO, 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-physical", err: errors.Join(context.DeadlineExceeded, syscall.EIO), 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-busy-physical-last", err: errors.Join(context.DeadlineExceeded, frontend.ErrBackendBusy, syscall.EIO), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true}, + {name: "deadline-busy-physical-first", err: errors.Join(syscall.EIO, 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, syscall.EIO))), 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}, + {name: "deadline-not-ready-physical-last", err: errors.Join(context.DeadlineExceeded, frontend.ErrNotReady, syscall.EIO), status: 0x02, key: 0x03, asc: 0x11, sct: 0, sc: 6, deadline: true}, + {name: "deadline-not-ready-physical-first", err: errors.Join(syscall.EIO, 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, syscall.EIO))), 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) { @@ -100,3 +123,25 @@ func TestBackendErrorClassesAcrossFrontends(t *testing.T) { } } } + +// INV-FE-ERROR-RETRY-CLASS-001 / V1-SPEC r2.42: unknown completions are +// retryable on both protocols, counted once per completion, and diagnosable. +func TestUnclassifiedBackendErrorIsRetryableAndCounted(t *testing.T) { + var logs bytes.Buffer + previous := log.Writer() + log.SetOutput(&logs) + t.Cleanup(func() { log.SetOutput(previous) }) + before := frontend.UnclassifiedBackendErrorCount() + b := classifiedErrorBackend{Backend: testback.NewRecordingBackend(frontend.Identity{VolumeID: "v"}), err: errors.New("unknown completion cause")} + scsi := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: b}).HandleCommand(context.Background(), [16]byte{iscsi.ScsiSyncCache10}, nil) + nv := nvme.NewIOHandler(nvme.HandlerConfig{Backend: b}).Handle(context.Background(), nvme.IOCommand{NSID: 1}) + if scsi.Status != 0x02 || scsi.SenseKey != 0x02 || scsi.ASC != 0x04 || scsi.ASCQ != 0x01 || nv.SCT != 0 || nv.SC != 0x82 { + t.Fatalf("unknown completion not retryable: SCSI=%+v NVMe=%+v", scsi, nv) + } + if got := frontend.UnclassifiedBackendErrorCount() - before; got != 2 { + t.Fatalf("unclassified completions=%d want 2", got) + } + if strings.Count(logs.String(), "frontend: unclassified backend error count=") != 2 || !strings.Contains(logs.String(), "unknown completion cause") { + t.Fatalf("unclassified reason/count missing: %q", logs.String()) + } +} diff --git a/seaweed-block/core/frontend/nvme/backend_error_class_test.go b/seaweed-block/core/frontend/nvme/backend_error_class_test.go index 541e9f46af..929966c0da 100644 --- a/seaweed-block/core/frontend/nvme/backend_error_class_test.go +++ b/seaweed-block/core/frontend/nvme/backend_error_class_test.go @@ -5,6 +5,7 @@ import ( "errors" "github.com/seaweedfs/seaweed-block/core/frontend" "github.com/seaweedfs/seaweed-block/core/frontend/testback" + "syscall" "testing" "time" ) @@ -26,12 +27,13 @@ func TestBackendRetryClassClearsWireDNR(t *testing.T) { dnr bool }{ {"not-ready", frontend.ErrNotReady, false}, + {"unknown", errors.New("unrecognized backend cause"), false}, {"busy", frontend.ErrBackendBusy, false}, - {"permanent", errors.New("physical media fault"), true}, + {"permanent", syscall.EIO, 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}, + {"deadline-busy-physical", errors.Join(context.DeadlineExceeded, frontend.ErrBackendBusy, syscall.EIO), true}, + {"deadline-not-ready-physical", errors.Join(context.DeadlineExceeded, frontend.ErrNotReady, syscall.EIO), true}, } { for _, op := range []uint8{ioRead, ioWrite, ioFlush} { t.Run(tc.name+string(rune('0'+op)), func(t *testing.T) { diff --git a/seaweed-block/core/frontend/nvme/flush_error_log_test.go b/seaweed-block/core/frontend/nvme/flush_error_log_test.go index a83c59a90b..de1fbb9213 100644 --- a/seaweed-block/core/frontend/nvme/flush_error_log_test.go +++ b/seaweed-block/core/frontend/nvme/flush_error_log_test.go @@ -3,11 +3,12 @@ package nvme import ( "bytes" "context" - "errors" + "fmt" "github.com/seaweedfs/seaweed-block/core/frontend" "github.com/seaweedfs/seaweed-block/core/frontend/testback" "log" "strings" + "syscall" "testing" ) @@ -20,7 +21,7 @@ func (b *flushErrorBackend) Sync(context.Context) error { return b.syncErr } func TestSessionFlushLogsBackendReason(t *testing.T) { var logs bytes.Buffer - b := &flushErrorBackend{Backend: testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1"}), syncErr: errors.New("injected Sync failure: extent EIO")} + b := &flushErrorBackend{Backend: testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1"}), syncErr: fmt.Errorf("injected Sync failure: extent EIO: %w", syscall.EIO)} s := &Session{handler: NewIOHandler(HandlerConfig{Backend: b}), logger: log.New(&logs, "", 0), qid: 7, respCh: make(chan *response, 1), done: make(chan struct{})} req := &Request{} req.capsule.OpCode = ioFlush diff --git a/seaweed-block/core/frontend/nvme/fua_test.go b/seaweed-block/core/frontend/nvme/fua_test.go index acd01356a9..1d44a9a2a4 100644 --- a/seaweed-block/core/frontend/nvme/fua_test.go +++ b/seaweed-block/core/frontend/nvme/fua_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "sync/atomic" + "syscall" "testing" "time" @@ -47,9 +48,9 @@ func TestNVMeWriteFUACompletion(t *testing.T) { wantSC uint8 }{ {name: "FUA waits for Sync", fua: true}, - {name: "Sync failure is not success", fua: true, syncErr: errors.New("sync failed"), wantSC: nvme.SCInternalError}, + {name: "Sync failure is not success", fua: true, syncErr: syscall.EIO, wantSC: nvme.SCInternalError}, {name: "ordinary write does not Sync"}, - {name: "failed write does not Sync", fua: true, writeErr: errors.New("write failed"), wantSC: nvme.SCInternalError}, + {name: "failed write does not Sync", fua: true, writeErr: syscall.EIO, wantSC: nvme.SCInternalError}, } { t.Run(tc.name, func(t *testing.T) { b := &fuaBackend{RecordingBackend: testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1}), entered: make(chan struct{}), release: make(chan struct{}), syncErr: tc.syncErr, writeErr: tc.writeErr} diff --git a/seaweed-block/core/frontend/nvme/pressure_retry_test.go b/seaweed-block/core/frontend/nvme/pressure_retry_test.go index 094c26274e..92f47a75a8 100644 --- a/seaweed-block/core/frontend/nvme/pressure_retry_test.go +++ b/seaweed-block/core/frontend/nvme/pressure_retry_test.go @@ -2,9 +2,9 @@ package nvme import ( "context" - "errors" "github.com/seaweedfs/seaweed-block/core/frontend" "github.com/seaweedfs/seaweed-block/core/frontend/testback" + "syscall" "testing" ) @@ -19,7 +19,7 @@ func TestSessionPressureTimeoutIsRetryableNamespaceNotReady(t *testing.T) { s := &Session{handler: NewIOHandler(HandlerConfig{Backend: b}), respCh: make(chan *response, 1), done: make(chan struct{})} for _, busy := range []bool{true, false} { if !busy { - b.err = errors.New("sticky physical I/O fault") + b.err = syscall.EIO } req := &Request{payload: make([]byte, 512)} req.capsule.OpCode = ioWrite diff --git a/seaweed-block/core/frontend/nvme/read_command_budget_test.go b/seaweed-block/core/frontend/nvme/read_command_budget_test.go index 5ff7456770..4bc44c57e1 100644 --- a/seaweed-block/core/frontend/nvme/read_command_budget_test.go +++ b/seaweed-block/core/frontend/nvme/read_command_budget_test.go @@ -3,6 +3,7 @@ package nvme import ( "context" "errors" + "syscall" "testing" "time" @@ -20,7 +21,7 @@ func (b *budgetReadBackend) Read(ctx context.Context, _ int64, p []byte) (int, e b.deadline, _ = ctx.Deadline() <-ctx.Done() if b.physical { - return 0, errors.Join(ctx.Err(), errors.New("physical read failure")) + return 0, errors.Join(ctx.Err(), syscall.EIO) } return 0, frontend.ErrBackendBusy } diff --git a/seaweed-block/core/frontend/nvme/read_ready_retry_test.go b/seaweed-block/core/frontend/nvme/read_ready_retry_test.go index 0b89d1dfad..e49a327eda 100644 --- a/seaweed-block/core/frontend/nvme/read_ready_retry_test.go +++ b/seaweed-block/core/frontend/nvme/read_ready_retry_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "syscall" "testing" "github.com/seaweedfs/seaweed-block/core/frontend" @@ -27,7 +28,7 @@ func TestSessionReadNotReadyIsRetryable(t *testing.T) { {"attach-pending", fmt.Errorf("awaiting HEAD attach: %w", frontend.ErrNotReady), SCTGeneric, SCNamespaceNotReady, false}, {"not-ready-closed", errors.Join(frontend.ErrNotReady, frontend.ErrBackendClosed), SCTPathRelated, SCPathAsymAccessInaccessible, true}, {"not-ready-stale", errors.Join(frontend.ErrNotReady, frontend.ErrStalePrimary), SCTPathRelated, SCPathAsymAccessTransition, true}, - {"physical-fault", errors.New("physical read failure"), SCTGeneric, SCInternalError, true}, + {"physical-fault", syscall.EIO, SCTGeneric, SCInternalError, true}, {"closed", frontend.ErrBackendClosed, SCTPathRelated, SCPathAsymAccessInaccessible, true}, {"stale", frontend.ErrStalePrimary, SCTPathRelated, SCPathAsymAccessTransition, true}, } { diff --git a/seaweed-block/core/frontend/nvme/write_command_budget_test.go b/seaweed-block/core/frontend/nvme/write_command_budget_test.go index 71910cc639..5adbf10708 100644 --- a/seaweed-block/core/frontend/nvme/write_command_budget_test.go +++ b/seaweed-block/core/frontend/nvme/write_command_budget_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "syscall" "testing" "time" @@ -49,7 +50,7 @@ type joinedBudgetBackend struct { func (b *joinedBudgetBackend) result(ctx context.Context) error { if b.physical { - return errors.Join(errors.New("physical fsync failure"), ctx.Err()) + return errors.Join(syscall.EIO, ctx.Err()) } return fmt.Errorf("durability wait: %w", ctx.Err()) } diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 658fc1261d..ee5a1033ef 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -413,14 +413,17 @@ snapshot lifetime; local persistence does not bypass it. non-retryable mapping. This is a local pressure outcome, not a whole-I/O deadline; the broader budget gap is tracked separately in issue221. - Every frontend I/O error completion uses one shared retry class - (`INV-FE-ERROR-RETRY-CLASS-001`): not-ready and pure expired-command - 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. - 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. + (`INV-FE-ERROR-RETRY-CLASS-001`, V1-SPEC r2.42): known permanent causes + anywhere in the wrapped/joined tree win over transient markers. These are + EIO, ENOSPC, EROFS, unexpected EOF, WAL integrity, prior fsync/append failure, + and invalid chunk maps. Busy, WAL pressure, hydration pending, and replication + ACK unavailable with a deadline map to SCSI BUSY or NVMe NotReady/DNR0. + Not-ready and pure command deadlines map to SCSI NOT READY04/01 or NVMe + NotReady/DNR0; stale lineage and closed retain distinct path meanings. + Otherwise the error is unclassified: increment the process counter, log the + error text, and return retryable not-ready. Initiators bound the retries. + Read, write and sync use the same classifier; no authority/storage state changes. + - 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 its LBA/data offset/LSN/nonce; the cache is local to the snapshot recovery @@ -500,7 +503,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-WAL-V3-ADMISSION-EXPIRY-STATE-001` | A v3 write refused for an expired deadline before its append leaves the WAL bytes, nextLSN and the dirty map unchanged. | M1 Serving (write admission) | `core/storage/walstore.go` `WALStore.WriteContext`, `WALStore.WriteBatchContext` | `TestStorageBackendExpiredWriteDoesNotAppend` | — | ACTIVE | | `INV-WAL-V3-ADMISSION-PREFIX-ERR-001` | A write batch that returns a committed prefix with a storage error keeps that error in the error set the frontend classifies. | M1 Serving (write admission) | `core/frontend/durable/storage_adapter.go` `writeFullBlockBatch`, `withStorageCause`, `observeWriteCause` | `TestStorageBackendPartialBatchPhysicalFaultSurvivesObserverDeadline` | — | ACTIVE | | `INV-WAL-V3-ADMISSION-RETRYABLE-001` | A write that fails only because the caller's deadline expired is reported retryable, also through a required write observer and on NVMe; a write whose error carries a physical cause is reported terminal. | M1 Serving (write admission) | `core/frontend/write_budget.go` `IsWriteDeadline`; `core/frontend/durable/storage_adapter.go` `StorageBackend.Write`, `replicationWriteError`; `core/frontend/nvme/io.go` `mapBackendError`; `core/frontend/nvme/session.go` `Session.handleWrite` | `TestStorageBackendRequiredObserverDeadlineStaysRetryable`, `TestStorageBackendPartialBatchPhysicalFaultSurvivesObserverDeadline`; `TestSessionWriteBudgetDeadlineIsRetryableIncludingFUA` (`core/frontend/nvme/write_command_budget_test.go`) | — | ACTIVE | -| `INV-FE-ERROR-RETRY-CLASS-001` | A backend error's retry class is decided once and every frontend reports it with its protocol's retryable form; only permanent errors become medium errors. | M1 I/O error completion (shared frontend classifier) | `core/frontend/error_class.go` `ClassifyBackendError`; `core/frontend/iscsi/scsi.go`, `core/frontend/nvme/io.go` `mapBackendError` | `TestBackendErrorClassesAcrossFrontends` (`core/frontend/iscsi/backend_error_class_test.go`); `TestBackendRetryClassClearsWireDNR` (`core/frontend/nvme/backend_error_class_test.go`); `TestSessionWriteBudgetDeadlineIsRetryableIncludingFUA` (`core/frontend/nvme/write_command_budget_test.go`) | Protocol output only; existing backend states, no new automaton state | ACTIVE | +| `INV-FE-ERROR-RETRY-CLASS-001` | A backend error's retry class is decided once and every frontend reports it with its protocol's retryable form; only permanent errors become medium errors. | M1 I/O error completion (shared frontend classifier) | `core/frontend/error_class.go` `ClassifyBackendError`; `core/frontend/iscsi/scsi.go`, `core/frontend/nvme/io.go` `mapBackendError` | `TestBackendErrorClassesAcrossFrontends` (`core/frontend/iscsi/backend_error_class_test.go`); `TestBackendRetryClassClearsWireDNR` (`core/frontend/nvme/backend_error_class_test.go`); `TestUnclassifiedBackendErrorIsRetryableAndCounted` (`core/frontend/iscsi/backend_error_class_test.go`); `TestSessionWriteBudgetDeadlineIsRetryableIncludingFUA` (`core/frontend/nvme/write_command_budget_test.go`) | Protocol output only; existing backend states, no new automaton state | ACTIVE | | `INV-WAL-V3-RECLAIM-001` | A mapped v3 checkpoint at cp moves retainedTail only to the end of a complete validated record whose last LSN is at most cp minus the retention window, and, while a BASE is installing, never past BaseCursor. | M1 checkpoint / existing two-slot retirement | `core/storage/walstore_map_checkpoint_v3.go` `WALStore.publishCheckpointV3`; `core/storage/wal_io_v3.go` `walWriterV3.reclaimThroughV3` | `TestWALStoreV3CheckpointReclaimsAcrossRingLaps`, `TestWALStoreV3ReclaimKeepsPartialBatchAndRetention`, `TestWALStoreV3ReclaimAfterInstallingPhysicalReopen` | Existing dual-slot retirement and nonce/cursor contract; concrete index/recovery/caller wiring is a code-test obligation | STUB | | `INV-WAL-V3-RECLAIM-INDEX-001` | A physical v3 recovery rebuilds the writer's volatile record-boundary index only from trusted write records of the kept scan; an installing reopen indexes them without moving the writer's cursor. | M1 checkpoint / existing two-slot retirement | `core/storage/wal_io_v3.go` `walWriterV3.restoreScanV3`, `walWriterV3.rememberReclaimScanV3`, `walWriterV3.indexReclaimScanLockedV3`; `core/storage/walstore_v3.go` `WALStore.recoverV3` | `TestWALStoreV3ReclaimRebuildsIndexAfterPhysicalRecovery`, `TestWALStoreV3ReclaimAfterInstallingPhysicalReopen` | — | STUB | | `INV-WAL-V3-RECLAIM-PUBLISH-001` | A mapped v3 checkpoint publishes retainedTail, retainedHead, the map root, CheckpointLSN and W in one slot publication, followed by a metadata-only rollover when the fallback slot still pins a lower tail. | M1 checkpoint / existing two-slot retirement | `core/storage/walstore_map_checkpoint_v3.go` `WALStore.publishCheckpointV3`; `core/storage/descriptor_v3.go` `descriptorPublisherV3.rolloverIfPinned` | `TestWALStoreV3CheckpointReclaimsAcrossRingLaps`, `TestWALStoreV3ReclaimSecondSlotFailureKeepsOldPin` | — | STUB |