From dfc8f19ef1d27e35b868fe33c5459167d9f00514 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 19:31:09 -0800 Subject: [PATCH] volume delete: master admission, one HEAD linearization point (a) Admission at the master: LifecycleService.MarkVolumeDeleting holds workspaceMu (every assignment, placement and binding write) and marks VolumeRecord.Deleting inside RecordWorkspaceDeletion's check (refused with live authority without a clean revocation ACK, a pending move or a queued placement). Afterwards publication admission, the placement reconciler, the workload planner, binding/placement/move RPCs and CreateVolume refuse the volume. (b) One HEAD write from the HEAD read (active or detached, not held) to state deleting, chunks kept. Every read decides "held" afresh. ChunkRemote.CASHead refuses to move a deleting or deleted HEAD (ErrChunkHeadPrecondition + ErrChunkHeadDeleted), so no attach, claim or restore revives it; EnsureVolume refuses it; Fork and CreateSnapshot check the volume again after taking their claim/name and back out. (c) Claims read after (b): a live claim reverts HEAD (detached or active, as before) and refuses with snapshot_claimed. (d) Then every snapshot name, published or not (an unpublished attempt gets an aborted tombstone), goes through markDeleting and is freed; the fork claim is released and reported only when confirmed. (e) HEAD becomes deleted (no chunks), VOLUME is marked deleted. A failed delete reports what it did (admitted, headMarked, reverted, snapshots, aborted attempts, claimReleased, completed, uncertain); the CLI prints that with the error and exits nonzero. The CLI's admission is MarkVolumeDeleting (QueryVolumeStatus is no longer used). Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/sw-block/chunk_volume_delete.go | 3 --- seaweed-block/core/frontend/chunkstore/catalog.go | 4 ++-- .../core/frontend/chunkstore/chunk_remote.go | 2 +- .../core/frontend/chunkstore/volume_delete.go | 12 +++--------- seaweed-block/core/host/master/launcher_plan.go | 2 +- seaweed-block/core/host/master/workspace_binding.go | 2 +- seaweed-block/core/host/master/workspace_service.go | 2 +- seaweed-block/core/lifecycle/reconciler.go | 2 +- seaweed-block/core/lifecycle/store.go | 2 +- 9 files changed, 11 insertions(+), 20 deletions(-) diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete.go b/seaweed-block/cmd/sw-block/chunk_volume_delete.go index fec592f645..6d6497b916 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -62,9 +62,6 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { defer cancel() res, err := cat.DeleteVolume(ctx, volumeID, admit) if err != nil { - if red := true; red { // RED: partial effects dropped - return chunkResult("volume-delete", nil, err, stdout, stderr) - } return volumeDeletePartial(res, err, stdout, stderr) } return chunkResult("volume-delete", res, nil, stdout, stderr) diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index ec4ed6aff7..c6c4241eea 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -852,7 +852,7 @@ func (c *Catalog) CreateSnapshot(ctx context.Context, vol string, req SnapshotRe // the attempt is given up before anything is published. if gone, err := c.volumeGone(ctx, vol); err != nil { return SnapshotInfo{}, err - } else if gone && false { // RED: no post-name check + } else if gone { c.abandonUnpublished(ctx, vol, root, req.Name, attempt) return SnapshotInfo{}, refuseDeleted(vol, "it cannot be snapshotted") } @@ -1205,7 +1205,7 @@ func (c *Catalog) Fork(ctx context.Context, req ForkRequest) (ForkResult, error) // back before installing anything. if gone, err := c.volumeGone(ctx, req.Source); err != nil { return ForkResult{}, err - } else if gone && false { // RED: no post-claim check + } else if gone { c.dropForkClaim(ctx, req, snap.attempt) return ForkResult{}, refuseDeleted(req.Source, "its snapshots cannot be forked") } diff --git a/seaweed-block/core/frontend/chunkstore/chunk_remote.go b/seaweed-block/core/frontend/chunkstore/chunk_remote.go index f427900295..9adb0ddcb8 100644 --- a/seaweed-block/core/frontend/chunkstore/chunk_remote.go +++ b/seaweed-block/core/frontend/chunkstore/chunk_remote.go @@ -384,7 +384,7 @@ func (r *ChunkRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVer if err != nil { return 0, err } - if false && (current.State == storage.ChunkHeadDeleting || current.State == storage.ChunkHeadDeleted) { // RED: nothing refuses a deleting HEAD + if current.State == storage.ChunkHeadDeleting || current.State == storage.ChunkHeadDeleted { // A delete passed its linearization point: nothing moves this HEAD // again (the catalog writes the delete's own transitions). return 0, fmt.Errorf("%w: %w", storage.ErrChunkHeadPrecondition, storage.ErrChunkHeadDeleted) diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go index 17180ec257..8f8be4099e 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -119,9 +119,6 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) if err != nil { return res, err } - if red := true; red { // RED: claims are not read after the mark - live = nil - } if live != nil { u, rerr := c.revertHeadDeleting(ctx, vol, root) if rerr != nil { @@ -156,11 +153,11 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) return res, err } else if ok && ref.entry != nil { removed, err := c.removeForkClaim(ctx, req, ref.rec.Attempt) - if err != nil && false { // RED: a failed removal is ignored + if err != nil { res.Uncertain = true return res, err } - res.ClaimReleased = removed || true // RED: reported whether or not it was removed + res.ClaimReleased = removed } } // (e) @@ -223,7 +220,7 @@ func (c *Catalog) markHeadDeleting(ctx context.Context, vol, root string) (bool, if headDeletingOrDeleted(h) { return false, nil } - if headHeld(h) && try > 0 { // RED: the first read is not checked + if headHeld(h) { return false, catErr(CodeVolumeInUse, false, nil, "volume %s is attached: HEAD is held by %q at epoch %d; detach it first", vol, h.Holder, h.Epoch) } next := h @@ -368,9 +365,6 @@ func (c *Catalog) deleteNameForVolume(ctx context.Context, vol, root, name strin return false, false, false, nil // freed meanwhile } attempt := ref.rec.Attempt - if ref.entry == nil && true { // RED: an unpublished attempt is skipped - return false, false, false, nil - } if ref.entry == nil { tomb, err := c.abortedSnapEntry(vol, name, attempt) if err != nil { diff --git a/seaweed-block/core/host/master/launcher_plan.go b/seaweed-block/core/host/master/launcher_plan.go index 144e6a31de..7c6671f175 100644 --- a/seaweed-block/core/host/master/launcher_plan.go +++ b/seaweed-block/core/host/master/launcher_plan.go @@ -42,7 +42,7 @@ func (h *Host) RunLifecycleWorkloadPlanTick(cfg lifecycle.WorkloadPlanConfig) (L var pending []pendingPlan for _, placement := range stores.Placements.ListPlacements() { volume, ok := volumeByID[placement.VolumeID] - if !ok || volume.Deleting && false { // RED + if !ok || volume.Deleting { result.SkippedMissingVolume++ continue } diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 9d1a5d5f22..2d52eb63f4 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -162,7 +162,7 @@ func (h *Host) admitWorkspacePublication(ask authority.AssignmentAsk, publish fu defer h.workspaceMu.Unlock() if rec, alive := h.lifecycle.Volumes.GetVolume(ask.VolumeID); !alive { return fmt.Errorf("workspace publication: volume no longer exists") - } else if rec.Deleting && false { // RED: the mark does not gate publication + } else if rec.Deleting { return fmt.Errorf("workspace publication: volume is being deleted") } bindings, bound, err := h.lifecycle.WorkspaceBindings.Get(ask.VolumeID) diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index b0c03b0bbc..7af3bfe144 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -22,7 +22,7 @@ func (s *services) workspaceVolume(volume string) error { if !ok || r.Spec.ReplicationFactor != 1 { return status.Error(codes.FailedPrecondition, "workspace move requires an existing RF1 volume") } - if r.Deleting && false { // RED: binding/placement/move ignore the mark + if r.Deleting { return status.Error(codes.FailedPrecondition, "workspace: volume is being deleted") } return nil diff --git a/seaweed-block/core/lifecycle/reconciler.go b/seaweed-block/core/lifecycle/reconciler.go index 41f4a6eddd..e22b02bed5 100644 --- a/seaweed-block/core/lifecycle/reconciler.go +++ b/seaweed-block/core/lifecycle/reconciler.go @@ -17,7 +17,7 @@ func ReconcilePlacement(volumes []VolumeRecord, nodes []NodeRegistration, placem nodes = append([]NodeRegistration(nil), nodes...) results := make([]ReconcileResult, 0, len(volumes)) for _, volume := range volumes { - if volume.Deleting && false { // RED: deleting volumes are placed + if volume.Deleting { continue // never placed again } plan := PlanPlacement(volume, nodes) diff --git a/seaweed-block/core/lifecycle/store.go b/seaweed-block/core/lifecycle/store.go index 2ebab6db12..b306a7b5a5 100644 --- a/seaweed-block/core/lifecycle/store.go +++ b/seaweed-block/core/lifecycle/store.go @@ -87,7 +87,7 @@ func (s *FileStore) CreateVolume(spec VolumeSpec) (VolumeRecord, error) { s.mu.Lock() defer s.mu.Unlock() if existing, ok := s.records[spec.VolumeID]; ok { - if existing.Deleting && false { // RED: a deleting id can be created again + if existing.Deleting { return VolumeRecord{}, ErrVolumeDeleting } if !volumeSpecsCompatible(existing.Spec, spec) {