From 2e078746ee698c615f0e13fd914a84cf9d4a2ef0 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 19:54:32 -0800 Subject: [PATCH] volume delete: durable master reservation, commit point, settled abort - Master: a deletion reservation store (core/lifecycle), separate from the desired-volume records, so an unknown id is reserved too and the ordinary DeleteVolume/CreateVolume path cannot clear it. Held by per-delete tokens (admitted), permanent once committed. Writes reuse the binding store's crash-safe pattern (synced temp file, atomic rename, synced directory); an unknown outcome keeps a protective change in memory (fail closed). MarkVolumeDeleting records it under RecordWorkspaceDeletion's check; new AbortVolumeDeleting and CommitVolumeDeleting. Every gate (publication admission, reconciler, workload planner, binding/placement/move, CreateVolume) consults it. VolumeRecord.Deleting is gone. - Catalog: Admission is Admit/Commit/Abort; ErrNotAdmitted marks a definite refusal, anything else is an unknown outcome (admissionUncertain). Every give-back aborts this delete's admission. A commit point (HEAD deleting -> purging, conditioned on the HEAD read) precedes the irreversible steps; a revert races on the same write, so a delete that sampled a claim cannot undo another delete's commit, and reports an error instead of a give-back. - CreateSnapshot's back-out settles its name like the delete does: the name is freed only after the attempt's tombstone or winning publication is confirmed. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/frontend/chunkstore/catalog.go | 9 +-------- seaweed-block/core/frontend/chunkstore/volume_delete.go | 7 ++----- seaweed-block/core/host/master/services.go | 2 +- seaweed-block/core/lifecycle/deletion_reservations.go | 3 --- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index 9859db5955..d7e1dfa2ba 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -856,14 +856,7 @@ func (c *Catalog) CreateSnapshot(ctx context.Context, vol string, req SnapshotRe // Settle this name as the delete does: the attempt's tombstone or // its winning publication is confirmed before the name is freed; // on failure the name stays, so the delete still finds it. - if red := true; red { // RED: the name is freed even when the abort write failed - if tomb, err := c.abortedSnapEntry(vol, req.Name, attempt); err == nil { - _ = c.f.CreateEntry(ctx, path.Join(root, snapsDir, req.Name), tomb, true) - } - _, _, _ = c.freeName(ctx, root, req.Name, attempt) - } else { - _, _, _, _ = c.deleteNameForVolume(ctx, vol, root, req.Name) - } + _, _, _, _ = c.deleteNameForVolume(ctx, vol, root, req.Name) return SnapshotInfo{}, refuseDeleted(vol, "it cannot be snapshotted") } diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go index fd95e4ef06..2a2b13c73a 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -124,7 +124,7 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) // commit an earlier run may have lost). if admit != nil { if err := admit.Admit(ctx, vol); err != nil { - if errors.Is(err, ErrNotAdmitted) || true { // RED: any admission error reads as a refusal + if errors.Is(err, ErrNotAdmitted) { return res, catErr(CodeVolumeInUse, false, err, "volume %s: delete not admitted", vol) } res.AdmissionUncertain, res.Uncertain = true, true @@ -133,9 +133,6 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) } res.Admitted = true giveBack := func(cause error) (VolumeDeleteResult, error) { - if red := true; red { // RED: a give-back leaves the admission in place - return res, cause - } if admit != nil { if err := admit.Abort(ctx, vol); err != nil { res.Uncertain = true @@ -169,7 +166,7 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) case rerr != nil: res.Uncertain = u return res, rerr - case !reverted && false: // RED: a revert that found the HEAD committed still counts as given back + case !reverted: // Another delete committed meanwhile: its irreversible steps // stand; this call neither reverts nor gives back. return res, catErr(CodeOutcomeUnknown, true, nil, "volume %s: another delete committed while this one found %v; rerun the delete", vol, live) diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index f6f4787896..8d78fa13aa 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -60,7 +60,7 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe // created again; the reservation is checked under the lock its writer // holds. s.host.workspaceMu.Lock() - reserved := stores.Deletions.Reserved(spec.VolumeID) && false // RED: the reservation does not stop CreateVolume + reserved := stores.Deletions.Reserved(spec.VolumeID) s.host.workspaceMu.Unlock() if reserved { return nil, status.Errorf(codes.FailedPrecondition, "create volume: %s is being deleted or was deleted; its id is never reused", spec.VolumeID) diff --git a/seaweed-block/core/lifecycle/deletion_reservations.go b/seaweed-block/core/lifecycle/deletion_reservations.go index f1f0b462d8..79ebd5cc6a 100644 --- a/seaweed-block/core/lifecycle/deletion_reservations.go +++ b/seaweed-block/core/lifecycle/deletion_reservations.go @@ -189,9 +189,6 @@ func (s *DeletionReservationStore) update(vol string, protective bool, change fu } func (s *DeletionReservationStore) persist(next map[string]DeletionReservation, protective bool) error { - if red := true; red { // RED: intent-only, nothing written or synced - return nil - } b, err := json.Marshal(next) if err != nil { return err