fix: a volume whose holder never claimed HEAD is deletable

One pure verdict for 'live holder of V' (TERM-LIVE-HOLDER-001):
WorkspaceHolderState(line, ACK, HEAD) -> no line, drained, sealed,
never started (HEAD below the line's epoch), live, or unknown. The chunk
volume delete's admission (MarkVolumeDeleting) reads HEAD before its
locks, bounded at 5 s, and admits no line, drained and never started; a
sealed HEAD without an ACK, a live one, or an unreadable HEAD is refused
as before. The delete's HEAD compare-and-swap to deleting stays the only
fence against a claim that lands after the read. The lifecycle
DeleteVolume reads no HEAD and keeps refusing a line without an ACK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-24 06:54:24 -08:00
1 parent 6be001de67
commit 5bf22f98e1
5 files changed
+241 -8

No files matched your search

+22 -6
View File
@@ -132,7 +132,16 @@ func (p *Publisher) RecordWorkspacePlacement(ctx context.Context, volume string,
// RecordWorkspaceDeletion protects reservation release against live or pending
// authority. A current clean ACK is proof of drain; a lease alone is not.
func (p *Publisher) RecordWorkspaceDeletion(ctx context.Context, volume string, pendingPlacement bool, persist func() error) error {
// RecordWorkspaceDeletion admits a delete of volume (INV-WS-DELETE-NO-LIVE-HOLDER-001)
// when it has no live holder (TERM-LIVE-HOLDER-001): no line (and no
// placement that may have queued one), a clean revocation ACK for the line,
// or a HEAD below the line's epoch (never started). head is HEAD as the
// caller read it before taking any lock (nil: not read, which refuses a line
// without an ACK, as before); owner is the line's owner "<server>/<replica>"
// ("" when unknown), used only to name the refusal. A Sealed HEAD without an
// ACK keeps the ACK rule. The delete's HEAD compare-and-swap to deleting is
// the fence against a claim that lands after the read.
func (p *Publisher) RecordWorkspaceDeletion(ctx context.Context, volume string, pendingPlacement bool, head *WorkspaceHead, owner string, persist func() error) error {
p.mu.Lock()
defer p.mu.Unlock()
if err := ctx.Err(); err != nil {
@@ -142,12 +151,19 @@ func (p *Publisher) RecordWorkspaceDeletion(ctx context.Context, volume string,
if s != nil && len(s.Moves) > 0 && !s.Moves[len(s.Moves)-1].Issued {
return fmt.Errorf("workspace delete: move pending")
}
if _, line, ok := p.workspaceLineLocked(volume); ok {
if s == nil || s.Ack == nil || s.Ack.Epoch != line.info.Epoch || s.Ack.ReplicaID != line.info.ReplicaID {
return fmt.Errorf("workspace delete: live authority requires clean revocation ACK: revoke the line with its sealed generation (sw-block ops workspace revoke --epoch E --sealed-gen G) and wait for the recorded ACK, then delete")
_, line, ok := p.workspaceLineLocked(volume)
var ack *WorkspaceRevokeAck
if s != nil {
ack = s.Ack
}
switch v := WorkspaceHolderState(ok, line.info.Epoch, line.info.ReplicaID, owner, ack, head); v {
case HolderNoLine:
if pendingPlacement {
return fmt.Errorf("workspace delete: placement may have queued authority")
}
} else if pendingPlacement {
return fmt.Errorf("workspace delete: placement may have queued authority")
case HolderDrained, HolderNeverStarted:
default:
return fmt.Errorf("workspace delete: live authority requires clean revocation ACK: revoke the line with its sealed generation (sw-block ops workspace revoke --epoch E --sealed-gen G) and wait for the recorded ACK, then delete (holder: %s)", v)
}
return persist()
}
@@ -0,0 +1,66 @@
package authority
// WorkspaceHolderVerdict is the one answer to "is there a live holder of V"
// (TERM-LIVE-HOLDER-001). The line's holder at epoch e may have acknowledged
// guest writes and may publish exactly when the verdict is Live.
type WorkspaceHolderVerdict int
const (
// HolderUnknown: HEAD was not read or could not be read, names a higher
// epoch, or names another holder at the line's epoch. Always refused.
HolderUnknown WorkspaceHolderVerdict = iota
// HolderNoLine: there is no authority line.
HolderNoLine
// HolderDrained: a clean revocation ACK is recorded for the line.
HolderDrained
// HolderSealed: HEAD names the line's holder at its epoch, detached.
HolderSealed
// HolderNeverStarted: HEAD is below the line's epoch. No claim at that
// epoch had applied when HEAD was read, so nothing was acknowledged or
// published under it (no I/O is admitted before the claim), whatever
// lease exists. The delete's HEAD compare-and-swap to deleting fences a
// claim that lands after the read.
HolderNeverStarted
// HolderLive: HEAD names the line's holder at its epoch, active.
HolderLive
)
func (v WorkspaceHolderVerdict) String() string {
switch v {
case HolderNoLine:
return "no line"
case HolderDrained:
return "drained"
case HolderSealed:
return "sealed"
case HolderNeverStarted:
return "never started"
case HolderLive:
return "live"
}
return "unknown"
}
// WorkspaceHolderState decides the verdict from durable inputs only: the
// authority line (present, epoch, replica, and its owner "<server>/<replica>"
// by the single owner decision; "" when unknown), the recorded revocation
// ACK, and HEAD as read (nil when it was not read or could not be read).
// Pure: no I/O, no state, no clock. It does not depend on master memory, so
// it holds across a blockmaster restart.
func WorkspaceHolderState(linePresent bool, lineEpoch uint64, lineReplica, owner string, ack *WorkspaceRevokeAck, head *WorkspaceHead) WorkspaceHolderVerdict {
switch {
case !linePresent:
return HolderNoLine
case ack != nil && ack.Epoch == lineEpoch && ack.ReplicaID == lineReplica:
return HolderDrained
case head == nil:
return HolderUnknown
case head.Epoch < lineEpoch:
return HolderNeverStarted
case head.Epoch > lineEpoch || owner == "" || head.Holder != owner:
return HolderUnknown
case head.Detached:
return HolderSealed
}
return HolderLive
}
@@ -0,0 +1,37 @@
package authority
import "testing"
// TERM-LIVE-HOLDER-001: one pure verdict from the line, the ACK and HEAD.
// "Never started" is HEAD below the line's epoch, not "never leased"; every
// doubtful case is Unknown (refused).
func TestWorkspaceHolderState(t *testing.T) {
const owner = "node-a/r1"
head := func(epoch uint64, holder string, detached bool) *WorkspaceHead {
return &WorkspaceHead{Gen: 3, Epoch: epoch, Holder: holder, Detached: detached}
}
for _, c := range []struct {
name string
line bool
ack *WorkspaceRevokeAck
head *WorkspaceHead
owner string
want WorkspaceHolderVerdict
}{
{"no line", false, nil, nil, owner, HolderNoLine},
{"ACK for the line", true, &WorkspaceRevokeAck{ReplicaID: "r1", Epoch: 2, HeadGen: 3}, nil, owner, HolderDrained},
{"ACK for an older epoch", true, &WorkspaceRevokeAck{ReplicaID: "r1", Epoch: 1}, head(2, owner, true), owner, HolderSealed},
{"HEAD not read", true, nil, nil, owner, HolderUnknown},
{"HEAD never claimed (epoch 0)", true, nil, head(0, "", false), owner, HolderNeverStarted},
{"HEAD at an older epoch", true, nil, head(1, "node-b/r1", false), owner, HolderNeverStarted},
{"HEAD claimed at the line's epoch, active", true, nil, head(2, owner, false), owner, HolderLive},
{"HEAD claimed at the line's epoch, sealed", true, nil, head(2, owner, true), owner, HolderSealed},
{"another holder at the line's epoch", true, nil, head(2, "node-b/r1", false), owner, HolderUnknown},
{"HEAD at a higher epoch", true, nil, head(3, owner, false), owner, HolderUnknown},
{"owner unknown at the line's epoch", true, nil, head(2, owner, false), "", HolderUnknown},
} {
if got := WorkspaceHolderState(c.line, 2, "r1", c.owner, c.ack, c.head); got != c.want {
t.Errorf("%s: %s; want %s", c.name, got, c.want)
}
}
}
+33 -2
View File
@@ -106,7 +106,10 @@ func (s *services) DeleteVolume(ctx context.Context, req *control.DeleteVolumeRe
return nil, lifecycleError("delete workspace bindings", err)
}
_, placed := stores.Placements.GetPlacement(req.GetVolumeId())
err = s.host.Publisher().RecordWorkspaceDeletion(ctx, req.GetVolumeId(), bound && placed, func() error {
// The lifecycle delete does not read HEAD: a line without an ACK is
// refused here even when it never started (INV-WS-DELETE-NO-LIVE-HOLDER-001
// admits that only through the chunk volume delete and its HEAD fence).
err = s.host.Publisher().RecordWorkspaceDeletion(ctx, req.GetVolumeId(), bound && placed, nil, "", func() error {
if e := stores.Placements.DeletePlacement(req.GetVolumeId()); e != nil {
return e
}
@@ -131,6 +134,11 @@ func (s *services) DeleteVolume(ctx context.Context, req *control.DeleteVolumeRe
// workload planner, binding/placement/move RPCs and CreateVolume all refuse
// it.
func (s *services) MarkVolumeDeleting(ctx context.Context, req *control.MarkVolumeDeletingRequest) (*control.MarkVolumeDeletingResponse, error) {
// HEAD and the line's owner, read before any lock (as MoveWorkspace
// does), bounded: a HEAD below the line's epoch proves the line never
// started (TERM-LIVE-HOLDER-001). A read that fails leaves head nil,
// which refuses a line without an ACK (fail closed).
head, owner := s.deleteHolderEvidence(ctx, req.GetVolumeId())
s.host.workspaceMu.Lock()
defer s.host.workspaceMu.Unlock()
if err := ctx.Err(); err != nil {
@@ -151,7 +159,7 @@ func (s *services) MarkVolumeDeleting(ctx context.Context, req *control.MarkVolu
_, placed := stores.Placements.GetPlacement(vol)
var res lifecycle.DeletionReservation
var persistErr error
err = s.host.Publisher().RecordWorkspaceDeletion(ctx, vol, bound && placed, func() error {
err = s.host.Publisher().RecordWorkspaceDeletion(ctx, vol, bound && placed, head, owner, func() error {
res, persistErr = stores.Deletions.Admit(vol, req.GetToken())
return persistErr
})
@@ -974,3 +982,26 @@ func (s *services) assignmentFact(info adapter.AssignmentInfo) *control.Assignme
fact.PeerSetGeneration = (info.Epoch << 32) | info.EndpointVersion
return fact
}
// deleteHolderEvidence reads vol's HEAD with the configured reader, bounded
// at 5 s, and the published line's owner "<server>/<replica>". Either may be
// missing: no reader, a failed read or no line gives a nil head or "".
func (s *services) deleteHolderEvidence(ctx context.Context, vol string) (*authority.WorkspaceHead, string) {
owner := ""
if line, ok := s.host.Publisher().PublishedAuthorityLine(vol); ok {
if server := s.host.workspaceLineOwner(line, vol, line.ReplicaID, line.Epoch); server != "" {
owner = server + "/" + line.ReplicaID
}
}
if s.host.cfg.WorkspaceHeadReader == nil || vol == "" {
return nil, owner
}
readCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
head, err := s.host.cfg.WorkspaceHeadReader(readCtx, vol)
if err != nil {
s.host.log.Printf("blockmaster: MarkVolumeDeleting volume=%q: HEAD unreadable (%v); a line without an ACK is refused", vol, err)
return nil, owner
}
return &head, owner
}
@@ -0,0 +1,83 @@
package master
import (
"context"
"errors"
"strings"
"sync/atomic"
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/authority"
"github.com/seaweedfs/seaweed-block/core/lifecycle"
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
)
// INV-WS-DELETE-NO-LIVE-HOLDER-001 on the real master: a line whose holder
// never claimed HEAD at its epoch is admitted for delete without an ACK, on
// HEAD's evidence read before the locks; a HEAD claimed at the line's epoch,
// or one that cannot be read, is refused as before; the lifecycle
// DeleteVolume RPC (which reads no HEAD) refuses even the never-started line.
func TestDeleteAdmitsANeverStartedLine(t *testing.T) {
var headEpoch atomic.Int64
var headFails atomic.Bool
h, conn, _ := reviewBindingHostBeforeStart(t, func(context.Context, string) (authority.WorkspaceHead, error) {
if headFails.Load() {
return authority.WorkspaceHead{}, errors.New("filer unreachable")
}
e := uint64(headEpoch.Load())
holder := ""
if e > 0 {
holder = "node-a/r1"
}
return authority.WorkspaceHead{Gen: 2, Epoch: e, Holder: holder}, nil
}, nil)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
t.Cleanup(cancel)
for _, vol := range []string{"v", "w"} {
reviewCreate(t, conn, ctx, vol)
ws := control.NewWorkspaceServiceClient(conn)
b := &control.WorkspaceBinding{VolumeId: vol, ServerId: "node-a", DataAddr: "127.0.0.1:10000", CtrlAddr: "127.0.0.1:10001"}
if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil {
t.Fatal(err)
}
if _, err := ws.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: vol, ServerId: "node-a", ReplicaId: "r1"}); err != nil {
t.Fatal(err)
}
reviewHeartbeat(t, conn, ctx, vol, "node-a", b.DataAddr, b.CtrlAddr)
}
if _, err := h.RunLifecycleProductTick(); err != nil {
t.Fatal(err)
}
line := waitAuthorityLine(t, h.Publisher(), "v")
waitAuthorityLine(t, h.Publisher(), "w")
// A lease granted, HEAD never claimed: the stranded state the release
// candidate could not delete.
if _, err := control.NewWorkspaceServiceClient(conn).RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r1", Epoch: line.Epoch, ServerId: "node-a"}); err != nil {
t.Fatal(err)
}
lc := control.NewLifecycleServiceClient(conn)
mark := func(vol, token string) error {
_, err := lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: vol, Token: token})
return err
}
refusedLive := func(what string, err error) {
t.Helper()
if err == nil || !strings.Contains(err.Error(), "live authority requires clean revocation ACK") {
t.Fatalf("%s: %v; want the live-authority refusal", what, err)
}
}
headEpoch.Store(int64(line.Epoch)) // claimed at the line's epoch: live
refusedLive("HEAD claimed at the line's epoch", mark("v", "del-live"))
headFails.Store(true) // unreadable HEAD: fail closed
refusedLive("HEAD unreadable", mark("v", "del-unreadable"))
headFails.Store(false)
headEpoch.Store(0) // never claimed
_, err := lc.DeleteVolume(ctx, &control.DeleteVolumeRequest{VolumeId: "w"})
refusedLive("the lifecycle DeleteVolume of a never-started line", err)
res, err := lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "v", Token: "del-never-started"})
if err != nil || res.GetState() != lifecycle.ReservationAdmitted {
t.Fatalf("delete of a never-started line: %+v %v; want admitted without an ACK", res, err)
}
}