diff --git a/seaweed-block/cmd/sw-block/chunk_gc.go b/seaweed-block/cmd/sw-block/chunk_gc.go index de60bc8295..0324be8329 100644 --- a/seaweed-block/cmd/sw-block/chunk_gc.go +++ b/seaweed-block/cmd/sw-block/chunk_gc.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" "fmt" "io" "time" @@ -67,5 +68,29 @@ func chunkGC(args []string, stdout, stderr io.Writer) int { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() out, e := cat.ExecuteGC(ctx, blobs, chunkstore.GCConfig{Grace: grace, IntentTTL: ttl, Now: chunkGCNow, IssuedEpoch: issuedEpoch}, apply) - return chunkResult("gc", out, e, stdout, stderr) + return chunkGCResult(out, e, stdout, stderr) +} + +// Error status and code remain failures, but a failure must not erase known +// effects or imply that a lost write response means the write did not commit. +func chunkGCResult(out chunkstore.GCExecution, err error, stdout, stderr io.Writer) int { + if err == nil { + return chunkResult("gc", out, nil, stdout, stderr) + } + body := struct { + chunkErrBody + GC chunkstore.GCExecution `json:"gc"` + }{GC: out} + body.Code, body.Message = codeInternalCLI, err.Error() + var ce *chunkstore.CatalogError + switch { + case errors.As(err, &ce): + body.Code, body.Message, body.Retryable = ce.Code, ce.Detail(), ce.Retryable + case errors.Is(err, context.DeadlineExceeded): + body.Code, body.Retryable = chunkstore.CodeDeadlineExceeded, true + } + fmt.Fprintf(stderr, "sw-block ops chunk gc: %s: %s\n", body.Code, body.Message) + // chunkResult also propagates output errors; either outcome remains FAIL. + chunkResult("gc", body, nil, stdout, stderr) + return chunkExitFailed } diff --git a/seaweed-block/core/frontend/chunkstore/GC.md b/seaweed-block/core/frontend/chunkstore/GC.md index 194acda3e5..8a3ad3bb9f 100644 --- a/seaweed-block/core/frontend/chunkstore/GC.md +++ b/seaweed-block/core/frontend/chunkstore/GC.md @@ -62,9 +62,10 @@ settle may still appear as a retained root in the preceding preview. Independent apply calls persist two-mark coverage in `_GC_MARK` under the catalog namespace. A conditional in-progress mark invalidates old coverage -before effects; only a completed pass saves fresh coverage. Errors, interrupted -passes, configuration changes and conditional-write conflicts cannot advance -coverage. Do not edit or copy this state between namespaces. All filer/master/ +before effects; only a completed pass saves fresh coverage. A failed scan after an acknowledged in-progress write does not save completed +coverage. Configuration changes cannot reuse prior coverage. A mark write can +commit and then lose its response: an error does **not** prove that remote +coverage is absent or unchanged. Do not edit or copy this state between namespaces. All filer/master/ blob calls share `--timeout` (default 1m). Grace must exceed the catalog operation deadline (5m) plus the measured mark duration. Increase timeout only if the pass still fits that safety margin. Permanent attempt, HEAD and key tombstones are @@ -73,7 +74,21 @@ never removed by this command. Pre-binding needle enumeration remains unknown. The CLI adds no storage lock edge: the collector retains its local mutex and uses the existing remote APIs. The persisted mark uses filer conditional writes, not a new WAL/publication/shard lock. Concurrent apply calls can conflict and -report an error; callers must not treat a failed command as a completed mark. +report an error. Callers must keep the failure status, but must not infer that +all effects were rolled back or that no completed mark exists remotely. + +Errors after GC execution begins return `{code,message,retryable,gc}` with the +known partial counters/root report preserved in `gc`. `mark_saved=true` means +the completed-write response was acknowledged, not merely attempted. +`mark_outcome` describes this invocation: `not_attempted`, `in_progress` +(acknowledged), `complete` (acknowledged), or `unknown` (write response lost or +failed; remote outcome not established). `unknown_outcomes` names incomplete +stages (`in_progress_mark_write`, `copy_intent_settlement`, `reclamation`, or +`completed_mark_write`). A stage may have partially taken effect even though +its acknowledged counters are lower; for example a blob delete may succeed +then lose its reply. Do not interpret the counters as an upper bound or assume +that retries start from a pristine store. The next invocation reads the actual +conditional mark and authoritative roots as usual. The opt-in end-to-end test invokes the actual CLI entrypoint against a real blockmaster runtime and real SeaweedFS master/volume/filer processes: diff --git a/seaweed-block/core/frontend/chunkstore/gc_execution.go b/seaweed-block/core/frontend/chunkstore/gc_execution.go index 0c07e05763..16821af5b1 100644 --- a/seaweed-block/core/frontend/chunkstore/gc_execution.go +++ b/seaweed-block/core/frontend/chunkstore/gc_execution.go @@ -36,19 +36,26 @@ type savedGCMark struct { } type GCExecution struct { - DryRun bool `json:"dry_run"` - SettledCopies int `json:"settled_copy_intents"` - MarkSaved bool `json:"mark_saved"` + // MarkSaved confirms this caller received the completed-write response; + // false does not prove that no completed mark exists remotely. + MarkOutcome string `json:"mark_outcome"` + UnknownOutcomes []string `json:"unknown_outcomes"` + DryRun bool `json:"dry_run"` + SettledCopies int `json:"settled_copy_intents"` + MarkSaved bool `json:"mark_saved"` GCResult } // ExecuteGC binds independent CLI calls to completed filer-side marks. // Preview never writes even the watermark. Apply first invalidates stored -// coverage with a conditional empty/in-progress record: crash or failure -// cannot leave a failed pass's old coverage available to a later process. +// coverage with a conditional empty/in-progress record before other effects. +// A write may commit despite a lost response: errors retain known effects +// and identify uncertain stages, rather than asserting remote absence. // The catalog namespace is the scope; permanent tombstones are untouched. func (c *Catalog) ExecuteGC(ctx context.Context, blobs BlobDeleter, cfg GCConfig, apply bool) (out GCExecution, err error) { out.DryRun = !apply + out.MarkOutcome = "not_attempted" + out.UnknownOutcomes = []string{} g, err := NewCollector(c, blobs, cfg) if err != nil { return out, err @@ -73,20 +80,28 @@ func (c *Catalog) ExecuteGC(ctx context.Context, blobs BlobDeleter, cfg GCConfig busy := g.mark(false) token, err := g.writeMark(ctx, busy, previous) if err != nil { + out.MarkOutcome = "unknown" + out.UnknownOutcomes = append(out.UnknownOutcomes, "in_progress_mark_write") return out, err } + out.MarkOutcome = "in_progress" out.SettledCopies, err = g.SweepCopies(ctx) if err != nil { + out.UnknownOutcomes = append(out.UnknownOutcomes, "copy_intent_settlement") return out, err } out.GCResult, err = g.Run(ctx) if err != nil { + out.UnknownOutcomes = append(out.UnknownOutcomes, "reclamation") return out, err } _, err = g.writeMark(ctx, g.mark(true), token) if err != nil { + out.MarkOutcome = "unknown" + out.UnknownOutcomes = append(out.UnknownOutcomes, "completed_mark_write") return out, err } + out.MarkOutcome = "complete" out.MarkSaved = true return out, nil }