From 04a70968fe172694f9c46138d52a6ddea3d5c8f8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 24 Nov 2026 08:09:38 -0800 Subject: [PATCH] fix: a delete that stopped midway can be run again The HEAD reader refused a deleting, purging or deleted HEAD as invalid, so a never-started delete whose commit timed out (or whose mark's outcome was unknown) was refused on every re-run: the volume stayed unusable and undeletable. Such a HEAD can no longer be claimed, so it is past the fence: the reader returns it with ErrWorkspaceHeadDeleting and the verdict admits it (HolderDeleting). Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/authority/workspace.go | 14 +++++++++++-- .../core/authority/workspace_holder_state.go | 9 ++++++++ .../authority/workspace_holder_state_test.go | 2 ++ seaweed-block/core/host/master/services.go | 4 ++-- .../workspace_delete_never_started_test.go | 12 ++++++++++- .../core/host/master/workspace_head.go | 5 +++++ .../core/host/master/workspace_head_test.go | 21 +++++++++++++++++++ 7 files changed, 62 insertions(+), 5 deletions(-) diff --git a/seaweed-block/core/authority/workspace.go b/seaweed-block/core/authority/workspace.go index 03bcabb9a0..3cf7c07e95 100644 --- a/seaweed-block/core/authority/workspace.go +++ b/seaweed-block/core/authority/workspace.go @@ -16,7 +16,10 @@ type WorkspaceHead struct { Gen, Epoch, RemoteLSN uint64 Holder string Detached bool - FilerMtimeNS int64 + // Deleting: HEAD is deleting, purging or deleted (returned with + // ErrWorkspaceHeadDeleting): no claim can move it again. + Deleting bool + FilerMtimeNS int64 } // ErrWorkspaceHeadUnclaimed is a HEAD reader's answer for a volume's initial @@ -26,6 +29,13 @@ type WorkspaceHead struct { // admission reads it as never started (TERM-LIVE-HOLDER-001). var ErrWorkspaceHeadUnclaimed = errors.New("HEAD never claimed: epoch 0, no holder") +// ErrWorkspaceHeadDeleting is a HEAD reader's answer for a HEAD that is +// deleting, purging or deleted: the head returned with it has Deleting set. +// A caller that needs an active or detached identity treats it as any read +// error; the delete admission reads it as past the fence (a re-run of a +// delete that stopped midway). +var ErrWorkspaceHeadDeleting = errors.New("HEAD is deleting, purging or deleted") + // ErrWorkspaceOutcomeUncertain marks a move whose outcome is unknown: its // issuing write failed after it may have reached the store, or the volume's // workspace persistence is already uncertain. Memory shows it unissued, but @@ -168,7 +178,7 @@ func (p *Publisher) RecordWorkspaceDeletion(ctx context.Context, volume string, if pendingPlacement { return fmt.Errorf("workspace delete: placement may have queued authority") } - case HolderDrained, HolderNeverStarted: + case HolderDrained, HolderNeverStarted, HolderDeleting: 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) } diff --git a/seaweed-block/core/authority/workspace_holder_state.go b/seaweed-block/core/authority/workspace_holder_state.go index 779165f527..ada9cdc303 100644 --- a/seaweed-block/core/authority/workspace_holder_state.go +++ b/seaweed-block/core/authority/workspace_holder_state.go @@ -23,6 +23,11 @@ const ( HolderNeverStarted // HolderLive: HEAD names the line's holder at its epoch, active. HolderLive + // HolderDeleting: HEAD is deleting, purging or deleted. No claim can + // move it again, so it is past the delete's fence: a delete that stopped + // midway (its commit timed out, its mark's outcome was unknown) is + // admitted again and can finish. + HolderDeleting ) func (v WorkspaceHolderVerdict) String() string { @@ -37,6 +42,8 @@ func (v WorkspaceHolderVerdict) String() string { return "never started" case HolderLive: return "live" + case HolderDeleting: + return "deleting" } return "unknown" } @@ -53,6 +60,8 @@ func WorkspaceHolderState(linePresent bool, lineEpoch uint64, lineReplica, owner return HolderNoLine case ack != nil && ack.Epoch == lineEpoch && ack.ReplicaID == lineReplica: return HolderDrained + case head != nil && head.Deleting: + return HolderDeleting case head == nil: return HolderUnknown case head.Epoch < lineEpoch: diff --git a/seaweed-block/core/authority/workspace_holder_state_test.go b/seaweed-block/core/authority/workspace_holder_state_test.go index 251b3951cf..5fe145e31f 100644 --- a/seaweed-block/core/authority/workspace_holder_state_test.go +++ b/seaweed-block/core/authority/workspace_holder_state_test.go @@ -29,6 +29,8 @@ func TestWorkspaceHolderState(t *testing.T) { {"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}, + {"HEAD deleting (a delete that stopped midway)", true, nil, &WorkspaceHead{Gen: 4, Epoch: 0, Deleting: true}, owner, HolderDeleting}, + {"HEAD deleting at the line's epoch", true, nil, &WorkspaceHead{Gen: 4, Epoch: 2, Holder: owner, Deleting: true}, owner, HolderDeleting}, } { 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) diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index e094b60936..9e3d827690 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -999,8 +999,8 @@ func (s *services) deleteHolderEvidence(ctx context.Context, vol string) (*autho readCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() head, err := s.host.cfg.WorkspaceHeadReader(readCtx, vol) - if errors.Is(err, authority.ErrWorkspaceHeadUnclaimed) { - return &head, owner // the initial HEAD: epoch 0, never claimed + if errors.Is(err, authority.ErrWorkspaceHeadUnclaimed) || errors.Is(err, authority.ErrWorkspaceHeadDeleting) { + return &head, owner // the initial HEAD (never claimed), or one past the delete's fence } if err != nil { s.host.log.Printf("blockmaster: MarkVolumeDeleting volume=%q: HEAD unreadable (%v); a line without an ACK is refused", vol, err) diff --git a/seaweed-block/core/host/master/workspace_delete_never_started_test.go b/seaweed-block/core/host/master/workspace_delete_never_started_test.go index ad0413c992..241ef563db 100644 --- a/seaweed-block/core/host/master/workspace_delete_never_started_test.go +++ b/seaweed-block/core/host/master/workspace_delete_never_started_test.go @@ -21,11 +21,14 @@ import ( // 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 + var headFails, headDeleting atomic.Bool h, conn, _ := reviewBindingHostBeforeStart(t, func(context.Context, string) (authority.WorkspaceHead, error) { if headFails.Load() { return authority.WorkspaceHead{}, errors.New("filer unreachable") } + if headDeleting.Load() { // marked by the delete + return authority.WorkspaceHead{Gen: 3, Deleting: true}, authority.ErrWorkspaceHeadDeleting + } e := uint64(headEpoch.Load()) if e == 0 { // the initial HEAD, as the filer reader returns it return authority.WorkspaceHead{Gen: 2}, authority.ErrWorkspaceHeadUnclaimed @@ -80,4 +83,11 @@ func TestDeleteAdmitsANeverStartedLine(t *testing.T) { if err != nil || res.GetState() != lifecycle.ReservationAdmitted { t.Fatalf("delete of a never-started line: %+v %v; want admitted without an ACK", res, err) } + // The delete marked HEAD deleting, then its commit timed out: the re-run + // is admitted again (HEAD past the fence), not stranded as volume_in_use. + headDeleting.Store(true) + res, err = lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "v", Token: "del-never-started"}) + if err != nil || res.GetState() != lifecycle.ReservationAdmitted { + t.Fatalf("re-run after a commit that timed out: %+v %v; want admitted again", res, err) + } } diff --git a/seaweed-block/core/host/master/workspace_head.go b/seaweed-block/core/host/master/workspace_head.go index aaf24eb252..72f8771ccf 100644 --- a/seaweed-block/core/host/master/workspace_head.go +++ b/seaweed-block/core/host/master/workspace_head.go @@ -86,6 +86,11 @@ func NewWorkspaceHEADReader(base string) (func(context.Context, string) (authori // The initial HEAD of a volume no holder ever claimed: epoch 0, no // holder, active. It names no identity, so callers that need one get // an error as before; the delete reads it as "never started". + // A HEAD the delete has marked (deleting, purging, deleted): no claim + // can move it again; the delete's re-run reads it as past the fence. + if doc.Gen > 0 && doc.LegacyDetached == nil && (doc.State == "deleting" || doc.State == "purging" || doc.State == "deleted") { + return authority.WorkspaceHead{Gen: doc.Gen, Epoch: doc.Epoch, Holder: doc.Holder, Deleting: true, FilerMtimeNS: headFilerMtimeNS(res.Header)}, authority.ErrWorkspaceHeadDeleting + } if doc.Gen > 0 && doc.Epoch == 0 && doc.Holder == "" && doc.LegacyDetached == nil && doc.DetachedBy == nil && (doc.State == "" || doc.State == "active") { return authority.WorkspaceHead{Gen: doc.Gen, FilerMtimeNS: headFilerMtimeNS(res.Header)}, authority.ErrWorkspaceHeadUnclaimed } diff --git a/seaweed-block/core/host/master/workspace_head_test.go b/seaweed-block/core/host/master/workspace_head_test.go index a59fc0cd89..0e250e1644 100644 --- a/seaweed-block/core/host/master/workspace_head_test.go +++ b/seaweed-block/core/host/master/workspace_head_test.go @@ -82,3 +82,24 @@ func TestWorkspaceHEADUnclaimed(t *testing.T) { }) } } + +// A HEAD the delete has marked (deleting, purging, deleted) reads as +// ErrWorkspaceHeadDeleting with Deleting set: the delete's re-run sees it as +// past the fence; every other caller still gets an error. +func TestWorkspaceHEADDeleting(t *testing.T) { + for _, state := range []string{"deleting", "purging", "deleted"} { + t.Run(state, func(t *testing.T) { + doc := `{"format":1,"gen":5,"epoch":0,"holder":"","remote_lsn":0,"state":"` + state + `"}` + s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(doc)) })) + defer s.Close() + read, err := NewWorkspaceHEADReader(s.URL) + if err != nil { + t.Fatal(err) + } + h, err := read(context.Background(), "v") + if !errors.Is(err, authority.ErrWorkspaceHeadDeleting) || !h.Deleting || h.Gen != 5 { + t.Fatalf("HEAD %s: %+v, %v; want ErrWorkspaceHeadDeleting with Deleting and its generation", state, h, err) + } + }) + } +}