diff --git a/seaweed-block/core/frontend/chunkstore/control_types.go b/seaweed-block/core/frontend/chunkstore/control_types.go index 3efd29a1bf..848d58d094 100644 --- a/seaweed-block/core/frontend/chunkstore/control_types.go +++ b/seaweed-block/core/frontend/chunkstore/control_types.go @@ -49,6 +49,7 @@ const ( CodeGeometryMismatch = "geometry_mismatch" CodeDeadlineExceeded = "deadline_exceeded" CodeRemoteUnavailable = "remote_unavailable" + CodeRemoteFull = "remote_full" // the chunk store has no space; retry after adding capacity CodeOutcomeUnknown = "outcome_unknown" CodeInvalidLabel = "invalid_label" ) diff --git a/seaweed-block/core/frontend/chunkstore/swfs.go b/seaweed-block/core/frontend/chunkstore/swfs.go index 0781b621a5..021fe5a114 100644 --- a/seaweed-block/core/frontend/chunkstore/swfs.go +++ b/seaweed-block/core/frontend/chunkstore/swfs.go @@ -16,6 +16,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" "github.com/seaweedfs/seaweed-block/core/rpc/link" + "github.com/seaweedfs/seaweed-block/core/storage" ) // SWFSConfig configures the minimal SeaweedFS client. @@ -225,6 +226,20 @@ func isFilerNotFound(err error) bool { return ok && (st.Code() == codes.NotFound || (st.Code() == codes.Unknown && strings.Contains(st.Message(), filerNotFoundText))) } +// seaweedNoFreeVolumes is in SeaweedFS's assign answer when the collection +// has no writable volume and no free volume slot to grow one: the store is +// full until capacity is added. +const seaweedNoFreeVolumes = "no free volumes left" + +// assignErr wraps a failed assign under prefix. A full store's answer is +// storage.ErrChunkRemoteFull; any other keeps only its cause. +func assignErr(prefix string, err error) error { + if strings.Contains(strings.ToLower(err.Error()), seaweedNoFreeVolumes) { + return fmt.Errorf("%w: %s: %w", storage.ErrChunkRemoteFull, prefix, err) + } + return fmt.Errorf("%s: %w", prefix, err) +} + // Put implements Blobs: filer AssignVolume, then a raw HTTP POST of data to // the assigned volume server. The body is sent as application/octet-stream // with no Content-Encoding, so the volume server stores it uncompressed (its @@ -239,10 +254,10 @@ func (c *SWFS) Put(ctx context.Context, data []byte) (string, error) { ExpectedDataSize: uint64(len(data)), }) if err != nil { - return "", fmt.Errorf("chunkstore: assign: %w", err) + return "", assignErr("chunkstore: assign", err) } if ar.GetError() != "" { - return "", fmt.Errorf("chunkstore: assign: %s", ar.GetError()) + return "", assignErr("chunkstore: assign", errors.New(ar.GetError())) } if ar.GetFileId() == "" || ar.GetLocation().GetUrl() == "" { return "", fmt.Errorf("chunkstore: assign returned no fid/location") diff --git a/seaweed-block/core/frontend/chunkstore/swfs_batch.go b/seaweed-block/core/frontend/chunkstore/swfs_batch.go index 5f0b18c891..f378df6a56 100644 --- a/seaweed-block/core/frontend/chunkstore/swfs_batch.go +++ b/seaweed-block/core/frontend/chunkstore/swfs_batch.go @@ -168,10 +168,10 @@ func (c *SWFS) reserve(ctx context.Context, n int, objSize uint64) (blobRange, e ExpectedDataSize: objSize, }) if err != nil { - return blobRange{}, fmt.Errorf("chunkstore: assign %d: %w", n, err) + return blobRange{}, assignErr(fmt.Sprintf("chunkstore: assign %d", n), err) } if ar.GetError() != "" { - return blobRange{}, fmt.Errorf("chunkstore: assign %d: %s", n, ar.GetError()) + return blobRange{}, assignErr(fmt.Sprintf("chunkstore: assign %d", n), errors.New(ar.GetError())) } if err := validHostPort(ar.GetLocation().GetUrl()); err != nil { return blobRange{}, err diff --git a/seaweed-block/core/frontend/chunkstore/swfs_test.go b/seaweed-block/core/frontend/chunkstore/swfs_test.go index b26eedeafa..3443fdd0c7 100644 --- a/seaweed-block/core/frontend/chunkstore/swfs_test.go +++ b/seaweed-block/core/frontend/chunkstore/swfs_test.go @@ -17,6 +17,7 @@ import ( "google.golang.org/grpc/status" "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" + "github.com/seaweedfs/seaweed-block/core/storage" ) // fakeFilerGRPC answers the real gRPC method paths with canned replies so the @@ -31,6 +32,7 @@ type fakeFilerGRPC struct { lookupResp *filerpb.LookupDirectoryEntryResponse lookupErr error assignResp *filerpb.AssignVolumeResponse + assignErr error lookupVol *filerpb.LookupVolumeResponse volLookups int // LookupVolume calls @@ -75,6 +77,9 @@ func (f *fakeFilerGRPC) AssignVolume(_ context.Context, r *filerpb.AssignVolumeR f.mu.Lock() defer f.mu.Unlock() f.lastAssign = r + if f.assignErr != nil { + return nil, f.assignErr + } return f.assignResp, nil } @@ -270,3 +275,42 @@ func TestSWFS_Put_AssignErrorIsFailure(t *testing.T) { t.Fatalf("assign error swallowed") } } + +// seaweedFullAnswer is SeaweedFS's assign answer once every volume is full +// and no volume slot is free (from a lab run on a store limited to -max 600). +const seaweedFullAnswer = `failed to find writable volumes for collection: replication:000 ttl: error: No writable volumes and no free volumes left for {"replication":{},"ttl":{"Count":0,"Unit":0}}` + +// A full store is told apart from an unreachable one, in both answer styles +// (gRPC error and the response's error field) and on both assign paths +// (one object and a reserved range). +func TestSWFS_AssignOnAFullStoreIsRemoteFull(t *testing.T) { + cases := []struct { + name string + f *fakeFilerGRPC + full bool + }{ + {"rpc error", &fakeFilerGRPC{assignErr: status.Error(codes.Unknown, seaweedFullAnswer)}, true}, + {"response error", &fakeFilerGRPC{assignResp: &filerpb.AssignVolumeResponse{Error: seaweedFullAnswer}}, true}, + {"growth still running", &fakeFilerGRPC{assignErr: status.Error(codes.Unknown, "failed to find writable volumes for collection: replication:000 ttl: error: No writable volumes\ncontext deadline exceeded")}, false}, + {"unreachable", &fakeFilerGRPC{assignErr: status.Error(codes.Unavailable, "connection refused")}, false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + c := startFakeFiler(t, tc.f) + _, err := c.Put(context.Background(), []byte("x")) + if err == nil { + t.Fatal("assign failure swallowed") + } + if got := errors.Is(err, storage.ErrChunkRemoteFull); got != tc.full { + t.Fatalf("Put: full=%v, want %v: %v", got, tc.full, err) + } + _, err = c.reserve(context.Background(), 4, 1) + if err == nil { + t.Fatal("range assign failure swallowed") + } + if got := errors.Is(err, storage.ErrChunkRemoteFull); got != tc.full { + t.Fatalf("reserve: full=%v, want %v: %v", got, tc.full, err) + } + }) + } +} diff --git a/seaweed-block/core/host/volume/chunk_control.go b/seaweed-block/core/host/volume/chunk_control.go index b76fa49ee0..f69b43efc6 100644 --- a/seaweed-block/core/host/volume/chunk_control.go +++ b/seaweed-block/core/host/volume/chunk_control.go @@ -363,6 +363,10 @@ func chunkErrorCode(err error) (int, string, bool) { // a remote outage. Keep authority and uncertain-publication precedence. case errors.Is(err, storage.ErrCutCOWAborted): return http.StatusServiceUnavailable, "cut_aborted", true + // A full store is a remote failure of its own: retrying helps only + // after capacity is added, so it is told apart from an unreachable one. + case errors.Is(err, storage.ErrChunkRemoteFull): + return http.StatusServiceUnavailable, chunkstore.CodeRemoteFull, true case errors.Is(err, storage.ErrChunkRemoteUnavailable): return http.StatusServiceUnavailable, chunkstore.CodeRemoteUnavailable, true case errors.Is(err, durable.ErrNotChunkVolume), errors.Is(err, durable.ErrVolumeNotOpen): @@ -394,7 +398,7 @@ func catalogStatus(code string) int { return http.StatusBadRequest case chunkstore.CodeSnapshotNotFound: return http.StatusNotFound - case chunkstore.CodeDeadlineExceeded, chunkstore.CodeRemoteUnavailable, chunkstore.CodeOutcomeUnknown: + case chunkstore.CodeDeadlineExceeded, chunkstore.CodeRemoteUnavailable, chunkstore.CodeRemoteFull, chunkstore.CodeOutcomeUnknown: return http.StatusServiceUnavailable default: // snapshot_exists, snapshot_deleting, target_exists, geometry_mismatch, fork_incomplete, not_chunk_volume return http.StatusConflict diff --git a/seaweed-block/core/host/volume/chunk_control_test.go b/seaweed-block/core/host/volume/chunk_control_test.go index 9ad1cff430..066027ccf2 100644 --- a/seaweed-block/core/host/volume/chunk_control_test.go +++ b/seaweed-block/core/host/volume/chunk_control_test.go @@ -233,6 +233,11 @@ func TestStatusServer_ChunkErrorBodyIsTyped(t *testing.T) { {errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkCASOutcomeUnknown, storage.ErrChunkRemoteUnavailable), "outcome_unknown", 503, true}, {errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkLayerFenced, storage.ErrChunkRemoteUnavailable), "fenced", 409, false}, {fmt.Errorf("x: %w", storage.ErrChunkRemoteUnavailable), "remote_unavailable", 503, true}, + // A full chunk store, as a cut's upload reports it (joined with the + // unavailable cause every upload failure carries). + {fmt.Errorf("x: %w", storage.ErrChunkRemoteFull), "remote_full", 503, true}, + {errors.Join(storage.ErrChunkRemoteUnavailable, errors.New("storage: cut upload failed"), fmt.Errorf("%w: chunkstore: assign", storage.ErrChunkRemoteFull)), "remote_full", 503, true}, + {errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkRemoteFull), "cut_aborted", 503, true}, {fmt.Errorf("x: %w", storage.ErrChunkLayerClosed), "closing", 503, false}, {errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkLayerClosed, storage.ErrChunkRemoteUnavailable, context.Canceled), "closing", 503, false}, {errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkLayerDetached, storage.ErrChunkRemoteUnavailable, context.Canceled), "closing", 409, false}, diff --git a/seaweed-block/core/storage/chunk_cut_failure_status_test.go b/seaweed-block/core/storage/chunk_cut_failure_status_test.go new file mode 100644 index 0000000000..3d49f0fedb --- /dev/null +++ b/seaweed-block/core/storage/chunk_cut_failure_status_test.go @@ -0,0 +1,105 @@ +package storage + +import ( + "bytes" + "context" + "fmt" + "log" + "strings" + "sync" + "testing" + "time" +) + +// lockedBuf is a log sink safe for the layer's background goroutines. +type lockedBuf struct { + mu sync.Mutex + buf bytes.Buffer +} + +func (b *lockedBuf) Write(p []byte) (int, error) { + b.mu.Lock() + defer b.mu.Unlock() + return b.buf.Write(p) +} + +func (b *lockedBuf) count(sub string) int { + b.mu.Lock() + defer b.mu.Unlock() + return strings.Count(b.buf.String(), sub) +} + +// A requested cut that fails on a full chunk store shows the failure's code +// and cause in the layer's status, and the log carries one WARN per change of +// code, not one per retry. A success clears the failure. +func TestChunkCutFailureStatusNamesAFullStore(t *testing.T) { + var logs lockedBuf + old := log.Writer() + log.SetOutput(&logs) + t.Cleanup(func() { log.SetOutput(old) }) + const warn = "level=WARN storage: cuts failing:" + + s, _ := newChunkTestStore(t) + f := newFakeChunkRemote() + layer := mustAttach(t, s, f, ctConfig(1)) + w := newWriteLog() + w.write(t, s, 5, 0x51) + mustSyncFlush(t, s) + + setPut := func(err error) { + f.mu.Lock() + f.failPut = err + f.mu.Unlock() + } + // A failing upload is retried until the cut's deadline: a short one keeps + // each failed cut brief. + capture := func(d time.Duration) error { + ctx, cancel := context.WithTimeout(context.Background(), d) + defer cancel() + _, err := layer.Capture(ctx) + return err + } + const failing = 300 * time.Millisecond + + // The fake remote answers as the chunkstore client does on a full store. + setPut(fmt.Errorf("%w: chunkstore: assign: No writable volumes and no free volumes left", ErrChunkRemoteFull)) + for i := 0; i < 3; i++ { + if err := capture(failing); err == nil { + t.Fatal("a cut on a full store succeeded") + } + } + st := layer.Stats() + if st.LastCutFailure == nil { + t.Fatal("status has no cut failure after three failed cuts") + } + if got := st.LastCutFailure.Code; got != "remote_full" { + t.Fatalf("cut failure code %q, want remote_full (cause %q)", got, st.LastCutFailure.Cause) + } + if !strings.Contains(st.LastCutFailure.Cause, "no free volumes left") || st.LastCutFailure.Repeats != 3 || st.LastCutFailure.Ns == 0 { + t.Fatalf("cut failure %+v: want the store's cause, 3 repeats and a time", *st.LastCutFailure) + } + if n := logs.count(warn); n != 1 { + t.Fatalf("%d WARN lines for three failures with one code, want 1", n) + } + + // The cause changes: one more WARN, and the status follows. + setPut(errFakeRemoteDown) + if err := capture(failing); err == nil { + t.Fatal("a cut on an unreachable store succeeded") + } + if st := layer.Stats(); st.LastCutFailure == nil || st.LastCutFailure.Code != "remote_unavailable" || st.LastCutFailure.Repeats != 1 { + t.Fatalf("cut failure after the cause changed: %+v, want remote_unavailable once", st.LastCutFailure) + } + if n := logs.count(warn); n != 2 { + t.Fatalf("%d WARN lines after one change of code, want 2", n) + } + + // Capacity is back: the next cut succeeds and the failure is cleared. + setPut(nil) + if err := capture(20 * time.Second); err != nil { + t.Fatalf("cut after the store recovered: %v", err) + } + if st := layer.Stats(); st.LastCutFailure != nil { + t.Fatalf("a successful cut left the failure %+v in status", *st.LastCutFailure) + } +} diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index b75c09ffea..8a5b46e7a4 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -154,7 +154,7 @@ type chunkLayerImpl struct { // captured version and hash, no bytes): the record's Commit for them // waits for the settlement that finds the proposal landed. pendingCaptured []capturedChunk - pendingCut chunkCutResult + pendingCut chunkCutResult // pendingBase is the version the unresolved CAS expected. While HEAD is // still at it, that CAS may still land, so a read alone never settles it. pendingBase chunkHeadVersion @@ -1909,6 +1909,7 @@ func (l *chunkLayerImpl) recordCut(r chunkCutResult, st chunkCutStats, err error reason = "detached" default: l.stats.CutsFailed++ + l.noteCutFailureLocked(err, abortReason) } if reason != "" { if l.stats.CutsRefused == nil { @@ -1919,15 +1920,61 @@ func (l *chunkLayerImpl) recordCut(r chunkCutResult, st chunkCutStats, err error if err == nil { l.stats.LastCut, l.stats.LastCutH, l.stats.LastCutNs = st, r.H, time.Now().UnixNano() l.stats.CutSeq++ + if l.stats.LastCutFailure != nil { + log.Printf("level=INFO storage: cuts succeed again after %d failure(s) with code %s", l.stats.LastCutFailure.Repeats, l.stats.LastCutFailure.Code) + l.stats.LastCutFailure = nil + } } if st.BarrierOverBound { l.stats.BarrierOverBound++ } } +// noteCutFailureLocked records a failed cut in LastCutFailure and logs +// one WARN each time the failure's code changes (not one per retry). +// Caller holds stMu. +func (l *chunkLayerImpl) noteCutFailureLocked(err error, abortReason string) { + code := cutFailureCode(err, abortReason) + cause := "" + if err != nil { + cause = err.Error() + } + if len(cause) > chunkCutFailureCauseMax { + cause = cause[:chunkCutFailureCauseMax] + } + prev := l.stats.LastCutFailure + f := &ChunkCutFailure{Code: code, Cause: cause, Ns: time.Now().UnixNano(), Repeats: 1} + if prev != nil && prev.Code == code { + f.Repeats = prev.Repeats + 1 + } else { + log.Printf("level=WARN storage: cuts failing: code=%s cause=%q", code, cause) + } + l.stats.LastCutFailure = f +} + +// cutFailureCode names a failed cut's cause for status: a full chunk store +// first, then an unreachable one, then a local abort's reason. +func cutFailureCode(err error, abortReason string) string { + switch { + case errors.Is(err, errChunkRemoteFull): + return "remote_full" + case abortReason != "" && abortReason != "upload": + return abortReason + case errors.Is(err, errChunkRemoteUnavailable): + return "remote_unavailable" + case abortReason != "": + return abortReason + } + return "cut_failed" +} + func (l *chunkLayerImpl) Stats() chunkLayerStats { l.stMu.Lock() out := l.stats + if f := l.stats.LastCutFailure; f != nil { + failure := *f + out.LastCutFailure = &failure + } if l.currentCut != nil { current := *l.currentCut out.CurrentCut = ¤t diff --git a/seaweed-block/core/storage/chunk_public.go b/seaweed-block/core/storage/chunk_public.go index 476165ffb3..361f419e6f 100644 --- a/seaweed-block/core/storage/chunk_public.go +++ b/seaweed-block/core/storage/chunk_public.go @@ -62,6 +62,7 @@ var ( ErrChunkLayerClosed = errChunkLayerClosed ErrChunkBaseInstalling = errChunkBaseInstalling ErrChunkRemoteUnavailable = errChunkRemoteUnavailable + ErrChunkRemoteFull = errChunkRemoteFull ErrChunkContentMismatch = errChunkContentMismatch ErrChunkLSNBehind = errChunkLSNBehind ) diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index 5eba590636..af2ebb9211 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -531,8 +531,23 @@ type chunkLayerStats struct { // free_space_unreadable (the free space could not be read). COWSpillCap int64 COWSpillCapReason string `json:",omitempty"` + // LastCutFailure is the last failed cut since the last successful one, + // whatever requested it; nil after a success. Refusals (admission, + // fenced, detached, reconciling) are not failures and leave it alone. + LastCutFailure *ChunkCutFailure `json:",omitempty"` } +// ChunkCutFailure names why cuts are failing. +type ChunkCutFailure struct { + Code string // remote_full (the chunk store has no space; retry after adding capacity), remote_unavailable, a CutsAborted reason, or cut_failed + Cause string // the failure's text, at most 1024 bytes + Ns int64 // when it failed (wall clock, Unix ns) + Repeats uint64 // failures with this code in a row, this one included +} + +// chunkCutFailureCauseMax bounds a failure's text in status. +const chunkCutFailureCauseMax = 1024 + // chunkCutResult is the outcome of one successful cut. // - H is the cut LSN; Head.RemoteLSN = H when the cut installed a HEAD. // A volume's LSNs carry forward across hosts: a new host's WAL starts @@ -639,6 +654,10 @@ var ( errChunkLayerClosed = errors.New("storage: chunk layer closed") errChunkBaseInstalling = errors.New("storage: chunk BASE install in progress") errChunkRemoteUnavailable = errors.New("storage: chunk remote unavailable") + // errChunkRemoteFull: the chunk store has no space for a new object + // (SeaweedFS has no writable volume and no free volume slot left). A + // retry succeeds only after capacity is added. + errChunkRemoteFull = errors.New("storage: chunk store full") // errChunkContentMismatch: a chunk read from the remote does not hash // (or size) to the HEAD ref that names it. Its bytes are never served // or installed. diff --git a/seaweed-block/docs/status-schema.md b/seaweed-block/docs/status-schema.md index b818324b38..26a106e989 100644 --- a/seaweed-block/docs/status-schema.md +++ b/seaweed-block/docs/status-schema.md @@ -317,6 +317,11 @@ Durable store state of the served volume. Go type `volume.durableStatusBody`. | `Volumes[].Chunk.Stats.AbsentChunks` | int | AbsentChunks is the number of HEAD-named chunks still absent with a block not local (what HydrateAll would still fetch); 0 = fully local. | | `Volumes[].Chunk.Stats.COWSpillCap` | int64 | COWSpillCap is the last cut's side-file cap in bytes, read once per cut; COWSpillCapReason is why it is 0, when the free space made it so: no_room_to_cut (half the free space is within the 1 GiB reserve) or free_space_unreadable (the free space could not be read). | | `Volumes[].Chunk.Stats.COWSpillCapReason` | string | (group of `COWSpillCap`) COWSpillCap is the last cut's side-file cap in bytes, read once per cut; COWSpillCapReason is why it is 0, when the free space made it so: no_room_to_cut (half the free space is within the 1 GiB reserve) or free_space_unreadable (the free space could not be read). (omitted when empty) | +| `Volumes[].Chunk.Stats.LastCutFailure` | object | LastCutFailure is the last failed cut since the last successful one, whatever requested it; nil after a success. Refusals (admission, fenced, detached, reconciling) are not failures and leave it alone. (omitted when empty) | +| `Volumes[].Chunk.Stats.LastCutFailure.Code` | string | remote_full (the chunk store has no space; retry after adding capacity), remote_unavailable, a CutsAborted reason, or cut_failed | +| `Volumes[].Chunk.Stats.LastCutFailure.Cause` | string | the failure's text, at most 1024 bytes | +| `Volumes[].Chunk.Stats.LastCutFailure.Ns` | int64 | when it failed (wall clock, Unix ns) | +| `Volumes[].Chunk.Stats.LastCutFailure.Repeats` | uint64 | failures with this code in a row, this one included | | `Volumes[].Chunk.HostBudget` | interface | the host background-cut budget state, with --host-limit-dir (omitted when empty) | | `Volumes[].Chunk.ScheduledSnapshot` | object | the scheduled-snapshot state; absent when the schedule is off or its loop has not started (omitted when empty) | | `Volumes[].Chunk.ScheduledSnapshot.periodNs` | int64 | PeriodNs is the schedule period; zero means off. | diff --git a/seaweed-block/docs/troubleshooting.md b/seaweed-block/docs/troubleshooting.md index cf2199ead6..fffbf56cda 100644 --- a/seaweed-block/docs/troubleshooting.md +++ b/seaweed-block/docs/troubleshooting.md @@ -130,8 +130,10 @@ than one 5-minute request is retried by the schedule. prove a new failure, so read the holder's log. Off the host: `not checked here: run on `. On a local-engine volume: `not applicable: no chunk store`. -**Fix:** a retryable code (`remote_unavailable`) clears when SeaweedFS answers again; keep free capacity in -SeaweedFS. `remote_unavailable` also follows a request that ran out of its own 5-minute bound while SeaweedFS was +**Fix:** the holder's `Chunk.Stats.LastCutFailure` names the last failed cut, whatever requested it, with its `Code` +and `Cause`; the holder logs one `cuts failing` WARN each time the code changes. `remote_full`: SeaweedFS has no +writable volume and no free volume slot; add capacity (see [size a host](operator-guide.md#size-a-host)), and cuts +resume on their next retry. A retryable `remote_unavailable` clears when SeaweedFS answers again. `remote_unavailable` also follows a request that ran out of its own 5-minute bound while SeaweedFS was still answering (a long first cut); rerun it: the work already done is kept. See [recovery point and sync policy](operator-guide.md#recovery-point-and-sync-policy). ## volume.cleaning