fix(gc): retain partial effects and unknown write outcomes in CLI failures

This commit is contained in:
pingqiu committed 2026-11-15 14:35:18 -08:00
1 parent efe65dbc4e
commit 16a27917ae
3 files changed
+65 -10

No files matched your search

+26 -1
View File
@@ -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
}
+19 -4
View File
@@ -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:
@@ -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
}