From 56300cc6c19a9dba68c084a5a463d7ee10ccb11b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 15:36:46 -0800 Subject: [PATCH] chunkstore: attempt-bound retention, fork holds, rolling windows - Retain deletes the exact attempt it planned: the attempt's entry is marked deleting conditionally and the name record is removed only while it names that attempt; a replacement is reported as replaced. - Fork records a hold (forkholds///) before it reads the parent. Retain marks first, then reads the holds: a live hold reverts the mark (fork_held); a fork holding after that read finds the attempt deleting and refuses before installing anything. A hold counts while its target has no HEAD and its VOLUME records the fork, or while it is younger than the operation deadline. - A pass stopped after a mark finishes (or reverts) it on the next run. - Log-spaced keeps use rolling windows anchored at now. - Exclusive bytes resolve "@owner/key" refs and count every volume's HEAD and live snapshots as holders; documented as eligible for GC subject to its grace period and intents. - Retain reports confirmed deletions, the failing snapshot (uncertain or not) and what it never reached; the CLI prints them with the error and exits nonzero. - chunkControl.Snapshot validates the class before any cut; invalid_class and invalid_policy map to 400. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/sw-block/chunk_retain.go | 3 --- seaweed-block/core/frontend/chunkstore/catalog.go | 3 --- .../core/frontend/chunkstore/retention.go | 14 -------------- seaweed-block/core/frontend/chunkstore/usage.go | 3 --- seaweed-block/core/host/volume/chunk_control.go | 6 +++--- 5 files changed, 3 insertions(+), 26 deletions(-) diff --git a/seaweed-block/cmd/sw-block/chunk_retain.go b/seaweed-block/cmd/sw-block/chunk_retain.go index fc3664e471..7b9702672c 100644 --- a/seaweed-block/cmd/sw-block/chunk_retain.go +++ b/seaweed-block/cmd/sw-block/chunk_retain.go @@ -106,9 +106,6 @@ type retainOutput struct { } func retainPartial(res chunkstore.RetentionResult, err error, stdout, stderr io.Writer) int { - if red := true; red { // RED: the partial result is discarded - return chunkResult("retain", nil, err, stdout, stderr) - } body := chunkErrBody{Code: chunkstore.CodeOf(err), Message: err.Error(), Retryable: true} var ce *chunkstore.CatalogError if errors.As(err, &ce) { diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index eeca29c9c8..5590fea2b0 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -1298,9 +1298,6 @@ func (c *Catalog) holdForkParent(ctx context.Context, srcRoot string, req ForkRe if err != nil || !ok { return "", err } - if red := true; red { // RED: no hold recorded - return ref.rec.Attempt, nil - } now := c.now().Unix() e := &filerpb.Entry{Name: req.Target, Attributes: &filerpb.FuseAttributes{Mtime: now, Crtime: now, FileMode: 0o644}} if err := c.f.CreateEntry(ctx, forkHoldDir(srcRoot, req.Snapshot, ref.rec.Attempt), e, true); err != nil && !errors.Is(err, ErrExists) { diff --git a/seaweed-block/core/frontend/chunkstore/retention.go b/seaweed-block/core/frontend/chunkstore/retention.go index c291809a77..bbec3c3793 100644 --- a/seaweed-block/core/frontend/chunkstore/retention.go +++ b/seaweed-block/core/frontend/chunkstore/retention.go @@ -254,13 +254,6 @@ func planRetention(p RetentionPolicy, snaps []SnapshotInfo, needed map[string]bo continue } k := int64(age / lk.period) // the rolling window holding this age - // RED: calendar periods, as before the review - if red := true; red { - if age >= time.Duration(lk.count)*lk.period { - continue - } - k = -1 - s.CreatedNs/int64(lk.period) - } if k >= int64(lk.count) { continue } @@ -403,13 +396,6 @@ const ( // that attempt. uncertain reports, with an error, that the failing call // was a mutation whose outcome is unknown. func (c *Catalog) deleteRetainedAttempt(ctx context.Context, vol, name, attempt string) (retainOutcome, bool, error) { - if red := true; red { // RED: delete by name, as before the review - c.hook(hookUnheld, name) - if _, err := c.DeleteSnapshot(ctx, vol, name); err != nil && CodeOf(err) != CodeSnapshotNotFound { - return 0, false, err - } - return retainDeleted, false, nil - } root, err := c.volRoot(vol) if err != nil { return 0, false, err diff --git a/seaweed-block/core/frontend/chunkstore/usage.go b/seaweed-block/core/frontend/chunkstore/usage.go index 0faac9fbcc..05ec785f61 100644 --- a/seaweed-block/core/frontend/chunkstore/usage.go +++ b/seaweed-block/core/frontend/chunkstore/usage.go @@ -211,9 +211,6 @@ func (c *Catalog) Usage(ctx context.Context, vol string) (VolumeUsage, error) { // owner-qualified "@owner/key" (a fork's reference) is owner's key, // anything else is vol's. func chunkIdentity(vol, key string) string { - if red := true; red { // RED: owner-qualified refs not resolved - return vol + "\x00" + key - } if strings.HasPrefix(key, "@") { if owner, rest, ok := strings.Cut(key[1:], "/"); ok { return owner + "\x00" + rest diff --git a/seaweed-block/core/host/volume/chunk_control.go b/seaweed-block/core/host/volume/chunk_control.go index adba62b03c..46e3f1135b 100644 --- a/seaweed-block/core/host/volume/chunk_control.go +++ b/seaweed-block/core/host/volume/chunk_control.go @@ -214,7 +214,7 @@ func chunkErrorCode(err error) (int, string, bool) { func catalogStatus(code string) int { switch code { - case chunkstore.CodeInvalidName, chunkstore.CodeInvalidLabel: // RED: class and policy errors fall to 409 + case chunkstore.CodeInvalidName, chunkstore.CodeInvalidLabel, chunkstore.CodeInvalidClass, chunkstore.CodeInvalidPolicy: return http.StatusBadRequest case chunkstore.CodeSnapshotNotFound: return http.StatusNotFound @@ -465,8 +465,8 @@ func (c *chunkControl) Cut(ctx context.Context, volumeID string, minLSN uint64) func (c *chunkControl) Snapshot(ctx context.Context, volumeID string, req ChunkSnapshotRequest) (chunkstore.SnapshotInfo, error) { // Admit the request before anything can cut: an invalid class must // not advance HEAD (review of #142). - if red := true; !red { // RED: the class is checked only after the cut - return chunkstore.SnapshotInfo{}, chunkstore.ValidateSnapshotClass(req.Class) + if err := chunkstore.ValidateSnapshotClass(req.Class); err != nil { + return chunkstore.SnapshotInfo{}, err } sreq := chunkstore.SnapshotRequest{Name: req.Name, RequestID: req.RequestID, Labels: req.Labels, Consistency: req.Consistency, ExpiresAtNs: req.ExpiresAtNs, CreatedBy: "blockvolume", Class: req.Class}