From a73001b121cd394dee55eb9c09662a9114e1ad79 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 18:49:17 -0800 Subject: [PATCH 01/16] chunkstore: RED controls for volume delete claude05's item (2026-11-16 02:39Z): `sw-block ops chunk volume-delete` plus Catalog.DeleteVolume. Controls, failing against a DeleteVolume stub that deletes nothing: - an attached volume (HEAD held) and one the blockmaster reports in use are refused with volume_in_use, nothing written; - a volume whose snapshot a live fork claims is refused with snapshot_claimed, nothing written; - fork w2 from s1, delete w2: HEAD tombstone (deleted, no chunks), VOLUME deleted, snapshots freed; DeleteSnapshot s1 then succeeds; the id is never attached, recreated or forked to again; an incomplete fork's claim is released; a rerun replays; - an attach between the check and the tombstone wins (held caller); - the CLI needs a volume and --master and refuses an attached volume; - real service + real GC: exactly the chunks only w2 and S1 reach are reclaimed, w1's HEAD and S2 stay readable. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/sw-block/chunk.go | 4 +- seaweed-block/cmd/sw-block/chunk_gc.go | 15 +- .../cmd/sw-block/chunk_volume_delete.go | 72 ++++++ .../cmd/sw-block/chunk_volume_delete_test.go | 78 ++++++ .../core/frontend/chunkstore/catalog.go | 24 ++ .../core/frontend/chunkstore/chunk_remote.go | 5 + .../core/frontend/chunkstore/volume_delete.go | 235 ++++++++++++++++++ .../volume_delete_integration_test.go | 157 ++++++++++++ .../frontend/chunkstore/volume_delete_test.go | 208 ++++++++++++++++ seaweed-block/core/storage/chunk_public.go | 1 + seaweed-block/core/storage/chunk_seam.go | 4 + 11 files changed, 799 insertions(+), 4 deletions(-) create mode 100644 seaweed-block/cmd/sw-block/chunk_volume_delete.go create mode 100644 seaweed-block/cmd/sw-block/chunk_volume_delete_test.go create mode 100644 seaweed-block/core/frontend/chunkstore/volume_delete.go create mode 100644 seaweed-block/core/frontend/chunkstore/volume_delete_integration_test.go create mode 100644 seaweed-block/core/frontend/chunkstore/volume_delete_test.go diff --git a/seaweed-block/cmd/sw-block/chunk.go b/seaweed-block/cmd/sw-block/chunk.go index 8991625249..894b0544b4 100644 --- a/seaweed-block/cmd/sw-block/chunk.go +++ b/seaweed-block/cmd/sw-block/chunk.go @@ -44,7 +44,7 @@ var dialChunkFiler = func(addr string) (chunkstore.Filer, func() error, error) { func runOpsChunk(args []string, stdout, stderr io.Writer) int { if len(args) == 0 { - return chunkFail("", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "expected cut|snapshot|snapshots|snapshot-delete|fork|detach|show|gc|usage|retain", false) + return chunkFail("", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "expected cut|snapshot|snapshots|snapshot-delete|fork|detach|show|gc|usage|retain|volume-delete", false) } switch args[0] { case "gc": @@ -67,6 +67,8 @@ func runOpsChunk(args []string, stdout, stderr io.Writer) int { return chunkUsage(args[1:], stdout, stderr) case "retain": return chunkRetain(args[1:], stdout, stderr) + case "volume-delete": + return chunkVolumeDelete(args[1:], stdout, stderr) default: return chunkFail("", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, fmt.Sprintf("unknown subcommand %q", args[0]), false) } diff --git a/seaweed-block/cmd/sw-block/chunk_gc.go b/seaweed-block/cmd/sw-block/chunk_gc.go index 0324be8329..a5a8cdfc61 100644 --- a/seaweed-block/cmd/sw-block/chunk_gc.go +++ b/seaweed-block/cmd/sw-block/chunk_gc.go @@ -49,12 +49,11 @@ func chunkGC(args []string, stdout, stderr io.Writer) int { if e != nil { return chunkFail("gc", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, e.Error(), false) } - conn, e := grpc.NewClient(master, grpc.WithTransportCredentials(insecure.NewCredentials())) + evidence, closeMaster, e := masterEvidence(master) if e != nil { return chunkResult("gc", nil, e, stdout, stderr) } - defer conn.Close() - evidence := control.NewEvidenceServiceClient(conn) + defer closeMaster() issuedEpoch := func(ctx context.Context, vol string) (uint64, error) { reply, e := evidence.QueryVolumeStatus(ctx, &control.StatusRequest{VolumeId: vol}) if e != nil { @@ -71,6 +70,16 @@ func chunkGC(args []string, stdout, stderr io.Writer) int { return chunkGCResult(out, e, stdout, stderr) } +// masterEvidence dials the blockmaster's evidence service (gc and +// volume-delete read volume status from it). +func masterEvidence(master string) (control.EvidenceServiceClient, func() error, error) { + conn, e := grpc.NewClient(master, grpc.WithTransportCredentials(insecure.NewCredentials())) + if e != nil { + return nil, nil, e + } + return control.NewEvidenceServiceClient(conn), conn.Close, nil +} + // Error status and code remain failures, but a failure must not erase known // effects or imply that a lost write response means the write did not commit. func chunkGCResult(out chunkstore.GCExecution, err error, stdout, stderr io.Writer) int { diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete.go b/seaweed-block/cmd/sw-block/chunk_volume_delete.go new file mode 100644 index 0000000000..afe4fca07d --- /dev/null +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" + "github.com/seaweedfs/seaweed-block/core/ops" + "github.com/seaweedfs/seaweed-block/core/rpc/control" +) + +// chunkVolumeDelete: sw-block ops chunk volume-delete --chunk-filer +// host:port --master host:port deletes a chunk volume (Catalog.DeleteVolume): +// refused while it is attached, assigned or served (volume_in_use) or while +// a live fork claims one of its snapshots (snapshot_claimed); GC reclaims. +func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { + fs := chunkFlagSet("volume-delete", stderr) + var ( + volumeID, filer, base, master string + timeout time.Duration + ) + fs.StringVar(&volumeID, "volume", "", "volume id (or the first argument)") + fs.StringVar(&filer, "chunk-filer", "", "SeaweedFS filer gRPC address host:port") + fs.StringVar(&base, "chunk-path", defaultChunkPathCLI, "filer directory holding one directory per volume") + fs.StringVar(&master, "master", "", "authoritative blockmaster gRPC address (refuses an assigned or served volume)") + fs.DurationVar(&timeout, "timeout", time.Minute, "bound for this delete") + if err := fs.Parse(args); err != nil { + return chunkFail(chunkName(fs), stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, err.Error(), false) + } + if volumeID == "" && fs.NArg() == 1 { + volumeID = fs.Arg(0) + } else if fs.NArg() != 0 { + return chunkFail("volume-delete", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "give the volume once, as an argument or --volume", false) + } + if volumeID == "" || master == "" || timeout <= 0 { + return chunkFail("volume-delete", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "a volume and --master are required; --timeout must be positive", false) + } + cat, closeFn, exit := chunkCatalog("volume-delete", filer, base, stdout, stderr) + if exit >= 0 { + return exit + } + defer closeFn() + evidence, closeMaster, err := masterEvidence(master) + if err != nil { + return chunkResult("volume-delete", nil, err, stdout, stderr) + } + defer closeMaster() + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + res, err := cat.DeleteVolume(ctx, volumeID, masterInUse(evidence)) + return chunkResult("volume-delete", res, err, stdout, stderr) +} + +// masterInUse: the blockmaster has the volume assigned, or a frontend +// serves it. +func masterInUse(evidence control.EvidenceServiceClient) chunkstore.InUseCheck { + return func(ctx context.Context, vol string) (bool, string, error) { + st, err := evidence.QueryVolumeStatus(ctx, &control.StatusRequest{VolumeId: vol}) + if err != nil { + return false, "", err + } + if st.GetAssigned() { + return true, fmt.Sprintf("the blockmaster has it assigned (replica %q, epoch %d)", st.GetReplicaId(), st.GetEpoch()), nil + } + if n := len(st.GetFrontends()); n > 0 { + return true, fmt.Sprintf("%d frontend(s) serve it", n), nil + } + return false, "", nil + } +} diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go new file mode 100644 index 0000000000..3f43657c5a --- /dev/null +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go @@ -0,0 +1,78 @@ +package main + +import ( + "context" + "encoding/json" + "strings" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" + "github.com/seaweedfs/seaweed-block/core/host/master" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// volume-delete needs a volume and --master; it refuses an attached volume +// and deletes a free one (the real master runtime reports it unassigned); +// the deleted id cannot be created again. +func TestOpsChunk_VolumeDelete(t *testing.T) { + ctx := context.Background() + mem := chunkstore.NewMemFiler() + prev := dialChunkFiler + dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return mem, func() error { return nil }, nil } + t.Cleanup(func() { dialChunkFiler = prev }) + cat, err := chunkstore.NewCatalog(mem, defaultChunkPathCLI) + if err != nil { + t.Fatal(err) + } + geo := chunkstore.Geometry{NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 8} + for _, vol := range []string{"v1", "v2"} { + if _, err := cat.EnsureVolume(ctx, vol, geo); err != nil { + t.Fatal(err) + } + } + // v2 is attached: its HEAD names a holder. + r, err := chunkstore.NewChunkRemote(mem, &gcCLIStore{MemFiler: mem}, defaultChunkPathCLI+"/v2") + if err != nil { + t.Fatal(err) + } + cur, err := r.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + if _, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, storage.ChunkHead{Epoch: 1, Holder: "h1", Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadActive}); err != nil { + t.Fatal(err) + } + + for _, args := range [][]string{ + {"volume-delete", "v1", "--chunk-filer", "f:1"}, // no --master + {"volume-delete", "--master", "m:1", "--chunk-filer", "f:1"}, // no volume + {"volume-delete", "--volume", "v1", "v2", "--master", "m:1", "--chunk-filer", "f:1"}, // two volumes + } { + if code, out, _ := runChunk(args...); code == 0 || !strings.Contains(out, codeBadRequestCLI) { + t.Fatalf("%v: %d %q; want a bad request", args, code, out) + } + } + + h, err := master.New(gcTestMasterConfig(t)) + if err != nil { + t.Fatal(err) + } + h.Start() + t.Cleanup(func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + _ = h.Close(ctx) + }) + if code, out, _ := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v2"); code == 0 || !strings.Contains(out, chunkstore.CodeVolumeInUse) { + t.Fatalf("delete of attached v2: %d %q; want volume_in_use", code, out) + } + code, out, errs := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v1") + var res chunkstore.VolumeDeleteResult + if code != 0 || json.Unmarshal([]byte(out), &res) != nil || res.VolumeID != "v1" || res.Replayed { + t.Fatalf("delete v1: %d %q %q", code, out, errs) + } + if _, err := cat.EnsureVolume(ctx, "v1", geo); chunkstore.CodeOf(err) != chunkstore.CodeVolumeDeleted { + t.Fatalf("recreate v1: %v; want volume_deleted", err) + } +} diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index 2ce0cc98a0..f88f2918aa 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -171,6 +171,9 @@ type VolumeInfo struct { // Fork records the fork operation that made this volume (origin fork): // a retry is bound to it, and a completed fork replays it. Fork *ForkRecord `json:"fork,omitempty"` + // State is VolumeDeleted for a deleted volume, read from the entry's + // extended attributes (never from the stored document). + State string `json:"state,omitempty"` } // ForkRecord is the operation identity and original result of a fork. @@ -394,6 +397,7 @@ func decodeVolume(p string, e *filerpb.Entry) (VolumeInfo, error) { if v.Origin == OriginFork && (v.Fork == nil || v.Fork.RequestID == "") { return VolumeInfo{}, fmt.Errorf("chunkstore: VOLUME %s: a fork without its fork record", p) } + v.State = string(e.Extended[extVolState]) return v, nil } @@ -496,6 +500,14 @@ func (c *Catalog) EnsureVolume(ctx context.Context, vol string, g Geometry) (Vol } } } + if v.State == VolumeDeleted { + return VolumeInfo{}, refuseDeleted(vol, "it cannot be attached or created again") + } + if h, has, err := c.ReadHead(ctx, vol); err != nil { + return VolumeInfo{}, err + } else if has && h.State == storage.ChunkHeadDeleted { + return VolumeInfo{}, refuseDeleted(vol, "its HEAD is a tombstone; it cannot be attached") + } if v.Geometry != g { return VolumeInfo{}, catErr(CodeGeometryMismatch, false, nil, "volume %s: VOLUME geometry %+v, this host serves %+v", vol, v.Geometry, g) } @@ -1151,6 +1163,9 @@ func (c *Catalog) Fork(ctx context.Context, req ForkRequest) (ForkResult, error) if err != nil { return ForkResult{}, err } + if ok && existing.State == VolumeDeleted { + return ForkResult{}, refuseDeleted(req.Target, "fork to a new volume id") + } if ok { if err := c.checkForkRecord(existing, req); err != nil { return ForkResult{}, err @@ -1175,6 +1190,15 @@ func (c *Catalog) Fork(ctx context.Context, req ForkRequest) (ForkResult, error) if err != nil { return ForkResult{}, err } + // Read after the claim: a delete of the source marks VOLUME before it + // marks the snapshots, so a fork that sees it live is protected by its + // claim, and one that sees it deleted gives the claim back. + if src, ok, err := c.ReadVolume(ctx, req.Source); err != nil { + return ForkResult{}, err + } else if ok && src.State == VolumeDeleted { + c.dropForkClaim(ctx, req, snap.attempt) + return ForkResult{}, refuseDeleted(req.Source, "its snapshots cannot be forked") + } if snap.geo == (Geometry{}) { return ForkResult{}, fmt.Errorf("chunkstore: snapshot %s/%s has no geometry", req.Source, req.Snapshot) } diff --git a/seaweed-block/core/frontend/chunkstore/chunk_remote.go b/seaweed-block/core/frontend/chunkstore/chunk_remote.go index cdea709acf..c522b58f30 100644 --- a/seaweed-block/core/frontend/chunkstore/chunk_remote.go +++ b/seaweed-block/core/frontend/chunkstore/chunk_remote.go @@ -497,6 +497,11 @@ func decodeHeadDoc(p string, content []byte) (storage.ChunkHead, error) { if doc.DetachedBy != nil || len(doc.Chunks) != 0 { return fail("an aborted HEAD with content") } + case storage.ChunkHeadDeleted: + // A deleted volume's tombstone (no chunks, no holder). + if doc.DetachedBy != nil || len(doc.Chunks) != 0 || doc.Holder != "" { + return fail("a deleted HEAD with content") + } case storage.ChunkHeadDetached: d := doc.DetachedBy if d == nil || d.Gen != doc.Gen || d.Holder != doc.Holder || d.Epoch != doc.Epoch { diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go new file mode 100644 index 0000000000..d46ac4682c --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -0,0 +1,235 @@ +package chunkstore + +import ( + "context" + "errors" + "sort" + "strconv" + + "google.golang.org/protobuf/proto" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// Volume delete (claude05's item, 2026-11-16 02:39Z). +// +// DeleteVolume refuses while the volume is in use: its HEAD is held (an +// active HEAD with a holder: a volume server attached it), or the caller's +// InUse check says so (the blockmaster has it assigned or served). It also +// refuses, before writing anything, while a live fork claims one of its +// snapshots (snapshot_claimed, the claim rule of retention.go). +// +// Otherwise, in this order: +// 1. HEAD becomes a tombstone (state deleted, no chunks), by a conditional +// write on the HEAD it read (or an exclusive create when there is no +// HEAD yet): a volume server that attached meanwhile makes it fail and +// the delete decides again. Its chunks stop being GC roots. +// 2. VOLUME is marked deleted (an extended attribute; the document is +// kept). The id is never reused: EnsureVolume (attach, create) and Fork +// refuse a deleted volume, and its VOLUME and HEAD entries stay. +// 3. Every snapshot is marked deleting through markDeleting (the one mark +// path) and its name freed; GC stops counting it after its grace. +// 4. A fork's claim on its parent snapshot is released. +// +// Reclamation is GC's. A rerun after a partial delete (e.g. a fork claimed +// a snapshot between the check and step 3) resumes from what is there. + +const ( + CodeVolumeInUse = "volume_in_use" + CodeVolumeDeleted = "volume_deleted" + + // VolumeDeleted is the state of a deleted volume's VOLUME entry. + VolumeDeleted = "deleted" + + extVolState = "swb.volume.state" + extVolDeletedNs = "swb.volume.deleted_ns" +) + +// InUseCheck reports whether a volume is in use outside the catalog (e.g. +// assigned or served by the blockmaster), with a reason for the error. +type InUseCheck func(ctx context.Context, vol string) (inUse bool, why string, err error) + +// VolumeDeleteResult is what DeleteVolume did. +type VolumeDeleteResult struct { + VolumeID string `json:"volumeID"` + Replayed bool `json:"replayed"` // the volume was already deleted; this call finished what was left + SnapshotsDeleted []string `json:"snapshotsDeleted"` + ClaimReleased bool `json:"claimReleased"` // its fork claim on the parent snapshot was removed +} + +// DeleteVolume deletes vol (see the header). inUse may be nil. +func (c *Catalog) DeleteVolume(ctx context.Context, vol string, inUse InUseCheck) (VolumeDeleteResult, error) { + res := VolumeDeleteResult{VolumeID: vol, SnapshotsDeleted: []string{}} + if red := true; red { // RED: deletes nothing + return res, nil + } + root, err := c.volRoot(vol) + if err != nil { + return res, err + } + v, ok, err := c.ReadVolume(ctx, vol) + if err != nil { + return res, err + } + if !ok { + return res, catErr(CodeNotChunkVolume, false, nil, "volume %s has no VOLUME entry", vol) + } + res.Replayed = v.State == VolumeDeleted + snaps, err := c.listSnapshots(ctx, vol, true) + if err != nil { + return res, err + } + if !res.Replayed { + if err := c.checkVolumeFree(ctx, vol, inUse); err != nil { + return res, err + } + // No mutation while a live fork claims a snapshot. + for _, s := range snaps { + if s.State != SnapActive { + continue + } + ref, ok, err := c.resolveSnap(ctx, vol, s.Name) + if err != nil { + return res, err + } + if !ok || ref.entry == nil { + continue + } + live, err := c.liveClaims(ctx, vol, s.Name, decodeClaims(ref.entry)) + if err != nil { + return res, err + } + if len(live) > 0 { + return res, claimedErr(vol, s.Name, live) + } + } + } + if err := c.tombstoneHead(ctx, vol, root, inUse, res.Replayed); err != nil { + return res, err + } + if !res.Replayed { + if err := c.markVolumeDeleted(ctx, vol, root); err != nil { + return res, err + } + } + sort.Slice(snaps, func(i, j int) bool { return snaps[i].Name < snaps[j].Name }) + for _, s := range snaps { + m, live, _, err := c.markDeleting(ctx, vol, s.Name, s.attempt) + if err != nil { + return res, err + } + if m == markClaimed { + return res, claimedErr(vol, s.Name, live) + } + if _, _, err := c.freeName(ctx, root, s.Name, s.attempt); err != nil { + return res, err + } + res.SnapshotsDeleted = append(res.SnapshotsDeleted, s.Name) + } + if v.Fork != nil { + req := ForkRequest{Source: v.Fork.Source, Snapshot: v.Fork.Snapshot, Target: vol, RequestID: v.Fork.RequestID} + if ref, ok, err := c.resolveSnap(ctx, req.Source, req.Snapshot); err == nil && ok && ref.entry != nil { + token := forkClaim(vol, v.Fork.RequestID) + for _, cl := range decodeClaims(ref.entry) { + if cl == token { + c.dropForkClaim(ctx, req, ref.rec.Attempt) + res.ClaimReleased = true + } + } + } + } + return res, nil +} + +// checkVolumeFree refuses a volume in use: a held HEAD, or inUse says so. +func (c *Catalog) checkVolumeFree(ctx context.Context, vol string, inUse InUseCheck) error { + h, has, err := c.ReadHead(ctx, vol) + if err != nil { + return err + } + if has && headHeld(h) { + return catErr(CodeVolumeInUse, false, nil, "volume %s is attached: HEAD is held by %q at epoch %d; detach it first", vol, h.Holder, h.Epoch) + } + if inUse != nil { + busy, why, err := inUse(ctx, vol) + if err != nil { + return remoteErr(err, "check whether volume %s is in use", vol) + } + if busy { + return catErr(CodeVolumeInUse, false, nil, "volume %s is in use: %s", vol, why) + } + } + return nil +} + +// headHeld: an active HEAD that names a holder belongs to an attached +// volume server (a clean detach publishes state detached). +func headHeld(h storage.ChunkHead) bool { + return (h.State == "" || h.State == storage.ChunkHeadActive) && h.Holder != "" +} + +// tombstoneHead replaces vol's HEAD with a deleted tombstone, conditioned +// on the HEAD read; a lost condition re-reads and decides again (refusing +// if the volume was attached meanwhile). +func (c *Catalog) tombstoneHead(ctx context.Context, vol, root string, inUse InUseCheck, replay bool) error { + r, err := NewChunkRemote(c.f, nilBlobs{}, root) + if err != nil { + return err + } + for try := 0; try < 5; try++ { + h, err := r.GetHead(ctx) + if err != nil { + return remoteErr(err, "read HEAD of %s", vol) + } + if h.State == storage.ChunkHeadDeleted { + return nil + } + if try > 0 || replay { + if err := c.checkVolumeFree(ctx, vol, inUse); err != nil { + return err + } + } + next := storage.ChunkHead{Epoch: h.Epoch, RemoteLSN: h.RemoteLSN, Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadDeleted} + _, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: h.Epoch}, next) + if errors.Is(err, storage.ErrChunkHeadPrecondition) { + continue + } + if err != nil { + return catErr(CodeOutcomeUnknown, true, err, "tombstone HEAD of %s: outcome unknown; rerun the delete", vol) + } + return nil + } + return remoteErr(nil, "HEAD of %s kept changing", vol) +} + +// markVolumeDeleted marks vol's VOLUME entry deleted, conditioned on it not +// being marked yet. +func (c *Catalog) markVolumeDeleted(ctx context.Context, vol, root string) error { + e, err := c.f.LookupEntry(ctx, root, volumeName) + if err != nil { + return remoteErr(err, "read VOLUME of %s", vol) + } + if string(e.Extended[extVolState]) == VolumeDeleted { + return nil + } + next := proto.Clone(e).(*filerpb.Entry) + if next.Extended == nil { + next.Extended = map[string][]byte{} + } + next.Extended[extVolState] = []byte(VolumeDeleted) + next.Extended[extVolDeletedNs] = []byte(strconv.FormatInt(c.now().UnixNano(), 10)) + err = c.f.UpdateEntry(ctx, root, next, map[string][]byte{extVolState: nil}) + if errors.Is(err, ErrPrecondition) { + return nil // marked by a concurrent delete + } + if err != nil { + return remoteErr(err, "mark VOLUME of %s deleted", vol) + } + return nil +} + +// refuseDeleted is volume_deleted for a deleted volume id. +func refuseDeleted(vol, what string) error { + return catErr(CodeVolumeDeleted, false, nil, "volume %s was deleted; %s (a deleted id is never reused)", vol, what) +} diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete_integration_test.go b/seaweed-block/core/frontend/chunkstore/volume_delete_integration_test.go new file mode 100644 index 0000000000..f835aeb6cb --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/volume_delete_integration_test.go @@ -0,0 +1,157 @@ +//go:build chunkstore_integration + +package chunkstore + +import ( + "bytes" + "context" + "fmt" + "path" + "sort" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// Volume delete against a real SeaweedFS (CHUNKSTORE_WEED), with a real GC +// (claude05's acceptance, 2026-11-16 02:39Z): fork w2 from S1, delete w2, +// then DeleteSnapshot S1 succeeds and GC reclaims exactly the chunks only +// w2 and S1 reach, while w1 (HEAD, S2) stays intact; deleting an attached +// volume is refused; a deleted id cannot be recreated. +func TestIntegration_DeleteVolumeThenGC(t *testing.T) { + c := startWeed(t) + ctx := context.Background() + const base = "/swblock/chunks" + geo := Geometry{NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 8} + full := int(geo.ChunkBlocks) * int(geo.BlockSize) + cl := c.client(t, base) + cat, err := NewCatalog(cl, base) + if err != nil { + t.Fatal(err) + } + for _, vol := range []string{"w1"} { + if _, err := cat.EnsureVolume(ctx, vol, geo); err != nil { + t.Fatal(err) + } + } + w1 := c.remote(t, path.Join(base, "w1")) + put := func(r *ChunkRemote, key string, b byte) storage.ChunkRef { + t.Helper() + data := bytes.Repeat([]byte{b}, full) + if err := r.Put(ctx, key, data); err != nil { + t.Fatal(err) + } + return ref(key, data) + } + publish := func(r *ChunkRemote, holder string, epoch uint64, chunks map[uint64]storage.ChunkRef) storage.ChunkHead { + t.Helper() + cur, err := r.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + next := storage.ChunkHead{Epoch: epoch, Holder: holder, RemoteLSN: cur.RemoteLSN + 1, Chunks: chunks, State: storage.ChunkHeadActive} + if next.Gen, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, next); err != nil { + t.Fatal(err) + } + return next + } + detach := func(r *ChunkRemote) { + t.Helper() + cur, err := r.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + next := cur + next.State, next.DetachedBy = storage.ChunkHeadDetached, &storage.ChunkDetachedBy{Holder: cur.Holder, Epoch: cur.Epoch, Gen: cur.Gen + 1} + if _, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, next); err != nil { + t.Fatal(err) + } + } + + // w1: S1 = {A, B}; then chunk 0 is rewritten: HEAD = S2 = {C, B}. + a, bb := put(w1, "chunks/e1/c0/a", 1), put(w1, "chunks/e1/c1/b", 2) + h1 := publish(w1, "h1", 1, map[uint64]storage.ChunkRef{0: a, 1: bb}) + if _, err := cat.CreateSnapshot(ctx, "w1", SnapshotRequest{Name: "S1", RequestID: "r1"}, h1); err != nil { + t.Fatal(err) + } + cc := put(w1, "chunks/e1/c0/c", 3) + h2 := publish(w1, "h1", 1, map[uint64]storage.ChunkRef{0: cc, 1: bb}) + if _, err := cat.CreateSnapshot(ctx, "w1", SnapshotRequest{Name: "S2", RequestID: "r2"}, h2); err != nil { + t.Fatal(err) + } + + // w2 = fork of S1, then it writes chunk 2 (D) of its own. + if _, err := cat.Fork(ctx, ForkRequest{Source: "w1", Snapshot: "S1", Target: "w2", RequestID: "f2"}); err != nil { + t.Fatalf("fork w2: %v", err) + } + w2 := c.remote(t, path.Join(base, "w2")) + fh, err := w2.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + d := put(w2, "chunks/e1/c2/d", 4) + chunks := map[uint64]storage.ChunkRef{2: d} + for k, v := range fh.Chunks { + chunks[k] = v + } + publish(w2, "h2", 1, chunks) + + // An attached volume is refused (w1 is held by h1; w2 by h2). + for _, vol := range []string{"w1", "w2"} { + if _, err := cat.DeleteVolume(ctx, vol, nil); CodeOf(err) != CodeVolumeInUse { + t.Fatalf("delete of attached %s: %v; want volume_in_use", vol, err) + } + } + detach(w2) + res, err := cat.DeleteVolume(ctx, "w2", nil) + if err != nil || res.Replayed { + t.Fatalf("delete w2: %+v %v", res, err) + } + if _, err := cat.EnsureVolume(ctx, "w2", geo); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("recreate w2: %v; want volume_deleted", err) + } + if _, err := cat.Fork(ctx, ForkRequest{Source: "w1", Snapshot: "S2", Target: "w2", RequestID: "again"}); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("fork to deleted w2: %v; want volume_deleted", err) + } + if _, err := cat.DeleteSnapshot(ctx, "w1", "S1"); err != nil { + t.Fatalf("DeleteSnapshot S1 after w2 was deleted: %v", err) + } + + // GC: two marks past grace reclaim exactly A (only S1 and w2 reached + // it) and D (only w2); B and C (w1's HEAD and S2) stay. + grace := 2 * DefaultOpDeadline + at := time.Now().Add(3 * grace) + g, err := NewCollector(cat, cl, GCConfig{Grace: grace, IntentTTL: time.Hour, Now: func() time.Time { return at }, + IssuedEpoch: func(context.Context, string) (uint64, error) { return 1, nil }}) + if err != nil { + t.Fatal(err) + } + if _, err := g.Run(ctx); err != nil { + t.Fatalf("GC mark 1: %v", err) + } + at = at.Add(grace + time.Minute) + gr, err := g.Run(ctx) + if err != nil { + t.Fatalf("GC mark 2: %v", err) + } + var got []string + for _, o := range gr.WouldDelete { + got = append(got, o.Volume+":"+o.Key) + } + sort.Strings(got) + if fmt.Sprint(got) != "[w1:chunks/e1/c0/a w2:chunks/e1/c2/d]" || gr.Reclaimed != 2 { + t.Fatalf("GC reclaimed %v (%d); want exactly w1's A and w2's D", got, gr.Reclaimed) + } + for _, kept := range []string{bb.Key, cc.Key} { + if _, err := w1.Get(ctx, kept); err != nil { + t.Fatalf("w1 chunk %s after GC: %v; want intact", kept, err) + } + } + if _, err := w1.Get(ctx, a.Key); err == nil { + t.Fatalf("w1 chunk %s still readable after GC reclaimed it", a.Key) + } + if s, err := cat.readSnap(ctx, "w1", "S2"); err != nil || s.State != SnapActive { + t.Fatalf("S2 after GC: %+v %v", s, err) + } +} diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go new file mode 100644 index 0000000000..e4ffac6a97 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go @@ -0,0 +1,208 @@ +package chunkstore + +import ( + "context" + "errors" + "path" + "strings" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// Volume delete (claude05's item, 2026-11-16 02:39Z). + +// detachHead publishes vol's HEAD as a clean detach by its holder (what a +// volume server's Detach writes). +func detachHead(t *testing.T, f *fakeFiler, b *fakeBlobs, vol string) { + t.Helper() + ctx := context.Background() + r, err := NewChunkRemote(f, b, path.Join(catBase, vol)) + if err != nil { + t.Fatal(err) + } + h, err := r.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + next := h + next.State = storage.ChunkHeadDetached + next.DetachedBy = &storage.ChunkDetachedBy{Holder: h.Holder, Epoch: h.Epoch, Gen: h.Gen + 1} + if _, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: h.Epoch}, next); err != nil { + t.Fatal(err) + } +} + +func deleteFixture(t *testing.T) (*fakeFiler, *fakeBlobs, *Catalog, storage.ChunkHead) { + t.Helper() + f, b, c, h := catalogFixture(t) // v1 HEAD held by h1 (attached) + ctx := context.Background() + for _, vol := range []string{"v1", "w2", "w3"} { + if err := f.CreateEntry(ctx, catBase, &filerpb.Entry{Name: vol, IsDirectory: true}, true); err != nil { + t.Fatal(err) + } + } + for _, name := range []string{"s1", "s2"} { + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: name, RequestID: "r-" + name}, h); err != nil { + t.Fatal(err) + } + } + return f, b, c, h +} + +// An attached volume (HEAD held), or one the blockmaster reports in use, +// is refused with volume_in_use and nothing is written. +func TestCatalog_DeleteVolumeRefusesAVolumeInUse(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + before := len(f.allWritten()) + if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { + t.Fatalf("delete of an attached volume: %v; want volume_in_use", err) + } + detachHead(t, f, b, "v1") + before = len(f.allWritten()) + busy := func(context.Context, string) (bool, string, error) { return true, "assigned to r1", nil } + _, err := c.DeleteVolume(ctx, "v1", busy) + var ce *CatalogError + if !errors.As(err, &ce) || ce.Code != CodeVolumeInUse || ce.Retryable || !strings.Contains(ce.Detail(), "assigned to r1") { + t.Fatalf("delete of an assigned volume: %v; want volume_in_use naming the reason", err) + } + if got := len(f.allWritten()); got != before { + t.Fatalf("a refused delete wrote %d entries", got-before) + } + if v, _, _ := c.ReadVolume(ctx, "v1"); v.State != "" { + t.Fatalf("refused delete changed VOLUME state to %q", v.State) + } +} + +// A volume with a snapshot a live fork claims is refused before anything +// is written (snapshot_claimed). +func TestCatalog_DeleteVolumeRefusesAClaimedSnapshot(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + holdFirst(f, catBase+"/w3/HEAD") + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { + t.Fatalf("fork w3: %v", err) + } + before := len(f.allWritten()) + if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeSnapshotClaimed { + t.Fatalf("delete with a claimed snapshot: %v; want snapshot_claimed", err) + } + if got := len(f.allWritten()); got != before { + t.Fatalf("a refused delete wrote %d entries", got-before) + } +} + +// The acceptance flow on the fake: fork w2 from s1, delete w2, then s1 can +// be deleted; the deleted id is never attached, recreated or forked to +// again; an incomplete fork w3 is deleted too and its claim released; a +// rerun replays. +func TestCatalog_DeleteVolumeTombstonesAndReleases(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "f2"}); err != nil { + t.Fatalf("fork w2: %v", err) + } + if _, err := c.CreateSnapshot(ctx, "w2", SnapshotRequest{Name: "w2snap", RequestID: "rw"}, mustHead(t, c, "w2")); err != nil { + t.Fatal(err) + } + res, err := c.DeleteVolume(ctx, "w2", nil) + if err != nil || res.Replayed || strings.Join(res.SnapshotsDeleted, ",") != "w2snap" { + t.Fatalf("delete w2: %+v %v", res, err) + } + h, has, err := c.ReadHead(ctx, "w2") + if err != nil || !has || h.State != storage.ChunkHeadDeleted || len(h.Chunks) != 0 { + t.Fatalf("w2 HEAD: %+v has=%t %v; want a deleted tombstone with no chunks", h, has, err) + } + if v, _, _ := c.ReadVolume(ctx, "w2"); v.State != VolumeDeleted { + t.Fatalf("w2 VOLUME state %q", v.State) + } + if _, ok, _ := c.resolveSnap(ctx, "w2", "w2snap"); ok { + t.Fatal("w2's snapshot name is still held") + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { + t.Fatalf("delete s1 after its fork was deleted: %v", err) + } + // The id is never reused. + if _, err := c.EnsureVolume(ctx, "w2", catGeo); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("attach/create of deleted w2: %v; want volume_deleted", err) + } + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w2", RequestID: "again"}); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("fork to deleted w2: %v; want volume_deleted", err) + } + // A rerun replays. + if res, err := c.DeleteVolume(ctx, "w2", nil); err != nil || !res.Replayed { + t.Fatalf("rerun: %+v %v; want a replay", res, err) + } + + // An incomplete fork (VOLUME, no HEAD) is deleted and its claim + // released, so its parent snapshot can be deleted. + holdFirst(f, catBase+"/w3/HEAD") + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { + t.Fatalf("fork w3: %v", err) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); CodeOf(err) != CodeSnapshotClaimed { + t.Fatalf("delete s2 under the incomplete fork: %v; want snapshot_claimed", err) + } + res, err = c.DeleteVolume(ctx, "w3", nil) + if err != nil || !res.ClaimReleased { + t.Fatalf("delete w3: %+v %v; want its claim released", res, err) + } + if got := claimsOf(t, c, "s2"); len(got) != 0 { + t.Fatalf("s2 claims after w3 was deleted: %v", got) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); err != nil { + t.Fatalf("delete s2 after w3 was deleted: %v", err) + } + _ = b +} + +// A volume server that attaches between the delete's check and its HEAD +// tombstone makes the tombstone's condition fail; the delete re-checks and +// refuses (volume_in_use), and VOLUME is untouched. +func TestCatalog_DeleteVolumeLosesToAConcurrentAttach(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + headPath := path.Join(catBase, "v1", headName) + lookups := 0 + f.afterLookup = func(p string) { + if p != headPath { + return + } + lookups++ + if lookups != 2 { // 1: the delete's check; 2: the tombstone's read + return + } + cur, _ := decodeHead(p, f.entries[p]) + att := cur + att.Gen, att.Epoch, att.Holder, att.State, att.DetachedBy = cur.Gen+1, cur.Epoch+1, "h2", storage.ChunkHeadActive, nil + e, err := headEntry(att) + if err != nil { + t.Fatal(err) + } + f.entries[p] = e // h2 attaches (takeover CAS) + } + if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { + t.Fatalf("delete racing an attach: %v; want volume_in_use", err) + } + f.afterLookup = nil + h, _, _ := c.ReadHead(ctx, "v1") + if h.Holder != "h2" || h.State == storage.ChunkHeadDeleted { + t.Fatalf("HEAD after the lost delete: %+v; want h2's", h) + } + if v, _, _ := c.ReadVolume(ctx, "v1"); v.State != "" { + t.Fatalf("VOLUME state %q after the refused delete", v.State) + } +} + +func mustHead(t *testing.T, c *Catalog, vol string) storage.ChunkHead { + t.Helper() + h, has, err := c.ReadHead(context.Background(), vol) + if err != nil || !has { + t.Fatalf("HEAD of %s: has=%t %v", vol, has, err) + } + return h +} diff --git a/seaweed-block/core/storage/chunk_public.go b/seaweed-block/core/storage/chunk_public.go index 7c6aa02ac4..2a06bf0323 100644 --- a/seaweed-block/core/storage/chunk_public.go +++ b/seaweed-block/core/storage/chunk_public.go @@ -27,6 +27,7 @@ const ( ChunkHeadActive = chunkHeadActive ChunkHeadDetached = chunkHeadDetached ChunkHeadAborted = chunkHeadAborted + ChunkHeadDeleted = chunkHeadDeleted ) // NewChunkIntentID returns a fresh intent id "-" for a remote diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index 2a11147c43..70d3baf2ce 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -203,6 +203,10 @@ type chunkDetachedBy struct { // 2026-11-15 17:30Z). Such a volume never attaches. const chunkHeadAborted = "aborted" +// chunkHeadDeleted marks a deleted volume's HEAD tombstone (no chunks, so +// nothing it held stays a GC root). Such a volume never attaches again. +const chunkHeadDeleted = "deleted" + func chunkHeadIsDetached(h chunkHead) bool { return h.State == chunkHeadDetached } // chunkRemote is the remote store. Keys are non-empty valid UTF-8 strings From 626c7de1a250e1615bd0d689b4c596131a719b72 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 18:49:18 -0800 Subject: [PATCH 02/16] chunkstore: volume delete - Catalog.DeleteVolume refuses a volume in use (an active HEAD with a holder, or the caller's InUseCheck: the CLI asks the blockmaster whether it is assigned or served) with volume_in_use, and a volume whose snapshot a live fork claims with snapshot_claimed, before any write. - Then: HEAD becomes a tombstone (state deleted, no chunks) by a conditional write on the HEAD read, so an attach in between wins; VOLUME is marked deleted; every snapshot goes through markDeleting (the one mark path) and its name is freed; a fork's claim on its parent is released. GC reclaims (the tombstone holds no roots; the snapshots drop out after grace). A rerun finishes a partial delete. - A deleted id is never reused: EnsureVolume (attach, create) refuses a deleted VOLUME or HEAD with volume_deleted, and so does Fork for a deleted target or source (the source checked after the claim). - storage: HEAD state "deleted"; the HEAD decoder accepts it only with no chunks, holder or detachedBy. - CLI: sw-block ops chunk volume-delete --chunk-filer --master; gc and volume-delete share masterEvidence. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/frontend/chunkstore/volume_delete.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go index d46ac4682c..527ba421fe 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -61,9 +61,6 @@ type VolumeDeleteResult struct { // DeleteVolume deletes vol (see the header). inUse may be nil. func (c *Catalog) DeleteVolume(ctx context.Context, vol string, inUse InUseCheck) (VolumeDeleteResult, error) { res := VolumeDeleteResult{VolumeID: vol, SnapshotsDeleted: []string{}} - if red := true; red { // RED: deletes nothing - return res, nil - } root, err := c.volRoot(vol) if err != nil { return res, err From 5b82b324d69cd9e77551bb00f9390fff62ba813a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 19:31:08 -0800 Subject: [PATCH 03/16] volume delete: RED controls for one linearization point Review of 626c7de (codex01). One control per schedule, each failing against a stub that restores the reviewed behaviour: - P1 1: a holder that attaches before the HEAD mark's first read is deleted (TestCatalog_DeleteVolumeRefusesAnAttachBeforeTheMark). - P1 2: an attach that passed EnsureVolume revives a deleting/deleted HEAD through CASHead (TestCatalog_DeletedHeadCannotBeRevivedByAClaim). - P1 3: after the master's delete mark, an existing placement still leads to an assignment, the reconciler places, the id can be created and bound again (TestMarkVolumeDeleting_StopsLaterAssignment...). - P2: a fork claim after the check is refused only after irreversible writes (TestCatalog_DeleteVolumeGivesBackOnALiveClaim); a fork after the mark installs (TestCatalog_ForkAfterTheDeleteMarkRefuses); a held snapshot publication and a snapshot started after the mark escape the delete (TestCatalog_DeleteVolumeCatchesInFlightSnapshots); a failed claim removal is reported released, and the CLI drops partial effects (TestCatalog_DeleteVolumeTombstonesAndReleases, TestOpsChunk_VolumeDelete). Co-Authored-By: Claude Opus 5.5 --- .../cmd/sw-block/chunk_volume_delete.go | 66 +- .../cmd/sw-block/chunk_volume_delete_test.go | 17 +- .../core/frontend/chunkstore/catalog.go | 62 +- .../core/frontend/chunkstore/chunk_remote.go | 8 + .../core/frontend/chunkstore/volume_delete.go | 450 ++++++++++---- .../frontend/chunkstore/volume_delete_test.go | 395 ++++++++---- .../core/host/master/launcher_plan.go | 2 +- seaweed-block/core/host/master/services.go | 44 ++ .../core/host/master/volume_deleting_test.go | 79 +++ .../core/host/master/workspace_binding.go | 4 +- .../core/host/master/workspace_service.go | 3 + seaweed-block/core/lifecycle/reconciler.go | 3 + seaweed-block/core/lifecycle/store.go | 31 + seaweed-block/core/rpc/control/control.pb.go | 562 +++++++++++------- .../core/rpc/control/control_grpc.pb.go | 53 +- seaweed-block/core/rpc/proto/control.proto | 17 + seaweed-block/core/storage/chunk_public.go | 2 + seaweed-block/core/storage/chunk_seam.go | 12 +- 18 files changed, 1324 insertions(+), 486 deletions(-) create mode 100644 seaweed-block/core/host/master/volume_deleting_test.go diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete.go b/seaweed-block/cmd/sw-block/chunk_volume_delete.go index afe4fca07d..fec592f645 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -2,19 +2,25 @@ package main import ( "context" + "encoding/json" + "errors" "fmt" "io" "time" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" "github.com/seaweedfs/seaweed-block/core/ops" "github.com/seaweedfs/seaweed-block/core/rpc/control" ) // chunkVolumeDelete: sw-block ops chunk volume-delete --chunk-filer -// host:port --master host:port deletes a chunk volume (Catalog.DeleteVolume): -// refused while it is attached, assigned or served (volume_in_use) or while -// a live fork claims one of its snapshots (snapshot_claimed); GC reclaims. +// host:port --master host:port deletes a chunk volume (Catalog.DeleteVolume) +// after the blockmaster admits it (MarkVolumeDeleting: refused while the +// volume has live or pending authority; afterwards nothing assigns, places +// or binds it again). A failure prints what was done with the error. func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { fs := chunkFlagSet("volume-delete", stderr) var ( @@ -24,7 +30,7 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { fs.StringVar(&volumeID, "volume", "", "volume id (or the first argument)") fs.StringVar(&filer, "chunk-filer", "", "SeaweedFS filer gRPC address host:port") fs.StringVar(&base, "chunk-path", defaultChunkPathCLI, "filer directory holding one directory per volume") - fs.StringVar(&master, "master", "", "authoritative blockmaster gRPC address (refuses an assigned or served volume)") + fs.StringVar(&master, "master", "", "authoritative blockmaster gRPC address (admits the delete)") fs.DurationVar(&timeout, "timeout", time.Minute, "bound for this delete") if err := fs.Parse(args); err != nil { return chunkFail(chunkName(fs), stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, err.Error(), false) @@ -42,31 +48,45 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { return exit } defer closeFn() - evidence, closeMaster, err := masterEvidence(master) + conn, err := grpc.NewClient(master, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return chunkResult("volume-delete", nil, err, stdout, stderr) } - defer closeMaster() + defer conn.Close() + lifecycle := control.NewLifecycleServiceClient(conn) + admit := func(ctx context.Context, vol string) error { + _, err := lifecycle.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: vol}) + return err + } ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - res, err := cat.DeleteVolume(ctx, volumeID, masterInUse(evidence)) - return chunkResult("volume-delete", res, err, stdout, stderr) + 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) } -// masterInUse: the blockmaster has the volume assigned, or a frontend -// serves it. -func masterInUse(evidence control.EvidenceServiceClient) chunkstore.InUseCheck { - return func(ctx context.Context, vol string) (bool, string, error) { - st, err := evidence.QueryVolumeStatus(ctx, &control.StatusRequest{VolumeId: vol}) - if err != nil { - return false, "", err - } - if st.GetAssigned() { - return true, fmt.Sprintf("the blockmaster has it assigned (replica %q, epoch %d)", st.GetReplicaId(), st.GetEpoch()), nil - } - if n := len(st.GetFrontends()); n > 0 { - return true, fmt.Sprintf("%d frontend(s) serve it", n), nil - } - return false, "", nil +// volumeDeletePartial prints what a failed delete did, with the error, and +// fails. +func volumeDeletePartial(res chunkstore.VolumeDeleteResult, err error, stdout, stderr io.Writer) int { + body := chunkErrBody{Code: codeInternalCLI, Message: err.Error()} + var ce *chunkstore.CatalogError + if errors.As(err, &ce) { + body = chunkErrBody{Code: ce.Code, Message: ce.Detail(), Retryable: ce.Retryable} } + fmt.Fprintf(stderr, "sw-block ops chunk volume-delete: %s: %s (headMarked=%t completed=%t uncertain=%t)\n", body.Code, body.Message, res.HeadMarked, res.Completed, res.Uncertain) + out, mErr := json.Marshal(struct { + chunkstore.VolumeDeleteResult + Error *chunkErrBody `json:"error"` + }{res, &body}) + if mErr == nil { + if wErr := writeAll(stdout, append(out, '\n')); wErr != nil { + fmt.Fprintf(stderr, "sw-block ops chunk volume-delete: write the result: %v\n", wErr) + } + } + return chunkExitFailed } diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go index 3f43657c5a..9ffc0cca1e 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go @@ -54,7 +54,9 @@ func TestOpsChunk_VolumeDelete(t *testing.T) { } } - h, err := master.New(gcTestMasterConfig(t)) + cfg := gcTestMasterConfig(t) + cfg.LifecycleStoreDir = t.TempDir() // MarkVolumeDeleting admits the delete + h, err := master.New(cfg) if err != nil { t.Fatal(err) } @@ -64,12 +66,19 @@ func TestOpsChunk_VolumeDelete(t *testing.T) { defer cancel() _ = h.Close(ctx) }) - if code, out, _ := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v2"); code == 0 || !strings.Contains(out, chunkstore.CodeVolumeInUse) { - t.Fatalf("delete of attached v2: %d %q; want volume_in_use", code, out) + // v2 is admitted by the master (it has no authority) but held in the + // catalog: refused, and the partial result says what was done. + code, out, _ := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v2") + var partial struct { + chunkstore.VolumeDeleteResult + Error *chunkErrBody `json:"error"` + } + if code == 0 || json.Unmarshal([]byte(out), &partial) != nil || partial.Error == nil || partial.Error.Code != chunkstore.CodeVolumeInUse || !partial.Admitted || partial.HeadMarked || partial.Completed { + t.Fatalf("delete of attached v2: %d %q; want volume_in_use with the partial result", code, out) } code, out, errs := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v1") var res chunkstore.VolumeDeleteResult - if code != 0 || json.Unmarshal([]byte(out), &res) != nil || res.VolumeID != "v1" || res.Replayed { + if code != 0 || json.Unmarshal([]byte(out), &res) != nil || res.VolumeID != "v1" || res.Replayed || !res.Completed { t.Fatalf("delete v1: %d %q %q", code, out, errs) } if _, err := cat.EnsureVolume(ctx, "v1", geo); chunkstore.CodeOf(err) != chunkstore.CodeVolumeDeleted { diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index f88f2918aa..ec4ed6aff7 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -505,8 +505,8 @@ func (c *Catalog) EnsureVolume(ctx context.Context, vol string, g Geometry) (Vol } if h, has, err := c.ReadHead(ctx, vol); err != nil { return VolumeInfo{}, err - } else if has && h.State == storage.ChunkHeadDeleted { - return VolumeInfo{}, refuseDeleted(vol, "its HEAD is a tombstone; it cannot be attached") + } else if has && headDeletingOrDeleted(h) { + return VolumeInfo{}, refuseDeleted(vol, "it cannot be attached") } if v.Geometry != g { return VolumeInfo{}, catErr(CodeGeometryMismatch, false, nil, "volume %s: VOLUME geometry %+v, this host serves %+v", vol, v.Geometry, g) @@ -847,6 +847,15 @@ func (c *Catalog) CreateSnapshot(ctx context.Context, vol string, req SnapshotRe if err != nil { return SnapshotInfo{}, err } + // A volume delete marks HEAD deleting before it lists the names: if + // this name was taken after that listing, this read sees the mark, and + // 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 + c.abandonUnpublished(ctx, vol, root, req.Name, attempt) + return SnapshotInfo{}, refuseDeleted(vol, "it cannot be snapshotted") + } headEnt, err := headEntry(head) if err != nil { @@ -1190,12 +1199,13 @@ func (c *Catalog) Fork(ctx context.Context, req ForkRequest) (ForkResult, error) if err != nil { return ForkResult{}, err } - // Read after the claim: a delete of the source marks VOLUME before it - // marks the snapshots, so a fork that sees it live is protected by its - // claim, and one that sees it deleted gives the claim back. - if src, ok, err := c.ReadVolume(ctx, req.Source); err != nil { + // Read after the claim: a delete of the source marks its HEAD deleting + // before it reads claims, so either it sees this claim (and gives its + // mark back) or this read sees the mark and the fork gives the claim + // back before installing anything. + if gone, err := c.volumeGone(ctx, req.Source); err != nil { return ForkResult{}, err - } else if ok && src.State == VolumeDeleted { + } else if gone && false { // RED: no post-claim check c.dropForkClaim(ctx, req, snap.attempt) return ForkResult{}, refuseDeleted(req.Source, "its snapshots cannot be forked") } @@ -1285,7 +1295,7 @@ func (c *Catalog) Fork(ctx context.Context, req ForkRequest) (ForkResult, error) if err != nil { return ForkResult{}, err } - if h.State == storage.ChunkHeadAborted { + if h.State == storage.ChunkHeadAborted || headDeletingOrDeleted(h) { c.dropIntent(ctx, dstRoot, id) // the tombstone is permanent: this create never lands c.dropForkClaim(ctx, req, snap.attempt) // and this fork never needs the parent again return ForkResult{}, catErr(CodeTargetExists, false, nil, "fork %s lost to a sweep: its HEAD is an aborted tombstone; fork to a new volume id", req.Target) @@ -1345,16 +1355,37 @@ func (c *Catalog) claimForkParent(ctx context.Context, req ForkRequest) (Snapsho // fork no longer needs it (best effort: retention treats a claim whose // target has a HEAD as dead anyway). func (c *Catalog) dropForkClaim(ctx context.Context, req ForkRequest, attempt string) { + _, _ = c.removeForkClaim(ctx, req, attempt) +} + +// abandonUnpublished gives up an attempt that was never published: an +// aborted tombstone at its path (so a late create cannot land), then the +// name freed while it names that attempt (best effort; a delete's own pass +// does the same). +func (c *Catalog) abandonUnpublished(ctx context.Context, vol, root, name, attempt string) { + if tomb, err := c.abortedSnapEntry(vol, name, attempt); err == nil { + _ = c.f.CreateEntry(ctx, path.Join(root, snapsDir, name), tomb, true) + } + _, _, _ = c.freeName(ctx, root, name, attempt) +} + +// removeForkClaim removes fork req's claim from its parent attempt and +// reports whether this call confirmed its removal (false with no error: +// the claim was not there). +func (c *Catalog) removeForkClaim(ctx context.Context, req ForkRequest, attempt string) (bool, error) { root, err := c.volRoot(req.Source) if err != nil || attempt == "" { - return + return false, err } token := forkClaim(req.Target, req.RequestID) dir := path.Join(root, snapsDir, req.Snapshot) for try := 0; try < 3; try++ { e, err := c.f.LookupEntry(ctx, dir, attempt) + if errors.Is(err, ErrNotFound) { + return false, nil + } if err != nil { - return + return false, remoteErr(err, "read %s/%s attempt %s", req.Source, req.Snapshot, attempt) } claims := decodeClaims(e) kept := claims[:0:0] @@ -1364,7 +1395,7 @@ func (c *Catalog) dropForkClaim(ctx context.Context, req ForkRequest, attempt st } } if len(kept) == len(claims) { - return + return false, nil } c.hook(hookClaimDrop, req.Snapshot) // Conditioned on the state read too (review of f42e723): a @@ -1373,10 +1404,15 @@ func (c *Catalog) dropForkClaim(ctx context.Context, req ForkRequest, attempt st raw := e.Extended[extSnapClaims] next := proto.Clone(e).(*filerpb.Entry) setClaims(next, kept) - if err := c.f.UpdateEntry(ctx, dir, next, map[string][]byte{extSnapState: e.Extended[extSnapState], extSnapClaims: raw}); !errors.Is(err, ErrPrecondition) { - return + err = c.f.UpdateEntry(ctx, dir, next, map[string][]byte{extSnapState: e.Extended[extSnapState], extSnapClaims: raw}) + if err == nil { + return true, nil + } + if !errors.Is(err, ErrPrecondition) { + return false, remoteErr(err, "remove the claim of %s on %s/%s", req.Target, req.Source, req.Snapshot) } } + return false, remoteErr(nil, "claim of %s on %s/%s kept changing", req.Target, req.Source, req.Snapshot) } // AbortFork settles a dead fork for a GC sweep (W5 ruling, 2026-11-15 diff --git a/seaweed-block/core/frontend/chunkstore/chunk_remote.go b/seaweed-block/core/frontend/chunkstore/chunk_remote.go index c522b58f30..f427900295 100644 --- a/seaweed-block/core/frontend/chunkstore/chunk_remote.go +++ b/seaweed-block/core/frontend/chunkstore/chunk_remote.go @@ -384,6 +384,11 @@ 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 + // 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) + } if current.Gen != expected.Gen || current.Epoch != expected.Epoch || next.RemoteLSN < current.RemoteLSN { return 0, storage.ErrChunkHeadPrecondition } @@ -497,6 +502,9 @@ func decodeHeadDoc(p string, content []byte) (storage.ChunkHead, error) { if doc.DetachedBy != nil || len(doc.Chunks) != 0 { return fail("an aborted HEAD with content") } + case storage.ChunkHeadDeleting: + // A delete's linearization mark over the HEAD it read: content and + // any detach record kept (a revert restores them). case storage.ChunkHeadDeleted: // A deleted volume's tombstone (no chunks, no holder). if doc.DetachedBy != nil || len(doc.Chunks) != 0 || doc.Holder != "" { diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go index 527ba421fe..17180ec257 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -3,7 +3,7 @@ package chunkstore import ( "context" "errors" - "sort" + "path" "strconv" "google.golang.org/protobuf/proto" @@ -12,28 +12,33 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" ) -// Volume delete (claude05's item, 2026-11-16 02:39Z). +// Volume delete (claude05's item, 2026-11-16 02:39Z; one linearization +// point per codex01's review of 7c43367). // -// DeleteVolume refuses while the volume is in use: its HEAD is held (an -// active HEAD with a holder: a volume server attached it), or the caller's -// InUse check says so (the blockmaster has it assigned or served). It also -// refuses, before writing anything, while a live fork claims one of its -// snapshots (snapshot_claimed, the claim rule of retention.go). +// (a) Admission: the caller's Admission (the CLI's is the blockmaster's +// MarkVolumeDeleting: refused while the volume has live or pending +// authority; once it passes, no new assignment, placement or binding +// is admitted and the id is never created again). +// (b) The linearization point: one conditional write of HEAD from the +// HEAD read (active or detached, NOT held: an active HEAD that names a +// holder belongs to an attached server) to state deleting, chunks +// kept. ChunkRemote.CASHead refuses to move a deleting or deleted +// HEAD, so no attach, claim or restore can revive it; EnsureVolume +// refuses it; Fork and CreateSnapshot check HEAD again after taking +// their claim or name and back out when it is deleting. +// (c) Claims are read after (b): a live fork claim reverts HEAD to its +// previous state (nothing irreversible was done) and refuses +// (snapshot_claimed). A fork claiming later sees the deleting HEAD +// and gives its claim back. +// (d) Only then the irreversible steps: every snapshot name, published or +// not (an unpublished attempt gets an aborted tombstone so its late +// publish cannot land), is marked through markDeleting (the one mark +// path) and freed; the volume's own fork claim is released. +// (e) Finally HEAD becomes deleted (no chunks: nothing it held stays a GC +// root) and VOLUME is marked deleted. GC reclaims. // -// Otherwise, in this order: -// 1. HEAD becomes a tombstone (state deleted, no chunks), by a conditional -// write on the HEAD it read (or an exclusive create when there is no -// HEAD yet): a volume server that attached meanwhile makes it fail and -// the delete decides again. Its chunks stop being GC roots. -// 2. VOLUME is marked deleted (an extended attribute; the document is -// kept). The id is never reused: EnsureVolume (attach, create) and Fork -// refuse a deleted volume, and its VOLUME and HEAD entries stay. -// 3. Every snapshot is marked deleting through markDeleting (the one mark -// path) and its name freed; GC stops counting it after its grace. -// 4. A fork's claim on its parent snapshot is released. -// -// Reclamation is GC's. A rerun after a partial delete (e.g. a fork claimed -// a snapshot between the check and step 3) resumes from what is there. +// A call that fails reports what it did (VolumeDeleteResult) with the +// error; a rerun resumes from the state it finds. const ( CodeVolumeInUse = "volume_in_use" @@ -44,23 +49,36 @@ const ( extVolState = "swb.volume.state" extVolDeletedNs = "swb.volume.deleted_ns" + + // Test seams (retainHook stages) in a DeleteVolume. + hookHeadMarked = "head-marked" // after (b) + hookClaimsChecked = "claims-checked" // after (c) ) -// InUseCheck reports whether a volume is in use outside the catalog (e.g. -// assigned or served by the blockmaster), with a reason for the error. -type InUseCheck func(ctx context.Context, vol string) (inUse bool, why string, err error) +// Admission admits a volume delete before anything is written; its error +// refuses the delete (volume_in_use). +type Admission func(ctx context.Context, vol string) error -// VolumeDeleteResult is what DeleteVolume did. +// VolumeDeleteResult is what DeleteVolume did, also on failure. type VolumeDeleteResult struct { VolumeID string `json:"volumeID"` - Replayed bool `json:"replayed"` // the volume was already deleted; this call finished what was left + Replayed bool `json:"replayed"` // it was already deleted + Admitted bool `json:"admitted"` // (a) passed + HeadMarked bool `json:"headMarked"` // HEAD is deleting or deleted + Reverted bool `json:"reverted"` // (c) gave the HEAD mark back SnapshotsDeleted []string `json:"snapshotsDeleted"` - ClaimReleased bool `json:"claimReleased"` // its fork claim on the parent snapshot was removed + AttemptsAborted []string `json:"attemptsAborted"` // unpublished attempts tombstoned + ClaimReleased bool `json:"claimReleased"` // its fork claim was confirmed removed + Completed bool `json:"completed"` // HEAD and VOLUME are deleted + // Uncertain is set when the failing call was a write whose outcome is + // unknown; a rerun settles it. + Uncertain bool `json:"uncertain"` } -// DeleteVolume deletes vol (see the header). inUse may be nil. -func (c *Catalog) DeleteVolume(ctx context.Context, vol string, inUse InUseCheck) (VolumeDeleteResult, error) { - res := VolumeDeleteResult{VolumeID: vol, SnapshotsDeleted: []string{}} +// DeleteVolume deletes vol (see the header). admit may be nil (a catalog- +// only delete, e.g. in tests): (b) still refuses a held HEAD. +func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) (VolumeDeleteResult, error) { + res := VolumeDeleteResult{VolumeID: vol, SnapshotsDeleted: []string{}, AttemptsAborted: []string{}} root, err := c.volRoot(vol) if err != nil { return res, err @@ -72,132 +90,315 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, inUse InUseCheck if !ok { return res, catErr(CodeNotChunkVolume, false, nil, "volume %s has no VOLUME entry", vol) } - res.Replayed = v.State == VolumeDeleted - snaps, err := c.listSnapshots(ctx, vol, true) + h, _, err := c.ReadHead(ctx, vol) if err != nil { return res, err } - if !res.Replayed { - if err := c.checkVolumeFree(ctx, vol, inUse); err != nil { - return res, err - } - // No mutation while a live fork claims a snapshot. - for _, s := range snaps { - if s.State != SnapActive { - continue - } - ref, ok, err := c.resolveSnap(ctx, vol, s.Name) - if err != nil { - return res, err - } - if !ok || ref.entry == nil { - continue - } - live, err := c.liveClaims(ctx, vol, s.Name, decodeClaims(ref.entry)) - if err != nil { - return res, err - } - if len(live) > 0 { - return res, claimedErr(vol, s.Name, live) - } + res.Replayed = v.State == VolumeDeleted && h.State == storage.ChunkHeadDeleted + marked := h.State == storage.ChunkHeadDeleting || h.State == storage.ChunkHeadDeleted + // (a) + if !marked && admit != nil { + if err := admit(ctx, vol); err != nil { + return res, catErr(CodeVolumeInUse, false, err, "volume %s: delete not admitted", vol) } } - if err := c.tombstoneHead(ctx, vol, root, inUse, res.Replayed); err != nil { - return res, err - } - if !res.Replayed { - if err := c.markVolumeDeleted(ctx, vol, root); err != nil { + res.Admitted = true + // (b) + if !marked { + u, err := c.markHeadDeleting(ctx, vol, root) + if err != nil { + res.Uncertain = u return res, err } } - sort.Slice(snaps, func(i, j int) bool { return snaps[i].Name < snaps[j].Name }) - for _, s := range snaps { - m, live, _, err := c.markDeleting(ctx, vol, s.Name, s.attempt) + res.HeadMarked = true + c.hook(hookHeadMarked, vol) + // (c) + if h.State != storage.ChunkHeadDeleted { + live, err := c.anyLiveClaim(ctx, vol) if err != nil { return res, err } - if m == markClaimed { - return res, claimedErr(vol, s.Name, live) + if red := true; red { // RED: claims are not read after the mark + live = nil } - if _, _, err := c.freeName(ctx, root, s.Name, s.attempt); err != nil { + if live != nil { + u, rerr := c.revertHeadDeleting(ctx, vol, root) + if rerr != nil { + res.Uncertain = u + return res, rerr + } + res.Reverted, res.HeadMarked = true, false + return res, live + } + } + c.hook(hookClaimsChecked, vol) + // (d) + names, err := c.listNames(ctx, root) + if err != nil { + return res, err + } + for _, name := range names { + gone, aborted, u, err := c.deleteNameForVolume(ctx, vol, root, name) + if err != nil { + res.Uncertain = u return res, err } - res.SnapshotsDeleted = append(res.SnapshotsDeleted, s.Name) + if aborted { + res.AttemptsAborted = append(res.AttemptsAborted, name) + } else if gone { + res.SnapshotsDeleted = append(res.SnapshotsDeleted, name) + } } if v.Fork != nil { req := ForkRequest{Source: v.Fork.Source, Snapshot: v.Fork.Snapshot, Target: vol, RequestID: v.Fork.RequestID} - if ref, ok, err := c.resolveSnap(ctx, req.Source, req.Snapshot); err == nil && ok && ref.entry != nil { - token := forkClaim(vol, v.Fork.RequestID) - for _, cl := range decodeClaims(ref.entry) { - if cl == token { - c.dropForkClaim(ctx, req, ref.rec.Attempt) - res.ClaimReleased = true - } + if ref, ok, err := c.resolveSnap(ctx, req.Source, req.Snapshot); err != nil { + 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 + res.Uncertain = true + return res, err } + res.ClaimReleased = removed || true // RED: reported whether or not it was removed } } + // (e) + if u, err := c.finishHeadDeleted(ctx, vol, root); err != nil { + res.Uncertain = u + return res, err + } + if err := c.markVolumeDeleted(ctx, vol, root); err != nil { + res.Uncertain = true + return res, err + } + res.Completed = true return res, nil } -// checkVolumeFree refuses a volume in use: a held HEAD, or inUse says so. -func (c *Catalog) checkVolumeFree(ctx context.Context, vol string, inUse InUseCheck) error { - h, has, err := c.ReadHead(ctx, vol) - if err != nil { - return err - } - if has && headHeld(h) { - return catErr(CodeVolumeInUse, false, nil, "volume %s is attached: HEAD is held by %q at epoch %d; detach it first", vol, h.Holder, h.Epoch) - } - if inUse != nil { - busy, why, err := inUse(ctx, vol) - if err != nil { - return remoteErr(err, "check whether volume %s is in use", vol) - } - if busy { - return catErr(CodeVolumeInUse, false, nil, "volume %s is in use: %s", vol, why) - } - } - return nil -} - // headHeld: an active HEAD that names a holder belongs to an attached // volume server (a clean detach publishes state detached). func headHeld(h storage.ChunkHead) bool { return (h.State == "" || h.State == storage.ChunkHeadActive) && h.Holder != "" } -// tombstoneHead replaces vol's HEAD with a deleted tombstone, conditioned -// on the HEAD read; a lost condition re-reads and decides again (refusing -// if the volume was attached meanwhile). -func (c *Catalog) tombstoneHead(ctx context.Context, vol, root string, inUse InUseCheck, replay bool) error { - r, err := NewChunkRemote(c.f, nilBlobs{}, root) +// headDeletingOrDeleted reports a HEAD a delete has passed its +// linearization point on. +func headDeletingOrDeleted(h storage.ChunkHead) bool { + return h.State == storage.ChunkHeadDeleting || h.State == storage.ChunkHeadDeleted +} + +// writeHead writes next over the HEAD read as cur (an exclusive create when +// there was none), conditioned on cur's generation and epoch. It is the +// catalog's own HEAD write for the delete transitions, which CASHead +// refuses to anyone else. +func (c *Catalog) writeHead(ctx context.Context, root string, cur, next storage.ChunkHead) error { + next.Gen = cur.Gen + 1 + e, err := headEntry(next) if err != nil { return err } + if cur.Gen == 0 { + return c.f.CreateEntry(ctx, root, e, true) + } + return c.f.UpdateEntry(ctx, root, e, map[string][]byte{ + extGen: []byte(strconv.FormatUint(cur.Gen, 10)), + extEpoch: []byte(strconv.FormatUint(cur.Epoch, 10)), + }) +} + +func lostCondition(err error) bool { + return errors.Is(err, ErrPrecondition) || errors.Is(err, ErrExists) || errors.Is(err, ErrNotFound) +} + +// markHeadDeleting is (b): every read decides afresh whether the HEAD is +// held, so an attach that landed before this read is refused, and one that +// lands after it makes the write's condition fail. +func (c *Catalog) markHeadDeleting(ctx context.Context, vol, root string) (bool, error) { for try := 0; try < 5; try++ { - h, err := r.GetHead(ctx) + h, _, err := c.ReadHead(ctx, vol) if err != nil { - return remoteErr(err, "read HEAD of %s", vol) + return false, err } - if h.State == storage.ChunkHeadDeleted { - return nil + if headDeletingOrDeleted(h) { + return false, nil } - if try > 0 || replay { - if err := c.checkVolumeFree(ctx, vol, inUse); err != nil { - return err - } + if headHeld(h) && try > 0 { // RED: the first read is not checked + 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 := storage.ChunkHead{Epoch: h.Epoch, RemoteLSN: h.RemoteLSN, Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadDeleted} - _, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: h.Epoch}, next) - if errors.Is(err, storage.ErrChunkHeadPrecondition) { + next := h + next.State = storage.ChunkHeadDeleting + if next.Chunks == nil { + next.Chunks = map[uint64]storage.ChunkRef{} + } + err = c.writeHead(ctx, root, h, next) + if lostCondition(err) { continue } if err != nil { - return catErr(CodeOutcomeUnknown, true, err, "tombstone HEAD of %s: outcome unknown; rerun the delete", vol) + return true, catErr(CodeOutcomeUnknown, true, err, "mark HEAD of %s deleting: outcome unknown; rerun the delete", vol) } - return nil + return false, nil } - return remoteErr(nil, "HEAD of %s kept changing", vol) + return false, remoteErr(nil, "HEAD of %s kept changing", vol) +} + +// revertHeadDeleting gives (b) back: deleting returns to detached when the +// HEAD carries its holder's detach record, else to active. +func (c *Catalog) revertHeadDeleting(ctx context.Context, vol, root string) (bool, error) { + for try := 0; try < 5; try++ { + h, _, err := c.ReadHead(ctx, vol) + if err != nil { + return false, err + } + if h.State != storage.ChunkHeadDeleting { + return false, nil + } + next := h + next.State = storage.ChunkHeadActive + if h.DetachedBy != nil { + next.State = storage.ChunkHeadDetached + d := *h.DetachedBy + d.Gen = h.Gen + 1 + next.DetachedBy = &d + } + err = c.writeHead(ctx, root, h, next) + if lostCondition(err) { + continue + } + if err != nil { + return true, catErr(CodeOutcomeUnknown, true, err, "revert the delete mark on HEAD of %s: outcome unknown; rerun the delete", vol) + } + return false, nil + } + return false, remoteErr(nil, "HEAD of %s kept changing", vol) +} + +// finishHeadDeleted is (e) for HEAD: deleting becomes deleted, no chunks. +func (c *Catalog) finishHeadDeleted(ctx context.Context, vol, root string) (bool, error) { + for try := 0; try < 5; try++ { + h, _, err := c.ReadHead(ctx, vol) + if err != nil { + return false, err + } + if h.State == storage.ChunkHeadDeleted { + return false, nil + } + if h.State != storage.ChunkHeadDeleting { + return false, remoteErr(nil, "HEAD of %s left the deleting state (%q)", vol, h.State) + } + next := storage.ChunkHead{Epoch: h.Epoch, RemoteLSN: h.RemoteLSN, Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadDeleted} + err = c.writeHead(ctx, root, h, next) + if lostCondition(err) { + continue + } + if err != nil { + return true, catErr(CodeOutcomeUnknown, true, err, "tombstone HEAD of %s: outcome unknown; rerun the delete", vol) + } + return false, nil + } + return false, remoteErr(nil, "HEAD of %s kept changing", vol) +} + +// anyLiveClaim returns snapshot_claimed for the first published snapshot of +// vol a live fork claims, or nil. +func (c *Catalog) anyLiveClaim(ctx context.Context, vol string) (error, error) { + root, err := c.volRoot(vol) + if err != nil { + return nil, err + } + names, err := c.listNames(ctx, root) + if err != nil { + return nil, err + } + for _, name := range names { + ref, ok, err := c.resolveSnap(ctx, vol, name) + if err != nil { + return nil, err + } + if !ok || ref.entry == nil || ref.info.State != SnapActive { + continue + } + live, err := c.liveClaims(ctx, vol, name, decodeClaims(ref.entry)) + if err != nil { + return nil, err + } + if len(live) > 0 { + return claimedErr(vol, name, live), nil + } + } + return nil, nil +} + +// listNames lists every snapshot name record of the volume at root. +func (c *Catalog) listNames(ctx context.Context, root string) ([]string, error) { + dir := path.Join(root, snapNamesDir) + var out []string + after := "" + for { + page, err := c.f.ListEntries(ctx, dir, "", after, listPage) + if err != nil { + return nil, remoteErr(err, "list the snapshot names under %s", root) + } + for _, e := range page { + if e.GetName() <= after { + return nil, errors.New("chunkstore: non-advancing snapshot name listing") + } + after = e.GetName() + if !e.GetIsDirectory() { + out = append(out, e.GetName()) + } + } + if len(page) < listPage { + return out, nil + } + } +} + +// deleteNameForVolume is (d) for one name: a published attempt goes through +// markDeleting; an unpublished one gets an aborted tombstone at its path +// (so its late publish can never land); then the name is freed. +func (c *Catalog) deleteNameForVolume(ctx context.Context, vol, root, name string) (gone, aborted, uncertain bool, err error) { + for try := 0; try < 5; try++ { + ref, ok, err := c.resolveSnap(ctx, vol, name) + if err != nil { + return false, false, false, err + } + if !ok { + 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 { + return false, false, false, err + } + if err := c.f.CreateEntry(ctx, path.Join(root, snapsDir, name), tomb, true); err != nil && !errors.Is(err, ErrExists) { + return false, false, true, remoteErr(err, "abort the unpublished attempt of %s/%s", vol, name) + } + continue // re-read: the tombstone, or the attempt that won + } + wasAborted := ref.info.State == SnapAborted + m, live, u, err := c.markDeleting(ctx, vol, name, attempt) + if err != nil { + return false, false, u, err + } + if m == markClaimed { + // A fork claimed after (c); it backs out on the deleting HEAD. + if try < 4 { + continue + } + return false, false, false, claimedErr(vol, name, live) + } + if _, u, err := c.freeName(ctx, root, name, attempt); err != nil { + return false, false, u, err + } + return !wasAborted, wasAborted, false, nil + } + return false, false, false, remoteErr(nil, "snapshot %s/%s kept changing", vol, name) } // markVolumeDeleted marks vol's VOLUME entry deleted, conditioned on it not @@ -226,7 +427,24 @@ func (c *Catalog) markVolumeDeleted(ctx context.Context, vol, root string) error return nil } -// refuseDeleted is volume_deleted for a deleted volume id. +// refuseDeleted is volume_deleted for a deleted (or deleting) volume id. func refuseDeleted(vol, what string) error { - return catErr(CodeVolumeDeleted, false, nil, "volume %s was deleted; %s (a deleted id is never reused)", vol, what) + return catErr(CodeVolumeDeleted, false, nil, "volume %s is deleted or being deleted; %s (a deleted id is never reused)", vol, what) +} + +// volumeGone reports whether vol is being deleted or deleted: its VOLUME +// is marked, or its HEAD is past the delete's linearization point. +func (c *Catalog) volumeGone(ctx context.Context, vol string) (bool, error) { + v, ok, err := c.ReadVolume(ctx, vol) + if err != nil { + return false, err + } + if ok && v.State == VolumeDeleted { + return true, nil + } + h, has, err := c.ReadHead(ctx, vol) + if err != nil { + return false, err + } + return has && headDeletingOrDeleted(h), nil } diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go index e4ffac6a97..a5fca1ab7a 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go @@ -11,7 +11,8 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" ) -// Volume delete (claude05's item, 2026-11-16 02:39Z). +// Volume delete (claude05's item; one linearization point per codex01's +// review of 7c43367). One control per review schedule. // detachHead publishes vol's HEAD as a clean detach by its holder (what a // volume server's Detach writes). @@ -34,6 +35,19 @@ func detachHead(t *testing.T, f *fakeFiler, b *fakeBlobs, vol string) { } } +// attachEntry is the HEAD an attaching holder installs over cur (a takeover: +// new holder, next epoch). +func attachEntry(t *testing.T, cur storage.ChunkHead, holder string) *filerpb.Entry { + t.Helper() + att := cur + att.Gen, att.Epoch, att.Holder, att.State, att.DetachedBy = cur.Gen+1, cur.Epoch+1, holder, storage.ChunkHeadActive, nil + e, err := headEntry(att) + if err != nil { + t.Fatal(err) + } + return e +} + func deleteFixture(t *testing.T) (*fakeFiler, *fakeBlobs, *Catalog, storage.ChunkHead) { t.Helper() f, b, c, h := catalogFixture(t) // v1 HEAD held by h1 (attached) @@ -51,8 +65,17 @@ func deleteFixture(t *testing.T) (*fakeFiler, *fakeBlobs, *Catalog, storage.Chun return f, b, c, h } -// An attached volume (HEAD held), or one the blockmaster reports in use, -// is refused with volume_in_use and nothing is written. +func headState(t *testing.T, c *Catalog, vol string) storage.ChunkHead { + t.Helper() + h, _, err := c.ReadHead(context.Background(), vol) + if err != nil { + t.Fatal(err) + } + return h +} + +// An attached volume (HEAD held), or one the admission refuses, is refused +// with volume_in_use and nothing is written. func TestCatalog_DeleteVolumeRefusesAVolumeInUse(t *testing.T) { f, b, c, _ := deleteFixture(t) ctx := context.Background() @@ -60,109 +83,26 @@ func TestCatalog_DeleteVolumeRefusesAVolumeInUse(t *testing.T) { if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { t.Fatalf("delete of an attached volume: %v; want volume_in_use", err) } + if got := len(f.allWritten()); got != before { + t.Fatalf("a refused delete wrote %d entries", got-before) + } detachHead(t, f, b, "v1") before = len(f.allWritten()) - busy := func(context.Context, string) (bool, string, error) { return true, "assigned to r1", nil } - _, err := c.DeleteVolume(ctx, "v1", busy) + refuse := func(context.Context, string) error { return errors.New("assigned to r1") } + res, err := c.DeleteVolume(ctx, "v1", refuse) var ce *CatalogError - if !errors.As(err, &ce) || ce.Code != CodeVolumeInUse || ce.Retryable || !strings.Contains(ce.Detail(), "assigned to r1") { - t.Fatalf("delete of an assigned volume: %v; want volume_in_use naming the reason", err) - } - if got := len(f.allWritten()); got != before { - t.Fatalf("a refused delete wrote %d entries", got-before) - } - if v, _, _ := c.ReadVolume(ctx, "v1"); v.State != "" { - t.Fatalf("refused delete changed VOLUME state to %q", v.State) - } -} - -// A volume with a snapshot a live fork claims is refused before anything -// is written (snapshot_claimed). -func TestCatalog_DeleteVolumeRefusesAClaimedSnapshot(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - holdFirst(f, catBase+"/w3/HEAD") - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { - t.Fatalf("fork w3: %v", err) - } - before := len(f.allWritten()) - if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeSnapshotClaimed { - t.Fatalf("delete with a claimed snapshot: %v; want snapshot_claimed", err) + if !errors.As(err, &ce) || ce.Code != CodeVolumeInUse || ce.Retryable || !strings.Contains(ce.Detail(), "assigned to r1") || res.Admitted { + t.Fatalf("delete the admission refuses: %+v %v; want volume_in_use naming the reason", res, err) } if got := len(f.allWritten()); got != before { t.Fatalf("a refused delete wrote %d entries", got-before) } } -// The acceptance flow on the fake: fork w2 from s1, delete w2, then s1 can -// be deleted; the deleted id is never attached, recreated or forked to -// again; an incomplete fork w3 is deleted too and its claim released; a -// rerun replays. -func TestCatalog_DeleteVolumeTombstonesAndReleases(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "f2"}); err != nil { - t.Fatalf("fork w2: %v", err) - } - if _, err := c.CreateSnapshot(ctx, "w2", SnapshotRequest{Name: "w2snap", RequestID: "rw"}, mustHead(t, c, "w2")); err != nil { - t.Fatal(err) - } - res, err := c.DeleteVolume(ctx, "w2", nil) - if err != nil || res.Replayed || strings.Join(res.SnapshotsDeleted, ",") != "w2snap" { - t.Fatalf("delete w2: %+v %v", res, err) - } - h, has, err := c.ReadHead(ctx, "w2") - if err != nil || !has || h.State != storage.ChunkHeadDeleted || len(h.Chunks) != 0 { - t.Fatalf("w2 HEAD: %+v has=%t %v; want a deleted tombstone with no chunks", h, has, err) - } - if v, _, _ := c.ReadVolume(ctx, "w2"); v.State != VolumeDeleted { - t.Fatalf("w2 VOLUME state %q", v.State) - } - if _, ok, _ := c.resolveSnap(ctx, "w2", "w2snap"); ok { - t.Fatal("w2's snapshot name is still held") - } - if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { - t.Fatalf("delete s1 after its fork was deleted: %v", err) - } - // The id is never reused. - if _, err := c.EnsureVolume(ctx, "w2", catGeo); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("attach/create of deleted w2: %v; want volume_deleted", err) - } - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w2", RequestID: "again"}); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("fork to deleted w2: %v; want volume_deleted", err) - } - // A rerun replays. - if res, err := c.DeleteVolume(ctx, "w2", nil); err != nil || !res.Replayed { - t.Fatalf("rerun: %+v %v; want a replay", res, err) - } - - // An incomplete fork (VOLUME, no HEAD) is deleted and its claim - // released, so its parent snapshot can be deleted. - holdFirst(f, catBase+"/w3/HEAD") - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { - t.Fatalf("fork w3: %v", err) - } - if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); CodeOf(err) != CodeSnapshotClaimed { - t.Fatalf("delete s2 under the incomplete fork: %v; want snapshot_claimed", err) - } - res, err = c.DeleteVolume(ctx, "w3", nil) - if err != nil || !res.ClaimReleased { - t.Fatalf("delete w3: %+v %v; want its claim released", res, err) - } - if got := claimsOf(t, c, "s2"); len(got) != 0 { - t.Fatalf("s2 claims after w3 was deleted: %v", got) - } - if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); err != nil { - t.Fatalf("delete s2 after w3 was deleted: %v", err) - } - _ = b -} - -// A volume server that attaches between the delete's check and its HEAD -// tombstone makes the tombstone's condition fail; the delete re-checks and -// refuses (volume_in_use), and VOLUME is untouched. -func TestCatalog_DeleteVolumeLosesToAConcurrentAttach(t *testing.T) { +// Schedule 1: a holder attaches after the delete's first read, before the +// HEAD mark's read. The mark reads the held HEAD and refuses; HEAD stays +// the holder's. +func TestCatalog_DeleteVolumeRefusesAnAttachBeforeTheMark(t *testing.T) { f, b, c, _ := deleteFixture(t) ctx := context.Background() detachHead(t, f, b, "v1") @@ -172,29 +112,262 @@ func TestCatalog_DeleteVolumeLosesToAConcurrentAttach(t *testing.T) { if p != headPath { return } - lookups++ - if lookups != 2 { // 1: the delete's check; 2: the tombstone's read - return + if lookups++; lookups == 1 { // the delete's first read; the mark reads next + cur, _ := decodeHead(p, f.entries[p]) + f.entries[p] = attachEntry(t, cur, "h2") } - cur, _ := decodeHead(p, f.entries[p]) - att := cur - att.Gen, att.Epoch, att.Holder, att.State, att.DetachedBy = cur.Gen+1, cur.Epoch+1, "h2", storage.ChunkHeadActive, nil - e, err := headEntry(att) - if err != nil { - t.Fatal(err) - } - f.entries[p] = e // h2 attaches (takeover CAS) } if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { t.Fatalf("delete racing an attach: %v; want volume_in_use", err) } f.afterLookup = nil - h, _, _ := c.ReadHead(ctx, "v1") - if h.Holder != "h2" || h.State == storage.ChunkHeadDeleted { + if h := headState(t, c, "v1"); h.Holder != "h2" || h.State != storage.ChunkHeadActive { + t.Fatalf("HEAD after the refused delete: %+v; want h2's, active", h) + } +} + +// An attach between the mark's read and its write makes the write's +// condition fail; the re-read sees the holder and refuses. +func TestCatalog_DeleteVolumeLosesToAnAttachAtTheMark(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + headPath := path.Join(catBase, "v1", headName) + lookups := 0 + f.afterLookup = func(p string) { + if p != headPath { + return + } + if lookups++; lookups == 2 { // the mark's read; the write is conditioned on it + cur, _ := decodeHead(p, f.entries[p]) + f.entries[p] = attachEntry(t, cur, "h2") + } + } + if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { + t.Fatalf("delete losing to an attach: %v; want volume_in_use", err) + } + f.afterLookup = nil + if h := headState(t, c, "v1"); h.Holder != "h2" || h.State != storage.ChunkHeadActive { t.Fatalf("HEAD after the lost delete: %+v; want h2's", h) } +} + +// Schedule 2: an attach that passed EnsureVolume before the mark claims +// HEAD afterwards (CASHead from the deleting or deleted HEAD it reads): the +// remote refuses, so nothing revives the volume. +func TestCatalog_DeletedHeadCannotBeRevivedByAClaim(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + r, err := NewChunkRemote(f, b, path.Join(catBase, "v1")) + if err != nil { + t.Fatal(err) + } + claim := func(stage string) { + t.Helper() + h, err := r.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + _, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: h.Epoch}, storage.ChunkHead{Epoch: h.Epoch + 1, Holder: "late", RemoteLSN: h.RemoteLSN, Chunks: h.Chunks, State: storage.ChunkHeadActive}) + if !errors.Is(err, storage.ErrChunkHeadPrecondition) || !errors.Is(err, storage.ErrChunkHeadDeleted) { + t.Fatalf("claim of a %s HEAD: %v; want a precondition failure (deleted)", stage, err) + } + if _, err := c.EnsureVolume(ctx, "v1", catGeo); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("attach of a %s volume: %v; want volume_deleted", stage, err) + } + } + c.retainHook = func(stage, _ string) { + if stage == hookHeadMarked { + claim("deleting") + } + } + res, err := c.DeleteVolume(ctx, "v1", nil) + c.retainHook = nil + if err != nil || !res.Completed { + t.Fatalf("delete: %+v %v", res, err) + } + claim("deleted") + if h := headState(t, c, "v1"); h.State != storage.ChunkHeadDeleted || h.Holder != "" || len(h.Chunks) != 0 { + t.Fatalf("HEAD after the delete: %+v; want the deleted tombstone", h) + } +} + +// A fork claim that lands before the claims are read (after the mark) +// makes the delete give the mark back: snapshot_claimed, HEAD restored, +// nothing irreversible done. +func TestCatalog_DeleteVolumeGivesBackOnALiveClaim(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + before := headState(t, c, "v1") + holdFirst(f, catBase+"/w3/HEAD") + c.retainHook = func(stage, _ string) { + if stage == hookHeadMarked { // the claim lands after the mark, before the read of claims + c.retainHook = nil + // Fork's own claim write is what lands here; its post-check then + // refuses on the deleting HEAD, so take only the claim. + if _, err := c.claimForkParent(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); err != nil { + t.Fatal(err) + } + // The fork published its VOLUME before the delete began. + ve, _ := volumeEntry(VolumeInfo{Format: volumeFormat, VolumeID: "w3", Geometry: catGeo, Origin: OriginFork, Parent: &Parent{VolumeID: "v1", Snapshot: "s2"}, + Fork: &ForkRecord{RequestID: "f3", Source: "v1", Snapshot: "s2"}}, "f3") + if err := f.CreateEntry(ctx, catBase+"/w3", ve, true); err != nil { + t.Fatal(err) + } + } + } + res, err := c.DeleteVolume(ctx, "v1", nil) + if CodeOf(err) != CodeSnapshotClaimed || !res.Reverted || res.HeadMarked || len(res.SnapshotsDeleted) != 0 { + t.Fatalf("delete under a live claim: %+v %v; want snapshot_claimed, reverted", res, err) + } + after := headState(t, c, "v1") + if after.State != storage.ChunkHeadDetached || after.DetachedBy == nil || after.Holder != before.Holder || len(after.Chunks) != len(before.Chunks) { + t.Fatalf("HEAD after the give-back: %+v; want the detached HEAD with its chunks", after) + } if v, _, _ := c.ReadVolume(ctx, "v1"); v.State != "" { - t.Fatalf("VOLUME state %q after the refused delete", v.State) + t.Fatalf("VOLUME state %q after the give-back", v.State) + } + for _, s := range []string{"s1", "s2"} { + if _, err := c.readSnap(ctx, "v1", s); err != nil { + t.Fatalf("%s after the give-back: %v", s, err) + } + } +} + +// A fork that claims after the claims were read sees the deleting HEAD and +// gives its claim back before installing anything; the delete completes. +func TestCatalog_ForkAfterTheDeleteMarkRefuses(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + ran := false + c.retainHook = func(stage, _ string) { + if stage != hookClaimsChecked || ran { + return + } + ran = true + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "late"}); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("fork after the delete mark: %v; want volume_deleted", err) + } + } + res, err := c.DeleteVolume(ctx, "v1", nil) + if err != nil || !ran || !res.Completed || strings.Join(res.SnapshotsDeleted, ",") != "s1,s2" { + t.Fatalf("delete: ran=%t %+v %v", ran, res, err) + } + if _, ok, _ := c.ReadVolume(ctx, "w2"); ok { + t.Fatal("the refused fork published its VOLUME") + } +} + +// P2: a snapshot whose publication is held while the delete lists the names +// (its name record exists, its attempt not yet) is tombstoned, so its late +// publish cannot land; a snapshot started after the mark refuses itself. +func TestCatalog_DeleteVolumeCatchesInFlightSnapshots(t *testing.T) { + f, b, c, h := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + held := catBase + "/v1/" + snapsDir + "/s3/" + f.deferCreate = func(p string, _ *filerpb.Entry) bool { return strings.HasPrefix(p, held) } + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s3", RequestID: "r-s3"}, h); err == nil { + t.Fatal("held snapshot publication reported success") + } + f.deferCreate = nil + late := false + c.retainHook = func(stage, _ string) { + if stage == hookHeadMarked && !late { + late = true + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s4", RequestID: "r-s4"}, h); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("snapshot started after the mark: %v; want volume_deleted", err) + } + } + } + res, err := c.DeleteVolume(ctx, "v1", nil) + c.retainHook = nil + if err != nil || !res.Completed || strings.Join(res.AttemptsAborted, ",") != "s3" { + t.Fatalf("delete: %+v %v; want s3's unpublished attempt aborted", res, err) + } + f.releaseDeferredCreates() // the held publish finally runs + for _, name := range []string{"s3", "s4"} { + if _, ok, _ := c.resolveSnap(ctx, "v1", name); ok { + t.Fatalf("%s's name survived the delete", name) + } + } + snaps, err := c.listSnapshots(ctx, "v1", true) + if err != nil || len(snaps) != 0 { + t.Fatalf("snapshots left after the delete: %v %v", snaps, err) + } + attempts, _ := f.ListEntries(ctx, held[:len(held)-1], "", "", 0) + for _, e := range attempts { + if s := string(e.Extended[extSnapState]); s != SnapAborted { + t.Fatalf("s3 attempt %s is %q after the late publish; want the aborted tombstone", e.GetName(), s) + } + } +} + +// The acceptance flow on the fake: fork w2 from s1, delete w2, then s1 can +// be deleted; the deleted id is never attached, recreated or forked to +// again; an incomplete fork w3 is deleted and its claim released (only +// when confirmed); a rerun replays. +func TestCatalog_DeleteVolumeTombstonesAndReleases(t *testing.T) { + f, _, c, _ := deleteFixture(t) + ctx := context.Background() + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "f2"}); err != nil { + t.Fatalf("fork w2: %v", err) + } + if _, err := c.CreateSnapshot(ctx, "w2", SnapshotRequest{Name: "w2snap", RequestID: "rw"}, mustHead(t, c, "w2")); err != nil { + t.Fatal(err) + } + res, err := c.DeleteVolume(ctx, "w2", nil) + if err != nil || res.Replayed || !res.Completed || strings.Join(res.SnapshotsDeleted, ",") != "w2snap" { + t.Fatalf("delete w2: %+v %v", res, err) + } + if h := headState(t, c, "w2"); h.State != storage.ChunkHeadDeleted || len(h.Chunks) != 0 { + t.Fatalf("w2 HEAD: %+v; want a deleted tombstone with no chunks", h) + } + if v, _, _ := c.ReadVolume(ctx, "w2"); v.State != VolumeDeleted { + t.Fatalf("w2 VOLUME state %q", v.State) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { + t.Fatalf("delete s1 after its fork was deleted: %v", err) + } + if _, err := c.EnsureVolume(ctx, "w2", catGeo); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("attach/create of deleted w2: %v; want volume_deleted", err) + } + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w2", RequestID: "again"}); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("fork to deleted w2: %v; want volume_deleted", err) + } + if res, err := c.DeleteVolume(ctx, "w2", nil); err != nil || !res.Replayed { + t.Fatalf("rerun: %+v %v; want a replay", res, err) + } + + // Incomplete fork w3: a failed claim removal is not reported released. + holdFirst(f, catBase+"/w3/HEAD") + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { + t.Fatalf("fork w3: %v", err) + } + s2 := path.Join(catBase, "v1", snapsDir, "s2") + f.failUpdate = func(p string) error { + if strings.HasPrefix(p, s2+"/") { + return errors.New("filer unavailable") + } + return nil + } + res, err = c.DeleteVolume(ctx, "w3", nil) + if err == nil || res.ClaimReleased || !res.Uncertain || res.Completed { + t.Fatalf("delete w3 with a failing claim removal: %+v %v; want an error, claim not released, uncertain", res, err) + } + f.failUpdate = nil + res, err = c.DeleteVolume(ctx, "w3", nil) + if err != nil || !res.ClaimReleased || !res.Completed { + t.Fatalf("delete w3 rerun: %+v %v; want its claim released", res, err) + } + if got := claimsOf(t, c, "s2"); len(got) != 0 { + t.Fatalf("s2 claims after w3 was deleted: %v", got) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); err != nil { + t.Fatalf("delete s2 after w3 was deleted: %v", err) } } diff --git a/seaweed-block/core/host/master/launcher_plan.go b/seaweed-block/core/host/master/launcher_plan.go index e68f7a7645..144e6a31de 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 { + if !ok || volume.Deleting && false { // RED result.SkippedMissingVolume++ continue } diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index 8fa4cfbf49..f4f257d1fa 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -107,6 +107,47 @@ func (s *services) DeleteVolume(ctx context.Context, req *control.DeleteVolumeRe return &control.DeleteVolumeResponse{}, nil } +// MarkVolumeDeleting admits a chunk volume delete (sw-block ops chunk +// volume-delete). It holds workspaceMu, the lock every assignment, +// placement and binding write takes, and runs the mark inside +// RecordWorkspaceDeletion's check under the publisher lock: a volume with a +// live authority line (and no clean revocation ACK), a pending move or a +// queued placement is refused; otherwise the record is marked deleting, and +// from then on publication admission, the placement reconciler, the +// workload planner, binding/placement/move RPCs and CreateVolume all refuse +// it. +func (s *services) MarkVolumeDeleting(ctx context.Context, req *control.MarkVolumeDeletingRequest) (*control.MarkVolumeDeletingResponse, error) { + s.host.workspaceMu.Lock() + defer s.host.workspaceMu.Unlock() + if err := ctx.Err(); err != nil { + return nil, workspaceError(err) + } + stores := s.host.Lifecycle() + if stores == nil { + return nil, status.Error(codes.FailedPrecondition, "lifecycle store is not configured") + } + vol := req.GetVolumeId() + if vol == "" { + return nil, status.Error(codes.InvalidArgument, "volume_id is required") + } + _, bound, err := stores.WorkspaceBindings.Get(vol) + if err != nil { + return nil, lifecycleError("mark volume deleting", err) + } + _, placed := stores.Placements.GetPlacement(vol) + known := false + err = s.host.Publisher().RecordWorkspaceDeletion(ctx, vol, bound && placed, func() error { + found, e := stores.Volumes.MarkDeleting(vol) + known = found + return e + }) + if err != nil { + return nil, status.Errorf(codes.FailedPrecondition, "mark volume deleting: %v", err) + } + s.host.log.Printf("blockmaster: MarkVolumeDeleting volume=%q known=%t", vol, known) + return &control.MarkVolumeDeletingResponse{Known: known}, nil +} + func (s *services) ExecuteFailback(ctx context.Context, req *control.FailbackRequest) (*control.FailbackResponse, error) { if !s.host.cfg.FailbackRuntimeRPC { return nil, status.Error(codes.FailedPrecondition, "failback runtime RPC is disabled") @@ -180,6 +221,9 @@ func lifecycleError(op string, err error) error { if errors.Is(err, lifecycle.ErrVolumeConflict) { return status.Errorf(codes.AlreadyExists, "%s: %v", op, err) } + if errors.Is(err, lifecycle.ErrVolumeDeleting) { + return status.Errorf(codes.FailedPrecondition, "%s: %v", op, err) + } return status.Errorf(codes.Internal, "%s: %v", op, err) } diff --git a/seaweed-block/core/host/master/volume_deleting_test.go b/seaweed-block/core/host/master/volume_deleting_test.go new file mode 100644 index 0000000000..1775da86b4 --- /dev/null +++ b/seaweed-block/core/host/master/volume_deleting_test.go @@ -0,0 +1,79 @@ +package master + +import ( + "testing" + "time" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/seaweedfs/seaweed-block/core/lifecycle" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" +) + +// MarkVolumeDeleting is the master-side admission of a chunk volume delete +// (codex01's review of #152, P1 3): refused while the volume has live +// authority; once marked, a placement that already exists no longer leads +// to an assignment, and the id is never created, placed or bound again. + +func TestMarkVolumeDeleting_RefusedWhileAssigned(t *testing.T) { + h, c, ctx := reviewBindingHost(t) + reviewLegacyBind(t, h, c, ctx, "live") + _, err := control.NewLifecycleServiceClient(c).MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "live"}) + if status.Code(err) != codes.FailedPrecondition { + t.Fatalf("mark of an assigned volume: %v; want FailedPrecondition", err) + } + if rec, _ := h.Lifecycle().Volumes.GetVolume("live"); rec.Deleting { + t.Fatal("a refused mark marked the record") + } +} + +func TestMarkVolumeDeleting_StopsLaterAssignmentPlacementAndBinding(t *testing.T) { + h, c, ctx := reviewBindingHost(t) + lc := control.NewLifecycleServiceClient(c) + // "placed" has a placement already (no authority yet); "fresh" has none. + for _, vol := range []string{"placed", "fresh"} { + reviewCreate(t, c, ctx, vol) + } + if _, e := h.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "placed", DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: "placed", ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); e != nil { + t.Fatal(e) + } + for _, vol := range []string{"placed", "fresh"} { + resp, err := lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: vol}) + if err != nil || !resp.GetKnown() { + t.Fatalf("mark %s: %+v %v", vol, resp, err) + } + if rec, _ := h.Lifecycle().Volumes.GetVolume(vol); !rec.Deleting { + t.Fatalf("%s not marked", vol) + } + } + // The placed volume's replica reports in; the product tick would bind + // it. Neither volume may get authority, and "fresh" no placement. + reviewHeartbeat(t, c, ctx, "placed", "node-a", "127.0.0.1:10000", "127.0.0.1:10001") + reviewHeartbeat(t, c, ctx, "fresh", "node-a", "127.0.0.1:10002", "127.0.0.1:10003") + for i := 0; i < 3; i++ { + if _, e := h.RunLifecycleProductTick(); e != nil { + t.Fatal(e) + } + } + time.Sleep(200 * time.Millisecond) // let the publisher drain any queued ask + for _, vol := range []string{"placed", "fresh"} { + if line, ok := h.Publisher().VolumeAuthorityLine(vol); ok { + t.Fatalf("%s got authority after its delete mark: %+v", vol, line) + } + } + if _, ok := h.Lifecycle().Placements.GetPlacement("fresh"); ok { + t.Fatal("the reconciler placed a volume marked deleting") + } + // Never created, bound or placed again. + if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "fresh", SizeBytes: 1 << 20, ReplicationFactor: 1}); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("re-create of a deleting volume: %v; want FailedPrecondition", err) + } + if _, err := control.NewWorkspaceServiceClient(c).RegisterWorkspaceBinding(ctx, &control.WorkspaceBinding{VolumeId: "fresh", ServerId: "node-b", DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("binding of a deleting volume: %v; want FailedPrecondition", err) + } + // A volume the master never knew is admitted after the authority check. + if resp, err := lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "unknown"}); err != nil || resp.GetKnown() { + t.Fatalf("mark of an unknown volume: %+v %v; want admitted, not known", resp, err) + } +} diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 10bc3e57a8..9d1a5d5f22 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -160,8 +160,10 @@ func (h *Host) admitWorkspacePublication(ask authority.AssignmentAsk, publish fu } h.workspaceMu.Lock() defer h.workspaceMu.Unlock() - if _, alive := h.lifecycle.Volumes.GetVolume(ask.VolumeID); !alive { + 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 + return fmt.Errorf("workspace publication: volume is being deleted") } bindings, bound, err := h.lifecycle.WorkspaceBindings.Get(ask.VolumeID) if err != nil { diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index f8f977ccf7..b0c03b0bbc 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -22,6 +22,9 @@ 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 + 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 c16765ec2d..41f4a6eddd 100644 --- a/seaweed-block/core/lifecycle/reconciler.go +++ b/seaweed-block/core/lifecycle/reconciler.go @@ -17,6 +17,9 @@ 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 + continue // never placed again + } plan := PlanPlacement(volume, nodes) result := ReconcileResult{ VolumeID: volume.Spec.VolumeID, diff --git a/seaweed-block/core/lifecycle/store.go b/seaweed-block/core/lifecycle/store.go index 1de3e090e2..2ebab6db12 100644 --- a/seaweed-block/core/lifecycle/store.go +++ b/seaweed-block/core/lifecycle/store.go @@ -23,6 +23,9 @@ var ( ErrVolumeNotFound = errors.New("lifecycle: volume not found") ErrAlreadyAttached = errors.New("lifecycle: volume already attached to another node") ErrAttachedElsewhere = errors.New("lifecycle: volume attached to another node") + // ErrVolumeDeleting: the volume is being deleted (or was); its id is + // never created, placed, bound or assigned again. + ErrVolumeDeleting = errors.New("lifecycle: volume is being deleted") ) var volumeIDPattern = regexp.MustCompile(`^[A-Za-z0-9._-]+$`) @@ -45,6 +48,8 @@ type VolumeSpec struct { type VolumeRecord struct { Spec VolumeSpec `json:"spec"` AttachedTo string `json:"attached_to,omitempty"` + // Deleting is set once by MarkDeleting and never cleared. + Deleting bool `json:"deleting,omitempty"` } // FileStore persists one JSON record per volume ID. @@ -82,6 +87,9 @@ 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 + return VolumeRecord{}, ErrVolumeDeleting + } if !volumeSpecsCompatible(existing.Spec, spec) { return VolumeRecord{}, ErrVolumeConflict } @@ -131,6 +139,29 @@ func mergeVolumeSpecMetadata(existing, incoming VolumeSpec) VolumeSpec { return out } +// MarkDeleting marks volumeID's record deleting (idempotent). found is +// false when there is no record (nothing is written). +func (s *FileStore) MarkDeleting(volumeID string) (found bool, err error) { + if err := validateVolumeID(volumeID); err != nil { + return false, err + } + s.mu.Lock() + defer s.mu.Unlock() + rec, ok := s.records[volumeID] + if !ok { + return false, nil + } + if rec.Deleting { + return true, nil + } + rec.Deleting = true + if err := s.putLocked(rec); err != nil { + return true, err + } + s.records[volumeID] = rec + return true, nil +} + // DeleteVolume removes a desired volume record. Missing volumes are a // successful no-op so delete is safe to retry. func (s *FileStore) DeleteVolume(volumeID string) error { diff --git a/seaweed-block/core/rpc/control/control.pb.go b/seaweed-block/core/rpc/control/control.pb.go index f0aec7594d..fcd1dc811e 100644 --- a/seaweed-block/core/rpc/control/control.pb.go +++ b/seaweed-block/core/rpc/control/control.pb.go @@ -2533,6 +2533,102 @@ func (*DeleteVolumeResponse) Descriptor() ([]byte, []int) { return file_control_proto_rawDescGZIP(), []int{27} } +type MarkVolumeDeletingRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + VolumeId string `protobuf:"bytes,1,opt,name=volume_id,json=volumeId,proto3" json:"volume_id,omitempty"` +} + +func (x *MarkVolumeDeletingRequest) Reset() { + *x = MarkVolumeDeletingRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_control_proto_msgTypes[28] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MarkVolumeDeletingRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MarkVolumeDeletingRequest) ProtoMessage() {} + +func (x *MarkVolumeDeletingRequest) ProtoReflect() protoreflect.Message { + mi := &file_control_proto_msgTypes[28] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MarkVolumeDeletingRequest.ProtoReflect.Descriptor instead. +func (*MarkVolumeDeletingRequest) Descriptor() ([]byte, []int) { + return file_control_proto_rawDescGZIP(), []int{28} +} + +func (x *MarkVolumeDeletingRequest) GetVolumeId() string { + if x != nil { + return x.VolumeId + } + return "" +} + +type MarkVolumeDeletingResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // known is false when the master has no lifecycle record for the volume + // (it then only checked that no authority is live or pending). + Known bool `protobuf:"varint,1,opt,name=known,proto3" json:"known,omitempty"` +} + +func (x *MarkVolumeDeletingResponse) Reset() { + *x = MarkVolumeDeletingResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_control_proto_msgTypes[29] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MarkVolumeDeletingResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MarkVolumeDeletingResponse) ProtoMessage() {} + +func (x *MarkVolumeDeletingResponse) ProtoReflect() protoreflect.Message { + mi := &file_control_proto_msgTypes[29] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MarkVolumeDeletingResponse.ProtoReflect.Descriptor instead. +func (*MarkVolumeDeletingResponse) Descriptor() ([]byte, []int) { + return file_control_proto_rawDescGZIP(), []int{29} +} + +func (x *MarkVolumeDeletingResponse) GetKnown() bool { + if x != nil { + return x.Known + } + return false +} + type FailbackRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2554,7 +2650,7 @@ type FailbackRequest struct { func (x *FailbackRequest) Reset() { *x = FailbackRequest{} if protoimpl.UnsafeEnabled { - mi := &file_control_proto_msgTypes[28] + mi := &file_control_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2567,7 +2663,7 @@ func (x *FailbackRequest) String() string { func (*FailbackRequest) ProtoMessage() {} func (x *FailbackRequest) ProtoReflect() protoreflect.Message { - mi := &file_control_proto_msgTypes[28] + mi := &file_control_proto_msgTypes[30] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2580,7 +2676,7 @@ func (x *FailbackRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use FailbackRequest.ProtoReflect.Descriptor instead. func (*FailbackRequest) Descriptor() ([]byte, []int) { - return file_control_proto_rawDescGZIP(), []int{28} + return file_control_proto_rawDescGZIP(), []int{30} } func (x *FailbackRequest) GetVolumeId() string { @@ -2677,7 +2773,7 @@ type FailbackResponse struct { func (x *FailbackResponse) Reset() { *x = FailbackResponse{} if protoimpl.UnsafeEnabled { - mi := &file_control_proto_msgTypes[29] + mi := &file_control_proto_msgTypes[31] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2690,7 +2786,7 @@ func (x *FailbackResponse) String() string { func (*FailbackResponse) ProtoMessage() {} func (x *FailbackResponse) ProtoReflect() protoreflect.Message { - mi := &file_control_proto_msgTypes[29] + mi := &file_control_proto_msgTypes[31] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2703,7 +2799,7 @@ func (x *FailbackResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use FailbackResponse.ProtoReflect.Descriptor instead. func (*FailbackResponse) Descriptor() ([]byte, []int) { - return file_control_proto_rawDescGZIP(), []int{29} + return file_control_proto_rawDescGZIP(), []int{31} } func (x *FailbackResponse) GetFailbackStarted() bool { @@ -3202,163 +3298,177 @@ var file_control_proto_rawDesc = []byte{ 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xa5, 0x04, - 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, - 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x28, 0x0a, - 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, - 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x44, - 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, - 0x74, 0x5f, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, - 0x72, 0x12, 0x3d, 0x0a, 0x1b, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, - 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, - 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, - 0x12, 0x34, 0x0a, 0x16, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, - 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x14, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, - 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, 0x5f, 0x65, 0x6c, - 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x61, 0x63, - 0x6b, 0x45, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, 0x66, 0x72, 0x6f, - 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x62, 0x65, 0x66, - 0x6f, 0x72, 0x65, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x08, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x1c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, 0x65, 0x6e, 0x63, - 0x65, 0x64, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, - 0x12, 0x38, 0x0a, 0x18, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, - 0x74, 0x69, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, - 0x69, 0x65, 0x72, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, - 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, - 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0a, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, - 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x66, 0x73, 0x22, 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, - 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x66, 0x61, - 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x74, - 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, - 0x74, 0x79, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, - 0x74, 0x79, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x12, - 0x41, 0x0a, 0x1d, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, - 0x79, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x50, 0x72, - 0x69, 0x6d, 0x61, 0x72, 0x79, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, - 0x63, 0x6b, 0x12, 0x50, 0x0a, 0x25, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, - 0x72, 0x67, 0x65, 0x74, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x66, 0x74, - 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x21, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, - 0x53, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, - 0x62, 0x61, 0x63, 0x6b, 0x12, 0x2e, 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x61, - 0x67, 0x65, 0x5f, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x11, 0x6e, 0x6f, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, 0x75, 0x74, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, - 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, - 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, - 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, - 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, - 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x32, - 0xdf, 0x01, 0x0a, 0x12, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, - 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, - 0x6f, 0x72, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, - 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, 0x12, 0x52, 0x65, - 0x70, 0x6f, 0x72, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, - 0x12, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x38, 0x0a, + 0x19, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x32, 0x0a, 0x1a, 0x4d, 0x61, 0x72, 0x6b, 0x56, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x22, 0xa5, 0x04, 0x0a, 0x0f, + 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, + 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x74, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x44, 0x61, 0x74, + 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, + 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, + 0x3d, 0x0a, 0x1b, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, + 0x65, 0x6e, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, + 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x34, + 0x0a, 0x16, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, + 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x14, + 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, + 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, 0x5f, 0x65, 0x6c, 0x69, 0x67, + 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x61, 0x63, 0x6b, 0x45, + 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, 0x66, 0x72, 0x6f, 0x6e, 0x74, + 0x65, 0x6e, 0x64, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x62, 0x65, 0x66, 0x6f, 0x72, + 0x65, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x1c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, 0x65, 0x6e, 0x63, 0x65, 0x64, + 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x38, + 0x0a, 0x18, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, + 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, + 0x72, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, + 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, + 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, + 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x66, 0x73, 0x22, 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x66, 0x61, 0x69, 0x6c, + 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x0f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x72, + 0x74, 0x65, 0x64, 0x12, 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x45, 0x70, 0x6f, 0x63, 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x41, 0x0a, + 0x1d, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, + 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x50, 0x72, 0x69, 0x6d, + 0x61, 0x72, 0x79, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, + 0x12, 0x50, 0x0a, 0x25, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, + 0x65, 0x74, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, + 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x21, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x53, 0x77, + 0x61, 0x70, 0x70, 0x65, 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, + 0x63, 0x6b, 0x12, 0x2e, 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, + 0x5f, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x11, 0x6e, 0x6f, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, + 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, + 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x32, 0xdf, 0x01, + 0x0a, 0x12, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, 0x65, + 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, - 0x6b, 0x32, 0x81, 0x01, 0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, 0x62, 0x73, 0x63, - 0x72, 0x69, 0x62, 0x65, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, - 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, - 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, - 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, - 0x61, 0x63, 0x74, 0x30, 0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, - 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, - 0x79, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x2e, - 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xd1, - 0x04, 0x0a, 0x16, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, - 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, 0x47, 0x65, 0x74, - 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x30, 0x2e, - 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x2e, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, - 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x68, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x2b, + 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, + 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, + 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, 0x12, 0x52, 0x65, 0x70, 0x6f, + 0x72, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x65, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, + 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, 0x32, + 0x81, 0x01, 0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, + 0x62, 0x65, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x29, 0x2e, + 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x63, + 0x74, 0x30, 0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x56, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, 0x47, 0x65, 0x74, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2f, 0x2e, 0x73, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xd1, 0x04, 0x0a, + 0x16, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x30, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, + 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, + 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, + 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x2b, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, - 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, - 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, 0x2e, 0x73, 0x65, - 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x71, 0x0a, 0x12, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, - 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, - 0x30, 0x01, 0x32, 0xec, 0x01, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x56, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2f, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, 0x2e, 0x73, 0x65, 0x61, 0x77, + 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, + 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, + 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, + 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x71, 0x0a, + 0x12, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x73, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x57, 0x61, + 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, + 0x32, 0xeb, 0x02, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x32, 0x79, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x46, - 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, - 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, - 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, - 0x65, 0x64, 0x66, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x7d, 0x0a, 0x12, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, + 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, + 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, + 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, + 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x79, + 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, + 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, + 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, + 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, + 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -3373,63 +3483,65 @@ func file_control_proto_rawDescGZIP() []byte { return file_control_proto_rawDescData } -var file_control_proto_msgTypes = make([]protoimpl.MessageInfo, 30) +var file_control_proto_msgTypes = make([]protoimpl.MessageInfo, 32) var file_control_proto_goTypes = []interface{}{ - (*HeartbeatReport)(nil), // 0: seaweedfs.block.control.HeartbeatReport - (*HeartbeatSlot)(nil), // 1: seaweedfs.block.control.HeartbeatSlot - (*FrontendTarget)(nil), // 2: seaweedfs.block.control.FrontendTarget - (*HeartbeatAck)(nil), // 3: seaweedfs.block.control.HeartbeatAck - (*ClusterEventAck)(nil), // 4: seaweedfs.block.control.ClusterEventAck - (*SubscribeRequest)(nil), // 5: seaweedfs.block.control.SubscribeRequest - (*ReplicaDescriptor)(nil), // 6: seaweedfs.block.control.ReplicaDescriptor - (*AssignmentFact)(nil), // 7: seaweedfs.block.control.AssignmentFact - (*StatusRequest)(nil), // 8: seaweedfs.block.control.StatusRequest - (*StatusResponse)(nil), // 9: seaweedfs.block.control.StatusResponse - (*ReplicaUnhealthy)(nil), // 10: seaweedfs.block.control.ReplicaUnhealthy - (*GetClusterStatusRequest)(nil), // 11: seaweedfs.block.control.GetClusterStatusRequest - (*ListVolumesRequest)(nil), // 12: seaweedfs.block.control.ListVolumesRequest - (*GetVolumeStatusRequest)(nil), // 13: seaweedfs.block.control.GetVolumeStatusRequest - (*GetVolumeTimelineRequest)(nil), // 14: seaweedfs.block.control.GetVolumeTimelineRequest - (*WatchClusterEventsRequest)(nil), // 15: seaweedfs.block.control.WatchClusterEventsRequest - (*ObservationCondition)(nil), // 16: seaweedfs.block.control.ObservationCondition - (*ClusterStatusResponse)(nil), // 17: seaweedfs.block.control.ClusterStatusResponse - (*NodeEvidence)(nil), // 18: seaweedfs.block.control.NodeEvidence - (*VolumeEvidence)(nil), // 19: seaweedfs.block.control.VolumeEvidence - (*ReplicaEvidence)(nil), // 20: seaweedfs.block.control.ReplicaEvidence - (*ClusterEvent)(nil), // 21: seaweedfs.block.control.ClusterEvent - (*ListVolumesResponse)(nil), // 22: seaweedfs.block.control.ListVolumesResponse - (*VolumeTimelineResponse)(nil), // 23: seaweedfs.block.control.VolumeTimelineResponse - (*CreateVolumeRequest)(nil), // 24: seaweedfs.block.control.CreateVolumeRequest - (*CreateVolumeResponse)(nil), // 25: seaweedfs.block.control.CreateVolumeResponse - (*DeleteVolumeRequest)(nil), // 26: seaweedfs.block.control.DeleteVolumeRequest - (*DeleteVolumeResponse)(nil), // 27: seaweedfs.block.control.DeleteVolumeResponse - (*FailbackRequest)(nil), // 28: seaweedfs.block.control.FailbackRequest - (*FailbackResponse)(nil), // 29: seaweedfs.block.control.FailbackResponse - (*timestamp.Timestamp)(nil), // 30: google.protobuf.Timestamp + (*HeartbeatReport)(nil), // 0: seaweedfs.block.control.HeartbeatReport + (*HeartbeatSlot)(nil), // 1: seaweedfs.block.control.HeartbeatSlot + (*FrontendTarget)(nil), // 2: seaweedfs.block.control.FrontendTarget + (*HeartbeatAck)(nil), // 3: seaweedfs.block.control.HeartbeatAck + (*ClusterEventAck)(nil), // 4: seaweedfs.block.control.ClusterEventAck + (*SubscribeRequest)(nil), // 5: seaweedfs.block.control.SubscribeRequest + (*ReplicaDescriptor)(nil), // 6: seaweedfs.block.control.ReplicaDescriptor + (*AssignmentFact)(nil), // 7: seaweedfs.block.control.AssignmentFact + (*StatusRequest)(nil), // 8: seaweedfs.block.control.StatusRequest + (*StatusResponse)(nil), // 9: seaweedfs.block.control.StatusResponse + (*ReplicaUnhealthy)(nil), // 10: seaweedfs.block.control.ReplicaUnhealthy + (*GetClusterStatusRequest)(nil), // 11: seaweedfs.block.control.GetClusterStatusRequest + (*ListVolumesRequest)(nil), // 12: seaweedfs.block.control.ListVolumesRequest + (*GetVolumeStatusRequest)(nil), // 13: seaweedfs.block.control.GetVolumeStatusRequest + (*GetVolumeTimelineRequest)(nil), // 14: seaweedfs.block.control.GetVolumeTimelineRequest + (*WatchClusterEventsRequest)(nil), // 15: seaweedfs.block.control.WatchClusterEventsRequest + (*ObservationCondition)(nil), // 16: seaweedfs.block.control.ObservationCondition + (*ClusterStatusResponse)(nil), // 17: seaweedfs.block.control.ClusterStatusResponse + (*NodeEvidence)(nil), // 18: seaweedfs.block.control.NodeEvidence + (*VolumeEvidence)(nil), // 19: seaweedfs.block.control.VolumeEvidence + (*ReplicaEvidence)(nil), // 20: seaweedfs.block.control.ReplicaEvidence + (*ClusterEvent)(nil), // 21: seaweedfs.block.control.ClusterEvent + (*ListVolumesResponse)(nil), // 22: seaweedfs.block.control.ListVolumesResponse + (*VolumeTimelineResponse)(nil), // 23: seaweedfs.block.control.VolumeTimelineResponse + (*CreateVolumeRequest)(nil), // 24: seaweedfs.block.control.CreateVolumeRequest + (*CreateVolumeResponse)(nil), // 25: seaweedfs.block.control.CreateVolumeResponse + (*DeleteVolumeRequest)(nil), // 26: seaweedfs.block.control.DeleteVolumeRequest + (*DeleteVolumeResponse)(nil), // 27: seaweedfs.block.control.DeleteVolumeResponse + (*MarkVolumeDeletingRequest)(nil), // 28: seaweedfs.block.control.MarkVolumeDeletingRequest + (*MarkVolumeDeletingResponse)(nil), // 29: seaweedfs.block.control.MarkVolumeDeletingResponse + (*FailbackRequest)(nil), // 30: seaweedfs.block.control.FailbackRequest + (*FailbackResponse)(nil), // 31: seaweedfs.block.control.FailbackResponse + (*timestamp.Timestamp)(nil), // 32: google.protobuf.Timestamp } var file_control_proto_depIdxs = []int32{ - 30, // 0: seaweedfs.block.control.HeartbeatReport.sent_at:type_name -> google.protobuf.Timestamp + 32, // 0: seaweedfs.block.control.HeartbeatReport.sent_at:type_name -> google.protobuf.Timestamp 1, // 1: seaweedfs.block.control.HeartbeatReport.slots:type_name -> seaweedfs.block.control.HeartbeatSlot 2, // 2: seaweedfs.block.control.HeartbeatSlot.frontends:type_name -> seaweedfs.block.control.FrontendTarget - 30, // 3: seaweedfs.block.control.HeartbeatAck.accepted_at:type_name -> google.protobuf.Timestamp - 30, // 4: seaweedfs.block.control.ClusterEventAck.accepted_at:type_name -> google.protobuf.Timestamp + 32, // 3: seaweedfs.block.control.HeartbeatAck.accepted_at:type_name -> google.protobuf.Timestamp + 32, // 4: seaweedfs.block.control.ClusterEventAck.accepted_at:type_name -> google.protobuf.Timestamp 6, // 5: seaweedfs.block.control.AssignmentFact.peers:type_name -> seaweedfs.block.control.ReplicaDescriptor 2, // 6: seaweedfs.block.control.StatusResponse.frontends:type_name -> seaweedfs.block.control.FrontendTarget 10, // 7: seaweedfs.block.control.StatusResponse.unhealthy_replicas:type_name -> seaweedfs.block.control.ReplicaUnhealthy - 30, // 8: seaweedfs.block.control.ClusterStatusResponse.captured_at:type_name -> google.protobuf.Timestamp + 32, // 8: seaweedfs.block.control.ClusterStatusResponse.captured_at:type_name -> google.protobuf.Timestamp 18, // 9: seaweedfs.block.control.ClusterStatusResponse.nodes:type_name -> seaweedfs.block.control.NodeEvidence 19, // 10: seaweedfs.block.control.ClusterStatusResponse.volumes:type_name -> seaweedfs.block.control.VolumeEvidence 16, // 11: seaweedfs.block.control.ClusterStatusResponse.conditions:type_name -> seaweedfs.block.control.ObservationCondition 21, // 12: seaweedfs.block.control.ClusterStatusResponse.events:type_name -> seaweedfs.block.control.ClusterEvent - 30, // 13: seaweedfs.block.control.NodeEvidence.last_heartbeat_at:type_name -> google.protobuf.Timestamp + 32, // 13: seaweedfs.block.control.NodeEvidence.last_heartbeat_at:type_name -> google.protobuf.Timestamp 16, // 14: seaweedfs.block.control.NodeEvidence.conditions:type_name -> seaweedfs.block.control.ObservationCondition 20, // 15: seaweedfs.block.control.VolumeEvidence.replicas:type_name -> seaweedfs.block.control.ReplicaEvidence 16, // 16: seaweedfs.block.control.VolumeEvidence.conditions:type_name -> seaweedfs.block.control.ObservationCondition 16, // 17: seaweedfs.block.control.ReplicaEvidence.conditions:type_name -> seaweedfs.block.control.ObservationCondition - 30, // 18: seaweedfs.block.control.ClusterEvent.event_time:type_name -> google.protobuf.Timestamp - 30, // 19: seaweedfs.block.control.ListVolumesResponse.captured_at:type_name -> google.protobuf.Timestamp + 32, // 18: seaweedfs.block.control.ClusterEvent.event_time:type_name -> google.protobuf.Timestamp + 32, // 19: seaweedfs.block.control.ListVolumesResponse.captured_at:type_name -> google.protobuf.Timestamp 19, // 20: seaweedfs.block.control.ListVolumesResponse.volumes:type_name -> seaweedfs.block.control.VolumeEvidence - 30, // 21: seaweedfs.block.control.VolumeTimelineResponse.captured_at:type_name -> google.protobuf.Timestamp + 32, // 21: seaweedfs.block.control.VolumeTimelineResponse.captured_at:type_name -> google.protobuf.Timestamp 21, // 22: seaweedfs.block.control.VolumeTimelineResponse.events:type_name -> seaweedfs.block.control.ClusterEvent 0, // 23: seaweedfs.block.control.ObservationService.ReportHeartbeat:input_type -> seaweedfs.block.control.HeartbeatReport 21, // 24: seaweedfs.block.control.ObservationService.ReportClusterEvent:input_type -> seaweedfs.block.control.ClusterEvent @@ -3442,21 +3554,23 @@ var file_control_proto_depIdxs = []int32{ 15, // 31: seaweedfs.block.control.ClusterEvidenceService.WatchClusterEvents:input_type -> seaweedfs.block.control.WatchClusterEventsRequest 24, // 32: seaweedfs.block.control.LifecycleService.CreateVolume:input_type -> seaweedfs.block.control.CreateVolumeRequest 26, // 33: seaweedfs.block.control.LifecycleService.DeleteVolume:input_type -> seaweedfs.block.control.DeleteVolumeRequest - 28, // 34: seaweedfs.block.control.FailbackService.ExecuteFailback:input_type -> seaweedfs.block.control.FailbackRequest - 3, // 35: seaweedfs.block.control.ObservationService.ReportHeartbeat:output_type -> seaweedfs.block.control.HeartbeatAck - 4, // 36: seaweedfs.block.control.ObservationService.ReportClusterEvent:output_type -> seaweedfs.block.control.ClusterEventAck - 7, // 37: seaweedfs.block.control.AssignmentService.SubscribeAssignments:output_type -> seaweedfs.block.control.AssignmentFact - 9, // 38: seaweedfs.block.control.EvidenceService.QueryVolumeStatus:output_type -> seaweedfs.block.control.StatusResponse - 17, // 39: seaweedfs.block.control.ClusterEvidenceService.GetClusterStatus:output_type -> seaweedfs.block.control.ClusterStatusResponse - 22, // 40: seaweedfs.block.control.ClusterEvidenceService.ListVolumes:output_type -> seaweedfs.block.control.ListVolumesResponse - 19, // 41: seaweedfs.block.control.ClusterEvidenceService.GetVolumeStatus:output_type -> seaweedfs.block.control.VolumeEvidence - 23, // 42: seaweedfs.block.control.ClusterEvidenceService.GetVolumeTimeline:output_type -> seaweedfs.block.control.VolumeTimelineResponse - 21, // 43: seaweedfs.block.control.ClusterEvidenceService.WatchClusterEvents:output_type -> seaweedfs.block.control.ClusterEvent - 25, // 44: seaweedfs.block.control.LifecycleService.CreateVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse - 27, // 45: seaweedfs.block.control.LifecycleService.DeleteVolume:output_type -> seaweedfs.block.control.DeleteVolumeResponse - 29, // 46: seaweedfs.block.control.FailbackService.ExecuteFailback:output_type -> seaweedfs.block.control.FailbackResponse - 35, // [35:47] is the sub-list for method output_type - 23, // [23:35] is the sub-list for method input_type + 28, // 34: seaweedfs.block.control.LifecycleService.MarkVolumeDeleting:input_type -> seaweedfs.block.control.MarkVolumeDeletingRequest + 30, // 35: seaweedfs.block.control.FailbackService.ExecuteFailback:input_type -> seaweedfs.block.control.FailbackRequest + 3, // 36: seaweedfs.block.control.ObservationService.ReportHeartbeat:output_type -> seaweedfs.block.control.HeartbeatAck + 4, // 37: seaweedfs.block.control.ObservationService.ReportClusterEvent:output_type -> seaweedfs.block.control.ClusterEventAck + 7, // 38: seaweedfs.block.control.AssignmentService.SubscribeAssignments:output_type -> seaweedfs.block.control.AssignmentFact + 9, // 39: seaweedfs.block.control.EvidenceService.QueryVolumeStatus:output_type -> seaweedfs.block.control.StatusResponse + 17, // 40: seaweedfs.block.control.ClusterEvidenceService.GetClusterStatus:output_type -> seaweedfs.block.control.ClusterStatusResponse + 22, // 41: seaweedfs.block.control.ClusterEvidenceService.ListVolumes:output_type -> seaweedfs.block.control.ListVolumesResponse + 19, // 42: seaweedfs.block.control.ClusterEvidenceService.GetVolumeStatus:output_type -> seaweedfs.block.control.VolumeEvidence + 23, // 43: seaweedfs.block.control.ClusterEvidenceService.GetVolumeTimeline:output_type -> seaweedfs.block.control.VolumeTimelineResponse + 21, // 44: seaweedfs.block.control.ClusterEvidenceService.WatchClusterEvents:output_type -> seaweedfs.block.control.ClusterEvent + 25, // 45: seaweedfs.block.control.LifecycleService.CreateVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse + 27, // 46: seaweedfs.block.control.LifecycleService.DeleteVolume:output_type -> seaweedfs.block.control.DeleteVolumeResponse + 29, // 47: seaweedfs.block.control.LifecycleService.MarkVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 31, // 48: seaweedfs.block.control.FailbackService.ExecuteFailback:output_type -> seaweedfs.block.control.FailbackResponse + 36, // [36:49] is the sub-list for method output_type + 23, // [23:36] is the sub-list for method input_type 23, // [23:23] is the sub-list for extension type_name 23, // [23:23] is the sub-list for extension extendee 0, // [0:23] is the sub-list for field type_name @@ -3805,7 +3919,7 @@ func file_control_proto_init() { } } file_control_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FailbackRequest); i { + switch v := v.(*MarkVolumeDeletingRequest); i { case 0: return &v.state case 1: @@ -3817,6 +3931,30 @@ func file_control_proto_init() { } } file_control_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MarkVolumeDeletingResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_control_proto_msgTypes[30].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FailbackRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_control_proto_msgTypes[31].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*FailbackResponse); i { case 0: return &v.state @@ -3835,7 +3973,7 @@ func file_control_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_control_proto_rawDesc, NumEnums: 0, - NumMessages: 30, + NumMessages: 32, NumExtensions: 0, NumServices: 6, }, diff --git a/seaweed-block/core/rpc/control/control_grpc.pb.go b/seaweed-block/core/rpc/control/control_grpc.pb.go index 96e774c783..782938a259 100644 --- a/seaweed-block/core/rpc/control/control_grpc.pb.go +++ b/seaweed-block/core/rpc/control/control_grpc.pb.go @@ -665,8 +665,9 @@ var ClusterEvidenceService_ServiceDesc = grpc.ServiceDesc{ } const ( - LifecycleService_CreateVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/CreateVolume" - LifecycleService_DeleteVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/DeleteVolume" + LifecycleService_CreateVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/CreateVolume" + LifecycleService_DeleteVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/DeleteVolume" + LifecycleService_MarkVolumeDeleting_FullMethodName = "/seaweedfs.block.control.LifecycleService/MarkVolumeDeleting" ) // LifecycleServiceClient is the client API for LifecycleService service. @@ -675,6 +676,13 @@ const ( type LifecycleServiceClient interface { CreateVolume(ctx context.Context, in *CreateVolumeRequest, opts ...grpc.CallOption) (*CreateVolumeResponse, error) DeleteVolume(ctx context.Context, in *DeleteVolumeRequest, opts ...grpc.CallOption) (*DeleteVolumeResponse, error) + // MarkVolumeDeleting is the admission of a chunk volume delete: under + // the same locks as every assignment, placement and binding write it + // refuses (FAILED_PRECONDITION) a volume with live or pending authority, + // and otherwise marks the lifecycle record deleting, after which no new + // assignment, placement or binding is admitted and the id is never + // created again. + MarkVolumeDeleting(ctx context.Context, in *MarkVolumeDeletingRequest, opts ...grpc.CallOption) (*MarkVolumeDeletingResponse, error) } type lifecycleServiceClient struct { @@ -703,12 +711,28 @@ func (c *lifecycleServiceClient) DeleteVolume(ctx context.Context, in *DeleteVol return out, nil } +func (c *lifecycleServiceClient) MarkVolumeDeleting(ctx context.Context, in *MarkVolumeDeletingRequest, opts ...grpc.CallOption) (*MarkVolumeDeletingResponse, error) { + out := new(MarkVolumeDeletingResponse) + err := c.cc.Invoke(ctx, LifecycleService_MarkVolumeDeleting_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // LifecycleServiceServer is the server API for LifecycleService service. // All implementations must embed UnimplementedLifecycleServiceServer // for forward compatibility type LifecycleServiceServer interface { CreateVolume(context.Context, *CreateVolumeRequest) (*CreateVolumeResponse, error) DeleteVolume(context.Context, *DeleteVolumeRequest) (*DeleteVolumeResponse, error) + // MarkVolumeDeleting is the admission of a chunk volume delete: under + // the same locks as every assignment, placement and binding write it + // refuses (FAILED_PRECONDITION) a volume with live or pending authority, + // and otherwise marks the lifecycle record deleting, after which no new + // assignment, placement or binding is admitted and the id is never + // created again. + MarkVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) mustEmbedUnimplementedLifecycleServiceServer() } @@ -722,6 +746,9 @@ func (UnimplementedLifecycleServiceServer) CreateVolume(context.Context, *Create func (UnimplementedLifecycleServiceServer) DeleteVolume(context.Context, *DeleteVolumeRequest) (*DeleteVolumeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteVolume not implemented") } +func (UnimplementedLifecycleServiceServer) MarkVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method MarkVolumeDeleting not implemented") +} func (UnimplementedLifecycleServiceServer) mustEmbedUnimplementedLifecycleServiceServer() {} // UnsafeLifecycleServiceServer may be embedded to opt out of forward compatibility for this service. @@ -771,6 +798,24 @@ func _LifecycleService_DeleteVolume_Handler(srv interface{}, ctx context.Context return interceptor(ctx, in, info, handler) } +func _LifecycleService_MarkVolumeDeleting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MarkVolumeDeletingRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LifecycleServiceServer).MarkVolumeDeleting(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: LifecycleService_MarkVolumeDeleting_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LifecycleServiceServer).MarkVolumeDeleting(ctx, req.(*MarkVolumeDeletingRequest)) + } + return interceptor(ctx, in, info, handler) +} + // LifecycleService_ServiceDesc is the grpc.ServiceDesc for LifecycleService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -786,6 +831,10 @@ var LifecycleService_ServiceDesc = grpc.ServiceDesc{ MethodName: "DeleteVolume", Handler: _LifecycleService_DeleteVolume_Handler, }, + { + MethodName: "MarkVolumeDeleting", + Handler: _LifecycleService_MarkVolumeDeleting_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "control.proto", diff --git a/seaweed-block/core/rpc/proto/control.proto b/seaweed-block/core/rpc/proto/control.proto index 8841d72118..defa92a336 100644 --- a/seaweed-block/core/rpc/proto/control.proto +++ b/seaweed-block/core/rpc/proto/control.proto @@ -84,6 +84,13 @@ service ClusterEvidenceService { service LifecycleService { rpc CreateVolume(CreateVolumeRequest) returns (CreateVolumeResponse); rpc DeleteVolume(DeleteVolumeRequest) returns (DeleteVolumeResponse); + // MarkVolumeDeleting is the admission of a chunk volume delete: under + // the same locks as every assignment, placement and binding write it + // refuses (FAILED_PRECONDITION) a volume with live or pending authority, + // and otherwise marks the lifecycle record deleting, after which no new + // assignment, placement or binding is admitted and the id is never + // created again. + rpc MarkVolumeDeleting(MarkVolumeDeletingRequest) returns (MarkVolumeDeletingResponse); } // FailbackService — disabled-by-default authority failback endpoint. @@ -404,6 +411,16 @@ message DeleteVolumeRequest { message DeleteVolumeResponse { } +message MarkVolumeDeletingRequest { + string volume_id = 1; +} + +message MarkVolumeDeletingResponse { + // known is false when the master has no lifecycle record for the volume + // (it then only checked that no authority is live or pending). + bool known = 1; +} + message FailbackRequest { string volume_id = 1; string replica_id = 2; diff --git a/seaweed-block/core/storage/chunk_public.go b/seaweed-block/core/storage/chunk_public.go index 2a06bf0323..aac1685333 100644 --- a/seaweed-block/core/storage/chunk_public.go +++ b/seaweed-block/core/storage/chunk_public.go @@ -27,6 +27,7 @@ const ( ChunkHeadActive = chunkHeadActive ChunkHeadDetached = chunkHeadDetached ChunkHeadAborted = chunkHeadAborted + ChunkHeadDeleting = chunkHeadDeleting ChunkHeadDeleted = chunkHeadDeleted ) @@ -45,6 +46,7 @@ const ( var ( ErrChunkKeyExists = errChunkKeyExists ErrChunkHeadPrecondition = errChunkHeadPrecondition + ErrChunkHeadDeleted = errChunkHeadDeleted ErrChunkLayerFenced = errChunkLayerFenced ErrChunkEvictRefused = errChunkEvictRefused ErrChunkCaptureRefused = errChunkCaptureRefused diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index 70d3baf2ce..858dcf3e41 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -203,9 +203,14 @@ type chunkDetachedBy struct { // 2026-11-15 17:30Z). Such a volume never attaches. const chunkHeadAborted = "aborted" -// chunkHeadDeleted marks a deleted volume's HEAD tombstone (no chunks, so -// nothing it held stays a GC root). Such a volume never attaches again. -const chunkHeadDeleted = "deleted" +// chunkHeadDeleting marks a volume a delete has admitted (chunks kept, so +// the delete can still be given back); chunkHeadDeleted is the final +// tombstone (no chunks, so nothing it held stays a GC root). Neither is +// ever moved by CASHead, so no attach, claim or restore can revive them. +const ( + chunkHeadDeleting = "deleting" + chunkHeadDeleted = "deleted" +) func chunkHeadIsDetached(h chunkHead) bool { return h.State == chunkHeadDetached } @@ -471,6 +476,7 @@ var ( errChunkLayerNotImplemented = errors.New("storage: chunk layer not implemented") errChunkKeyExists = errors.New("storage: chunk key already exists") errChunkHeadPrecondition = errors.New("storage: chunk HEAD precondition failed") + errChunkHeadDeleted = errors.New("storage: chunk HEAD is being deleted or deleted") errChunkLayerFenced = errors.New("storage: chunk layer fenced") errChunkEvictRefused = errors.New("storage: chunk eviction refused") errChunkCaptureRefused = errors.New("storage: chunk capture refused") From dfc8f19ef1d27e35b868fe33c5459167d9f00514 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 19:31:09 -0800 Subject: [PATCH 04/16] 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) { From 77d238ce59ecfff62698ecb76fe6a255106a8eb4 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 19:54:32 -0800 Subject: [PATCH 05/16] volume delete: RED controls for the r2 review Review of dfc8f19 (codex01, V:/share/rdma/codex01-block152-r2-review- 20261116T0342Z/REVIEW.md). Controls failing against stubs restoring the reviewed behaviour: - P1: an unknown id's admission and a known record's ordinary DeleteVolume leave CreateVolume free, also after a restart (TestMarkVolumeDeleting_ReservesUnknownIdsAndSurvivesDeleteAndRestart). - P2 persistence: the mark is intent-only (no write/sync); write, rename and directory-sync faults and a restart lose it (TestDeletionReservations_*). - P2 rollback: a give-back (claim, held HEAD) leaves the master exclusion in place; a lost admission response reads as a refusal (TestCatalog_DeleteVolumeGivesBackOnALiveClaim, ...HeldAfterAdmission GivesBack, ...LostAdmissionResponse, TestOpsChunk_VolumeDelete with a real master: claim refusal must leave the id usable). - P2 failed abort: B's failed tombstone write still frees the name, so A's late publication survives a completed delete (TestCatalog_FailedAbortCannotHideALatePublication). - P2 concurrent deletes: D1's revert after D2 committed counts as a give-back (TestCatalog_ConcurrentDeleteCannotRollBackACommittedOne). Co-Authored-By: Claude Opus 5.5 --- .../cmd/sw-block/chunk_volume_delete.go | 58 ++- .../cmd/sw-block/chunk_volume_delete_test.go | 62 ++- .../core/frontend/chunkstore/catalog.go | 23 +- .../core/frontend/chunkstore/chunk_remote.go | 8 +- .../core/frontend/chunkstore/volume_delete.go | 187 ++++++-- .../frontend/chunkstore/volume_delete_test.go | 218 +++++++++- seaweed-block/core/host/master/host.go | 7 + .../core/host/master/launcher_plan.go | 2 +- .../core/host/master/product_loop.go | 2 +- seaweed-block/core/host/master/services.go | 88 +++- .../core/host/master/volume_deleting_test.go | 125 ++++-- .../core/host/master/workspace_binding.go | 7 +- .../core/host/master/workspace_service.go | 2 +- .../core/lifecycle/deletion_reservations.go | 249 +++++++++++ .../lifecycle/deletion_reservations_test.go | 98 +++++ seaweed-block/core/lifecycle/reconciler.go | 3 - seaweed-block/core/lifecycle/store.go | 31 -- seaweed-block/core/rpc/control/control.pb.go | 400 ++++++++++-------- .../core/rpc/control/control_grpc.pb.go | 110 ++++- seaweed-block/core/rpc/proto/control.proto | 26 +- seaweed-block/core/storage/chunk_public.go | 1 + seaweed-block/core/storage/chunk_seam.go | 3 + 22 files changed, 1358 insertions(+), 352 deletions(-) create mode 100644 seaweed-block/core/lifecycle/deletion_reservations.go create mode 100644 seaweed-block/core/lifecycle/deletion_reservations_test.go diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete.go b/seaweed-block/cmd/sw-block/chunk_volume_delete.go index 6d6497b916..1c64d169ac 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -2,6 +2,8 @@ package main import ( "context" + "crypto/rand" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -9,7 +11,9 @@ import ( "time" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/status" "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" "github.com/seaweedfs/seaweed-block/core/ops" @@ -53,10 +57,9 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { return chunkResult("volume-delete", nil, err, stdout, stderr) } defer conn.Close() - lifecycle := control.NewLifecycleServiceClient(conn) - admit := func(ctx context.Context, vol string) error { - _, err := lifecycle.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: vol}) - return err + admit, err := newMasterAdmission(control.NewLifecycleServiceClient(conn)) + if err != nil { + return chunkResult("volume-delete", nil, err, stdout, stderr) } ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -67,6 +70,53 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { return chunkResult("volume-delete", res, nil, stdout, stderr) } +// masterAdmission is the delete's reservation at the blockmaster, under +// one random token per delete. +type masterAdmission struct { + lc control.LifecycleServiceClient + token string +} + +func newMasterAdmission(lc control.LifecycleServiceClient) (*masterAdmission, error) { + var b [12]byte + if _, err := rand.Read(b[:]); err != nil { + return nil, err + } + return &masterAdmission{lc: lc, token: hex.EncodeToString(b[:])}, nil +} + +func (m *masterAdmission) req(vol string) *control.MarkVolumeDeletingRequest { + return &control.MarkVolumeDeletingRequest{VolumeId: vol, Token: m.token} +} + +// admissionErr: FailedPrecondition and InvalidArgument are definite +// refusals; anything else (unavailable, deadline, a lost response) leaves +// the outcome unknown. +func admissionErr(err error) error { + switch status.Code(err) { + case codes.OK: + return nil + case codes.FailedPrecondition, codes.InvalidArgument: + return fmt.Errorf("%w: %v", chunkstore.ErrNotAdmitted, err) + } + return err +} + +func (m *masterAdmission) Admit(ctx context.Context, vol string) error { + _, err := m.lc.MarkVolumeDeleting(ctx, m.req(vol)) + return admissionErr(err) +} + +func (m *masterAdmission) Commit(ctx context.Context, vol string) error { + _, err := m.lc.CommitVolumeDeleting(ctx, m.req(vol)) + return err +} + +func (m *masterAdmission) Abort(ctx context.Context, vol string) error { + _, err := m.lc.AbortVolumeDeleting(ctx, m.req(vol)) + return err +} + // volumeDeletePartial prints what a failed delete did, with the error, and // fails. func volumeDeletePartial(res chunkstore.VolumeDeleteResult, err error, stdout, stderr io.Writer) int { diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go index 9ffc0cca1e..1378988546 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go @@ -7,8 +7,14 @@ import ( "testing" "time" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/status" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" "github.com/seaweedfs/seaweed-block/core/host/master" + "github.com/seaweedfs/seaweed-block/core/rpc/control" "github.com/seaweedfs/seaweed-block/core/storage" ) @@ -73,8 +79,44 @@ func TestOpsChunk_VolumeDelete(t *testing.T) { chunkstore.VolumeDeleteResult Error *chunkErrBody `json:"error"` } - if code == 0 || json.Unmarshal([]byte(out), &partial) != nil || partial.Error == nil || partial.Error.Code != chunkstore.CodeVolumeInUse || !partial.Admitted || partial.HeadMarked || partial.Completed { - t.Fatalf("delete of attached v2: %d %q; want volume_in_use with the partial result", code, out) + if code == 0 || json.Unmarshal([]byte(out), &partial) != nil || partial.Error == nil || partial.Error.Code != chunkstore.CodeVolumeInUse || !partial.Admitted || !partial.AdmissionAborted || partial.HeadMarked || partial.Completed { + t.Fatalf("delete of attached v2: %d %q; want volume_in_use with the partial result, admission given back", code, out) + } + lc := lifecycleClient(t, h.Addr()) + // The given-back id is usable at the master again. + if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v2", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatalf("create v2 after its delete gave back: %v", err) + } + + // Integrated claim refusal: v3 has a snapshot a real, incomplete fork + // claims (VOLUME published, stopped before HEAD by its deadline). + if _, err := cat.EnsureVolume(ctx, "v3", geo); err != nil { + t.Fatal(err) + } + h3, _, err := cat.ReadHead(ctx, "v3") + if err != nil { + t.Fatal(err) + } + if _, err := cat.CreateSnapshot(ctx, "v3", chunkstore.SnapshotRequest{Name: "s", RequestID: "rs"}, h3); err != nil { + t.Fatal(err) + } + clock := time.Now() + cat.SetClock(func() time.Time { clock = clock.Add(time.Second); return clock }) + cat.OpDeadline = time.Nanosecond + if _, err := cat.Fork(ctx, chunkstore.ForkRequest{Source: "v3", Snapshot: "s", Target: "w3", RequestID: "f"}); chunkstore.CodeOf(err) != chunkstore.CodeDeadlineExceeded { + t.Fatalf("stopped fork: %v", err) + } + cat.OpDeadline = 0 + code, out, _ = runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v3") + partial.Error = nil + if code == 0 || json.Unmarshal([]byte(out), &partial) != nil || partial.Error == nil || partial.Error.Code != chunkstore.CodeSnapshotClaimed || !partial.Reverted || !partial.AdmissionAborted { + t.Fatalf("delete of claimed v3: %d %q; want snapshot_claimed, reverted, admission given back", code, out) + } + if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v3", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatalf("create v3 after the claim refusal: %v; want usable again", err) + } + if _, err := cat.EnsureVolume(ctx, "v3", geo); err != nil { + t.Fatalf("attach v3 after the claim refusal: %v; want usable again", err) } code, out, errs := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v1") var res chunkstore.VolumeDeleteResult @@ -84,4 +126,20 @@ func TestOpsChunk_VolumeDelete(t *testing.T) { if _, err := cat.EnsureVolume(ctx, "v1", geo); chunkstore.CodeOf(err) != chunkstore.CodeVolumeDeleted { t.Fatalf("recreate v1: %v; want volume_deleted", err) } + if !res.Committed { + t.Fatalf("delete v1: %+v; want committed", res) + } + if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v1", SizeBytes: 1 << 20, ReplicationFactor: 1}); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("create v1 after its committed delete: %v; want FailedPrecondition", err) + } +} + +func lifecycleClient(t *testing.T, addr string) control.LifecycleServiceClient { + t.Helper() + c, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { c.Close() }) + return control.NewLifecycleServiceClient(c) } diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index c6c4241eea..9859db5955 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -853,7 +853,17 @@ func (c *Catalog) CreateSnapshot(ctx context.Context, vol string, req SnapshotRe if gone, err := c.volumeGone(ctx, vol); err != nil { return SnapshotInfo{}, err } else if gone { - c.abandonUnpublished(ctx, vol, root, req.Name, attempt) + // 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) + } return SnapshotInfo{}, refuseDeleted(vol, "it cannot be snapshotted") } @@ -1358,17 +1368,6 @@ func (c *Catalog) dropForkClaim(ctx context.Context, req ForkRequest, attempt st _, _ = c.removeForkClaim(ctx, req, attempt) } -// abandonUnpublished gives up an attempt that was never published: an -// aborted tombstone at its path (so a late create cannot land), then the -// name freed while it names that attempt (best effort; a delete's own pass -// does the same). -func (c *Catalog) abandonUnpublished(ctx context.Context, vol, root, name, attempt string) { - if tomb, err := c.abortedSnapEntry(vol, name, attempt); err == nil { - _ = c.f.CreateEntry(ctx, path.Join(root, snapsDir, name), tomb, true) - } - _, _, _ = c.freeName(ctx, root, name, attempt) -} - // removeForkClaim removes fork req's claim from its parent attempt and // reports whether this call confirmed its removal (false with no error: // the claim was not there). diff --git a/seaweed-block/core/frontend/chunkstore/chunk_remote.go b/seaweed-block/core/frontend/chunkstore/chunk_remote.go index 9adb0ddcb8..882a3df71e 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 current.State == storage.ChunkHeadDeleting || current.State == storage.ChunkHeadDeleted { + if current.State == storage.ChunkHeadDeleting || current.State == storage.ChunkHeadPurging || 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) @@ -502,9 +502,9 @@ func decodeHeadDoc(p string, content []byte) (storage.ChunkHead, error) { if doc.DetachedBy != nil || len(doc.Chunks) != 0 { return fail("an aborted HEAD with content") } - case storage.ChunkHeadDeleting: - // A delete's linearization mark over the HEAD it read: content and - // any detach record kept (a revert restores them). + case storage.ChunkHeadDeleting, storage.ChunkHeadPurging: + // A delete's mark over the HEAD it read (deleting: still revertible; + // purging: committed): content and any detach record kept. case storage.ChunkHeadDeleted: // A deleted volume's tombstone (no chunks, no holder). if doc.DetachedBy != nil || len(doc.Chunks) != 0 || doc.Holder != "" { diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go index 8f8be4099e..fd95e4ef06 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -15,10 +15,12 @@ import ( // Volume delete (claude05's item, 2026-11-16 02:39Z; one linearization // point per codex01's review of 7c43367). // -// (a) Admission: the caller's Admission (the CLI's is the blockmaster's -// MarkVolumeDeleting: refused while the volume has live or pending -// authority; once it passes, no new assignment, placement or binding -// is admitted and the id is never created again). +// (a) Admission: the caller's Admission (the CLI's: the blockmaster's +// durable deletion reservation, MarkVolumeDeleting; refused while the +// volume has live or pending authority; while held, no new assignment, +// placement or binding is admitted and the id is not created again). +// Every give-back below aborts this delete's admission (restoring the +// volume's usability); the commit point commits it (permanent). // (b) The linearization point: one conditional write of HEAD from the // HEAD read (active or detached, NOT held: an active HEAD that names a // holder belongs to an attached server) to state deleting, chunks @@ -30,6 +32,11 @@ import ( // previous state (nothing irreversible was done) and refuses // (snapshot_claimed). A fork claiming later sees the deleting HEAD // and gives its claim back. +// (c') The commit point: HEAD deleting -> purging, conditioned on the +// HEAD read, then the admission is committed. A revert and a commit +// race on the same conditional write, so a delete that sampled a +// claim can never undo another delete's irreversible steps, and a +// delete whose mark was given back never starts them. // (d) Only then the irreversible steps: every snapshot name, published or // not (an unpublished attempt gets an aborted tombstone so its late // publish cannot land), is marked through markDeleting (the one mark @@ -52,24 +59,42 @@ const ( // Test seams (retainHook stages) in a DeleteVolume. hookHeadMarked = "head-marked" // after (b) - hookClaimsChecked = "claims-checked" // after (c) + hookClaimFound = "claim-found" // (c) found a live claim, before the revert + hookClaimsChecked = "claims-checked" // after (c), before the commit point ) -// Admission admits a volume delete before anything is written; its error -// refuses the delete (volume_in_use). -type Admission func(ctx context.Context, vol string) error +// ErrNotAdmitted marks an Admission error that is a definite refusal +// (nothing was recorded). Any other Admission error leaves the outcome +// unknown. +var ErrNotAdmitted = errors.New("chunkstore: volume delete not admitted") + +// Admission is the delete's reservation outside the catalog (the CLI's is +// the blockmaster's). Admit before anything is written; Commit at the +// irreversible boundary; Abort when the delete gives back with no +// irreversible effect. +type Admission interface { + Admit(ctx context.Context, vol string) error + Commit(ctx context.Context, vol string) error + Abort(ctx context.Context, vol string) error +} // VolumeDeleteResult is what DeleteVolume did, also on failure. type VolumeDeleteResult struct { - VolumeID string `json:"volumeID"` - Replayed bool `json:"replayed"` // it was already deleted - Admitted bool `json:"admitted"` // (a) passed - HeadMarked bool `json:"headMarked"` // HEAD is deleting or deleted - Reverted bool `json:"reverted"` // (c) gave the HEAD mark back - SnapshotsDeleted []string `json:"snapshotsDeleted"` - AttemptsAborted []string `json:"attemptsAborted"` // unpublished attempts tombstoned - ClaimReleased bool `json:"claimReleased"` // its fork claim was confirmed removed - Completed bool `json:"completed"` // HEAD and VOLUME are deleted + VolumeID string `json:"volumeID"` + Replayed bool `json:"replayed"` // it was already deleted + Admitted bool `json:"admitted"` // (a) passed + // AdmissionUncertain: the admission call failed with an unknown + // outcome (it may have been recorded); AdmissionAborted: this delete + // gave its admission back; Committed: the admission is permanent. + AdmissionUncertain bool `json:"admissionUncertain"` + AdmissionAborted bool `json:"admissionAborted"` + Committed bool `json:"committed"` + HeadMarked bool `json:"headMarked"` // HEAD is deleting or deleted + Reverted bool `json:"reverted"` // (c) gave the HEAD mark back + SnapshotsDeleted []string `json:"snapshotsDeleted"` + AttemptsAborted []string `json:"attemptsAborted"` // unpublished attempts tombstoned + ClaimReleased bool `json:"claimReleased"` // its fork claim was confirmed removed + Completed bool `json:"completed"` // HEAD and VOLUME are deleted // Uncertain is set when the failing call was a write whose outcome is // unknown; a rerun settles it. Uncertain bool `json:"uncertain"` @@ -95,41 +120,83 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) return res, err } res.Replayed = v.State == VolumeDeleted && h.State == storage.ChunkHeadDeleted - marked := h.State == storage.ChunkHeadDeleting || h.State == storage.ChunkHeadDeleted - // (a) - if !marked && admit != nil { - if err := admit(ctx, vol); err != nil { - return res, catErr(CodeVolumeInUse, false, err, "volume %s: delete not admitted", vol) + // (a) Every call takes its own admission (a rerun too: it settles a + // 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 + return res, catErr(CodeVolumeInUse, false, err, "volume %s: delete not admitted", vol) + } + res.AdmissionUncertain, res.Uncertain = true, true + return res, catErr(CodeOutcomeUnknown, true, err, "volume %s: delete admission outcome unknown (it may be recorded); rerun the delete", vol) } } 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 + return res, catErr(CodeOutcomeUnknown, true, err, "volume %s: %v; giving the admission back failed, rerun the delete", vol, cause) + } + res.AdmissionAborted = true + } + return res, cause + } // (b) - if !marked { + if h.State != storage.ChunkHeadPurging && h.State != storage.ChunkHeadDeleted { u, err := c.markHeadDeleting(ctx, vol, root) if err != nil { - res.Uncertain = u - return res, err + if u { + res.Uncertain = true + return res, err + } + return giveBack(err) } - } - res.HeadMarked = true - c.hook(hookHeadMarked, vol) - // (c) - if h.State != storage.ChunkHeadDeleted { + res.HeadMarked = true + c.hook(hookHeadMarked, vol) + // (c) live, err := c.anyLiveClaim(ctx, vol) if err != nil { return res, err } if live != nil { - u, rerr := c.revertHeadDeleting(ctx, vol, root) - if rerr != nil { + c.hook(hookClaimFound, vol) + reverted, u, rerr := c.revertHeadDeleting(ctx, vol, root) + switch { + 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 + // 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) } res.Reverted, res.HeadMarked = true, false - return res, live + return giveBack(live) + } + c.hook(hookClaimsChecked, vol) + // (c') the commit point + committed, u, err := c.commitHeadPurging(ctx, vol, root) + if err != nil { + res.Uncertain = u + return res, err + } + if !committed { + res.HeadMarked = false + return giveBack(catErr(CodeOutcomeUnknown, true, nil, "volume %s: a concurrent delete gave the mark back; rerun the delete", vol)) } } - c.hook(hookClaimsChecked, vol) + res.HeadMarked = true + if admit != nil { + if err := admit.Commit(ctx, vol); err != nil { + res.Uncertain = true + return res, catErr(CodeOutcomeUnknown, true, err, "volume %s: committing the admission failed; rerun the delete", vol) + } + } + res.Committed = true // (d) names, err := c.listNames(ctx, root) if err != nil { @@ -182,7 +249,7 @@ func headHeld(h storage.ChunkHead) bool { // headDeletingOrDeleted reports a HEAD a delete has passed its // linearization point on. func headDeletingOrDeleted(h storage.ChunkHead) bool { - return h.State == storage.ChunkHeadDeleting || h.State == storage.ChunkHeadDeleted + return h.State == storage.ChunkHeadDeleting || h.State == storage.ChunkHeadPurging || h.State == storage.ChunkHeadDeleted } // writeHead writes next over the HEAD read as cur (an exclusive create when @@ -241,15 +308,17 @@ func (c *Catalog) markHeadDeleting(ctx context.Context, vol, root string) (bool, } // revertHeadDeleting gives (b) back: deleting returns to detached when the -// HEAD carries its holder's detach record, else to active. -func (c *Catalog) revertHeadDeleting(ctx context.Context, vol, root string) (bool, error) { +// HEAD carries its holder's detach record, else to active. reverted is +// false when the HEAD is no longer deleting (another delete committed, or +// already gave it back). +func (c *Catalog) revertHeadDeleting(ctx context.Context, vol, root string) (reverted, uncertain bool, err error) { for try := 0; try < 5; try++ { h, _, err := c.ReadHead(ctx, vol) if err != nil { - return false, err + return false, false, err } if h.State != storage.ChunkHeadDeleting { - return false, nil + return h.State == storage.ChunkHeadActive || h.State == storage.ChunkHeadDetached || h.State == "", false, nil } next := h next.State = storage.ChunkHeadActive @@ -264,11 +333,41 @@ func (c *Catalog) revertHeadDeleting(ctx context.Context, vol, root string) (boo continue } if err != nil { - return true, catErr(CodeOutcomeUnknown, true, err, "revert the delete mark on HEAD of %s: outcome unknown; rerun the delete", vol) + return false, true, catErr(CodeOutcomeUnknown, true, err, "revert the delete mark on HEAD of %s: outcome unknown; rerun the delete", vol) } - return false, nil + return true, false, nil } - return false, remoteErr(nil, "HEAD of %s kept changing", vol) + return false, false, remoteErr(nil, "HEAD of %s kept changing", vol) +} + +// commitHeadPurging is the commit point: deleting -> purging, conditioned +// on the HEAD read. committed is false when the mark was given back (the +// HEAD is active or detached again). +func (c *Catalog) commitHeadPurging(ctx context.Context, vol, root string) (committed, uncertain bool, err error) { + for try := 0; try < 5; try++ { + h, _, err := c.ReadHead(ctx, vol) + if err != nil { + return false, false, err + } + switch h.State { + case storage.ChunkHeadPurging, storage.ChunkHeadDeleted: + return true, false, nil // committed (by this call's earlier try or another delete) + case storage.ChunkHeadDeleting: + default: + return false, false, nil + } + next := h + next.State = storage.ChunkHeadPurging + err = c.writeHead(ctx, root, h, next) + if lostCondition(err) { + continue + } + if err != nil { + return false, true, catErr(CodeOutcomeUnknown, true, err, "commit the delete of %s: outcome unknown; rerun the delete", vol) + } + return true, false, nil + } + return false, false, remoteErr(nil, "HEAD of %s kept changing", vol) } // finishHeadDeleted is (e) for HEAD: deleting becomes deleted, no chunks. @@ -281,8 +380,8 @@ func (c *Catalog) finishHeadDeleted(ctx context.Context, vol, root string) (bool if h.State == storage.ChunkHeadDeleted { return false, nil } - if h.State != storage.ChunkHeadDeleting { - return false, remoteErr(nil, "HEAD of %s left the deleting state (%q)", vol, h.State) + if h.State != storage.ChunkHeadPurging { + return false, remoteErr(nil, "HEAD of %s is not committed for deletion (%q)", vol, h.State) } next := storage.ChunkHead{Epoch: h.Epoch, RemoteLSN: h.RemoteLSN, Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadDeleted} err = c.writeHead(ctx, root, h, next) diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go index a5fca1ab7a..c064dc7191 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go @@ -3,8 +3,10 @@ package chunkstore import ( "context" "errors" + "fmt" "path" "strings" + "sync" "testing" "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" @@ -88,10 +90,9 @@ func TestCatalog_DeleteVolumeRefusesAVolumeInUse(t *testing.T) { } detachHead(t, f, b, "v1") before = len(f.allWritten()) - refuse := func(context.Context, string) error { return errors.New("assigned to r1") } - res, err := c.DeleteVolume(ctx, "v1", refuse) + res, err := c.DeleteVolume(ctx, "v1", (&fakeReservation{refuse: true}).admission("d1")) var ce *CatalogError - if !errors.As(err, &ce) || ce.Code != CodeVolumeInUse || ce.Retryable || !strings.Contains(ce.Detail(), "assigned to r1") || res.Admitted { + if !errors.As(err, &ce) || ce.Code != CodeVolumeInUse || ce.Retryable || !strings.Contains(ce.Detail(), "assigned to r1") || res.Admitted || res.AdmissionUncertain { t.Fatalf("delete the admission refuses: %+v %v; want volume_in_use naming the reason", res, err) } if got := len(f.allWritten()); got != before { @@ -218,9 +219,13 @@ func TestCatalog_DeleteVolumeGivesBackOnALiveClaim(t *testing.T) { } } } - res, err := c.DeleteVolume(ctx, "v1", nil) - if CodeOf(err) != CodeSnapshotClaimed || !res.Reverted || res.HeadMarked || len(res.SnapshotsDeleted) != 0 { - t.Fatalf("delete under a live claim: %+v %v; want snapshot_claimed, reverted", res, err) + rsv := &fakeReservation{} + res, err := c.DeleteVolume(ctx, "v1", rsv.admission("d1")) + if CodeOf(err) != CodeSnapshotClaimed || !res.Reverted || res.HeadMarked || len(res.SnapshotsDeleted) != 0 || !res.AdmissionAborted || res.Committed { + t.Fatalf("delete under a live claim: %+v %v; want snapshot_claimed, reverted, admission given back", res, err) + } + if rsv.state != "" { + t.Fatalf("reservation after the give-back: %q; want none (the volume is usable again)", rsv.state) } after := headState(t, c, "v1") if after.State != storage.ChunkHeadDetached || after.DetachedBy == nil || after.Holder != before.Holder || len(after.Chunks) != len(before.Chunks) { @@ -359,8 +364,9 @@ func TestCatalog_DeleteVolumeTombstonesAndReleases(t *testing.T) { t.Fatalf("delete w3 with a failing claim removal: %+v %v; want an error, claim not released, uncertain", res, err) } f.failUpdate = nil - res, err = c.DeleteVolume(ctx, "w3", nil) - if err != nil || !res.ClaimReleased || !res.Completed { + rsv := &fakeReservation{} + res, err = c.DeleteVolume(ctx, "w3", rsv.admission("d3")) + if err != nil || !res.ClaimReleased || !res.Completed || !res.Committed || rsv.state != reservationCommitted { t.Fatalf("delete w3 rerun: %+v %v; want its claim released", res, err) } if got := claimsOf(t, c, "s2"); len(got) != 0 { @@ -371,6 +377,202 @@ func TestCatalog_DeleteVolumeTombstonesAndReleases(t *testing.T) { } } +// fakeReservation mirrors the blockmaster's deletion reservation (tokens, +// admitted/committed) for the catalog's Admission. +type fakeReservation struct { + mu sync.Mutex + state string + holders map[string]bool + refuse bool // Admit refuses (nothing recorded) + loseAdmit bool // Admit records, then its response is lost +} + +const ( + reservationAdmitted = "admitted" + reservationCommitted = "committed" +) + +type fakeAdmit struct { + r *fakeReservation + tok string +} + +func (r *fakeReservation) admission(tok string) Admission { return &fakeAdmit{r, tok} } + +func (a *fakeAdmit) Admit(context.Context, string) error { + a.r.mu.Lock() + defer a.r.mu.Unlock() + if a.r.refuse { + return fmt.Errorf("%w: assigned to r1", ErrNotAdmitted) + } + if a.r.holders == nil { + a.r.holders = map[string]bool{} + } + a.r.holders[a.tok] = true + if a.r.state == "" { + a.r.state = reservationAdmitted + } + if a.r.loseAdmit { + return errors.New("response lost") + } + return nil +} + +func (a *fakeAdmit) Commit(context.Context, string) error { + a.r.mu.Lock() + defer a.r.mu.Unlock() + if a.r.state != reservationCommitted && !a.r.holders[a.tok] { + return errors.New("token holds nothing") + } + a.r.state = reservationCommitted + return nil +} + +func (a *fakeAdmit) Abort(context.Context, string) error { + a.r.mu.Lock() + defer a.r.mu.Unlock() + if a.r.state == reservationCommitted { + return errors.New("committed") + } + delete(a.r.holders, a.tok) + if len(a.r.holders) == 0 { + a.r.state = "" + } + return nil +} + +// A held HEAD found after the admission gives the admission back. +func TestCatalog_DeleteVolumeHeldAfterAdmissionGivesBack(t *testing.T) { + _, _, c, _ := deleteFixture(t) // v1 is attached + rsv := &fakeReservation{} + res, err := c.DeleteVolume(context.Background(), "v1", rsv.admission("d1")) + if CodeOf(err) != CodeVolumeInUse || !res.Admitted || !res.AdmissionAborted || rsv.state != "" { + t.Fatalf("held after admission: %+v %v reservation=%q; want volume_in_use and the admission given back", res, err, rsv.state) + } +} + +// A lost admission response is reported as an unknown outcome (it may be +// recorded), never as a plain refusal, and nothing is written. +func TestCatalog_DeleteVolumeLostAdmissionResponse(t *testing.T) { + f, b, c, _ := deleteFixture(t) + detachHead(t, f, b, "v1") + before := len(f.allWritten()) + rsv := &fakeReservation{loseAdmit: true} + res, err := c.DeleteVolume(context.Background(), "v1", rsv.admission("d1")) + var ce *CatalogError + if !errors.As(err, &ce) || ce.Code != CodeOutcomeUnknown || !ce.Retryable || !res.AdmissionUncertain || !res.Uncertain || res.Admitted { + t.Fatalf("lost admission response: %+v %v; want outcome_unknown, admission uncertain", res, err) + } + if got := len(f.allWritten()); got != before || rsv.state != reservationAdmitted { + t.Fatalf("wrote %d entries; reservation %q (the lost admission did land)", got-before, rsv.state) + } +} + +// P2 (concurrent deletes): D1 samples a live claim and pauses before its +// revert; the fork completes, D2 joins the deleting HEAD, finds no claim, +// commits and deletes. D1's revert then finds the HEAD past the commit +// point: it neither reverts nor gives its admission back, and the +// reservation stays committed. +func TestCatalog_ConcurrentDeleteCannotRollBackACommittedOne(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + holdFirst(f, catBase+"/w3/HEAD") + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { + t.Fatalf("fork w3: %v", err) + } + rsv := &fakeReservation{} + var d2 VolumeDeleteResult + var d2err error + c.retainHook = func(stage, _ string) { + if stage != hookClaimFound { + return + } + c.retainHook = nil + // The fork completes (its claim is no longer live), then D2 runs. + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeVolumeDeleted { + // Its retry sees the deleting source and backs out; give the + // target a real HEAD as a completed fork would have. + t.Logf("fork retry during the delete: %v", err) + } + forceHead(t, f, b, "w3") + d2, d2err = c.DeleteVolume(ctx, "v1", rsv.admission("d2")) + } + d1, err := c.DeleteVolume(ctx, "v1", rsv.admission("d1")) + if d2err != nil || !d2.Completed { + t.Fatalf("D2: %+v %v; want completed", d2, d2err) + } + if err == nil || d1.Reverted || d1.AdmissionAborted { + t.Fatalf("D1 after D2 committed: %+v %v; want an error, no revert, no give-back", d1, err) + } + if h := headState(t, c, "v1"); h.State != storage.ChunkHeadDeleted { + t.Fatalf("HEAD after both: %+v; want deleted", h) + } + if rsv.state != reservationCommitted { + t.Fatalf("reservation %q; want committed", rsv.state) + } +} + +// forceHead installs a real active HEAD for vol (a completed fork's). +func forceHead(t *testing.T, f *fakeFiler, b *fakeBlobs, vol string) { + t.Helper() + f.mu.Lock() + defer f.mu.Unlock() + e, err := headEntry(storage.ChunkHead{Gen: 1, Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadActive}) + if err != nil { + t.Fatal(err) + } + f.entries[path.Join(catBase, vol, headName)] = e + _ = b +} + +// P2 (failed abort, late publication): snapshot A takes name s5 and parks +// before publishing; the delete marks HEAD; A's same-request retry B sees +// the mark and tries to abort the attempt, but the tombstone write fails: +// the name must stay (not freed), so the delete still finds and settles it +// and the late publication cannot leave an active root. +func TestCatalog_FailedAbortCannotHideALatePublication(t *testing.T) { + f, b, c, h := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + held := catBase + "/v1/" + snapsDir + "/s5/" + f.deferCreate = func(p string, _ *filerpb.Entry) bool { return strings.HasPrefix(p, held) } + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s5", RequestID: "r-s5"}, h); err == nil { + t.Fatal("A's held publication reported success") + } + f.deferCreate = nil + c.retainHook = func(stage, _ string) { + if stage != hookHeadMarked { + return + } + c.retainHook = nil + f.failCreate = func(p string) error { + if strings.HasPrefix(p, held) { + return errors.New("filer unavailable") + } + return nil + } + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s5", RequestID: "r-s5"}, h); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("B, the same request after the mark: %v; want volume_deleted", err) + } + f.failCreate = nil + if _, ok, _ := c.resolveSnap(ctx, "v1", "s5"); !ok { + t.Fatal("B freed s5's name although its abort failed") + } + } + res, err := c.DeleteVolume(ctx, "v1", nil) + if err != nil || !res.Completed { + t.Fatalf("delete: %+v %v", res, err) + } + f.releaseDeferredCreates() // A's publish finally runs + attempts, _ := f.ListEntries(ctx, held[:len(held)-1], "", "", 0) + for _, e := range attempts { + if s := string(e.Extended[extSnapState]); s == SnapActive { + t.Fatalf("an active s5 attempt %s survived the completed delete", e.GetName()) + } + } +} + func mustHead(t *testing.T, c *Catalog, vol string) storage.ChunkHead { t.Helper() h, has, err := c.ReadHead(context.Background(), vol) diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index a829f0a713..077d3bd3c9 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -89,6 +89,8 @@ type LifecycleStores struct { Nodes *lifecycle.NodeInventoryStore Placements *lifecycle.PlacementIntentStore WorkspaceBindings *lifecycle.WorkspaceBindingStore + // Deletions holds the chunk-volume deletion reservations. + Deletions *lifecycle.DeletionReservationStore } // Host is the composed master-side block product daemon. Lifecycle @@ -311,11 +313,16 @@ func openLifecycleStores(dir string) (*LifecycleStores, error) { if err != nil { return nil, err } + deletions, err := lifecycle.OpenDeletionReservationStore(filepath.Join(dir, "deletion-reservations")) + if err != nil { + return nil, err + } return &LifecycleStores{ Volumes: volumes, Nodes: nodes, Placements: placements, WorkspaceBindings: bindings, + Deletions: deletions, }, nil } diff --git a/seaweed-block/core/host/master/launcher_plan.go b/seaweed-block/core/host/master/launcher_plan.go index 7c6671f175..901fe070b5 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 { + if !ok || stores.Deletions.Reserved(placement.VolumeID) { result.SkippedMissingVolume++ continue } diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index 4b9bc82cfd..ae62d1aa6d 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -58,7 +58,7 @@ func (h *Host) RunLifecycleProductTick() (LifecycleProductTickResult, error) { return LifecycleProductTickResult{}, nil } nodes := stores.Nodes.ListNodes() - reconciled := lifecycle.ReconcilePlacement(stores.Volumes.ListVolumes(), nodes, stores.Placements) + reconciled := lifecycle.ReconcilePlacement(stores.liveVolumes(), nodes, stores.Placements) placements := stores.Placements.ListPlacements() verified := h.verifyPlacements(placements, nodes) result := LifecycleProductTickResult{ diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index f4f257d1fa..f6f4787896 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -56,6 +56,15 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe return nil, status.Error(codes.FailedPrecondition, "lifecycle store is not configured") } spec := lifecycleSpecFromWire(req) + // A reserved id (a chunk volume delete admitted or committed) is never + // 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 + 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) + } s.host.log.Printf("blockmaster: CreateVolume volume=%q protocol=%q replication_factor=%d pvc=%q namespace=%q", spec.VolumeID, spec.Protocol, spec.ReplicationFactor, spec.PVCName, spec.PVCNamespace) rec, err := stores.Volumes.CreateVolume(spec) if err != nil { @@ -135,17 +144,78 @@ func (s *services) MarkVolumeDeleting(ctx context.Context, req *control.MarkVolu return nil, lifecycleError("mark volume deleting", err) } _, placed := stores.Placements.GetPlacement(vol) - known := false + var res lifecycle.DeletionReservation + var persistErr error err = s.host.Publisher().RecordWorkspaceDeletion(ctx, vol, bound && placed, func() error { - found, e := stores.Volumes.MarkDeleting(vol) - known = found - return e + res, persistErr = stores.Deletions.Admit(vol, req.GetToken()) + return persistErr }) - if err != nil { + switch { + case persistErr != nil: + // The admission check passed; the reservation write failed or its + // outcome is unknown (the store keeps it in memory, fail closed). + return nil, status.Errorf(codes.Unavailable, "mark volume deleting: %v", persistErr) + case err != nil: return nil, status.Errorf(codes.FailedPrecondition, "mark volume deleting: %v", err) } - s.host.log.Printf("blockmaster: MarkVolumeDeleting volume=%q known=%t", vol, known) - return &control.MarkVolumeDeletingResponse{Known: known}, nil + _, known := stores.Volumes.GetVolume(vol) + s.host.log.Printf("blockmaster: MarkVolumeDeleting volume=%q known=%t state=%s", vol, known, res.State) + return &control.MarkVolumeDeletingResponse{Known: known, State: res.State}, nil +} + +// AbortVolumeDeleting gives a delete's admission back (the delete found it +// could not proceed and undid its own effects). A committed deletion is +// never given back (FAILED_PRECONDITION). +func (s *services) AbortVolumeDeleting(ctx context.Context, req *control.MarkVolumeDeletingRequest) (*control.MarkVolumeDeletingResponse, error) { + return s.settleVolumeDeleting(ctx, req, "abort", (*lifecycle.DeletionReservationStore).Abort) +} + +// CommitVolumeDeleting makes a delete's reservation permanent: the delete +// is about to take irreversible steps. +func (s *services) CommitVolumeDeleting(ctx context.Context, req *control.MarkVolumeDeletingRequest) (*control.MarkVolumeDeletingResponse, error) { + return s.settleVolumeDeleting(ctx, req, "commit", (*lifecycle.DeletionReservationStore).Commit) +} + +func (s *services) settleVolumeDeleting(ctx context.Context, req *control.MarkVolumeDeletingRequest, op string, + apply func(*lifecycle.DeletionReservationStore, string, string) (lifecycle.DeletionReservation, error)) (*control.MarkVolumeDeletingResponse, error) { + s.host.workspaceMu.Lock() + defer s.host.workspaceMu.Unlock() + if err := ctx.Err(); err != nil { + return nil, workspaceError(err) + } + stores := s.host.Lifecycle() + if stores == nil { + return nil, status.Error(codes.FailedPrecondition, "lifecycle store is not configured") + } + if req.GetVolumeId() == "" || req.GetToken() == "" { + return nil, status.Error(codes.InvalidArgument, "volume_id and token are required") + } + res, err := apply(stores.Deletions, req.GetVolumeId(), req.GetToken()) + switch { + case errors.Is(err, lifecycle.ErrReservationCommitted), errors.Is(err, lifecycle.ErrReservationToken): + return nil, status.Errorf(codes.FailedPrecondition, "%s volume deleting: %v", op, err) + case err != nil: + return nil, status.Errorf(codes.Unavailable, "%s volume deleting: %v", op, err) + } + s.host.log.Printf("blockmaster: %s VolumeDeleting volume=%q state=%s", op, req.GetVolumeId(), res.State) + state := res.State + if state == lifecycle.ReservationAdmitted && len(res.Tokens) == 0 { + state = "" + } + return &control.MarkVolumeDeletingResponse{State: state}, nil +} + +// liveVolumes is the desired volumes the placement reconciler may plan: +// every record whose id no delete has reserved. +func (st *LifecycleStores) liveVolumes() []lifecycle.VolumeRecord { + all := st.Volumes.ListVolumes() + out := all[:0:0] + for _, v := range all { + if !st.Deletions.Reserved(v.Spec.VolumeID) { + out = append(out, v) + } + } + return out } func (s *services) ExecuteFailback(ctx context.Context, req *control.FailbackRequest) (*control.FailbackResponse, error) { @@ -221,9 +291,7 @@ func lifecycleError(op string, err error) error { if errors.Is(err, lifecycle.ErrVolumeConflict) { return status.Errorf(codes.AlreadyExists, "%s: %v", op, err) } - if errors.Is(err, lifecycle.ErrVolumeDeleting) { - return status.Errorf(codes.FailedPrecondition, "%s: %v", op, err) - } + return status.Errorf(codes.Internal, "%s: %v", op, err) } diff --git a/seaweed-block/core/host/master/volume_deleting_test.go b/seaweed-block/core/host/master/volume_deleting_test.go index 1775da86b4..b58f3d427a 100644 --- a/seaweed-block/core/host/master/volume_deleting_test.go +++ b/seaweed-block/core/host/master/volume_deleting_test.go @@ -1,37 +1,124 @@ package master import ( + "context" "testing" "time" + "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/status" "github.com/seaweedfs/seaweed-block/core/lifecycle" control "github.com/seaweedfs/seaweed-block/core/rpc/control" ) -// MarkVolumeDeleting is the master-side admission of a chunk volume delete -// (codex01's review of #152, P1 3): refused while the volume has live -// authority; once marked, a placement that already exists no longer leads -// to an assignment, and the id is never created, placed or bound again. +// The master's deletion reservation (review of #152 r2): durable, separate +// from the desired-volume record, held by token, given back by Abort, +// permanent after Commit. + +func markReq(vol, tok string) *control.MarkVolumeDeletingRequest { + return &control.MarkVolumeDeletingRequest{VolumeId: vol, Token: tok} +} + +func createReq(vol string) *control.CreateVolumeRequest { + return &control.CreateVolumeRequest{VolumeId: vol, SizeBytes: 1 << 20, ReplicationFactor: 1} +} + +// hostOn starts a master on fixed store directories (so a test can restart +// it) and returns it with a lifecycle client. +func hostOn(t *testing.T, authDir, lcDir string) (*Host, control.LifecycleServiceClient, func()) { + t.Helper() + h, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: authDir, LifecycleStoreDir: lcDir}) + if err != nil { + t.Fatal(err) + } + h.Start() + c, err := grpc.NewClient(h.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + t.Fatal(err) + } + stop := func() { + c.Close() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + _ = h.Close(ctx) + } + return h, control.NewLifecycleServiceClient(c), stop +} func TestMarkVolumeDeleting_RefusedWhileAssigned(t *testing.T) { h, c, ctx := reviewBindingHost(t) reviewLegacyBind(t, h, c, ctx, "live") - _, err := control.NewLifecycleServiceClient(c).MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "live"}) + _, err := control.NewLifecycleServiceClient(c).MarkVolumeDeleting(ctx, markReq("live", "d1")) if status.Code(err) != codes.FailedPrecondition { t.Fatalf("mark of an assigned volume: %v; want FailedPrecondition", err) } - if rec, _ := h.Lifecycle().Volumes.GetVolume("live"); rec.Deleting { - t.Fatal("a refused mark marked the record") + if h.Lifecycle().Deletions.Reserved("live") { + t.Fatal("a refused mark reserved the id") } } +// P1: an id the master never knew is reserved too, and the ordinary +// DeleteVolume of a known record does not clear the reservation; both hold +// across a restart. +func TestMarkVolumeDeleting_ReservesUnknownIdsAndSurvivesDeleteAndRestart(t *testing.T) { + authDir, lcDir := t.TempDir(), t.TempDir() + ctx := context.Background() + h, lc, stop := hostOn(t, authDir, lcDir) + if resp, err := lc.MarkVolumeDeleting(ctx, markReq("forkvol", "d1")); err != nil || resp.GetKnown() || resp.GetState() != lifecycle.ReservationAdmitted { + t.Fatalf("mark of an unknown id: %+v %v; want admitted, not known", resp, err) + } + if _, err := lc.CreateVolume(ctx, createReq("known")); err != nil { + t.Fatal(err) + } + if resp, err := lc.MarkVolumeDeleting(ctx, markReq("known", "d2")); err != nil || !resp.GetKnown() { + t.Fatalf("mark of a known volume: %+v %v", resp, err) + } + if _, err := lc.DeleteVolume(ctx, &control.DeleteVolumeRequest{VolumeId: "known"}); err != nil { + t.Fatalf("ordinary delete of the record: %v", err) + } + for _, vol := range []string{"forkvol", "known"} { + if _, err := lc.CreateVolume(ctx, createReq(vol)); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("create of reserved %s: %v; want FailedPrecondition", vol, err) + } + } + _ = h + stop() + h, lc, stop = hostOn(t, authDir, lcDir) + defer stop() + for _, vol := range []string{"forkvol", "known"} { + if !h.Lifecycle().Deletions.Reserved(vol) { + t.Fatalf("%s's reservation lost on restart", vol) + } + if _, err := lc.CreateVolume(ctx, createReq(vol)); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("create of reserved %s after restart: %v; want FailedPrecondition", vol, err) + } + } + // Abort gives the unknown id back (usable again); a committed one never. + if resp, err := lc.AbortVolumeDeleting(ctx, markReq("forkvol", "d1")); err != nil || resp.GetState() != "" { + t.Fatalf("abort: %+v %v; want the reservation gone", resp, err) + } + if _, err := lc.CreateVolume(ctx, createReq("forkvol")); err != nil { + t.Fatalf("create after the abort: %v", err) + } + if _, err := lc.CommitVolumeDeleting(ctx, markReq("known", "d2")); err != nil { + t.Fatal(err) + } + if _, err := lc.AbortVolumeDeleting(ctx, markReq("known", "d2")); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("abort of a committed deletion: %v; want FailedPrecondition", err) + } + if _, err := lc.CommitVolumeDeleting(ctx, markReq("nothing", "dx")); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("commit of an unreserved id: %v; want FailedPrecondition", err) + } +} + +// P1: a reserved volume with an existing placement gets no assignment, and +// the reserved id is not placed, created or bound. func TestMarkVolumeDeleting_StopsLaterAssignmentPlacementAndBinding(t *testing.T) { h, c, ctx := reviewBindingHost(t) lc := control.NewLifecycleServiceClient(c) - // "placed" has a placement already (no authority yet); "fresh" has none. for _, vol := range []string{"placed", "fresh"} { reviewCreate(t, c, ctx, vol) } @@ -39,16 +126,10 @@ func TestMarkVolumeDeleting_StopsLaterAssignmentPlacementAndBinding(t *testing.T t.Fatal(e) } for _, vol := range []string{"placed", "fresh"} { - resp, err := lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: vol}) - if err != nil || !resp.GetKnown() { - t.Fatalf("mark %s: %+v %v", vol, resp, err) - } - if rec, _ := h.Lifecycle().Volumes.GetVolume(vol); !rec.Deleting { - t.Fatalf("%s not marked", vol) + if _, err := lc.MarkVolumeDeleting(ctx, markReq(vol, "d-"+vol)); err != nil { + t.Fatalf("mark %s: %v", vol, err) } } - // The placed volume's replica reports in; the product tick would bind - // it. Neither volume may get authority, and "fresh" no placement. reviewHeartbeat(t, c, ctx, "placed", "node-a", "127.0.0.1:10000", "127.0.0.1:10001") reviewHeartbeat(t, c, ctx, "fresh", "node-a", "127.0.0.1:10002", "127.0.0.1:10003") for i := 0; i < 3; i++ { @@ -63,17 +144,9 @@ func TestMarkVolumeDeleting_StopsLaterAssignmentPlacementAndBinding(t *testing.T } } if _, ok := h.Lifecycle().Placements.GetPlacement("fresh"); ok { - t.Fatal("the reconciler placed a volume marked deleting") - } - // Never created, bound or placed again. - if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "fresh", SizeBytes: 1 << 20, ReplicationFactor: 1}); status.Code(err) != codes.FailedPrecondition { - t.Fatalf("re-create of a deleting volume: %v; want FailedPrecondition", err) + t.Fatal("the reconciler placed a reserved volume") } if _, err := control.NewWorkspaceServiceClient(c).RegisterWorkspaceBinding(ctx, &control.WorkspaceBinding{VolumeId: "fresh", ServerId: "node-b", DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); status.Code(err) != codes.FailedPrecondition { - t.Fatalf("binding of a deleting volume: %v; want FailedPrecondition", err) - } - // A volume the master never knew is admitted after the authority check. - if resp, err := lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "unknown"}); err != nil || resp.GetKnown() { - t.Fatalf("mark of an unknown volume: %+v %v; want admitted, not known", resp, err) + t.Fatalf("binding of a reserved volume: %v; want FailedPrecondition", err) } } diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 2d52eb63f4..854adb49ad 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -160,11 +160,12 @@ func (h *Host) admitWorkspacePublication(ask authority.AssignmentAsk, publish fu } h.workspaceMu.Lock() 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 { + if h.lifecycle.Deletions.Reserved(ask.VolumeID) { return fmt.Errorf("workspace publication: volume is being deleted") } + if _, alive := h.lifecycle.Volumes.GetVolume(ask.VolumeID); !alive { + return fmt.Errorf("workspace publication: volume no longer exists") + } bindings, bound, err := h.lifecycle.WorkspaceBindings.Get(ask.VolumeID) if err != nil { return err diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index 7af3bfe144..f1e17f69a3 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 { + if s.host.lifecycle.Deletions.Reserved(volume) { return status.Error(codes.FailedPrecondition, "workspace: volume is being deleted") } return nil diff --git a/seaweed-block/core/lifecycle/deletion_reservations.go b/seaweed-block/core/lifecycle/deletion_reservations.go new file mode 100644 index 0000000000..f1f0b462d8 --- /dev/null +++ b/seaweed-block/core/lifecycle/deletion_reservations.go @@ -0,0 +1,249 @@ +package lifecycle + +import ( + "encoding/json" + "errors" + "fmt" + "os" + "path/filepath" + "sort" + "sync" +) + +// Deletion reservations (review of #152 r2): the master-side exclusion of a +// chunk volume id that a delete has admitted. It is kept apart from the +// desired-volume records, so neither an unknown id (no VolumeRecord) nor the +// ordinary DeleteVolume/CreateVolume path can drop it. +// +// - admitted: one or more deletes hold it (by token). An admitted delete +// that gives back without irreversible effects aborts its token; the +// reservation goes when no token is left. +// - committed: a delete passed its irreversible boundary. Permanent: the +// id is never created, placed, bound or assigned again. +// +// Writes are crash-safe and durable (synced temp file, atomic rename, synced +// directory). A write whose outcome is unknown fails closed: the store keeps +// the more protective state in memory and reports the error. + +const ( + ReservationAdmitted = "admitted" + ReservationCommitted = "committed" + + reservationsFile = "reservations.json" +) + +var ( + // ErrReservationCommitted refuses giving back a committed deletion. + ErrReservationCommitted = errors.New("lifecycle: volume deletion is committed") + // ErrReservationToken refuses an empty or unknown delete token. + ErrReservationToken = errors.New("lifecycle: deletion token required") +) + +// DeletionReservation is one volume's deletion exclusion. +type DeletionReservation struct { + VolumeID string `json:"volume_id"` + State string `json:"state"` + Tokens []string `json:"tokens,omitempty"` +} + +// DeletionReservationStore persists the reservations as one JSON document. +type DeletionReservationStore struct { + mu sync.Mutex + dir string + records map[string]DeletionReservation + + // Test seams for persistence faults (nil in production). + failWrite, failRename, failDirSync func() error +} + +// OpenDeletionReservationStore opens or creates the store in dir. +func OpenDeletionReservationStore(dir string) (*DeletionReservationStore, error) { + if dir == "" { + return nil, fmt.Errorf("%w: empty dir", ErrInvalidVolumeSpec) + } + if err := os.MkdirAll(dir, 0o755); err != nil { + return nil, fmt.Errorf("lifecycle: mkdir %q: %w", dir, err) + } + s := &DeletionReservationStore{dir: dir, records: map[string]DeletionReservation{}} + b, err := os.ReadFile(filepath.Join(dir, reservationsFile)) + switch { + case errors.Is(err, os.ErrNotExist): + return s, nil + case err != nil: + return nil, fmt.Errorf("lifecycle: read deletion reservations: %w", err) + } + if err := json.Unmarshal(b, &s.records); err != nil { + return nil, fmt.Errorf("lifecycle: decode deletion reservations: %w", err) + } + for v, r := range s.records { + if r.VolumeID != v || (r.State != ReservationAdmitted && r.State != ReservationCommitted) { + return nil, fmt.Errorf("lifecycle: deletion reservation %q is invalid", v) + } + } + return s, nil +} + +// Get returns vol's reservation. +func (s *DeletionReservationStore) Get(vol string) (DeletionReservation, bool) { + s.mu.Lock() + defer s.mu.Unlock() + r, ok := s.records[vol] + return r, ok +} + +// Reserved reports whether vol is excluded (admitted or committed). +func (s *DeletionReservationStore) Reserved(vol string) bool { + _, ok := s.Get(vol) + return ok +} + +// Admit adds token's hold on vol (idempotent; a committed reservation stays +// committed). +func (s *DeletionReservationStore) Admit(vol, token string) (DeletionReservation, error) { + if err := validateVolumeID(vol); err != nil { + return DeletionReservation{}, err + } + if token == "" { + return DeletionReservation{}, ErrReservationToken + } + return s.update(vol, true, func(r *DeletionReservation, ok bool) (bool, error) { + if !ok { + *r = DeletionReservation{VolumeID: vol, State: ReservationAdmitted} + } + if !containsToken(r.Tokens, token) { + r.Tokens = append(r.Tokens, token) + sort.Strings(r.Tokens) + } + return true, nil + }) +} + +// Commit makes vol's reservation permanent; token must hold it. +func (s *DeletionReservationStore) Commit(vol, token string) (DeletionReservation, error) { + return s.update(vol, true, func(r *DeletionReservation, ok bool) (bool, error) { + if !ok || (r.State != ReservationCommitted && !containsToken(r.Tokens, token)) { + return false, ErrReservationToken + } + r.State = ReservationCommitted + return true, nil + }) +} + +// Abort gives back token's hold; the reservation goes with its last token. +// A committed reservation is never given back. +func (s *DeletionReservationStore) Abort(vol, token string) (DeletionReservation, error) { + return s.update(vol, false, func(r *DeletionReservation, ok bool) (bool, error) { + if !ok { + return false, nil // nothing held: already given back + } + if r.State == ReservationCommitted { + return false, ErrReservationCommitted + } + kept := r.Tokens[:0:0] + for _, t := range r.Tokens { + if t != token { + kept = append(kept, t) + } + } + r.Tokens = kept + return true, nil + }) +} + +func containsToken(tokens []string, t string) bool { + for _, x := range tokens { + if x == t { + return true + } + } + return false +} + +// update applies change to vol's reservation and persists it. protective +// says whether the change only adds exclusion: on a write whose outcome is +// unknown (rename or directory sync failed) a protective change is kept in +// memory (fail closed), a releasing one is not. +func (s *DeletionReservationStore) update(vol string, protective bool, change func(r *DeletionReservation, ok bool) (bool, error)) (DeletionReservation, error) { + s.mu.Lock() + defer s.mu.Unlock() + r, ok := s.records[vol] + r.Tokens = append([]string(nil), r.Tokens...) + changed, err := change(&r, ok) + if err != nil || !changed { + return r, err + } + next := make(map[string]DeletionReservation, len(s.records)+1) + for k, v := range s.records { + next[k] = v + } + if r.State == ReservationAdmitted && len(r.Tokens) == 0 { + delete(next, vol) + } else { + next[vol] = r + } + if err := s.persist(next, protective); err != nil { + return r, err + } + s.records = next + return r, nil +} + +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 + } + f, err := os.CreateTemp(s.dir, "reservations-*.tmp") + if err != nil { + return fmt.Errorf("lifecycle: deletion reservation write: %w", err) + } + defer os.Remove(f.Name()) + if s.failWrite != nil { + err = s.failWrite() + } + if err == nil { + _, err = f.Write(b) + } + if err == nil { + err = f.Sync() + } + if cerr := f.Close(); err == nil { + err = cerr + } + if err != nil { + return fmt.Errorf("lifecycle: deletion reservation write: %w", err) // nothing replaced + } + unknown := func(err error) error { + if protective { + s.records = next // may be on disk: keep the exclusion + } + return fmt.Errorf("lifecycle: deletion reservation outcome unknown: %w", err) + } + if s.failRename != nil { + if err := s.failRename(); err != nil { + return unknown(err) + } + } + if err := os.Rename(f.Name(), filepath.Join(s.dir, reservationsFile)); err != nil { + return unknown(err) + } + if s.failDirSync != nil { + if err := s.failDirSync(); err != nil { + return unknown(err) + } + } + d, err := os.Open(s.dir) + if err == nil { + err = d.Sync() + if cerr := d.Close(); err == nil { + err = cerr + } + } + if err != nil { + return unknown(err) + } + return nil +} diff --git a/seaweed-block/core/lifecycle/deletion_reservations_test.go b/seaweed-block/core/lifecycle/deletion_reservations_test.go new file mode 100644 index 0000000000..280e4c0237 --- /dev/null +++ b/seaweed-block/core/lifecycle/deletion_reservations_test.go @@ -0,0 +1,98 @@ +package lifecycle + +import ( + "errors" + "testing" +) + +func reopen(t *testing.T, dir string) *DeletionReservationStore { + t.Helper() + s, err := OpenDeletionReservationStore(dir) + if err != nil { + t.Fatal(err) + } + return s +} + +// Admit holds by token, Abort gives a token back (the reservation goes with +// the last), Commit is permanent; every state survives a reopen. +func TestDeletionReservations_AdmitAbortCommitSurviveRestart(t *testing.T) { + dir := t.TempDir() + s := reopen(t, dir) + if _, err := s.Admit("v1", ""); !errors.Is(err, ErrReservationToken) { + t.Fatalf("admit without a token: %v", err) + } + for _, tok := range []string{"d1", "d2"} { + if _, err := s.Admit("v1", tok); err != nil { + t.Fatal(err) + } + } + if _, err := s.Abort("v1", "d1"); err != nil || !reopen(t, dir).Reserved("v1") { + t.Fatalf("abort of one of two tokens: %v; want still reserved after restart", err) + } + if _, err := s.Abort("v1", "d2"); err != nil || s.Reserved("v1") || reopen(t, dir).Reserved("v1") { + t.Fatalf("abort of the last token: %v; want the reservation gone (also after restart)", err) + } + if _, err := s.Admit("v2", "d3"); err != nil { + t.Fatal(err) + } + if _, err := s.Commit("v2", "other"); !errors.Is(err, ErrReservationToken) { + t.Fatalf("commit by a token that holds nothing: %v", err) + } + if _, err := s.Commit("v2", "d3"); err != nil { + t.Fatal(err) + } + r := reopen(t, dir) + if got, ok := r.Get("v2"); !ok || got.State != ReservationCommitted { + t.Fatalf("committed reservation after restart: %+v %t", got, ok) + } + if _, err := r.Abort("v2", "d3"); !errors.Is(err, ErrReservationCommitted) || !r.Reserved("v2") { + t.Fatalf("abort of a committed deletion: %v; want refused, still reserved", err) + } + if _, err := r.Admit("v2", "d4"); err != nil { + t.Fatalf("a rerun's admission of a committed deletion: %v", err) + } + if got, _ := r.Get("v2"); got.State != ReservationCommitted { + t.Fatalf("admit downgraded a committed reservation: %+v", got) + } +} + +// Persistence faults fail closed: a failed write before the rename leaves +// nothing (and returns the error); an unknown outcome (rename or directory +// sync failed) keeps a protective change in memory and never a releasing +// one. +func TestDeletionReservations_PersistenceFaultsFailClosed(t *testing.T) { + fail := errors.New("injected") + dir := t.TempDir() + s := reopen(t, dir) + + s.failWrite = func() error { return fail } + if _, err := s.Admit("w", "d1"); !errors.Is(err, fail) || s.Reserved("w") || reopen(t, dir).Reserved("w") { + t.Fatalf("admit with a failing write: %v; want an error and no reservation", err) + } + s.failWrite = nil + + s.failRename = func() error { return fail } + if _, err := s.Admit("r", "d1"); !errors.Is(err, fail) || !s.Reserved("r") { + t.Fatalf("admit with a failing rename: %v; want an error and the reservation kept in memory", err) + } + s.failRename = nil + + s.failDirSync = func() error { return fail } + if _, err := s.Admit("y", "d1"); !errors.Is(err, fail) || !s.Reserved("y") { + t.Fatalf("admit with a failing directory sync: %v; want an error and the reservation kept", err) + } + s.failDirSync = nil + + if _, err := s.Admit("a", "d1"); err != nil { + t.Fatal(err) + } + s.failRename = func() error { return fail } + if _, err := s.Abort("a", "d1"); !errors.Is(err, fail) || !s.Reserved("a") { + t.Fatalf("abort with a failing rename: %v; want an error and the reservation kept", err) + } + s.failRename = nil + if !reopen(t, dir).Reserved("a") { + t.Fatal("a successfully written reservation is lost on restart") + } +} diff --git a/seaweed-block/core/lifecycle/reconciler.go b/seaweed-block/core/lifecycle/reconciler.go index e22b02bed5..c16765ec2d 100644 --- a/seaweed-block/core/lifecycle/reconciler.go +++ b/seaweed-block/core/lifecycle/reconciler.go @@ -17,9 +17,6 @@ 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 { - continue // never placed again - } plan := PlanPlacement(volume, nodes) result := ReconcileResult{ VolumeID: volume.Spec.VolumeID, diff --git a/seaweed-block/core/lifecycle/store.go b/seaweed-block/core/lifecycle/store.go index b306a7b5a5..1de3e090e2 100644 --- a/seaweed-block/core/lifecycle/store.go +++ b/seaweed-block/core/lifecycle/store.go @@ -23,9 +23,6 @@ var ( ErrVolumeNotFound = errors.New("lifecycle: volume not found") ErrAlreadyAttached = errors.New("lifecycle: volume already attached to another node") ErrAttachedElsewhere = errors.New("lifecycle: volume attached to another node") - // ErrVolumeDeleting: the volume is being deleted (or was); its id is - // never created, placed, bound or assigned again. - ErrVolumeDeleting = errors.New("lifecycle: volume is being deleted") ) var volumeIDPattern = regexp.MustCompile(`^[A-Za-z0-9._-]+$`) @@ -48,8 +45,6 @@ type VolumeSpec struct { type VolumeRecord struct { Spec VolumeSpec `json:"spec"` AttachedTo string `json:"attached_to,omitempty"` - // Deleting is set once by MarkDeleting and never cleared. - Deleting bool `json:"deleting,omitempty"` } // FileStore persists one JSON record per volume ID. @@ -87,9 +82,6 @@ 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 { - return VolumeRecord{}, ErrVolumeDeleting - } if !volumeSpecsCompatible(existing.Spec, spec) { return VolumeRecord{}, ErrVolumeConflict } @@ -139,29 +131,6 @@ func mergeVolumeSpecMetadata(existing, incoming VolumeSpec) VolumeSpec { return out } -// MarkDeleting marks volumeID's record deleting (idempotent). found is -// false when there is no record (nothing is written). -func (s *FileStore) MarkDeleting(volumeID string) (found bool, err error) { - if err := validateVolumeID(volumeID); err != nil { - return false, err - } - s.mu.Lock() - defer s.mu.Unlock() - rec, ok := s.records[volumeID] - if !ok { - return false, nil - } - if rec.Deleting { - return true, nil - } - rec.Deleting = true - if err := s.putLocked(rec); err != nil { - return true, err - } - s.records[volumeID] = rec - return true, nil -} - // DeleteVolume removes a desired volume record. Missing volumes are a // successful no-op so delete is safe to retry. func (s *FileStore) DeleteVolume(volumeID string) error { diff --git a/seaweed-block/core/rpc/control/control.pb.go b/seaweed-block/core/rpc/control/control.pb.go index fcd1dc811e..ecaa109beb 100644 --- a/seaweed-block/core/rpc/control/control.pb.go +++ b/seaweed-block/core/rpc/control/control.pb.go @@ -2539,6 +2539,8 @@ type MarkVolumeDeletingRequest struct { unknownFields protoimpl.UnknownFields VolumeId string `protobuf:"bytes,1,opt,name=volume_id,json=volumeId,proto3" json:"volume_id,omitempty"` + // token identifies one delete operation (chosen by the caller). + Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"` } func (x *MarkVolumeDeletingRequest) Reset() { @@ -2580,14 +2582,24 @@ func (x *MarkVolumeDeletingRequest) GetVolumeId() string { return "" } +func (x *MarkVolumeDeletingRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + type MarkVolumeDeletingResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // known is false when the master has no lifecycle record for the volume - // (it then only checked that no authority is live or pending). + // known is true when the master also has a lifecycle record for the + // volume (the reservation applies either way). Known bool `protobuf:"varint,1,opt,name=known,proto3" json:"known,omitempty"` + // state is the reservation after the call: "admitted", "committed" or + // "" (none left). + State string `protobuf:"bytes,2,opt,name=state,proto3" json:"state,omitempty"` } func (x *MarkVolumeDeletingResponse) Reset() { @@ -2629,6 +2641,13 @@ func (x *MarkVolumeDeletingResponse) GetKnown() bool { return false } +func (x *MarkVolumeDeletingResponse) GetState() string { + if x != nil { + return x.State + } + return "" +} + type FailbackRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -3298,177 +3317,196 @@ var file_control_proto_rawDesc = []byte{ 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x38, 0x0a, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x4e, 0x0a, 0x19, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x32, 0x0a, 0x1a, 0x4d, 0x61, 0x72, 0x6b, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x22, 0xa5, 0x04, 0x0a, 0x0f, - 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, - 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x74, - 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x44, 0x61, 0x74, - 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, - 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, - 0x3d, 0x0a, 0x1b, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, - 0x65, 0x6e, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, - 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x34, - 0x0a, 0x16, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, - 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x14, - 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, - 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, 0x5f, 0x65, 0x6c, 0x69, 0x67, - 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x61, 0x63, 0x6b, 0x45, - 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, 0x66, 0x72, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x64, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x62, 0x65, 0x66, 0x6f, 0x72, - 0x65, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x1c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, 0x65, 0x6e, 0x63, 0x65, 0x64, - 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x38, - 0x0a, 0x18, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, - 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, - 0x72, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, - 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, - 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, - 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, - 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, - 0x65, 0x66, 0x73, 0x22, 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x66, 0x61, 0x69, 0x6c, - 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x0f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x72, - 0x74, 0x65, 0x64, 0x12, 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, - 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, - 0x45, 0x70, 0x6f, 0x63, 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x41, 0x0a, - 0x1d, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, - 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x50, 0x72, 0x69, 0x6d, - 0x61, 0x72, 0x79, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, - 0x12, 0x50, 0x0a, 0x25, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, - 0x65, 0x74, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, - 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x21, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x53, 0x77, - 0x61, 0x70, 0x70, 0x65, 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, - 0x63, 0x6b, 0x12, 0x2e, 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, - 0x5f, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x11, 0x6e, 0x6f, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, - 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, - 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x32, 0xdf, 0x01, - 0x0a, 0x12, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, 0x65, - 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, - 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, - 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, 0x12, 0x52, 0x65, 0x70, 0x6f, - 0x72, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, 0x32, - 0x81, 0x01, 0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, - 0x62, 0x65, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x29, 0x2e, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x48, 0x0a, + 0x1a, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6b, + 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x77, + 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0xa5, 0x04, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, + 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, + 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x44, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, + 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x63, 0x74, 0x72, 0x6c, + 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, 0x3d, 0x0a, 0x1b, 0x65, + 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, + 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, + 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x34, 0x0a, 0x16, 0x65, 0x78, + 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, + 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x14, 0x65, 0x78, 0x70, 0x65, + 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, + 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, 0x5f, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x61, 0x63, 0x6b, 0x45, 0x6c, 0x69, 0x67, 0x69, + 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, + 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x5f, 0x66, 0x61, + 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1c, 0x66, 0x72, + 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x42, 0x65, 0x66, 0x6f, + 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x38, 0x0a, 0x18, 0x64, 0x75, + 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x63, + 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x64, 0x75, + 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x43, 0x6f, 0x76, + 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, + 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, + 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, + 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x22, + 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, + 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, + 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, + 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x5f, 0x65, 0x70, 0x6f, + 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x45, 0x70, 0x6f, 0x63, + 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x41, 0x0a, 0x1d, 0x73, 0x69, 0x6e, + 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x61, 0x66, 0x74, 0x65, + 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x41, + 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x50, 0x0a, 0x25, + 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x73, + 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, + 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x21, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x70, 0x65, + 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x2e, + 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x6d, 0x75, 0x74, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x6e, 0x6f, 0x53, + 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x44, + 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, + 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, + 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, + 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x32, 0xdf, 0x01, 0x0a, 0x12, 0x4f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, + 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, + 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, - 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x63, - 0x74, 0x30, 0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x2e, 0x73, 0x65, - 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xd1, 0x04, 0x0a, - 0x16, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, 0x6c, - 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x30, 0x2e, 0x73, 0x65, - 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, - 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, - 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x2b, 0x2e, 0x73, - 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x56, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2f, 0x2e, 0x73, 0x65, 0x61, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, + 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, 0x12, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x43, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, - 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, - 0x65, 0x6e, 0x63, 0x65, 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, 0x2e, 0x73, 0x65, 0x61, 0x77, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, + 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, 0x32, 0x81, 0x01, 0x0a, 0x11, + 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x41, 0x73, + 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, - 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x73, - 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, - 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x71, 0x0a, - 0x12, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, - 0x6e, 0x74, 0x73, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x57, 0x61, - 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, + 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x41, + 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x30, 0x01, 0x32, + 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, - 0x32, 0xeb, 0x02, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xd1, 0x04, 0x0a, 0x16, 0x43, 0x6c, 0x75, + 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, + 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x30, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, + 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x73, 0x65, 0x61, 0x77, + 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, + 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, 0x0b, 0x4c, 0x69, 0x73, + 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x2b, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x7d, 0x0a, 0x12, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, + 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, + 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, + 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, + 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x71, 0x0a, 0x12, 0x57, 0x61, 0x74, + 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, + 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, + 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, 0x32, 0xec, 0x04, 0x0a, + 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, + 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7d, 0x0a, 0x12, 0x4d, + 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, + 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, - 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x79, - 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, - 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, - 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, - 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, - 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7e, 0x0a, 0x13, 0x41, 0x62, + 0x6f, 0x72, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, + 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, + 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, + 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7f, 0x0a, 0x14, 0x43, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, + 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, + 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x79, 0x0a, 0x0f, 0x46, + 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, + 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, + 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2f, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x63, 0x6f, 0x72, + 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3b, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -3555,22 +3593,26 @@ var file_control_proto_depIdxs = []int32{ 24, // 32: seaweedfs.block.control.LifecycleService.CreateVolume:input_type -> seaweedfs.block.control.CreateVolumeRequest 26, // 33: seaweedfs.block.control.LifecycleService.DeleteVolume:input_type -> seaweedfs.block.control.DeleteVolumeRequest 28, // 34: seaweedfs.block.control.LifecycleService.MarkVolumeDeleting:input_type -> seaweedfs.block.control.MarkVolumeDeletingRequest - 30, // 35: seaweedfs.block.control.FailbackService.ExecuteFailback:input_type -> seaweedfs.block.control.FailbackRequest - 3, // 36: seaweedfs.block.control.ObservationService.ReportHeartbeat:output_type -> seaweedfs.block.control.HeartbeatAck - 4, // 37: seaweedfs.block.control.ObservationService.ReportClusterEvent:output_type -> seaweedfs.block.control.ClusterEventAck - 7, // 38: seaweedfs.block.control.AssignmentService.SubscribeAssignments:output_type -> seaweedfs.block.control.AssignmentFact - 9, // 39: seaweedfs.block.control.EvidenceService.QueryVolumeStatus:output_type -> seaweedfs.block.control.StatusResponse - 17, // 40: seaweedfs.block.control.ClusterEvidenceService.GetClusterStatus:output_type -> seaweedfs.block.control.ClusterStatusResponse - 22, // 41: seaweedfs.block.control.ClusterEvidenceService.ListVolumes:output_type -> seaweedfs.block.control.ListVolumesResponse - 19, // 42: seaweedfs.block.control.ClusterEvidenceService.GetVolumeStatus:output_type -> seaweedfs.block.control.VolumeEvidence - 23, // 43: seaweedfs.block.control.ClusterEvidenceService.GetVolumeTimeline:output_type -> seaweedfs.block.control.VolumeTimelineResponse - 21, // 44: seaweedfs.block.control.ClusterEvidenceService.WatchClusterEvents:output_type -> seaweedfs.block.control.ClusterEvent - 25, // 45: seaweedfs.block.control.LifecycleService.CreateVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse - 27, // 46: seaweedfs.block.control.LifecycleService.DeleteVolume:output_type -> seaweedfs.block.control.DeleteVolumeResponse - 29, // 47: seaweedfs.block.control.LifecycleService.MarkVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse - 31, // 48: seaweedfs.block.control.FailbackService.ExecuteFailback:output_type -> seaweedfs.block.control.FailbackResponse - 36, // [36:49] is the sub-list for method output_type - 23, // [23:36] is the sub-list for method input_type + 28, // 35: seaweedfs.block.control.LifecycleService.AbortVolumeDeleting:input_type -> seaweedfs.block.control.MarkVolumeDeletingRequest + 28, // 36: seaweedfs.block.control.LifecycleService.CommitVolumeDeleting:input_type -> seaweedfs.block.control.MarkVolumeDeletingRequest + 30, // 37: seaweedfs.block.control.FailbackService.ExecuteFailback:input_type -> seaweedfs.block.control.FailbackRequest + 3, // 38: seaweedfs.block.control.ObservationService.ReportHeartbeat:output_type -> seaweedfs.block.control.HeartbeatAck + 4, // 39: seaweedfs.block.control.ObservationService.ReportClusterEvent:output_type -> seaweedfs.block.control.ClusterEventAck + 7, // 40: seaweedfs.block.control.AssignmentService.SubscribeAssignments:output_type -> seaweedfs.block.control.AssignmentFact + 9, // 41: seaweedfs.block.control.EvidenceService.QueryVolumeStatus:output_type -> seaweedfs.block.control.StatusResponse + 17, // 42: seaweedfs.block.control.ClusterEvidenceService.GetClusterStatus:output_type -> seaweedfs.block.control.ClusterStatusResponse + 22, // 43: seaweedfs.block.control.ClusterEvidenceService.ListVolumes:output_type -> seaweedfs.block.control.ListVolumesResponse + 19, // 44: seaweedfs.block.control.ClusterEvidenceService.GetVolumeStatus:output_type -> seaweedfs.block.control.VolumeEvidence + 23, // 45: seaweedfs.block.control.ClusterEvidenceService.GetVolumeTimeline:output_type -> seaweedfs.block.control.VolumeTimelineResponse + 21, // 46: seaweedfs.block.control.ClusterEvidenceService.WatchClusterEvents:output_type -> seaweedfs.block.control.ClusterEvent + 25, // 47: seaweedfs.block.control.LifecycleService.CreateVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse + 27, // 48: seaweedfs.block.control.LifecycleService.DeleteVolume:output_type -> seaweedfs.block.control.DeleteVolumeResponse + 29, // 49: seaweedfs.block.control.LifecycleService.MarkVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 29, // 50: seaweedfs.block.control.LifecycleService.AbortVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 29, // 51: seaweedfs.block.control.LifecycleService.CommitVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 31, // 52: seaweedfs.block.control.FailbackService.ExecuteFailback:output_type -> seaweedfs.block.control.FailbackResponse + 38, // [38:53] is the sub-list for method output_type + 23, // [23:38] is the sub-list for method input_type 23, // [23:23] is the sub-list for extension type_name 23, // [23:23] is the sub-list for extension extendee 0, // [0:23] is the sub-list for field type_name diff --git a/seaweed-block/core/rpc/control/control_grpc.pb.go b/seaweed-block/core/rpc/control/control_grpc.pb.go index 782938a259..cb2855bebf 100644 --- a/seaweed-block/core/rpc/control/control_grpc.pb.go +++ b/seaweed-block/core/rpc/control/control_grpc.pb.go @@ -665,9 +665,11 @@ var ClusterEvidenceService_ServiceDesc = grpc.ServiceDesc{ } const ( - LifecycleService_CreateVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/CreateVolume" - LifecycleService_DeleteVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/DeleteVolume" - LifecycleService_MarkVolumeDeleting_FullMethodName = "/seaweedfs.block.control.LifecycleService/MarkVolumeDeleting" + LifecycleService_CreateVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/CreateVolume" + LifecycleService_DeleteVolume_FullMethodName = "/seaweedfs.block.control.LifecycleService/DeleteVolume" + LifecycleService_MarkVolumeDeleting_FullMethodName = "/seaweedfs.block.control.LifecycleService/MarkVolumeDeleting" + LifecycleService_AbortVolumeDeleting_FullMethodName = "/seaweedfs.block.control.LifecycleService/AbortVolumeDeleting" + LifecycleService_CommitVolumeDeleting_FullMethodName = "/seaweedfs.block.control.LifecycleService/CommitVolumeDeleting" ) // LifecycleServiceClient is the client API for LifecycleService service. @@ -676,13 +678,18 @@ const ( type LifecycleServiceClient interface { CreateVolume(ctx context.Context, in *CreateVolumeRequest, opts ...grpc.CallOption) (*CreateVolumeResponse, error) DeleteVolume(ctx context.Context, in *DeleteVolumeRequest, opts ...grpc.CallOption) (*DeleteVolumeResponse, error) - // MarkVolumeDeleting is the admission of a chunk volume delete: under - // the same locks as every assignment, placement and binding write it - // refuses (FAILED_PRECONDITION) a volume with live or pending authority, - // and otherwise marks the lifecycle record deleting, after which no new - // assignment, placement or binding is admitted and the id is never - // created again. + // MarkVolumeDeleting admits a chunk volume delete: under the same locks + // as every assignment, placement and binding write it refuses + // (FAILED_PRECONDITION) a volume with live or pending authority, and + // otherwise records the delete's token in a durable deletion + // reservation, independent of the volume record. While reserved, no + // new assignment, placement or binding is admitted and the id is not + // created again. AbortVolumeDeleting gives a token back (the + // reservation goes with its last token); CommitVolumeDeleting makes it + // permanent (never given back). MarkVolumeDeleting(ctx context.Context, in *MarkVolumeDeletingRequest, opts ...grpc.CallOption) (*MarkVolumeDeletingResponse, error) + AbortVolumeDeleting(ctx context.Context, in *MarkVolumeDeletingRequest, opts ...grpc.CallOption) (*MarkVolumeDeletingResponse, error) + CommitVolumeDeleting(ctx context.Context, in *MarkVolumeDeletingRequest, opts ...grpc.CallOption) (*MarkVolumeDeletingResponse, error) } type lifecycleServiceClient struct { @@ -720,19 +727,42 @@ func (c *lifecycleServiceClient) MarkVolumeDeleting(ctx context.Context, in *Mar return out, nil } +func (c *lifecycleServiceClient) AbortVolumeDeleting(ctx context.Context, in *MarkVolumeDeletingRequest, opts ...grpc.CallOption) (*MarkVolumeDeletingResponse, error) { + out := new(MarkVolumeDeletingResponse) + err := c.cc.Invoke(ctx, LifecycleService_AbortVolumeDeleting_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *lifecycleServiceClient) CommitVolumeDeleting(ctx context.Context, in *MarkVolumeDeletingRequest, opts ...grpc.CallOption) (*MarkVolumeDeletingResponse, error) { + out := new(MarkVolumeDeletingResponse) + err := c.cc.Invoke(ctx, LifecycleService_CommitVolumeDeleting_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // LifecycleServiceServer is the server API for LifecycleService service. // All implementations must embed UnimplementedLifecycleServiceServer // for forward compatibility type LifecycleServiceServer interface { CreateVolume(context.Context, *CreateVolumeRequest) (*CreateVolumeResponse, error) DeleteVolume(context.Context, *DeleteVolumeRequest) (*DeleteVolumeResponse, error) - // MarkVolumeDeleting is the admission of a chunk volume delete: under - // the same locks as every assignment, placement and binding write it - // refuses (FAILED_PRECONDITION) a volume with live or pending authority, - // and otherwise marks the lifecycle record deleting, after which no new - // assignment, placement or binding is admitted and the id is never - // created again. + // MarkVolumeDeleting admits a chunk volume delete: under the same locks + // as every assignment, placement and binding write it refuses + // (FAILED_PRECONDITION) a volume with live or pending authority, and + // otherwise records the delete's token in a durable deletion + // reservation, independent of the volume record. While reserved, no + // new assignment, placement or binding is admitted and the id is not + // created again. AbortVolumeDeleting gives a token back (the + // reservation goes with its last token); CommitVolumeDeleting makes it + // permanent (never given back). MarkVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) + AbortVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) + CommitVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) mustEmbedUnimplementedLifecycleServiceServer() } @@ -749,6 +779,12 @@ func (UnimplementedLifecycleServiceServer) DeleteVolume(context.Context, *Delete func (UnimplementedLifecycleServiceServer) MarkVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method MarkVolumeDeleting not implemented") } +func (UnimplementedLifecycleServiceServer) AbortVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AbortVolumeDeleting not implemented") +} +func (UnimplementedLifecycleServiceServer) CommitVolumeDeleting(context.Context, *MarkVolumeDeletingRequest) (*MarkVolumeDeletingResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CommitVolumeDeleting not implemented") +} func (UnimplementedLifecycleServiceServer) mustEmbedUnimplementedLifecycleServiceServer() {} // UnsafeLifecycleServiceServer may be embedded to opt out of forward compatibility for this service. @@ -816,6 +852,42 @@ func _LifecycleService_MarkVolumeDeleting_Handler(srv interface{}, ctx context.C return interceptor(ctx, in, info, handler) } +func _LifecycleService_AbortVolumeDeleting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MarkVolumeDeletingRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LifecycleServiceServer).AbortVolumeDeleting(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: LifecycleService_AbortVolumeDeleting_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LifecycleServiceServer).AbortVolumeDeleting(ctx, req.(*MarkVolumeDeletingRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _LifecycleService_CommitVolumeDeleting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MarkVolumeDeletingRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LifecycleServiceServer).CommitVolumeDeleting(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: LifecycleService_CommitVolumeDeleting_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LifecycleServiceServer).CommitVolumeDeleting(ctx, req.(*MarkVolumeDeletingRequest)) + } + return interceptor(ctx, in, info, handler) +} + // LifecycleService_ServiceDesc is the grpc.ServiceDesc for LifecycleService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -835,6 +907,14 @@ var LifecycleService_ServiceDesc = grpc.ServiceDesc{ MethodName: "MarkVolumeDeleting", Handler: _LifecycleService_MarkVolumeDeleting_Handler, }, + { + MethodName: "AbortVolumeDeleting", + Handler: _LifecycleService_AbortVolumeDeleting_Handler, + }, + { + MethodName: "CommitVolumeDeleting", + Handler: _LifecycleService_CommitVolumeDeleting_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "control.proto", diff --git a/seaweed-block/core/rpc/proto/control.proto b/seaweed-block/core/rpc/proto/control.proto index defa92a336..1efa3f4021 100644 --- a/seaweed-block/core/rpc/proto/control.proto +++ b/seaweed-block/core/rpc/proto/control.proto @@ -84,13 +84,18 @@ service ClusterEvidenceService { service LifecycleService { rpc CreateVolume(CreateVolumeRequest) returns (CreateVolumeResponse); rpc DeleteVolume(DeleteVolumeRequest) returns (DeleteVolumeResponse); - // MarkVolumeDeleting is the admission of a chunk volume delete: under - // the same locks as every assignment, placement and binding write it - // refuses (FAILED_PRECONDITION) a volume with live or pending authority, - // and otherwise marks the lifecycle record deleting, after which no new - // assignment, placement or binding is admitted and the id is never - // created again. + // MarkVolumeDeleting admits a chunk volume delete: under the same locks + // as every assignment, placement and binding write it refuses + // (FAILED_PRECONDITION) a volume with live or pending authority, and + // otherwise records the delete's token in a durable deletion + // reservation, independent of the volume record. While reserved, no + // new assignment, placement or binding is admitted and the id is not + // created again. AbortVolumeDeleting gives a token back (the + // reservation goes with its last token); CommitVolumeDeleting makes it + // permanent (never given back). rpc MarkVolumeDeleting(MarkVolumeDeletingRequest) returns (MarkVolumeDeletingResponse); + rpc AbortVolumeDeleting(MarkVolumeDeletingRequest) returns (MarkVolumeDeletingResponse); + rpc CommitVolumeDeleting(MarkVolumeDeletingRequest) returns (MarkVolumeDeletingResponse); } // FailbackService — disabled-by-default authority failback endpoint. @@ -413,12 +418,17 @@ message DeleteVolumeResponse { message MarkVolumeDeletingRequest { string volume_id = 1; + // token identifies one delete operation (chosen by the caller). + string token = 2; } message MarkVolumeDeletingResponse { - // known is false when the master has no lifecycle record for the volume - // (it then only checked that no authority is live or pending). + // known is true when the master also has a lifecycle record for the + // volume (the reservation applies either way). bool known = 1; + // state is the reservation after the call: "admitted", "committed" or + // "" (none left). + string state = 2; } message FailbackRequest { diff --git a/seaweed-block/core/storage/chunk_public.go b/seaweed-block/core/storage/chunk_public.go index aac1685333..a81d157e2f 100644 --- a/seaweed-block/core/storage/chunk_public.go +++ b/seaweed-block/core/storage/chunk_public.go @@ -28,6 +28,7 @@ const ( ChunkHeadDetached = chunkHeadDetached ChunkHeadAborted = chunkHeadAborted ChunkHeadDeleting = chunkHeadDeleting + ChunkHeadPurging = chunkHeadPurging ChunkHeadDeleted = chunkHeadDeleted ) diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index 858dcf3e41..3d5e01fa1c 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -207,8 +207,11 @@ const chunkHeadAborted = "aborted" // the delete can still be given back); chunkHeadDeleted is the final // tombstone (no chunks, so nothing it held stays a GC root). Neither is // ever moved by CASHead, so no attach, claim or restore can revive them. +// chunkHeadPurging is the delete's irreversible boundary (chunks still +// kept until the final tombstone). const ( chunkHeadDeleting = "deleting" + chunkHeadPurging = "purging" chunkHeadDeleted = "deleted" ) From 2e078746ee698c615f0e13fd914a84cf9d4a2ef0 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 19:54:32 -0800 Subject: [PATCH 06/16] 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 From 425161bbe37cd0e3214936d2e8bea48886ce8063 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 20:27:44 -0800 Subject: [PATCH 07/16] volume delete: RED controls for the cut and the r3 P2s claude05's 04:08Z cut (no snapshot cascade) and codex01's r3 P2s (V:/share/rdma/codex01-block152-r3-review-20261116T0405Z/REVIEW.md). Controls failing against stubs: - the cut: a volume with a snapshot, an in-flight snapshot attempt, or a fork's snapshot is deleted (TestCatalog_DeleteVolumeRefusesWhile SnapshotsExist, TestCatalog_InFlightSnapshotRefusesTheDelete, ...Fork DuringTheDeleteMarkRefuses, ...TombstonesAndRefusesReuse); - incarnation: a claim check under generation G commits a re-marked G' (TestCatalog_DeleteCommitIsBoundToItsIncarnation); - lost CLI token: a rerun cannot release the earlier hold (TestOpsChunk_VolumeDelete, real master, restart); - CreateVolume drops workspaceMu before the create (TestMarkVolumeDeleting_CreateHoldsTheReservationLock); - the reservation directory's parent is not synced (TestDeletionReservations_ParentSyncBeforeUse). Co-Authored-By: Claude Opus 5.5 --- .../cmd/sw-block/chunk_volume_delete.go | 30 +- .../cmd/sw-block/chunk_volume_delete_test.go | 169 ++-- .../core/frontend/chunkstore/catalog.go | 11 +- .../core/frontend/chunkstore/volume_delete.go | 352 ++++----- .../frontend/chunkstore/volume_delete_test.go | 747 ++++++++---------- seaweed-block/core/host/master/services.go | 15 +- .../core/host/master/volume_deleting_test.go | 53 ++ .../core/lifecycle/deletion_reservations.go | 9 + .../lifecycle/deletion_reservations_test.go | 21 + 9 files changed, 685 insertions(+), 722 deletions(-) diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete.go b/seaweed-block/cmd/sw-block/chunk_volume_delete.go index 1c64d169ac..4283774d5f 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -2,8 +2,6 @@ package main import ( "context" - "crypto/rand" - "encoding/hex" "encoding/json" "errors" "fmt" @@ -28,9 +26,10 @@ import ( func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { fs := chunkFlagSet("volume-delete", stderr) var ( - volumeID, filer, base, master string - timeout time.Duration + volumeID, filer, base, master, requestID string + timeout time.Duration ) + fs.StringVar(&requestID, "request-id", "", "this delete's operation id; a rerun with the same id resumes (or gives back) its earlier admission") fs.StringVar(&volumeID, "volume", "", "volume id (or the first argument)") fs.StringVar(&filer, "chunk-filer", "", "SeaweedFS filer gRPC address host:port") fs.StringVar(&base, "chunk-path", defaultChunkPathCLI, "filer directory holding one directory per volume") @@ -44,8 +43,8 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { } else if fs.NArg() != 0 { return chunkFail("volume-delete", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "give the volume once, as an argument or --volume", false) } - if volumeID == "" || master == "" || timeout <= 0 { - return chunkFail("volume-delete", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "a volume and --master are required; --timeout must be positive", false) + if volumeID == "" || master == "" || requestID == "" || timeout <= 0 { + return chunkFail("volume-delete", stdout, stderr, ops.VolumeStatusExitInvalid, codeBadRequestCLI, "a volume, --master and --request-id are required; --timeout must be positive", false) } cat, closeFn, exit := chunkCatalog("volume-delete", filer, base, stdout, stderr) if exit >= 0 { @@ -57,10 +56,7 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { return chunkResult("volume-delete", nil, err, stdout, stderr) } defer conn.Close() - admit, err := newMasterAdmission(control.NewLifecycleServiceClient(conn)) - if err != nil { - return chunkResult("volume-delete", nil, err, stdout, stderr) - } + admit := &masterAdmission{lc: control.NewLifecycleServiceClient(conn), token: requestID + "-" + fmt.Sprint(time.Now().UnixNano())} // RED: a fresh token per invocation ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() res, err := cat.DeleteVolume(ctx, volumeID, admit) @@ -70,21 +66,15 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { return chunkResult("volume-delete", res, nil, stdout, stderr) } -// masterAdmission is the delete's reservation at the blockmaster, under -// one random token per delete. +// masterAdmission is the delete's reservation at the blockmaster, held +// under the operation's request id: a rerun with the same id adopts the +// hold an earlier run left (e.g. after a lost response), so its give-back +// releases it, while another operation's hold stays. type masterAdmission struct { lc control.LifecycleServiceClient token string } -func newMasterAdmission(lc control.LifecycleServiceClient) (*masterAdmission, error) { - var b [12]byte - if _, err := rand.Read(b[:]); err != nil { - return nil, err - } - return &masterAdmission{lc: lc, token: hex.EncodeToString(b[:])}, nil -} - func (m *masterAdmission) req(vol string) *control.MarkVolumeDeletingRequest { return &control.MarkVolumeDeletingRequest{VolumeId: vol, Token: m.token} } diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go index 1378988546..535811e3a3 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go @@ -18,9 +18,40 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" ) -// volume-delete needs a volume and --master; it refuses an attached volume -// and deletes a free one (the real master runtime reports it unassigned); -// the deleted id cannot be created again. +type volumeDeleteOutput struct { + chunkstore.VolumeDeleteResult + Error *chunkErrBody `json:"error"` +} + +func lifecycleClient(t *testing.T, addr string) control.LifecycleServiceClient { + t.Helper() + c, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { c.Close() }) + return control.NewLifecycleServiceClient(c) +} + +func startDeleteMaster(t *testing.T, cfg master.Config) (*master.Host, func()) { + t.Helper() + h, err := master.New(cfg) + if err != nil { + t.Fatal(err) + } + h.Start() + return h, func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + _ = h.Close(ctx) + } +} + +// volume-delete against a real master runtime: argument checks; a held +// volume and a volume with a snapshot are refused with the admission given +// back (usable again); a lost first admission is adopted and given back by +// a rerun with the same request id (usable after a master restart); a +// completed delete is committed (never created again). func TestOpsChunk_VolumeDelete(t *testing.T) { ctx := context.Background() mem := chunkstore.NewMemFiler() @@ -32,7 +63,7 @@ func TestOpsChunk_VolumeDelete(t *testing.T) { t.Fatal(err) } geo := chunkstore.Geometry{NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 8} - for _, vol := range []string{"v1", "v2"} { + for _, vol := range []string{"v1", "v2", "v3"} { if _, err := cat.EnsureVolume(ctx, vol, geo); err != nil { t.Fatal(err) } @@ -49,50 +80,7 @@ func TestOpsChunk_VolumeDelete(t *testing.T) { if _, err := r.CASHead(ctx, storage.ChunkHeadVersion{Gen: cur.Gen, Epoch: cur.Epoch}, storage.ChunkHead{Epoch: 1, Holder: "h1", Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadActive}); err != nil { t.Fatal(err) } - - for _, args := range [][]string{ - {"volume-delete", "v1", "--chunk-filer", "f:1"}, // no --master - {"volume-delete", "--master", "m:1", "--chunk-filer", "f:1"}, // no volume - {"volume-delete", "--volume", "v1", "v2", "--master", "m:1", "--chunk-filer", "f:1"}, // two volumes - } { - if code, out, _ := runChunk(args...); code == 0 || !strings.Contains(out, codeBadRequestCLI) { - t.Fatalf("%v: %d %q; want a bad request", args, code, out) - } - } - - cfg := gcTestMasterConfig(t) - cfg.LifecycleStoreDir = t.TempDir() // MarkVolumeDeleting admits the delete - h, err := master.New(cfg) - if err != nil { - t.Fatal(err) - } - h.Start() - t.Cleanup(func() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - _ = h.Close(ctx) - }) - // v2 is admitted by the master (it has no authority) but held in the - // catalog: refused, and the partial result says what was done. - code, out, _ := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v2") - var partial struct { - chunkstore.VolumeDeleteResult - Error *chunkErrBody `json:"error"` - } - if code == 0 || json.Unmarshal([]byte(out), &partial) != nil || partial.Error == nil || partial.Error.Code != chunkstore.CodeVolumeInUse || !partial.Admitted || !partial.AdmissionAborted || partial.HeadMarked || partial.Completed { - t.Fatalf("delete of attached v2: %d %q; want volume_in_use with the partial result, admission given back", code, out) - } - lc := lifecycleClient(t, h.Addr()) - // The given-back id is usable at the master again. - if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v2", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { - t.Fatalf("create v2 after its delete gave back: %v", err) - } - - // Integrated claim refusal: v3 has a snapshot a real, incomplete fork - // claims (VOLUME published, stopped before HEAD by its deadline). - if _, err := cat.EnsureVolume(ctx, "v3", geo); err != nil { - t.Fatal(err) - } + // v3 has a snapshot. h3, _, err := cat.ReadHead(ctx, "v3") if err != nil { t.Fatal(err) @@ -100,46 +88,71 @@ func TestOpsChunk_VolumeDelete(t *testing.T) { if _, err := cat.CreateSnapshot(ctx, "v3", chunkstore.SnapshotRequest{Name: "s", RequestID: "rs"}, h3); err != nil { t.Fatal(err) } - clock := time.Now() - cat.SetClock(func() time.Time { clock = clock.Add(time.Second); return clock }) - cat.OpDeadline = time.Nanosecond - if _, err := cat.Fork(ctx, chunkstore.ForkRequest{Source: "v3", Snapshot: "s", Target: "w3", RequestID: "f"}); chunkstore.CodeOf(err) != chunkstore.CodeDeadlineExceeded { - t.Fatalf("stopped fork: %v", err) + + for _, args := range [][]string{ + {"volume-delete", "--chunk-filer", "f:1", "--request-id", "x", "v1"}, // no --master + {"volume-delete", "--chunk-filer", "f:1", "--master", "m:1", "v1"}, // no --request-id + {"volume-delete", "--master", "m:1", "--request-id", "x", "--chunk-filer", "f:1"}, // no volume + {"volume-delete", "--volume", "v1", "--master", "m:1", "--request-id", "x", "v2", "extra"}, // two volumes + } { + if code, out, _ := runChunk(args...); code == 0 || !strings.Contains(out, codeBadRequestCLI) { + t.Fatalf("%v: %d %q; want a bad request", args, code, out) + } } - cat.OpDeadline = 0 - code, out, _ = runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v3") - partial.Error = nil - if code == 0 || json.Unmarshal([]byte(out), &partial) != nil || partial.Error == nil || partial.Error.Code != chunkstore.CodeSnapshotClaimed || !partial.Reverted || !partial.AdmissionAborted { - t.Fatalf("delete of claimed v3: %d %q; want snapshot_claimed, reverted, admission given back", code, out) + + cfg := gcTestMasterConfig(t) + cfg.LifecycleStoreDir = t.TempDir() // the reservation store lives here + h, stop := startDeleteMaster(t, cfg) + lc := lifecycleClient(t, h.Addr()) + run := func(vol, op string) (int, volumeDeleteOutput) { + t.Helper() + code, out, _ := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "--request-id", op, vol) + var got volumeDeleteOutput + if err := json.Unmarshal([]byte(out), &got); err != nil { + t.Fatalf("volume-delete %s: %q", vol, out) + } + return code, got } - if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v3", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { - t.Fatalf("create v3 after the claim refusal: %v; want usable again", err) + usable := func(vol string) { + t.Helper() + if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: vol, SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatalf("create %s: %v; want usable", vol, err) + } } + + // Held: refused, admission given back. + if code, got := run("v2", "op-v2"); code == 0 || got.Error == nil || got.Error.Code != chunkstore.CodeVolumeInUse || !got.Admitted || !got.AdmissionAborted || got.Completed { + t.Fatalf("delete of attached v2: %d %+v", code, got) + } + usable("v2") + + // A first invocation's admission landed and its reply was lost (the + // master holds op-v3); the rerun with the same request id meets the + // snapshot, gives back and so releases that hold too. + if _, err := lc.MarkVolumeDeleting(ctx, &control.MarkVolumeDeletingRequest{VolumeId: "v3", Token: "op-v3"}); err != nil { + t.Fatal(err) + } + if code, got := run("v3", "op-v3"); code == 0 || got.Error == nil || got.Error.Code != chunkstore.CodeVolumeHasSnapshots || !got.Reverted || !got.AdmissionAborted { + t.Fatalf("rerun of v3's delete: %d %+v; want volume_has_snapshots, reverted, given back", code, got) + } + stop() + h, stop = startDeleteMaster(t, cfg) // restart: the given-back id stays usable + defer stop() + lc = lifecycleClient(t, h.Addr()) + usable("v3") if _, err := cat.EnsureVolume(ctx, "v3", geo); err != nil { - t.Fatalf("attach v3 after the claim refusal: %v; want usable again", err) + t.Fatalf("attach v3 after the refused delete: %v", err) } - code, out, errs := runChunk("volume-delete", "--chunk-filer", "f:1", "--master", h.Addr(), "v1") - var res chunkstore.VolumeDeleteResult - if code != 0 || json.Unmarshal([]byte(out), &res) != nil || res.VolumeID != "v1" || res.Replayed || !res.Completed { - t.Fatalf("delete v1: %d %q %q", code, out, errs) + + // Completed: committed, never created again. + code, got := run("v1", "op-v1") + if code != 0 || got.VolumeID != "v1" || !got.Completed || !got.Committed { + t.Fatalf("delete v1: %d %+v", code, got) } if _, err := cat.EnsureVolume(ctx, "v1", geo); chunkstore.CodeOf(err) != chunkstore.CodeVolumeDeleted { t.Fatalf("recreate v1: %v; want volume_deleted", err) } - if !res.Committed { - t.Fatalf("delete v1: %+v; want committed", res) - } if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v1", SizeBytes: 1 << 20, ReplicationFactor: 1}); status.Code(err) != codes.FailedPrecondition { t.Fatalf("create v1 after its committed delete: %v; want FailedPrecondition", err) } } - -func lifecycleClient(t *testing.T, addr string) control.LifecycleServiceClient { - t.Helper() - c, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { c.Close() }) - return control.NewLifecycleServiceClient(c) -} diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index d7e1dfa2ba..8c58201cf5 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -847,16 +847,13 @@ func (c *Catalog) CreateSnapshot(ctx context.Context, vol string, req SnapshotRe if err != nil { return SnapshotInfo{}, err } - // A volume delete marks HEAD deleting before it lists the names: if - // this name was taken after that listing, this read sees the mark, and - // the attempt is given up before anything is published. + // A volume delete marks HEAD deleting before it checks for snapshot + // names: either it sees this name (and refuses), or this read sees the + // mark and nothing is published. The name stays as it is (the delete + // never touches snapshot names; DeleteSnapshot settles it). if gone, err := c.volumeGone(ctx, vol); err != nil { return SnapshotInfo{}, err } else if gone { - // 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. - _, _, _, _ = 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 2a2b13c73a..ef77076bce 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -5,6 +5,7 @@ import ( "errors" "path" "strconv" + "strings" "google.golang.org/protobuf/proto" @@ -12,8 +13,8 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" ) -// Volume delete (claude05's item, 2026-11-16 02:39Z; one linearization -// point per codex01's review of 7c43367). +// Volume delete (claude05's item, 2026-11-16 02:39Z; claude05's 04:08Z +// cut: no snapshot cascade). // // (a) Admission: the caller's Admission (the CLI's: the blockmaster's // durable deletion reservation, MarkVolumeDeleting; refused while the @@ -21,35 +22,36 @@ import ( // placement or binding is admitted and the id is not created again). // Every give-back below aborts this delete's admission (restoring the // volume's usability); the commit point commits it (permanent). -// (b) The linearization point: one conditional write of HEAD from the -// HEAD read (active or detached, NOT held: an active HEAD that names a -// holder belongs to an attached server) to state deleting, chunks -// kept. ChunkRemote.CASHead refuses to move a deleting or deleted -// HEAD, so no attach, claim or restore can revive it; EnsureVolume -// refuses it; Fork and CreateSnapshot check HEAD again after taking -// their claim or name and back out when it is deleting. -// (c) Claims are read after (b): a live fork claim reverts HEAD to its -// previous state (nothing irreversible was done) and refuses -// (snapshot_claimed). A fork claiming later sees the deleting HEAD -// and gives its claim back. -// (c') The commit point: HEAD deleting -> purging, conditioned on the -// HEAD read, then the admission is committed. A revert and a commit -// race on the same conditional write, so a delete that sampled a -// claim can never undo another delete's irreversible steps, and a -// delete whose mark was given back never starts them. -// (d) Only then the irreversible steps: every snapshot name, published or -// not (an unpublished attempt gets an aborted tombstone so its late -// publish cannot land), is marked through markDeleting (the one mark -// path) and freed; the volume's own fork claim is released. -// (e) Finally HEAD becomes deleted (no chunks: nothing it held stays a GC -// root) and VOLUME is marked deleted. GC reclaims. +// (b) One HEAD write from the HEAD read (active or detached, NOT held: an +// active HEAD that names a holder belongs to an attached server) to +// state deleting, chunks kept: a new incarnation of the delete mark +// (its generation). ChunkRemote.CASHead refuses to move a deleting, +// purging or deleted HEAD, so no attach, claim or restore can revive +// it; EnsureVolume refuses it; CreateSnapshot and Fork check the +// volume after taking their name or claim and refuse. +// (c) Under that incarnation, the volume must have no snapshot at all: no +// snapshot name record (a published snapshot, one being deleted, or an +// attempt still in flight). Any is volume_has_snapshots: HEAD is +// reverted and the admission given back. The operator deletes the +// snapshots first (DeleteSnapshot); a delete never touches snapshot +// names, attempts or their roots. (A fork claim lives on a named +// snapshot, so it is covered too.) +// (c') The commit point: HEAD deleting -> purging for that same +// incarnation only (conditioned on its generation); if HEAD moved (a +// revert and re-mark by another delete), the check is made again on +// the incarnation found. A revert is bound the same way, so no delete +// can undo another's commit, nor commit an incarnation it did not +// check. Then the admission is committed. +// (e) HEAD becomes deleted (no chunks: nothing it held stays a GC root) and +// VOLUME is marked deleted. GC reclaims. // // A call that fails reports what it did (VolumeDeleteResult) with the // error; a rerun resumes from the state it finds. const ( - CodeVolumeInUse = "volume_in_use" - CodeVolumeDeleted = "volume_deleted" + CodeVolumeInUse = "volume_in_use" + CodeVolumeDeleted = "volume_deleted" + CodeVolumeHasSnapshots = "volume_has_snapshots" // VolumeDeleted is the state of a deleted volume's VOLUME entry. VolumeDeleted = "deleted" @@ -59,7 +61,7 @@ const ( // Test seams (retainHook stages) in a DeleteVolume. hookHeadMarked = "head-marked" // after (b) - hookClaimFound = "claim-found" // (c) found a live claim, before the revert + hookBlocked = "blocked" // (c) found a snapshot, before the revert hookClaimsChecked = "claims-checked" // after (c), before the commit point ) @@ -86,15 +88,12 @@ type VolumeDeleteResult struct { // AdmissionUncertain: the admission call failed with an unknown // outcome (it may have been recorded); AdmissionAborted: this delete // gave its admission back; Committed: the admission is permanent. - AdmissionUncertain bool `json:"admissionUncertain"` - AdmissionAborted bool `json:"admissionAborted"` - Committed bool `json:"committed"` - HeadMarked bool `json:"headMarked"` // HEAD is deleting or deleted - Reverted bool `json:"reverted"` // (c) gave the HEAD mark back - SnapshotsDeleted []string `json:"snapshotsDeleted"` - AttemptsAborted []string `json:"attemptsAborted"` // unpublished attempts tombstoned - ClaimReleased bool `json:"claimReleased"` // its fork claim was confirmed removed - Completed bool `json:"completed"` // HEAD and VOLUME are deleted + AdmissionUncertain bool `json:"admissionUncertain"` + AdmissionAborted bool `json:"admissionAborted"` + Committed bool `json:"committed"` + HeadMarked bool `json:"headMarked"` // HEAD is deleting or deleted + Reverted bool `json:"reverted"` // (c) gave the HEAD mark back + Completed bool `json:"completed"` // HEAD and VOLUME are deleted // Uncertain is set when the failing call was a write whose outcome is // unknown; a rerun settles it. Uncertain bool `json:"uncertain"` @@ -103,7 +102,7 @@ type VolumeDeleteResult struct { // DeleteVolume deletes vol (see the header). admit may be nil (a catalog- // only delete, e.g. in tests): (b) still refuses a held HEAD. func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) (VolumeDeleteResult, error) { - res := VolumeDeleteResult{VolumeID: vol, SnapshotsDeleted: []string{}, AttemptsAborted: []string{}} + res := VolumeDeleteResult{VolumeID: vol} root, err := c.volRoot(vol) if err != nil { return res, err @@ -142,9 +141,15 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) } return res, cause } - // (b) - if h.State != storage.ChunkHeadPurging && h.State != storage.ChunkHeadDeleted { - u, err := c.markHeadDeleting(ctx, vol, root) + // (b), (c), (c'), each bound to one deleting incarnation (the HEAD + // generation the mark produced or joined): a claim check is only valid + // for the generation it ran under, so if HEAD moved (another delete + // reverted and re-marked it) the check is run again on the new one. + for incarnation := 0; h.State != storage.ChunkHeadPurging && h.State != storage.ChunkHeadDeleted; incarnation++ { + if incarnation == 5 { + return res, remoteErr(nil, "volume %s: the delete mark kept changing", vol) + } + gen, u, err := c.markHeadDeleting(ctx, vol, root) if err != nil { if u { res.Uncertain = true @@ -155,18 +160,23 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) res.HeadMarked = true c.hook(hookHeadMarked, vol) // (c) - live, err := c.anyLiveClaim(ctx, vol) + live, err := c.snapshotsBlock(ctx, vol, root) if err != nil { return res, err } if live != nil { - c.hook(hookClaimFound, vol) - reverted, u, rerr := c.revertHeadDeleting(ctx, vol, root) + c.hook(hookBlocked, vol) + out, u, rerr := c.revertHeadDeleting(ctx, vol, root, gen) switch { case rerr != nil: res.Uncertain = u return res, rerr - case !reverted: + case out == incarnationMoved: + if h, _, err = c.ReadHead(ctx, vol); err != nil { + return res, err + } + continue // decide again on what HEAD is now + case out == incarnationCommitted: // 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) @@ -175,16 +185,22 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) return giveBack(live) } c.hook(hookClaimsChecked, vol) - // (c') the commit point - committed, u, err := c.commitHeadPurging(ctx, vol, root) + // (c') the commit point, on the incarnation the check ran under + out, u, err := c.commitHeadPurging(ctx, vol, root, gen) if err != nil { res.Uncertain = u return res, err } - if !committed { + if out == incarnationDone { + break + } + if out == incarnationGivenBack { res.HeadMarked = false return giveBack(catErr(CodeOutcomeUnknown, true, nil, "volume %s: a concurrent delete gave the mark back; rerun the delete", vol)) } + if h, _, err = c.ReadHead(ctx, vol); err != nil { // moved: validate again + return res, err + } } res.HeadMarked = true if admit != nil { @@ -194,36 +210,6 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) } } res.Committed = true - // (d) - names, err := c.listNames(ctx, root) - if err != nil { - return res, err - } - for _, name := range names { - gone, aborted, u, err := c.deleteNameForVolume(ctx, vol, root, name) - if err != nil { - res.Uncertain = u - return res, err - } - if aborted { - res.AttemptsAborted = append(res.AttemptsAborted, name) - } else if gone { - res.SnapshotsDeleted = append(res.SnapshotsDeleted, name) - } - } - if v.Fork != nil { - req := ForkRequest{Source: v.Fork.Source, Snapshot: v.Fork.Snapshot, Target: vol, RequestID: v.Fork.RequestID} - if ref, ok, err := c.resolveSnap(ctx, req.Source, req.Snapshot); err != nil { - return res, err - } else if ok && ref.entry != nil { - removed, err := c.removeForkClaim(ctx, req, ref.rec.Attempt) - if err != nil { - res.Uncertain = true - return res, err - } - res.ClaimReleased = removed - } - } // (e) if u, err := c.finishHeadDeleted(ctx, vol, root); err != nil { res.Uncertain = u @@ -274,18 +260,22 @@ func lostCondition(err error) bool { // markHeadDeleting is (b): every read decides afresh whether the HEAD is // held, so an attach that landed before this read is refused, and one that -// lands after it makes the write's condition fail. -func (c *Catalog) markHeadDeleting(ctx context.Context, vol, root string) (bool, error) { +// lands after it makes the write's condition fail. gen is the generation of +// the deleting HEAD this call produced or joined (its incarnation). +func (c *Catalog) markHeadDeleting(ctx context.Context, vol, root string) (gen uint64, uncertain bool, err error) { for try := 0; try < 5; try++ { h, _, err := c.ReadHead(ctx, vol) if err != nil { - return false, err + return 0, false, err + } + if h.State == storage.ChunkHeadDeleting { + return h.Gen, false, nil // join this incarnation } if headDeletingOrDeleted(h) { - return false, nil + return h.Gen, false, nil } 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) + return 0, 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 next.State = storage.ChunkHeadDeleting @@ -297,74 +287,82 @@ func (c *Catalog) markHeadDeleting(ctx context.Context, vol, root string) (bool, continue } if err != nil { - return true, catErr(CodeOutcomeUnknown, true, err, "mark HEAD of %s deleting: outcome unknown; rerun the delete", vol) + return 0, true, catErr(CodeOutcomeUnknown, true, err, "mark HEAD of %s deleting: outcome unknown; rerun the delete", vol) } - return false, nil + return h.Gen + 1, false, nil } - return false, remoteErr(nil, "HEAD of %s kept changing", vol) + return 0, false, remoteErr(nil, "HEAD of %s kept changing", vol) } -// revertHeadDeleting gives (b) back: deleting returns to detached when the -// HEAD carries its holder's detach record, else to active. reverted is -// false when the HEAD is no longer deleting (another delete committed, or -// already gave it back). -func (c *Catalog) revertHeadDeleting(ctx context.Context, vol, root string) (reverted, uncertain bool, err error) { - for try := 0; try < 5; try++ { - h, _, err := c.ReadHead(ctx, vol) - if err != nil { - return false, false, err - } - if h.State != storage.ChunkHeadDeleting { - return h.State == storage.ChunkHeadActive || h.State == storage.ChunkHeadDetached || h.State == "", false, nil - } - next := h - next.State = storage.ChunkHeadActive - if h.DetachedBy != nil { - next.State = storage.ChunkHeadDetached - d := *h.DetachedBy - d.Gen = h.Gen + 1 - next.DetachedBy = &d - } - err = c.writeHead(ctx, root, h, next) - if lostCondition(err) { - continue - } - if err != nil { - return false, true, catErr(CodeOutcomeUnknown, true, err, "revert the delete mark on HEAD of %s: outcome unknown; rerun the delete", vol) - } - return true, false, nil +// What a revert or commit found of the incarnation it was bound to. +type incarnationOutcome int + +const ( + incarnationDone incarnationOutcome = iota // reverted / committed by this call, or committed already + incarnationMoved // HEAD is another deleting incarnation now: validate again + incarnationCommitted // past the commit point (by another delete) + incarnationGivenBack // active or detached again (another delete reverted) +) + +// revertHeadDeleting gives (b) back for incarnation gen only: deleting +// returns to detached when the HEAD carries its holder's detach record, +// else to active. +func (c *Catalog) revertHeadDeleting(ctx context.Context, vol, root string, gen uint64) (incarnationOutcome, bool, error) { + h, _, err := c.ReadHead(ctx, vol) + if err != nil { + return 0, false, err } - return false, false, remoteErr(nil, "HEAD of %s kept changing", vol) + switch { + case h.State == storage.ChunkHeadPurging || h.State == storage.ChunkHeadDeleted: + return incarnationCommitted, false, nil + case h.State != storage.ChunkHeadDeleting: + return incarnationGivenBack, false, nil // already given back: nothing to do + case h.Gen != gen: + return incarnationMoved, false, nil + } + next := h + next.State = storage.ChunkHeadActive + if h.DetachedBy != nil { + next.State = storage.ChunkHeadDetached + d := *h.DetachedBy + d.Gen = h.Gen + 1 + next.DetachedBy = &d + } + err = c.writeHead(ctx, root, h, next) + if lostCondition(err) { + return incarnationMoved, false, nil // HEAD moved under the write: decide again + } + if err != nil { + return 0, true, catErr(CodeOutcomeUnknown, true, err, "revert the delete mark on HEAD of %s: outcome unknown; rerun the delete", vol) + } + return incarnationDone, false, nil } -// commitHeadPurging is the commit point: deleting -> purging, conditioned -// on the HEAD read. committed is false when the mark was given back (the -// HEAD is active or detached again). -func (c *Catalog) commitHeadPurging(ctx context.Context, vol, root string) (committed, uncertain bool, err error) { - for try := 0; try < 5; try++ { - h, _, err := c.ReadHead(ctx, vol) - if err != nil { - return false, false, err - } - switch h.State { - case storage.ChunkHeadPurging, storage.ChunkHeadDeleted: - return true, false, nil // committed (by this call's earlier try or another delete) - case storage.ChunkHeadDeleting: - default: - return false, false, nil - } - next := h - next.State = storage.ChunkHeadPurging - err = c.writeHead(ctx, root, h, next) - if lostCondition(err) { - continue - } - if err != nil { - return false, true, catErr(CodeOutcomeUnknown, true, err, "commit the delete of %s: outcome unknown; rerun the delete", vol) - } - return true, false, nil +// commitHeadPurging is the commit point for incarnation gen only: deleting +// -> purging, conditioned on that exact HEAD. +func (c *Catalog) commitHeadPurging(ctx context.Context, vol, root string, gen uint64) (incarnationOutcome, bool, error) { + h, _, err := c.ReadHead(ctx, vol) + if err != nil { + return 0, false, err } - return false, false, remoteErr(nil, "HEAD of %s kept changing", vol) + switch { + case h.State == storage.ChunkHeadPurging || h.State == storage.ChunkHeadDeleted: + return incarnationDone, false, nil // committed (by another delete of the same mark) + case h.State != storage.ChunkHeadDeleting: + return incarnationGivenBack, false, nil + case h.Gen != gen && false: // RED: any deleting incarnation is committed + return incarnationMoved, false, nil + } + next := h + next.State = storage.ChunkHeadPurging + err = c.writeHead(ctx, root, h, next) + if lostCondition(err) { + return incarnationMoved, false, nil + } + if err != nil { + return 0, true, catErr(CodeOutcomeUnknown, true, err, "commit the delete of %s: outcome unknown; rerun the delete", vol) + } + return incarnationDone, false, nil } // finishHeadDeleted is (e) for HEAD: deleting becomes deleted, no chunks. @@ -393,32 +391,15 @@ func (c *Catalog) finishHeadDeleted(ctx context.Context, vol, root string) (bool return false, remoteErr(nil, "HEAD of %s kept changing", vol) } -// anyLiveClaim returns snapshot_claimed for the first published snapshot of -// vol a live fork claims, or nil. -func (c *Catalog) anyLiveClaim(ctx context.Context, vol string) (error, error) { - root, err := c.volRoot(vol) - if err != nil { - return nil, err - } +// snapshotsBlock returns volume_has_snapshots when vol has any snapshot +// name record (published, being deleted, or an attempt in flight), or nil. +func (c *Catalog) snapshotsBlock(ctx context.Context, vol, root string) (error, error) { names, err := c.listNames(ctx, root) if err != nil { return nil, err } - for _, name := range names { - ref, ok, err := c.resolveSnap(ctx, vol, name) - if err != nil { - return nil, err - } - if !ok || ref.entry == nil || ref.info.State != SnapActive { - continue - } - live, err := c.liveClaims(ctx, vol, name, decodeClaims(ref.entry)) - if err != nil { - return nil, err - } - if len(live) > 0 { - return claimedErr(vol, name, live), nil - } + if len(names) > 0 && false { // RED: snapshots do not block the delete + return catErr(CodeVolumeHasSnapshots, false, nil, "volume %s has snapshots (%s); delete them first", vol, strings.Join(names, ", ")), nil } return nil, nil } @@ -448,49 +429,6 @@ func (c *Catalog) listNames(ctx context.Context, root string) ([]string, error) } } -// deleteNameForVolume is (d) for one name: a published attempt goes through -// markDeleting; an unpublished one gets an aborted tombstone at its path -// (so its late publish can never land); then the name is freed. -func (c *Catalog) deleteNameForVolume(ctx context.Context, vol, root, name string) (gone, aborted, uncertain bool, err error) { - for try := 0; try < 5; try++ { - ref, ok, err := c.resolveSnap(ctx, vol, name) - if err != nil { - return false, false, false, err - } - if !ok { - return false, false, false, nil // freed meanwhile - } - attempt := ref.rec.Attempt - if ref.entry == nil { - tomb, err := c.abortedSnapEntry(vol, name, attempt) - if err != nil { - return false, false, false, err - } - if err := c.f.CreateEntry(ctx, path.Join(root, snapsDir, name), tomb, true); err != nil && !errors.Is(err, ErrExists) { - return false, false, true, remoteErr(err, "abort the unpublished attempt of %s/%s", vol, name) - } - continue // re-read: the tombstone, or the attempt that won - } - wasAborted := ref.info.State == SnapAborted - m, live, u, err := c.markDeleting(ctx, vol, name, attempt) - if err != nil { - return false, false, u, err - } - if m == markClaimed { - // A fork claimed after (c); it backs out on the deleting HEAD. - if try < 4 { - continue - } - return false, false, false, claimedErr(vol, name, live) - } - if _, u, err := c.freeName(ctx, root, name, attempt); err != nil { - return false, false, u, err - } - return !wasAborted, wasAborted, false, nil - } - return false, false, false, remoteErr(nil, "snapshot %s/%s kept changing", vol, name) -} - // markVolumeDeleted marks vol's VOLUME entry deleted, conditioned on it not // being marked yet. func (c *Catalog) markVolumeDeleted(ctx context.Context, vol, root string) error { diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go index c064dc7191..0f851565b9 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go @@ -13,8 +13,8 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" ) -// Volume delete (claude05's item; one linearization point per codex01's -// review of 7c43367). One control per review schedule. +// Volume delete: one linearization point, no snapshot cascade (claude05, +// 04:08Z). One control per review schedule. // detachHead publishes vol's HEAD as a clean detach by its holder (what a // volume server's Detach writes). @@ -37,8 +37,7 @@ func detachHead(t *testing.T, f *fakeFiler, b *fakeBlobs, vol string) { } } -// attachEntry is the HEAD an attaching holder installs over cur (a takeover: -// new holder, next epoch). +// attachEntry is the HEAD an attaching holder installs over cur. func attachEntry(t *testing.T, cur storage.ChunkHead, holder string) *filerpb.Entry { t.Helper() att := cur @@ -50,20 +49,17 @@ func attachEntry(t *testing.T, cur storage.ChunkHead, holder string) *filerpb.En return e } +// deleteFixture: v1 with an attached HEAD (held by h1) and no snapshots; +// directory entries for v1, w2, w3 (the fake lists only what it holds). func deleteFixture(t *testing.T) (*fakeFiler, *fakeBlobs, *Catalog, storage.ChunkHead) { t.Helper() - f, b, c, h := catalogFixture(t) // v1 HEAD held by h1 (attached) + f, b, c, h := catalogFixture(t) ctx := context.Background() for _, vol := range []string{"v1", "w2", "w3"} { if err := f.CreateEntry(ctx, catBase, &filerpb.Entry{Name: vol, IsDirectory: true}, true); err != nil { t.Fatal(err) } } - for _, name := range []string{"s1", "s2"} { - if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: name, RequestID: "r-" + name}, h); err != nil { - t.Fatal(err) - } - } return f, b, c, h } @@ -76,305 +72,13 @@ func headState(t *testing.T, c *Catalog, vol string) storage.ChunkHead { return h } -// An attached volume (HEAD held), or one the admission refuses, is refused -// with volume_in_use and nothing is written. -func TestCatalog_DeleteVolumeRefusesAVolumeInUse(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - before := len(f.allWritten()) - if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { - t.Fatalf("delete of an attached volume: %v; want volume_in_use", err) - } - if got := len(f.allWritten()); got != before { - t.Fatalf("a refused delete wrote %d entries", got-before) - } - detachHead(t, f, b, "v1") - before = len(f.allWritten()) - res, err := c.DeleteVolume(ctx, "v1", (&fakeReservation{refuse: true}).admission("d1")) - var ce *CatalogError - if !errors.As(err, &ce) || ce.Code != CodeVolumeInUse || ce.Retryable || !strings.Contains(ce.Detail(), "assigned to r1") || res.Admitted || res.AdmissionUncertain { - t.Fatalf("delete the admission refuses: %+v %v; want volume_in_use naming the reason", res, err) - } - if got := len(f.allWritten()); got != before { - t.Fatalf("a refused delete wrote %d entries", got-before) - } -} - -// Schedule 1: a holder attaches after the delete's first read, before the -// HEAD mark's read. The mark reads the held HEAD and refuses; HEAD stays -// the holder's. -func TestCatalog_DeleteVolumeRefusesAnAttachBeforeTheMark(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - headPath := path.Join(catBase, "v1", headName) - lookups := 0 - f.afterLookup = func(p string) { - if p != headPath { - return - } - if lookups++; lookups == 1 { // the delete's first read; the mark reads next - cur, _ := decodeHead(p, f.entries[p]) - f.entries[p] = attachEntry(t, cur, "h2") - } - } - if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { - t.Fatalf("delete racing an attach: %v; want volume_in_use", err) - } - f.afterLookup = nil - if h := headState(t, c, "v1"); h.Holder != "h2" || h.State != storage.ChunkHeadActive { - t.Fatalf("HEAD after the refused delete: %+v; want h2's, active", h) - } -} - -// An attach between the mark's read and its write makes the write's -// condition fail; the re-read sees the holder and refuses. -func TestCatalog_DeleteVolumeLosesToAnAttachAtTheMark(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - headPath := path.Join(catBase, "v1", headName) - lookups := 0 - f.afterLookup = func(p string) { - if p != headPath { - return - } - if lookups++; lookups == 2 { // the mark's read; the write is conditioned on it - cur, _ := decodeHead(p, f.entries[p]) - f.entries[p] = attachEntry(t, cur, "h2") - } - } - if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeInUse { - t.Fatalf("delete losing to an attach: %v; want volume_in_use", err) - } - f.afterLookup = nil - if h := headState(t, c, "v1"); h.Holder != "h2" || h.State != storage.ChunkHeadActive { - t.Fatalf("HEAD after the lost delete: %+v; want h2's", h) - } -} - -// Schedule 2: an attach that passed EnsureVolume before the mark claims -// HEAD afterwards (CASHead from the deleting or deleted HEAD it reads): the -// remote refuses, so nothing revives the volume. -func TestCatalog_DeletedHeadCannotBeRevivedByAClaim(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - r, err := NewChunkRemote(f, b, path.Join(catBase, "v1")) - if err != nil { - t.Fatal(err) - } - claim := func(stage string) { - t.Helper() - h, err := r.GetHead(ctx) - if err != nil { - t.Fatal(err) - } - _, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: h.Epoch}, storage.ChunkHead{Epoch: h.Epoch + 1, Holder: "late", RemoteLSN: h.RemoteLSN, Chunks: h.Chunks, State: storage.ChunkHeadActive}) - if !errors.Is(err, storage.ErrChunkHeadPrecondition) || !errors.Is(err, storage.ErrChunkHeadDeleted) { - t.Fatalf("claim of a %s HEAD: %v; want a precondition failure (deleted)", stage, err) - } - if _, err := c.EnsureVolume(ctx, "v1", catGeo); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("attach of a %s volume: %v; want volume_deleted", stage, err) - } - } - c.retainHook = func(stage, _ string) { - if stage == hookHeadMarked { - claim("deleting") - } - } - res, err := c.DeleteVolume(ctx, "v1", nil) - c.retainHook = nil - if err != nil || !res.Completed { - t.Fatalf("delete: %+v %v", res, err) - } - claim("deleted") - if h := headState(t, c, "v1"); h.State != storage.ChunkHeadDeleted || h.Holder != "" || len(h.Chunks) != 0 { - t.Fatalf("HEAD after the delete: %+v; want the deleted tombstone", h) - } -} - -// A fork claim that lands before the claims are read (after the mark) -// makes the delete give the mark back: snapshot_claimed, HEAD restored, -// nothing irreversible done. -func TestCatalog_DeleteVolumeGivesBackOnALiveClaim(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - before := headState(t, c, "v1") - holdFirst(f, catBase+"/w3/HEAD") - c.retainHook = func(stage, _ string) { - if stage == hookHeadMarked { // the claim lands after the mark, before the read of claims - c.retainHook = nil - // Fork's own claim write is what lands here; its post-check then - // refuses on the deleting HEAD, so take only the claim. - if _, err := c.claimForkParent(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); err != nil { - t.Fatal(err) - } - // The fork published its VOLUME before the delete began. - ve, _ := volumeEntry(VolumeInfo{Format: volumeFormat, VolumeID: "w3", Geometry: catGeo, Origin: OriginFork, Parent: &Parent{VolumeID: "v1", Snapshot: "s2"}, - Fork: &ForkRecord{RequestID: "f3", Source: "v1", Snapshot: "s2"}}, "f3") - if err := f.CreateEntry(ctx, catBase+"/w3", ve, true); err != nil { - t.Fatal(err) - } - } - } - rsv := &fakeReservation{} - res, err := c.DeleteVolume(ctx, "v1", rsv.admission("d1")) - if CodeOf(err) != CodeSnapshotClaimed || !res.Reverted || res.HeadMarked || len(res.SnapshotsDeleted) != 0 || !res.AdmissionAborted || res.Committed { - t.Fatalf("delete under a live claim: %+v %v; want snapshot_claimed, reverted, admission given back", res, err) - } - if rsv.state != "" { - t.Fatalf("reservation after the give-back: %q; want none (the volume is usable again)", rsv.state) - } - after := headState(t, c, "v1") - if after.State != storage.ChunkHeadDetached || after.DetachedBy == nil || after.Holder != before.Holder || len(after.Chunks) != len(before.Chunks) { - t.Fatalf("HEAD after the give-back: %+v; want the detached HEAD with its chunks", after) - } - if v, _, _ := c.ReadVolume(ctx, "v1"); v.State != "" { - t.Fatalf("VOLUME state %q after the give-back", v.State) - } - for _, s := range []string{"s1", "s2"} { - if _, err := c.readSnap(ctx, "v1", s); err != nil { - t.Fatalf("%s after the give-back: %v", s, err) - } - } -} - -// A fork that claims after the claims were read sees the deleting HEAD and -// gives its claim back before installing anything; the delete completes. -func TestCatalog_ForkAfterTheDeleteMarkRefuses(t *testing.T) { - f, b, c, _ := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - ran := false - c.retainHook = func(stage, _ string) { - if stage != hookClaimsChecked || ran { - return - } - ran = true - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "late"}); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("fork after the delete mark: %v; want volume_deleted", err) - } - } - res, err := c.DeleteVolume(ctx, "v1", nil) - if err != nil || !ran || !res.Completed || strings.Join(res.SnapshotsDeleted, ",") != "s1,s2" { - t.Fatalf("delete: ran=%t %+v %v", ran, res, err) - } - if _, ok, _ := c.ReadVolume(ctx, "w2"); ok { - t.Fatal("the refused fork published its VOLUME") - } -} - -// P2: a snapshot whose publication is held while the delete lists the names -// (its name record exists, its attempt not yet) is tombstoned, so its late -// publish cannot land; a snapshot started after the mark refuses itself. -func TestCatalog_DeleteVolumeCatchesInFlightSnapshots(t *testing.T) { - f, b, c, h := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - held := catBase + "/v1/" + snapsDir + "/s3/" - f.deferCreate = func(p string, _ *filerpb.Entry) bool { return strings.HasPrefix(p, held) } - if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s3", RequestID: "r-s3"}, h); err == nil { - t.Fatal("held snapshot publication reported success") - } - f.deferCreate = nil - late := false - c.retainHook = func(stage, _ string) { - if stage == hookHeadMarked && !late { - late = true - if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s4", RequestID: "r-s4"}, h); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("snapshot started after the mark: %v; want volume_deleted", err) - } - } - } - res, err := c.DeleteVolume(ctx, "v1", nil) - c.retainHook = nil - if err != nil || !res.Completed || strings.Join(res.AttemptsAborted, ",") != "s3" { - t.Fatalf("delete: %+v %v; want s3's unpublished attempt aborted", res, err) - } - f.releaseDeferredCreates() // the held publish finally runs - for _, name := range []string{"s3", "s4"} { - if _, ok, _ := c.resolveSnap(ctx, "v1", name); ok { - t.Fatalf("%s's name survived the delete", name) - } - } - snaps, err := c.listSnapshots(ctx, "v1", true) - if err != nil || len(snaps) != 0 { - t.Fatalf("snapshots left after the delete: %v %v", snaps, err) - } - attempts, _ := f.ListEntries(ctx, held[:len(held)-1], "", "", 0) - for _, e := range attempts { - if s := string(e.Extended[extSnapState]); s != SnapAborted { - t.Fatalf("s3 attempt %s is %q after the late publish; want the aborted tombstone", e.GetName(), s) - } - } -} - -// The acceptance flow on the fake: fork w2 from s1, delete w2, then s1 can -// be deleted; the deleted id is never attached, recreated or forked to -// again; an incomplete fork w3 is deleted and its claim released (only -// when confirmed); a rerun replays. -func TestCatalog_DeleteVolumeTombstonesAndReleases(t *testing.T) { - f, _, c, _ := deleteFixture(t) - ctx := context.Background() - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "f2"}); err != nil { - t.Fatalf("fork w2: %v", err) - } - if _, err := c.CreateSnapshot(ctx, "w2", SnapshotRequest{Name: "w2snap", RequestID: "rw"}, mustHead(t, c, "w2")); err != nil { - t.Fatal(err) - } - res, err := c.DeleteVolume(ctx, "w2", nil) - if err != nil || res.Replayed || !res.Completed || strings.Join(res.SnapshotsDeleted, ",") != "w2snap" { - t.Fatalf("delete w2: %+v %v", res, err) - } - if h := headState(t, c, "w2"); h.State != storage.ChunkHeadDeleted || len(h.Chunks) != 0 { - t.Fatalf("w2 HEAD: %+v; want a deleted tombstone with no chunks", h) - } - if v, _, _ := c.ReadVolume(ctx, "w2"); v.State != VolumeDeleted { - t.Fatalf("w2 VOLUME state %q", v.State) - } - if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { - t.Fatalf("delete s1 after its fork was deleted: %v", err) - } - if _, err := c.EnsureVolume(ctx, "w2", catGeo); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("attach/create of deleted w2: %v; want volume_deleted", err) - } - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w2", RequestID: "again"}); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("fork to deleted w2: %v; want volume_deleted", err) - } - if res, err := c.DeleteVolume(ctx, "w2", nil); err != nil || !res.Replayed { - t.Fatalf("rerun: %+v %v; want a replay", res, err) - } - - // Incomplete fork w3: a failed claim removal is not reported released. - holdFirst(f, catBase+"/w3/HEAD") - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { - t.Fatalf("fork w3: %v", err) - } - s2 := path.Join(catBase, "v1", snapsDir, "s2") - f.failUpdate = func(p string) error { - if strings.HasPrefix(p, s2+"/") { - return errors.New("filer unavailable") - } - return nil - } - res, err = c.DeleteVolume(ctx, "w3", nil) - if err == nil || res.ClaimReleased || !res.Uncertain || res.Completed { - t.Fatalf("delete w3 with a failing claim removal: %+v %v; want an error, claim not released, uncertain", res, err) - } - f.failUpdate = nil - rsv := &fakeReservation{} - res, err = c.DeleteVolume(ctx, "w3", rsv.admission("d3")) - if err != nil || !res.ClaimReleased || !res.Completed || !res.Committed || rsv.state != reservationCommitted { - t.Fatalf("delete w3 rerun: %+v %v; want its claim released", res, err) - } - if got := claimsOf(t, c, "s2"); len(got) != 0 { - t.Fatalf("s2 claims after w3 was deleted: %v", got) - } - if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); err != nil { - t.Fatalf("delete s2 after w3 was deleted: %v", err) +func mustHead(t *testing.T, c *Catalog, vol string) storage.ChunkHead { + t.Helper() + h, has, err := c.ReadHead(context.Background(), vol) + if err != nil || !has { + t.Fatalf("HEAD of %s: has=%t %v", vol, has, err) } + return h } // fakeReservation mirrors the blockmaster's deletion reservation (tokens, @@ -441,61 +145,284 @@ func (a *fakeAdmit) Abort(context.Context, string) error { return nil } -// A held HEAD found after the admission gives the admission back. -func TestCatalog_DeleteVolumeHeldAfterAdmissionGivesBack(t *testing.T) { - _, _, c, _ := deleteFixture(t) // v1 is attached +// An attached volume (HEAD held), or one the admission refuses, is refused +// with volume_in_use and nothing is written; a held HEAD found after the +// admission gives the admission back. +func TestCatalog_DeleteVolumeRefusesAVolumeInUse(t *testing.T) { + f, b, c, _ := deleteFixture(t) + ctx := context.Background() + before := len(f.allWritten()) rsv := &fakeReservation{} - res, err := c.DeleteVolume(context.Background(), "v1", rsv.admission("d1")) - if CodeOf(err) != CodeVolumeInUse || !res.Admitted || !res.AdmissionAborted || rsv.state != "" { - t.Fatalf("held after admission: %+v %v reservation=%q; want volume_in_use and the admission given back", res, err, rsv.state) + res, err := c.DeleteVolume(ctx, "v1", rsv.admission("d1")) + if CodeOf(err) != CodeVolumeInUse || !res.AdmissionAborted || rsv.state != "" { + t.Fatalf("delete of an attached volume: %+v %v reservation=%q; want volume_in_use, admission given back", res, err, rsv.state) + } + if got := len(f.allWritten()); got != before { + t.Fatalf("a refused delete wrote %d entries", got-before) + } + detachHead(t, f, b, "v1") + before = len(f.allWritten()) + res, err = c.DeleteVolume(ctx, "v1", (&fakeReservation{refuse: true}).admission("d1")) + var ce *CatalogError + if !errors.As(err, &ce) || ce.Code != CodeVolumeInUse || ce.Retryable || !strings.Contains(ce.Detail(), "assigned to r1") || res.Admitted { + t.Fatalf("delete the admission refuses: %+v %v", res, err) + } + if got := len(f.allWritten()); got != before { + t.Fatalf("a refused delete wrote %d entries", got-before) } } -// A lost admission response is reported as an unknown outcome (it may be -// recorded), never as a plain refusal, and nothing is written. -func TestCatalog_DeleteVolumeLostAdmissionResponse(t *testing.T) { +// Schedule: a holder attaches after the delete's first read, before the +// mark's read; the mark reads the held HEAD and refuses. +func TestCatalog_DeleteVolumeRefusesAnAttachBeforeTheMark(t *testing.T) { f, b, c, _ := deleteFixture(t) detachHead(t, f, b, "v1") - before := len(f.allWritten()) - rsv := &fakeReservation{loseAdmit: true} - res, err := c.DeleteVolume(context.Background(), "v1", rsv.admission("d1")) - var ce *CatalogError - if !errors.As(err, &ce) || ce.Code != CodeOutcomeUnknown || !ce.Retryable || !res.AdmissionUncertain || !res.Uncertain || res.Admitted { - t.Fatalf("lost admission response: %+v %v; want outcome_unknown, admission uncertain", res, err) + headPath := path.Join(catBase, "v1", headName) + lookups := 0 + f.afterLookup = func(p string) { + if p != headPath { + return + } + if lookups++; lookups == 1 { + cur, _ := decodeHead(p, f.entries[p]) + f.entries[p] = attachEntry(t, cur, "h2") + } } - if got := len(f.allWritten()); got != before || rsv.state != reservationAdmitted { - t.Fatalf("wrote %d entries; reservation %q (the lost admission did land)", got-before, rsv.state) + if _, err := c.DeleteVolume(context.Background(), "v1", nil); CodeOf(err) != CodeVolumeInUse { + t.Fatalf("delete racing an attach: %v; want volume_in_use", err) + } + f.afterLookup = nil + if h := headState(t, c, "v1"); h.Holder != "h2" || h.State != storage.ChunkHeadActive { + t.Fatalf("HEAD after the refused delete: %+v; want h2's", h) } } -// P2 (concurrent deletes): D1 samples a live claim and pauses before its -// revert; the fork completes, D2 joins the deleting HEAD, finds no claim, -// commits and deletes. D1's revert then finds the HEAD past the commit -// point: it neither reverts nor gives its admission back, and the -// reservation stays committed. -func TestCatalog_ConcurrentDeleteCannotRollBackACommittedOne(t *testing.T) { +// An attach between the mark's read and its write makes the write's +// condition fail; the re-read sees the holder and refuses. +func TestCatalog_DeleteVolumeLosesToAnAttachAtTheMark(t *testing.T) { + f, b, c, _ := deleteFixture(t) + detachHead(t, f, b, "v1") + headPath := path.Join(catBase, "v1", headName) + lookups := 0 + f.afterLookup = func(p string) { + if p != headPath { + return + } + if lookups++; lookups == 2 { + cur, _ := decodeHead(p, f.entries[p]) + f.entries[p] = attachEntry(t, cur, "h2") + } + } + if _, err := c.DeleteVolume(context.Background(), "v1", nil); CodeOf(err) != CodeVolumeInUse { + t.Fatalf("delete losing to an attach: %v; want volume_in_use", err) + } + f.afterLookup = nil + if h := headState(t, c, "v1"); h.Holder != "h2" { + t.Fatalf("HEAD after the lost delete: %+v; want h2's", h) + } +} + +// An attach that passed EnsureVolume before the mark claims HEAD afterwards +// (CASHead from the deleting or deleted HEAD): the remote refuses. +func TestCatalog_DeletedHeadCannotBeRevivedByAClaim(t *testing.T) { f, b, c, _ := deleteFixture(t) ctx := context.Background() detachHead(t, f, b, "v1") - holdFirst(f, catBase+"/w3/HEAD") - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { - t.Fatalf("fork w3: %v", err) + r, err := NewChunkRemote(f, b, path.Join(catBase, "v1")) + if err != nil { + t.Fatal(err) + } + claim := func(stage string) { + t.Helper() + h, err := r.GetHead(ctx) + if err != nil { + t.Fatal(err) + } + _, err = r.CASHead(ctx, storage.ChunkHeadVersion{Gen: h.Gen, Epoch: h.Epoch}, storage.ChunkHead{Epoch: h.Epoch + 1, Holder: "late", RemoteLSN: h.RemoteLSN, Chunks: h.Chunks, State: storage.ChunkHeadActive}) + if !errors.Is(err, storage.ErrChunkHeadPrecondition) || !errors.Is(err, storage.ErrChunkHeadDeleted) { + t.Fatalf("claim of a %s HEAD: %v; want a precondition failure (deleted)", stage, err) + } + if _, err := c.EnsureVolume(ctx, "v1", catGeo); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("attach of a %s volume: %v; want volume_deleted", stage, err) + } + } + c.retainHook = func(stage, _ string) { + if stage == hookHeadMarked { + claim("deleting") + } + } + res, err := c.DeleteVolume(ctx, "v1", nil) + c.retainHook = nil + if err != nil || !res.Completed { + t.Fatalf("delete: %+v %v", res, err) + } + claim("deleted") +} + +// The cut: a volume with any snapshot is refused (volume_has_snapshots) +// with HEAD restored and the admission given back; deleting the snapshot +// first lets the delete complete; snapshots are never touched by it. +func TestCatalog_DeleteVolumeRefusesWhileSnapshotsExist(t *testing.T) { + f, b, c, h := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r-s1"}, h); err != nil { + t.Fatal(err) + } + before := headState(t, c, "v1") + rsv := &fakeReservation{} + res, err := c.DeleteVolume(ctx, "v1", rsv.admission("d1")) + if CodeOf(err) != CodeVolumeHasSnapshots || !res.Reverted || !res.AdmissionAborted || res.Committed || rsv.state != "" { + t.Fatalf("delete with a snapshot: %+v %v reservation=%q; want volume_has_snapshots, reverted, given back", res, err, rsv.state) + } + after := headState(t, c, "v1") + if after.State != storage.ChunkHeadDetached || after.Holder != before.Holder || len(after.Chunks) != len(before.Chunks) { + t.Fatalf("HEAD after the refusal: %+v; want the detached HEAD with its chunks", after) + } + if s, err := c.readSnap(ctx, "v1", "s1"); err != nil || s.State != SnapActive { + t.Fatalf("s1 after the refusal: %+v %v; want untouched", s, err) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { + t.Fatal(err) + } + res, err = c.DeleteVolume(ctx, "v1", rsv.admission("d2")) + if err != nil || !res.Completed || !res.Committed || rsv.state != reservationCommitted { + t.Fatalf("delete after DeleteSnapshot: %+v %v", res, err) + } +} + +// claude05's test: a snapshot attempt in flight (name taken, publication +// held) when the delete marks HEAD: the delete refuses and reverts, and the +// snapshot then publishes cleanly. A snapshot started after the mark +// refuses itself. +func TestCatalog_InFlightSnapshotRefusesTheDelete(t *testing.T) { + f, b, c, h := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + held := catBase + "/v1/" + snapsDir + "/s3/" + f.deferCreate = func(p string, _ *filerpb.Entry) bool { return strings.HasPrefix(p, held) } + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s3", RequestID: "r-s3"}, h); err == nil { + t.Fatal("held snapshot publication reported success") + } + f.deferCreate = nil + late := false + c.retainHook = func(stage, _ string) { + if stage == hookHeadMarked && !late { + late = true + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s4", RequestID: "r-s4"}, h); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("snapshot started after the mark: %v; want volume_deleted", err) + } + } + } + res, err := c.DeleteVolume(ctx, "v1", nil) + c.retainHook = nil + if CodeOf(err) != CodeVolumeHasSnapshots || !res.Reverted { + t.Fatalf("delete with an in-flight snapshot: %+v %v; want volume_has_snapshots, reverted", res, err) + } + if n := f.releaseDeferredCreates(); n != 1 { + t.Fatalf("released %d held publications, want 1", n) + } + s, err := c.readSnap(ctx, "v1", "s3") + if err != nil || s.State != SnapActive { + t.Fatalf("s3 after the refused delete: %+v %v; want published", s, err) + } + if hh := headState(t, c, "v1"); hh.State != storage.ChunkHeadDetached { + t.Fatalf("HEAD after the refused delete: %+v", hh) + } +} + +// A fork that claims during the delete mark sees the deleting source and +// refuses before installing anything; the delete refuses too (the forked +// snapshot exists) and reverts. +func TestCatalog_ForkDuringTheDeleteMarkRefuses(t *testing.T) { + f, b, c, h := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r-s1"}, h); err != nil { + t.Fatal(err) + } + c.retainHook = func(stage, _ string) { + if stage == hookHeadMarked { + c.retainHook = nil + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "late"}); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("fork during the delete mark: %v; want volume_deleted", err) + } + } + } + if _, err := c.DeleteVolume(ctx, "v1", nil); CodeOf(err) != CodeVolumeHasSnapshots { + t.Fatalf("delete: %v; want volume_has_snapshots", err) + } + if _, ok, _ := c.ReadVolume(ctx, "w2"); ok { + t.Fatal("the refused fork published its VOLUME") + } + if got := claimsOf(t, c, "s1"); len(got) != 0 { + t.Fatalf("the refused fork left claims %v", got) + } +} + +// P2 (incarnation): D1 checks under deleting generation G and pauses +// before its commit. A blocker appears, D2 sees it and reverts G, and a +// new delete mark (D3's) installs generation G'. D1 must not commit G' +// (whose snapshots it never checked): it checks again, finds the blocker +// and gives back. +func TestCatalog_DeleteCommitIsBoundToItsIncarnation(t *testing.T) { + f, b, c, h := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + root := path.Join(catBase, "v1") + rsv := &fakeReservation{} + var d2err error + c.retainHook = func(stage, _ string) { + if stage != hookClaimsChecked { + return + } + c.retainHook = nil + // A snapshot name appears (a creator that took its name, then saw + // the mark and refused: its name record stays). + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "late", RequestID: "r-late"}, h); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("snapshot during the mark: %v", err) + } + _, d2err = c.DeleteVolume(ctx, "v1", rsv.admission("d2")) // sees it, reverts G + if _, _, err := c.markHeadDeleting(ctx, "v1", root); err != nil { // D3 re-marks: G' + t.Fatal(err) + } + } + res, err := c.DeleteVolume(ctx, "v1", rsv.admission("d1")) + if CodeOf(d2err) != CodeVolumeHasSnapshots { + t.Fatalf("D2: %v; want volume_has_snapshots", d2err) + } + if CodeOf(err) != CodeVolumeHasSnapshots || res.Committed { + t.Fatalf("D1 after the re-mark: %+v %v; want volume_has_snapshots, not committed", res, err) + } + if hh := headState(t, c, "v1"); hh.State == storage.ChunkHeadPurging || hh.State == storage.ChunkHeadDeleted { + t.Fatalf("HEAD %q: D1 committed an incarnation it did not check", hh.State) + } + if rsv.state == reservationCommitted { + t.Fatal("the reservation was committed") + } +} + +// Concurrent deletes: D1 finds a snapshot and pauses before its revert; +// the snapshot is deleted and D2 joins, commits and completes. D1's revert +// then finds the HEAD committed: it neither reverts nor gives back. +func TestCatalog_ConcurrentDeleteCannotRollBackACommittedOne(t *testing.T) { + f, b, c, h := deleteFixture(t) + ctx := context.Background() + detachHead(t, f, b, "v1") + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r-s1"}, h); err != nil { + t.Fatal(err) } rsv := &fakeReservation{} var d2 VolumeDeleteResult var d2err error c.retainHook = func(stage, _ string) { - if stage != hookClaimFound { + if stage != hookBlocked { return } c.retainHook = nil - // The fork completes (its claim is no longer live), then D2 runs. - if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeVolumeDeleted { - // Its retry sees the deleting source and backs out; give the - // target a real HEAD as a completed fork would have. - t.Logf("fork retry during the delete: %v", err) + if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { + t.Fatal(err) } - forceHead(t, f, b, "w3") d2, d2err = c.DeleteVolume(ctx, "v1", rsv.admission("d2")) } d1, err := c.DeleteVolume(ctx, "v1", rsv.admission("d1")) @@ -505,79 +432,85 @@ func TestCatalog_ConcurrentDeleteCannotRollBackACommittedOne(t *testing.T) { if err == nil || d1.Reverted || d1.AdmissionAborted { t.Fatalf("D1 after D2 committed: %+v %v; want an error, no revert, no give-back", d1, err) } - if h := headState(t, c, "v1"); h.State != storage.ChunkHeadDeleted { - t.Fatalf("HEAD after both: %+v; want deleted", h) - } - if rsv.state != reservationCommitted { - t.Fatalf("reservation %q; want committed", rsv.state) + if hh := headState(t, c, "v1"); hh.State != storage.ChunkHeadDeleted || rsv.state != reservationCommitted { + t.Fatalf("after both: HEAD %q reservation %q; want deleted, committed", hh.State, rsv.state) } } -// forceHead installs a real active HEAD for vol (a completed fork's). -func forceHead(t *testing.T, f *fakeFiler, b *fakeBlobs, vol string) { - t.Helper() - f.mu.Lock() - defer f.mu.Unlock() - e, err := headEntry(storage.ChunkHead{Gen: 1, Chunks: map[uint64]storage.ChunkRef{}, State: storage.ChunkHeadActive}) - if err != nil { +// A lost admission response is an unknown outcome (it may be recorded), +// never a refusal, and nothing is written. +func TestCatalog_DeleteVolumeLostAdmissionResponse(t *testing.T) { + f, b, c, _ := deleteFixture(t) + detachHead(t, f, b, "v1") + before := len(f.allWritten()) + rsv := &fakeReservation{loseAdmit: true} + res, err := c.DeleteVolume(context.Background(), "v1", rsv.admission("d1")) + var ce *CatalogError + if !errors.As(err, &ce) || ce.Code != CodeOutcomeUnknown || !ce.Retryable || !res.AdmissionUncertain || !res.Uncertain || res.Admitted { + t.Fatalf("lost admission response: %+v %v", res, err) + } + if got := len(f.allWritten()); got != before || rsv.state != reservationAdmitted { + t.Fatalf("wrote %d entries; reservation %q (the lost admission did land)", got-before, rsv.state) + } +} + +// The acceptance flow on the fake: fork w2 from s1; w2's own snapshot must +// be deleted first; then w2 is deleted, s1 can be deleted, and the id is +// never attached, recreated or forked to again; an incomplete fork w3 is +// deleted too (its claim is then dead); a rerun replays. +func TestCatalog_DeleteVolumeTombstonesAndRefusesReuse(t *testing.T) { + f, _, c, h := deleteFixture(t) + ctx := context.Background() + for _, name := range []string{"s1", "s2"} { + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: name, RequestID: "r-" + name}, h); err != nil { + t.Fatal(err) + } + } + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "f2"}); err != nil { + t.Fatalf("fork w2: %v", err) + } + if _, err := c.CreateSnapshot(ctx, "w2", SnapshotRequest{Name: "w2snap", RequestID: "rw"}, mustHead(t, c, "w2")); err != nil { t.Fatal(err) } - f.entries[path.Join(catBase, vol, headName)] = e - _ = b -} - -// P2 (failed abort, late publication): snapshot A takes name s5 and parks -// before publishing; the delete marks HEAD; A's same-request retry B sees -// the mark and tries to abort the attempt, but the tombstone write fails: -// the name must stay (not freed), so the delete still finds and settles it -// and the late publication cannot leave an active root. -func TestCatalog_FailedAbortCannotHideALatePublication(t *testing.T) { - f, b, c, h := deleteFixture(t) - ctx := context.Background() - detachHead(t, f, b, "v1") - held := catBase + "/v1/" + snapsDir + "/s5/" - f.deferCreate = func(p string, _ *filerpb.Entry) bool { return strings.HasPrefix(p, held) } - if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s5", RequestID: "r-s5"}, h); err == nil { - t.Fatal("A's held publication reported success") + if _, err := c.DeleteVolume(ctx, "w2", nil); CodeOf(err) != CodeVolumeHasSnapshots { + t.Fatalf("delete w2 with a snapshot: %v; want volume_has_snapshots", err) } - f.deferCreate = nil - c.retainHook = func(stage, _ string) { - if stage != hookHeadMarked { - return - } - c.retainHook = nil - f.failCreate = func(p string) error { - if strings.HasPrefix(p, held) { - return errors.New("filer unavailable") - } - return nil - } - if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s5", RequestID: "r-s5"}, h); CodeOf(err) != CodeVolumeDeleted { - t.Fatalf("B, the same request after the mark: %v; want volume_deleted", err) - } - f.failCreate = nil - if _, ok, _ := c.resolveSnap(ctx, "v1", "s5"); !ok { - t.Fatal("B freed s5's name although its abort failed") - } + if _, err := c.DeleteSnapshot(ctx, "w2", "w2snap"); err != nil { + t.Fatal(err) } - res, err := c.DeleteVolume(ctx, "v1", nil) - if err != nil || !res.Completed { - t.Fatalf("delete: %+v %v", res, err) + res, err := c.DeleteVolume(ctx, "w2", nil) + if err != nil || res.Replayed || !res.Completed { + t.Fatalf("delete w2: %+v %v", res, err) } - f.releaseDeferredCreates() // A's publish finally runs - attempts, _ := f.ListEntries(ctx, held[:len(held)-1], "", "", 0) - for _, e := range attempts { - if s := string(e.Extended[extSnapState]); s == SnapActive { - t.Fatalf("an active s5 attempt %s survived the completed delete", e.GetName()) - } + if hh := headState(t, c, "w2"); hh.State != storage.ChunkHeadDeleted || len(hh.Chunks) != 0 { + t.Fatalf("w2 HEAD: %+v; want a deleted tombstone with no chunks", hh) + } + if v, _, _ := c.ReadVolume(ctx, "w2"); v.State != VolumeDeleted { + t.Fatalf("w2 VOLUME state %q", v.State) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { + t.Fatalf("delete s1 after its fork was deleted: %v", err) + } + if _, err := c.EnsureVolume(ctx, "w2", catGeo); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("attach/create of deleted w2: %v; want volume_deleted", err) + } + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w2", RequestID: "again"}); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("fork to deleted w2: %v; want volume_deleted", err) + } + if res, err := c.DeleteVolume(ctx, "w2", nil); err != nil || !res.Replayed { + t.Fatalf("rerun: %+v %v; want a replay", res, err) + } + holdFirst(f, catBase+"/w3/HEAD") + if _, err := c.Fork(ctx, ForkRequest{Source: "v1", Snapshot: "s2", Target: "w3", RequestID: "f3"}); CodeOf(err) != CodeOutcomeUnknown { + t.Fatalf("fork w3: %v", err) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); CodeOf(err) != CodeSnapshotClaimed { + t.Fatalf("delete s2 under the incomplete fork: %v; want snapshot_claimed", err) + } + if res, err := c.DeleteVolume(ctx, "w3", nil); err != nil || !res.Completed { + t.Fatalf("delete w3: %+v %v", res, err) + } + if _, err := c.DeleteSnapshot(ctx, "v1", "s2"); err != nil { + t.Fatalf("delete s2 after w3 was deleted (its claim is dead): %v", err) } } - -func mustHead(t *testing.T, c *Catalog, vol string) storage.ChunkHead { - t.Helper() - h, has, err := c.ReadHead(context.Background(), vol) - if err != nil || !has { - t.Fatalf("HEAD of %s: has=%t %v", vol, has, err) - } - return h -} diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index 8d78fa13aa..f074083321 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -59,12 +59,17 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe // A reserved id (a chunk volume delete admitted or committed) is never // created again; the reservation is checked under the lock its writer // holds. + // held through the create (workspace_protocol.md: reservation checks + // and commits stay under workspaceMu). s.host.workspaceMu.Lock() - reserved := stores.Deletions.Reserved(spec.VolumeID) - s.host.workspaceMu.Unlock() - if reserved { + reservedNow := stores.Deletions.Reserved(spec.VolumeID) + s.host.workspaceMu.Unlock() // RED: the lock is dropped before the create + if reservedNow { return nil, status.Errorf(codes.FailedPrecondition, "create volume: %s is being deleted or was deleted; its id is never reused", spec.VolumeID) } + if createVolumeHook != nil { + createVolumeHook(spec.VolumeID) + } s.host.log.Printf("blockmaster: CreateVolume volume=%q protocol=%q replication_factor=%d pvc=%q namespace=%q", spec.VolumeID, spec.Protocol, spec.ReplicationFactor, spec.PVCName, spec.PVCNamespace) rec, err := stores.Volumes.CreateVolume(spec) if err != nil { @@ -163,6 +168,10 @@ func (s *services) MarkVolumeDeleting(ctx context.Context, req *control.MarkVolu return &control.MarkVolumeDeletingResponse{Known: known, State: res.State}, nil } +// createVolumeHook is a test seam: it runs in CreateVolume after the +// reservation check, before the create. +var createVolumeHook func(vol string) + // AbortVolumeDeleting gives a delete's admission back (the delete found it // could not proceed and undid its own effects). A committed deletion is // never given back (FAILED_PRECONDITION). diff --git a/seaweed-block/core/host/master/volume_deleting_test.go b/seaweed-block/core/host/master/volume_deleting_test.go index b58f3d427a..a1a7bdb54f 100644 --- a/seaweed-block/core/host/master/volume_deleting_test.go +++ b/seaweed-block/core/host/master/volume_deleting_test.go @@ -150,3 +150,56 @@ func TestMarkVolumeDeleting_StopsLaterAssignmentPlacementAndBinding(t *testing.T t.Fatalf("binding of a reserved volume: %v; want FailedPrecondition", err) } } + +// P2: CreateVolume keeps workspaceMu from its reservation check through the +// create: a Mark/Commit arriving while a create is past its check waits, +// so no create can succeed for an id reserved after its check. +func TestMarkVolumeDeleting_CreateHoldsTheReservationLock(t *testing.T) { + _, lc, stop := hostOn(t, t.TempDir(), t.TempDir()) + defer stop() + ctx := context.Background() + inCreate, release := make(chan struct{}), make(chan struct{}) + createVolumeHook = func(vol string) { + if vol == "held" { + close(inCreate) + <-release + } + } + defer func() { createVolumeHook = nil }() + created := make(chan error, 1) + go func() { + _, err := lc.CreateVolume(ctx, createReq("held")) + created <- err + }() + <-inCreate + marked := make(chan error, 1) + go func() { + if _, err := lc.MarkVolumeDeleting(ctx, markReq("held", "d1")); err != nil { + marked <- err + return + } + _, err := lc.CommitVolumeDeleting(ctx, markReq("held", "d1")) + marked <- err + }() + var early error + raced := false + select { + case early = <-marked: + raced = true + case <-time.After(300 * time.Millisecond): + } + close(release) // never leave the create parked, even on failure + if raced { + <-created + t.Fatalf("the mark completed while a create was past its check (%v)", early) + } + if err := <-created; err != nil { + t.Fatalf("create: %v", err) + } + if err := <-marked; err != nil { + t.Fatalf("mark/commit after the create: %v", err) + } + if _, err := lc.CreateVolume(ctx, createReq("held")); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("create after the commit: %v; want FailedPrecondition", err) + } +} diff --git a/seaweed-block/core/lifecycle/deletion_reservations.go b/seaweed-block/core/lifecycle/deletion_reservations.go index 79ebd5cc6a..f286dbcc54 100644 --- a/seaweed-block/core/lifecycle/deletion_reservations.go +++ b/seaweed-block/core/lifecycle/deletion_reservations.go @@ -58,12 +58,21 @@ type DeletionReservationStore struct { // OpenDeletionReservationStore opens or creates the store in dir. func OpenDeletionReservationStore(dir string) (*DeletionReservationStore, error) { + return openDeletionReservationStore(dir, syncBindingParent) +} + +func openDeletionReservationStore(dir string, syncParent func(string) error) (*DeletionReservationStore, error) { if dir == "" { return nil, fmt.Errorf("%w: empty dir", ErrInvalidVolumeSpec) } if err := os.MkdirAll(dir, 0o755); err != nil { return nil, fmt.Errorf("lifecycle: mkdir %q: %w", dir, err) } + // Persist the directory entry before any reservation can be + // acknowledged (the binding store's initialization guarantee). + if err := syncParent(filepath.Dir(dir)); err != nil && false { // RED: the parent is not synced + return nil, fmt.Errorf("lifecycle: sync the parent of %q: %w", dir, err) + } s := &DeletionReservationStore{dir: dir, records: map[string]DeletionReservation{}} b, err := os.ReadFile(filepath.Join(dir, reservationsFile)) switch { diff --git a/seaweed-block/core/lifecycle/deletion_reservations_test.go b/seaweed-block/core/lifecycle/deletion_reservations_test.go index 280e4c0237..d6be8a4207 100644 --- a/seaweed-block/core/lifecycle/deletion_reservations_test.go +++ b/seaweed-block/core/lifecycle/deletion_reservations_test.go @@ -96,3 +96,24 @@ func TestDeletionReservations_PersistenceFaultsFailClosed(t *testing.T) { t.Fatal("a successfully written reservation is lost on restart") } } + +// The store's directory entry is made durable in its parent before any +// reservation is acknowledged; a failing parent sync refuses to open. +func TestDeletionReservations_ParentSyncBeforeUse(t *testing.T) { + parent := t.TempDir() + fail := errors.New("injected") + var synced []string + if _, err := openDeletionReservationStore(parent+"/r", func(dir string) error { synced = append(synced, dir); return fail }); !errors.Is(err, fail) { + t.Fatalf("open with a failing parent sync: %v; want the error", err) + } + if len(synced) != 1 || synced[0] != parent { + t.Fatalf("synced %v; want the parent %s", synced, parent) + } + s, err := openDeletionReservationStore(parent+"/r", syncBindingParent) + if err != nil { + t.Fatal(err) + } + if _, err := s.Admit("v", "d"); err != nil { + t.Fatal(err) + } +} From 9f82dcd48a60d5f79009141253186b831e155284 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 20:27:44 -0800 Subject: [PATCH 08/16] volume delete: no snapshot cascade; incarnation-bound commit claude05's cut (04:08Z): volume-delete refuses with volume_has_snapshots while the volume has any snapshot name record (a published snapshot, one being deleted, or an attempt in flight); the operator deletes snapshots first. The delete never touches snapshot names, attempts or roots: the snapshot loop, the claim check and claim release (a claim lives on a named snapshot; a deleted target's claim is dead by rule), and CreateSnapshot's back-out are gone. CreateSnapshot and Fork still refuse once they see the delete mark. codex01's r3 P2s: - the snapshot check, the revert and the commit are bound to one deleting incarnation (its generation); if HEAD moved, the check runs again on the incarnation found; - the CLI's admission token is --request-id (required), so a rerun adopts and can give back an earlier invocation's hold; - CreateVolume holds workspaceMu through the create; - the reservation store syncs its parent directory before use (the binding store's helper). Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/sw-block/chunk_volume_delete.go | 2 +- seaweed-block/core/frontend/chunkstore/volume_delete.go | 6 +++--- seaweed-block/core/host/master/services.go | 5 ++--- seaweed-block/core/lifecycle/deletion_reservations.go | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete.go b/seaweed-block/cmd/sw-block/chunk_volume_delete.go index 4283774d5f..52e05da0cc 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -56,7 +56,7 @@ func chunkVolumeDelete(args []string, stdout, stderr io.Writer) int { return chunkResult("volume-delete", nil, err, stdout, stderr) } defer conn.Close() - admit := &masterAdmission{lc: control.NewLifecycleServiceClient(conn), token: requestID + "-" + fmt.Sprint(time.Now().UnixNano())} // RED: a fresh token per invocation + admit := &masterAdmission{lc: control.NewLifecycleServiceClient(conn), token: requestID} ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() res, err := cat.DeleteVolume(ctx, volumeID, admit) diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go index ef77076bce..4c7acde2d8 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -350,8 +350,8 @@ func (c *Catalog) commitHeadPurging(ctx context.Context, vol, root string, gen u return incarnationDone, false, nil // committed (by another delete of the same mark) case h.State != storage.ChunkHeadDeleting: return incarnationGivenBack, false, nil - case h.Gen != gen && false: // RED: any deleting incarnation is committed - return incarnationMoved, false, nil + case h.Gen != gen: + return incarnationMoved, false, nil // another incarnation: its claims were not checked here } next := h next.State = storage.ChunkHeadPurging @@ -398,7 +398,7 @@ func (c *Catalog) snapshotsBlock(ctx context.Context, vol, root string) (error, if err != nil { return nil, err } - if len(names) > 0 && false { // RED: snapshots do not block the delete + if len(names) > 0 { return catErr(CodeVolumeHasSnapshots, false, nil, "volume %s has snapshots (%s); delete them first", vol, strings.Join(names, ", ")), nil } return nil, nil diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index f074083321..511d355e56 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -62,9 +62,8 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe // held through the create (workspace_protocol.md: reservation checks // and commits stay under workspaceMu). s.host.workspaceMu.Lock() - reservedNow := stores.Deletions.Reserved(spec.VolumeID) - s.host.workspaceMu.Unlock() // RED: the lock is dropped before the create - if reservedNow { + defer s.host.workspaceMu.Unlock() + if stores.Deletions.Reserved(spec.VolumeID) { return nil, status.Errorf(codes.FailedPrecondition, "create volume: %s is being deleted or was deleted; its id is never reused", spec.VolumeID) } if createVolumeHook != nil { diff --git a/seaweed-block/core/lifecycle/deletion_reservations.go b/seaweed-block/core/lifecycle/deletion_reservations.go index f286dbcc54..75cd4f381d 100644 --- a/seaweed-block/core/lifecycle/deletion_reservations.go +++ b/seaweed-block/core/lifecycle/deletion_reservations.go @@ -70,7 +70,7 @@ func openDeletionReservationStore(dir string, syncParent func(string) error) (*D } // Persist the directory entry before any reservation can be // acknowledged (the binding store's initialization guarantee). - if err := syncParent(filepath.Dir(dir)); err != nil && false { // RED: the parent is not synced + if err := syncParent(filepath.Dir(dir)); err != nil { return nil, fmt.Errorf("lifecycle: sync the parent of %q: %w", dir, err) } s := &DeletionReservationStore{dir: dir, records: map[string]DeletionReservation{}} From a60daf2376f1e405a3da6bf0cba33d461f9fadc6 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 21:06:23 -0800 Subject: [PATCH 09/16] volume delete: RED controls for the r4 P2s codex01's r4 review (V:/share/rdma/codex01-block152-r4-review- 20261116T0445Z/REVIEW.md). Controls failing against stubs: - Fork's early replay reports success for a target past the delete mark (deleting, purging, HEAD deleted before VOLUME is marked) (TestCatalog_ForkReplayRefusesADeletingTarget); - the cluster-spec import re-creates and places a reserved id after a restart with the original spec (TestClusterSpecImportSkipsAReserved Volume). Co-Authored-By: Claude Opus 5.5 --- .../blockmaster/cluster_spec_reserved_test.go | 76 +++++++++++++++++++ seaweed-block/cmd/blockmaster/main.go | 11 ++- .../core/frontend/chunkstore/catalog.go | 5 ++ .../core/frontend/chunkstore/volume_delete.go | 4 + .../frontend/chunkstore/volume_delete_test.go | 37 +++++++++ seaweed-block/core/host/master/services.go | 20 +++++ 6 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 seaweed-block/cmd/blockmaster/cluster_spec_reserved_test.go diff --git a/seaweed-block/cmd/blockmaster/cluster_spec_reserved_test.go b/seaweed-block/cmd/blockmaster/cluster_spec_reserved_test.go new file mode 100644 index 0000000000..52fc9beea1 --- /dev/null +++ b/seaweed-block/cmd/blockmaster/cluster_spec_reserved_test.go @@ -0,0 +1,76 @@ +package main + +import ( + "context" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/host/master" + "github.com/seaweedfs/seaweed-block/core/lifecycle" +) + +// r4 P2: the cluster-spec import never re-creates (or places) an id a +// volume delete reserved, also after a restart with the original spec; +// unreserved ids keep importing idempotently. +func TestClusterSpecImportSkipsAReservedVolume(t *testing.T) { + cfg := master.Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir()} + open := func() *master.Host { + t.Helper() + h, err := master.New(cfg) + if err != nil { + t.Fatal(err) + } + return h + } + // Imports run before Start, as in run(); a host is started before Close + // (Close waits on a server that Start launches). + closeHost := func(h *master.Host) { + h.Start() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + _ = h.Close(ctx) + } + specs := []lifecycle.VolumeSpec{ + {VolumeID: "gone", SizeBytes: 1 << 20, ReplicationFactor: 1}, + {VolumeID: "kept", SizeBytes: 1 << 20, ReplicationFactor: 1}, + } + h := open() + if err := importLifecycleVolumes(h, specs); err != nil { + t.Fatal(err) + } + // "gone" is deleted: reservation committed, its record removed by the + // ordinary lifecycle delete. + if _, err := h.Lifecycle().Deletions.Admit("gone", "d1"); err != nil { + t.Fatal(err) + } + if _, err := h.Lifecycle().Deletions.Commit("gone", "d1"); err != nil { + t.Fatal(err) + } + if err := h.Lifecycle().Volumes.DeleteVolume("gone"); err != nil { + t.Fatal(err) + } + closeHost(h) + + h = open() // restart with the original spec + defer closeHost(h) + for i := 0; i < 2; i++ { + if err := importLifecycleVolumes(h, specs); err != nil { + t.Fatalf("import %d: %v", i, err) + } + } + if _, ok := h.Lifecycle().Volumes.GetVolume("gone"); ok { + t.Fatal("the import re-created a reserved id") + } + if _, ok := h.Lifecycle().Volumes.GetVolume("kept"); !ok { + t.Fatal("an unreserved volume was not imported") + } + intents := []lifecycle.PlacementIntent{ + {VolumeID: "gone", DesiredRF: 1, Slots: []lifecycle.PlacementSlotIntent{{ServerID: "s1", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}, + } + if err := importLifecyclePlacementIntents(h, intents); err != nil { + t.Fatal(err) + } + if _, ok := h.Lifecycle().Placements.GetPlacement("gone"); ok { + t.Fatal("the import placed a reserved id") + } +} diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index 60a73fa74c..250d738996 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -282,9 +282,15 @@ func importLifecycleVolumes(h *master.Host, volumes []lifecycle.VolumeSpec) erro merged.ReplicationFactor = spec.ReplicationFactor spec = merged } - if _, err := stores.Volumes.CreateVolume(spec); err != nil { + imported, err := h.ImportLifecycleVolume(spec) + if err != nil { return fmt.Errorf("register lifecycle volume %s: %w", spec.VolumeID, err) } + if !imported { + // A chunk volume delete reserved this id: it is never created + // again, also when the cluster spec still lists it. + fmt.Fprintf(os.Stderr, "blockmaster: cluster spec volume %s not imported: its id is reserved by a volume delete\n", spec.VolumeID) + } } return nil } @@ -324,6 +330,9 @@ func importLifecyclePlacementIntents(h *master.Host, intents []lifecycle.Placeme return fmt.Errorf("lifecycle placement import requires --lifecycle-store") } for _, intent := range intents { + if stores.Deletions.Reserved(intent.VolumeID) && false { // RED + continue // never placed again (see importLifecycleVolumes) + } plan := lifecycle.PlacementPlan{ VolumeID: intent.VolumeID, DesiredRF: intent.DesiredRF, diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index 13cb22a3f8..ae1d555bfa 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -1195,6 +1195,11 @@ func (c *Catalog) Fork(ctx context.Context, req ForkRequest) (ForkResult, error) if has && h.State == storage.ChunkHeadAborted { return ForkResult{}, catErr(CodeTargetExists, false, nil, "fork %s was aborted (its HEAD is a tombstone); fork to a new volume id", req.Target) } + if has && headDeletingOrDeleted(h) && false { // RED: the early replay accepts a deleting target + // The target is being (or was) deleted: never a successful + // replay, also before its VOLUME is marked. + return ForkResult{}, refuseDeleted(req.Target, "fork to a new volume id") + } if has { return forkResult(existing, true), nil } diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete.go b/seaweed-block/core/frontend/chunkstore/volume_delete.go index 4c7acde2d8..238e860e19 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -63,6 +63,8 @@ const ( hookHeadMarked = "head-marked" // after (b) hookBlocked = "blocked" // (c) found a snapshot, before the revert hookClaimsChecked = "claims-checked" // after (c), before the commit point + hookCommitted = "committed" // after the commit point (HEAD purging) + hookHeadDeleted = "head-deleted" // HEAD deleted, VOLUME not yet marked ) // ErrNotAdmitted marks an Admission error that is a definite refusal @@ -203,6 +205,7 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) } } res.HeadMarked = true + c.hook(hookCommitted, vol) if admit != nil { if err := admit.Commit(ctx, vol); err != nil { res.Uncertain = true @@ -215,6 +218,7 @@ func (c *Catalog) DeleteVolume(ctx context.Context, vol string, admit Admission) res.Uncertain = u return res, err } + c.hook(hookHeadDeleted, vol) if err := c.markVolumeDeleted(ctx, vol, root); err != nil { res.Uncertain = true return res, err diff --git a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go index 0f851565b9..5190f32eba 100644 --- a/seaweed-block/core/frontend/chunkstore/volume_delete_test.go +++ b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go @@ -514,3 +514,40 @@ func TestCatalog_DeleteVolumeTombstonesAndRefusesReuse(t *testing.T) { t.Fatalf("delete s2 after w3 was deleted (its claim is dead): %v", err) } } + +// r4 P2: the original fork request's early replay never reports success +// for a target past the delete mark, in every window (deleting, purging, +// HEAD deleted before VOLUME is marked) and after; a completed fork still +// replays before its delete. +func TestCatalog_ForkReplayRefusesADeletingTarget(t *testing.T) { + _, _, c, h := deleteFixture(t) + ctx := context.Background() + if _, err := c.CreateSnapshot(ctx, "v1", SnapshotRequest{Name: "s1", RequestID: "r-s1"}, h); err != nil { + t.Fatal(err) + } + req := ForkRequest{Source: "v1", Snapshot: "s1", Target: "w2", RequestID: "f2"} + if _, err := c.Fork(ctx, req); err != nil { + t.Fatalf("fork w2: %v", err) + } + if res, err := c.Fork(ctx, req); err != nil || !res.Replayed { + t.Fatalf("replay before the delete: %+v %v; want a successful replay", res, err) + } + seen := map[string]bool{} + c.retainHook = func(stage, _ string) { + switch stage { + case hookHeadMarked, hookCommitted, hookHeadDeleted: + seen[stage] = true + if _, err := c.Fork(ctx, req); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("replay at %s: %v; want volume_deleted", stage, err) + } + } + } + res, err := c.DeleteVolume(ctx, "w2", nil) + c.retainHook = nil + if err != nil || !res.Completed || len(seen) != 3 { + t.Fatalf("delete w2: %+v %v; windows seen %v", res, err, seen) + } + if _, err := c.Fork(ctx, req); CodeOf(err) != CodeVolumeDeleted { + t.Fatalf("replay after the delete: %v; want volume_deleted", err) + } +} diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index 511d355e56..0d6d42fde3 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -167,6 +167,26 @@ func (s *services) MarkVolumeDeleting(ctx context.Context, req *control.MarkVolu return &control.MarkVolumeDeletingResponse{Known: known, State: res.State}, nil } +// ImportLifecycleVolume registers a desired volume from the cluster spec +// (blockmaster startup), under the same boundary as the CreateVolume RPC: +// a reserved id (a chunk volume delete admitted or committed) is skipped, +// never created again. imported is false for a skipped id. +func (h *Host) ImportLifecycleVolume(spec lifecycle.VolumeSpec) (imported bool, err error) { + stores := h.Lifecycle() + if stores == nil { + return false, fmt.Errorf("cluster volume import requires --lifecycle-store") + } + h.workspaceMu.Lock() + defer h.workspaceMu.Unlock() + if stores.Deletions.Reserved(spec.VolumeID) && false { // RED: the import ignores the reservation + return false, nil + } + if _, err := stores.Volumes.CreateVolume(spec); err != nil { + return false, err + } + return true, nil +} + // createVolumeHook is a test seam: it runs in CreateVolume after the // reservation check, before the create. var createVolumeHook func(vol string) From 41f00e5b1a256982e05271fc8f391cf029422032 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 21:06:24 -0800 Subject: [PATCH 10/16] volume delete: terminal-state fork replay; reservation-aware import - Fork's early replay of a completed request refuses (volume_deleted) a target whose HEAD is deleting, purging or deleted, also before its VOLUME is marked, like the later publication path. - Host.ImportLifecycleVolume registers a cluster-spec volume under the CreateVolume RPC's boundary (workspaceMu, reservation check through the create); blockmaster startup uses it, skipping (and logging) a reserved id, and the placement import skips reserved ids too. Unreserved ids keep importing idempotently. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/blockmaster/main.go | 2 +- seaweed-block/core/frontend/chunkstore/catalog.go | 2 +- seaweed-block/core/host/master/services.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index 250d738996..9a49dbb074 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -330,7 +330,7 @@ func importLifecyclePlacementIntents(h *master.Host, intents []lifecycle.Placeme return fmt.Errorf("lifecycle placement import requires --lifecycle-store") } for _, intent := range intents { - if stores.Deletions.Reserved(intent.VolumeID) && false { // RED + if stores.Deletions.Reserved(intent.VolumeID) { continue // never placed again (see importLifecycleVolumes) } plan := lifecycle.PlacementPlan{ diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index ae1d555bfa..c8577c41a1 100644 --- a/seaweed-block/core/frontend/chunkstore/catalog.go +++ b/seaweed-block/core/frontend/chunkstore/catalog.go @@ -1195,7 +1195,7 @@ func (c *Catalog) Fork(ctx context.Context, req ForkRequest) (ForkResult, error) if has && h.State == storage.ChunkHeadAborted { return ForkResult{}, catErr(CodeTargetExists, false, nil, "fork %s was aborted (its HEAD is a tombstone); fork to a new volume id", req.Target) } - if has && headDeletingOrDeleted(h) && false { // RED: the early replay accepts a deleting target + if has && headDeletingOrDeleted(h) { // The target is being (or was) deleted: never a successful // replay, also before its VOLUME is marked. return ForkResult{}, refuseDeleted(req.Target, "fork to a new volume id") diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index 0d6d42fde3..3bec693596 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -178,7 +178,7 @@ func (h *Host) ImportLifecycleVolume(spec lifecycle.VolumeSpec) (imported bool, } h.workspaceMu.Lock() defer h.workspaceMu.Unlock() - if stores.Deletions.Reserved(spec.VolumeID) && false { // RED: the import ignores the reservation + if stores.Deletions.Reserved(spec.VolumeID) { return false, nil } if _, err := stores.Volumes.CreateVolume(spec); err != nil { From 243f73633fd2a3d1c167250ec6a3ed8eb9646cea Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 21:29:56 -0800 Subject: [PATCH 11/16] fix: gate replication listeners on assigned replica slots --- seaweed-block/cmd/blockvolume/main.go | 84 +------ .../cmd/blockvolume/replication_ingress.go | 129 ++++++++++ .../replication_ingress_binary_test.go | 230 ++++++++++++++++++ seaweed-block/core/host/volume/host.go | 33 ++- seaweed-block/core/transport/replica.go | 11 + 5 files changed, 404 insertions(+), 83 deletions(-) create mode 100644 seaweed-block/cmd/blockvolume/replication_ingress.go create mode 100644 seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go diff --git a/seaweed-block/cmd/blockvolume/main.go b/seaweed-block/cmd/blockvolume/main.go index 467873372d..f2e5f791db 100644 --- a/seaweed-block/cmd/blockvolume/main.go +++ b/seaweed-block/cmd/blockvolume/main.go @@ -696,8 +696,8 @@ func run(f flags) int { // Bind the replication stack — ReplicationVolume for outbound peer // fan-out (primary role) + ReplicaListener for incoming WAL traffic - // (replica role). Both code paths are bound at startup; whichever - // role the master assignment selects is the active one. Construction + // (replica role). Incoming listeners are bound only when the master + // assignment includes replica slots; RF=1 never opens either lane. Construction // is post-dp.RecoverVolume because both borrow the same // LogicalStorage the durable Backend wraps; the LogicalStorage // isn't usable until recovery completes. @@ -711,7 +711,7 @@ func run(f flags) int { // control-plane split (no current binder). var ( replVolume *replication.ReplicationVolume - replListen *transport.ReplicaListener + replListen *replicationIngress ) if durableProv != nil { store := durableProv.LogicalStorage(f.volumeID) @@ -868,13 +868,13 @@ func run(f flags) int { fmt.Fprintln(os.Stderr, "blockvolume: write-observer wire: Backend(", f.volumeID, ") returned nil; replication fan-out disabled") } - // G1: the replica's epoch floor lives beside the volume's durable - // files so it survives a restart; non-durable (memback) runs keep it - // in memory only. Either way the listener refuses every mutation - // until the host's role call succeeds. - listener, err := transport.NewReplicaListenerWithFloor(f.dataAddr, store, f.volumeID, replicaFloorPath(f)) - if err != nil { - fmt.Fprintln(os.Stderr, "blockvolume: replica listener:", err) + // No replication socket exists until a master assignment includes + // replica slots. The role gate starts/fences both lanes before admission. + replListen = &replicationIngress{addr: f.dataAddr, store: store, + volumeID: f.volumeID, floorPath: replicaFloorPath(f), dualLane: f.recoveryMode == "dual-lane"} + if err := h.SetSelfFence(replListen); err != nil { + fmt.Fprintln(os.Stderr, "blockvolume: replica listener role:", err) + replListen.Stop() _ = replVolume.Close() _ = durableProv.Close() if status != nil { @@ -885,70 +885,6 @@ func run(f flags) int { _ = h.Close() return 1 } - // G2: fence the listener with the role the host already holds - // (the assignment stream started above) before it serves. G1: if - // that role cannot be made durable, do not serve at all. - if fErr := h.SetSelfFence(listener); fErr != nil { - fmt.Fprintln(os.Stderr, "blockvolume: replica listener role:", fErr) - listener.Stop() - _ = replVolume.Close() - _ = durableProv.Close() - if status != nil { - shutCtx, shutCancel := context.WithTimeout(context.Background(), 2*time.Second) - _ = status.Close(shutCtx) - shutCancel() - } - _ = h.Close() - return 1 - } - listener.Serve() - replListen = listener - - // When --recovery-mode=dual-lane, also bind a separate listener - // at port=data-addr-port+1 for inbound dual-lane recover-session - // connections. Each accepted conn is handed to a fresh - // recovery.Receiver via ReplicaBridge.AcceptDualLaneLoop. - // Listener lifecycle is goroutine-scoped here; daemon shutdown - // closes the underlying net.Listener via the deferred close - // added below. - if f.recoveryMode == "dual-lane" { - dualLaneAddr, err := deriveDualLaneAddr(f.dataAddr) - if err != nil { - fmt.Fprintln(os.Stderr, "blockvolume: dual-lane listen addr derive:", err) - replListen.Stop() - _ = replVolume.Close() - _ = durableProv.Close() - if status != nil { - shutCtx, shutCancel := context.WithTimeout(context.Background(), 2*time.Second) - _ = status.Close(shutCtx) - shutCancel() - } - _ = h.Close() - return 1 - } - dlLn, err := net.Listen("tcp", dualLaneAddr) - if err != nil { - fmt.Fprintln(os.Stderr, "blockvolume: dual-lane listen:", err) - replListen.Stop() - _ = replVolume.Close() - _ = durableProv.Close() - if status != nil { - shutCtx, shutCancel := context.WithTimeout(context.Background(), 2*time.Second) - _ = status.Close(shutCtx) - shutCancel() - } - _ = h.Close() - return 1 - } - replicaBridge := recovery.NewReplicaBridgeWithGate(store, replListen) - dualLaneCtx, dualLaneCancel := context.WithCancel(context.Background()) - go replicaBridge.AcceptDualLaneLoop(dualLaneCtx, dlLn) - defer func() { - dualLaneCancel() - _ = dlLn.Close() - }() - fmt.Fprintf(os.Stderr, "blockvolume: dual-lane listener bound at %s\n", dualLaneAddr) - } } // Frontend volume capacity MUST derive from the daemon's diff --git a/seaweed-block/cmd/blockvolume/replication_ingress.go b/seaweed-block/cmd/blockvolume/replication_ingress.go new file mode 100644 index 0000000000..4117fbad45 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/replication_ingress.go @@ -0,0 +1,129 @@ +package main + +import ( + "context" + "fmt" + "net" + "sync" + + "github.com/seaweedfs/seaweed-block/core/recovery" + "github.com/seaweedfs/seaweed-block/core/storage" + "github.com/seaweedfs/seaweed-block/core/transport" +) + +// replicationIngress owns both inbound lanes. Lock order: Host.selfFenceMu -> +// mu -> listener role gate. Stop never calls Host. No socket is created until +// an assignment permits a replica role, and each listener is fenced before Serve. +type replicationIngress struct { + mu sync.Mutex + addr, volumeID, floorPath string + store storage.LogicalStorage + dualLane bool + listener *transport.ReplicaListener + dual net.Listener + cancel context.CancelFunc + closed bool +} + +func (r *replicationIngress) FenceAsPrimary(epoch uint64) error { + return r.FenceAsPrimaryWithPeers(epoch, true) +} +func (r *replicationIngress) FenceAsPrimaryWithPeers(epoch uint64, hasPeers bool) error { + r.mu.Lock() + defer r.mu.Unlock() + if r.closed { + return fmt.Errorf("replication ingress closed") + } + if !hasPeers { + if r.listener != nil { + if err := r.listener.FenceAsPrimary(epoch); err != nil { + return err + } + } + r.stopLocked(true) + return nil + } + return r.roleLocked(epoch, true) +} +func (r *replicationIngress) AdmitAsReplica(epoch uint64) error { + r.mu.Lock() + defer r.mu.Unlock() + if r.closed { + return fmt.Errorf("replication ingress closed") + } + return r.roleLocked(epoch, false) +} +func (r *replicationIngress) roleLocked(epoch uint64, primary bool) error { + listener := r.listener + fresh := listener == nil + if fresh { + var err error + listener, err = transport.NewReplicaListenerWithFloor(r.addr, r.store, r.volumeID, r.floorPath) + if err != nil { + return err + } + } + var err error + if primary { + err = listener.FenceAsPrimary(epoch) + } else { + err = listener.AdmitAsReplica(epoch) + } + if err != nil { + if fresh { + listener.Stop() + } + return err + } + if !fresh { + return nil + } + var dl net.Listener + if r.dualLane { + var addr string + addr, err = deriveDualLaneAddr(r.addr) + if err == nil { + dl, err = net.Listen("tcp", addr) + } + if err != nil { + listener.Stop() + return err + } + } + r.listener, r.dual = listener, dl + listener.Serve() + if dl != nil { + ctx, cancel := context.WithCancel(context.Background()) + r.cancel = cancel + bridge := recovery.NewReplicaBridgeWithGate(r.store, listener) + go bridge.AcceptDualLaneLoop(ctx, dl) + } + return nil +} +func (r *replicationIngress) stopLocked(withdrawn bool) { + if r.cancel != nil { + r.cancel() + r.cancel = nil + } + if r.dual != nil { + _ = r.dual.Close() + r.dual = nil + } + if r.listener != nil { + if withdrawn { + // FenceAsPrimary already drained admitted mutations. The role has + // been revoked, so disconnect idle peers instead of waiting for + // them to close a connection to an endpoint they no longer own. + r.listener.StopHard() + } else { + r.listener.Stop() + } + r.listener = nil + } +} +func (r *replicationIngress) Stop() { + r.mu.Lock() + defer r.mu.Unlock() + r.closed = true + r.stopLocked(false) +} diff --git a/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go b/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go new file mode 100644 index 0000000000..d9edda999b --- /dev/null +++ b/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go @@ -0,0 +1,230 @@ +//go:build subprocess && !windows + +package main_test + +import ( + "context" + "encoding/json" + "errors" + "net" + "net/http" + "os" + "os/exec" + "path/filepath" + "syscall" + "testing" + "time" + + control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/transport" + "google.golang.org/grpc" +) + +// Controlled master stream exercises the real binary's normal assignment path. +// It does not model the master's placement or epoch-minting policy. +type ingressAssignments struct { + control.UnimplementedAssignmentServiceServer + control.UnimplementedObservationServiceServer + facts chan *control.AssignmentFact +} + +func (m *ingressAssignments) ReportHeartbeat(context.Context, *control.HeartbeatReport) (*control.HeartbeatAck, error) { + return &control.HeartbeatAck{}, nil +} +func (m *ingressAssignments) SubscribeAssignments(_ *control.SubscribeRequest, s control.AssignmentService_SubscribeAssignmentsServer) error { + for { + select { + case <-s.Context().Done(): + return s.Context().Err() + case f := <-m.facts: + if err := s.Send(f); err != nil { + return err + } + } + } +} +func ingressPortPair(t *testing.T) (string, string) { + t.Helper() + for i := 0; i < 100; i++ { + a, e := net.Listen("tcp", "127.0.0.1:0") + if e != nil { + t.Fatal(e) + } + port := a.Addr().(*net.TCPAddr).Port + b, e := net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: port + 1}) + if e == nil { + x, y := a.Addr().String(), b.Addr().String() + a.Close() + b.Close() + return x, y + } + a.Close() + } + t.Fatal("no adjacent free ports") + return "", "" +} +func ingressWait(t *testing.T, what string, fn func() bool) { + t.Helper() + end := time.Now().Add(10 * time.Second) + for !fn() { + if time.Now().After(end) { + t.Fatal(what) + } + time.Sleep(20 * time.Millisecond) + } +} +func ingressRefused(t *testing.T, addr string) { + t.Helper() + c, e := net.DialTimeout("tcp", addr, 300*time.Millisecond) + if c != nil { + _ = c.SetDeadline(time.Now().Add(300 * time.Millisecond)) + _ = transport.WriteMsg(c, transport.MsgProbeReq, transport.EncodeProbeReq(transport.ProbeRequest{Lineage: transport.RecoveryLineage{Epoch: 999, SessionID: 1, EndpointVersion: 1, FrontierHint: 1}})) + c.Close() + } + if !errors.Is(e, syscall.ECONNREFUSED) { + t.Fatalf("replication connection to %s: want connection refused, got %v", addr, e) + } +} +func TestBinaryReplicationIngressFollowsAssignedSlots(t *testing.T) { + exe := filepath.Join(t.TempDir(), "blockvolume") + cmd := exec.Command("go", "build", "-race", "-p", "4", "-o", exe, ".") + if b, e := cmd.CombinedOutput(); e != nil { + t.Fatalf("build: %v %s", e, b) + } + for _, mode := range []string{"legacy", "dual-lane"} { + t.Run(mode, func(t *testing.T) { + m := &ingressAssignments{facts: make(chan *control.AssignmentFact, 4)} + ln, e := net.Listen("tcp", "127.0.0.1:0") + if e != nil { + t.Fatal(e) + } + server := grpc.NewServer() + control.RegisterAssignmentServiceServer(server, m) + control.RegisterObservationServiceServer(server, m) + go server.Serve(ln) + t.Cleanup(server.Stop) + data, dual := ingressPortPair(t) + status := pickAddr(t) + ctrl := pickAddr(t) + root := t.TempDir() + logPath := filepath.Join(t.TempDir(), "volume.log") + log, e := os.Create(logPath) + if e != nil { + t.Fatal(e) + } + child := exec.Command(exe, "--master", ln.Addr().String(), "--server-id", "s1", "--volume-id", "v1", "--replica-id", "r1", "--data-addr", data, "--ctrl-addr", ctrl, "--status-addr", status, "--t1-readiness", "--durable-root", root, "--durable-impl", "walstore", "--durable-blocks", "64", "--heartbeat-interval", "50ms", "--recovery-mode", mode) + child.Stdout, child.Stderr = log, log + if e = child.Start(); e != nil { + t.Fatal(e) + } + done := make(chan error, 1) + go func() { done <- child.Wait() }() + t.Cleanup(func() { + child.Process.Signal(syscall.SIGTERM) + select { + case <-done: + case <-time.After(5 * time.Second): + child.Process.Kill() + select { + case <-done: + case <-time.After(3 * time.Second): + t.Error("child reap timeout") + } + } + log.Close() + if t.Failed() { + b, _ := os.ReadFile(logPath) + t.Logf("binary log: %s", b) + } + }) + client := &http.Client{Timeout: 300 * time.Millisecond} + epoch := func(want float64) bool { + resp, e := client.Get("http://" + status + "/status?volume=v1") + if e != nil { + return false + } + defer resp.Body.Close() + var p map[string]any + if json.NewDecoder(resp.Body).Decode(&p) != nil { + return false + } + if want == 0 { + return true + } + return p["Epoch"] == want + } + ingressWait(t, "binary status not ready", func() bool { return epoch(0) }) + // No assignment: do not open an unauthorised replication socket. + ingressRefused(t, data) + ingressRefused(t, dual) + fact := func(e uint64, peers []*control.ReplicaDescriptor) *control.AssignmentFact { + return &control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: e, EndpointVersion: e, DataAddr: data, CtrlAddr: ctrl, PeerSetGeneration: e, Peers: peers} + } + m.facts <- fact(1, nil) + ingressWait(t, "RF1 assignment not applied", func() bool { return epoch(1) }) + // An attempted higher-epoch frame cannot even establish a connection. + ingressRefused(t, data) + ingressRefused(t, dual) + // RF can grow only through the authoritative assignment stream. + peer := &control.ReplicaDescriptor{ReplicaId: "r2", Epoch: 2, EndpointVersion: 2, DataAddr: pickAddr(t), CtrlAddr: pickAddr(t)} + m.facts <- fact(2, []*control.ReplicaDescriptor{peer}) + ingressWait(t, "RF2 assignment not applied", func() bool { return epoch(2) }) + for _, addr := range []string{data, dual} { + if addr == dual && mode != "dual-lane" { + ingressRefused(t, addr) + continue + } + c, e := net.DialTimeout("tcp", addr, time.Second) + if e != nil { + t.Fatalf("RF2 listener %s: %v", addr, e) + } + c.Close() + } + // A withdrawn role must close existing idle connections as well as + // the listening socket, without waiting for the peer to disconnect. + held, e := net.DialTimeout("tcp", data, time.Second) + if e != nil { + t.Fatal(e) + } + defer held.Close() + m.facts <- fact(3, nil) + ingressWait(t, "RF1 shrink not applied", func() bool { return epoch(3) }) + _ = held.SetReadDeadline(time.Now().Add(time.Second)) + var one [1]byte + if _, err := held.Read(one[:]); err == nil { + t.Fatal("withdrawn connection still usable") + } else if n, ok := err.(net.Error); ok && n.Timeout() { + t.Fatal("withdrawn connection not closed") + } + ingressRefused(t, data) + ingressRefused(t, dual) + // A supporting slot also opens both configured lanes. Removal from + // the authoritative set closes them, even without a primary role. + supporting := fact(4, []*control.ReplicaDescriptor{{ReplicaId: "r1", Epoch: 4, EndpointVersion: 4, DataAddr: data, CtrlAddr: ctrl}}) + supporting.ReplicaId = "r2" + m.facts <- supporting + ingressWait(t, "supporting assignment not applied", func() bool { return epoch(4) }) + for _, addr := range []string{data, dual} { + if addr == dual && mode != "dual-lane" { + continue + } + c, e := net.DialTimeout("tcp", addr, time.Second) + if e != nil { + t.Fatalf("supporting listener %s: %v", addr, e) + } + c.Close() + } + excluded := fact(5, nil) + excluded.ReplicaId = "r2" + m.facts <- excluded + ingressWait(t, "excluded slot still listens", func() bool { + c, e := net.DialTimeout("tcp", data, 200*time.Millisecond) + if c != nil { + c.Close() + } + return errors.Is(e, syscall.ECONNREFUSED) + }) + ingressRefused(t, dual) + }) + } +} diff --git a/seaweed-block/core/host/volume/host.go b/seaweed-block/core/host/volume/host.go index 01f4a1e563..f934dd7ec6 100644 --- a/seaweed-block/core/host/volume/host.go +++ b/seaweed-block/core/host/volume/host.go @@ -132,10 +132,11 @@ type Host struct { // admitted as a supporting replica it re-admits replication at that // epoch. selfRole/selfEpoch remember the last decision so a listener // wired after the first fact (the binary path) is fenced on install. - selfFenceMu sync.Mutex - selfFence selfFencer - selfRole selfRole - selfEpoch uint64 + selfFenceMu sync.Mutex + selfFence selfFencer + selfRole selfRole + selfEpoch uint64 + selfHasPeers bool // roleAdmissionFailed (G1) latches a failed role call on the listener // (a floor that could not be persisted, or a fence that did not drain). // While set, the frontend projection is not Healthy, so writes refuse @@ -404,7 +405,7 @@ func (h *Host) SetSelfFence(f selfFencer) error { if f == nil { return nil } - err := applySelfRole(f, h.selfRole, h.selfEpoch) + err := applySelfRoleWithPeers(f, h.selfRole, h.selfEpoch, h.selfHasPeers) h.latchRoleAdmission(h.selfRole, h.selfEpoch, err) return err } @@ -440,23 +441,32 @@ func (h *Host) RoleAdmissionFailure() (bool, string) { // desired role or touching the admission latch, so a stale success can never // reconcile a newer failure (codex01 R1 on #83). func (h *Host) fenceSelf(role selfRole, epoch uint64) error { + return h.fenceSelfWithPeers(role, epoch, true) +} + +func (h *Host) fenceSelfWithPeers(role selfRole, epoch uint64, hasPeers bool) error { h.selfFenceMu.Lock() defer h.selfFenceMu.Unlock() if epoch < h.selfEpoch { return fmt.Errorf("stale role call at epoch %d (current desired epoch %d)", epoch, h.selfEpoch) } - h.selfRole, h.selfEpoch = role, epoch + h.selfRole, h.selfEpoch, h.selfHasPeers = role, epoch, hasPeers if h.selfFence == nil { return nil } - err := applySelfRole(h.selfFence, role, epoch) + err := applySelfRoleWithPeers(h.selfFence, role, epoch, hasPeers) h.latchRoleAdmission(role, epoch, err) return err } -func applySelfRole(f selfFencer, role selfRole, epoch uint64) error { +// Optional listener lifecycle policy consumes only master-assigned peer slots. +// Called under selfFenceMu, before role admission; legacy fencers are unchanged. +func applySelfRoleWithPeers(f selfFencer, role selfRole, epoch uint64, hasPeers bool) error { switch role { case selfRolePrimary: + if gated, ok := f.(interface{ FenceAsPrimaryWithPeers(uint64, bool) error }); ok { + return gated.FenceAsPrimaryWithPeers(epoch, hasPeers) + } return f.FenceAsPrimary(epoch) case selfRoleReplica: return f.AdmitAsReplica(epoch) @@ -787,6 +797,11 @@ func (h *Host) applyFact(fact *control.AssignmentFact) { h.emitSupportingReadyMarker(info) return } + // The new authoritative set excludes us: close assignment-gated + // ingress as well as withdrawing the frontend through recordOtherLine. + if err := h.fenceSelfWithPeers(selfRolePrimary, fact.Epoch, false); err != nil { + h.log.Printf("blockvolume: excluded replica ingress fence: %v", err) + } h.log.Printf("blockvolume: volume %s authority is now %s@%d (not this replica %s); recording supersede, not applying to adapter", h.cfg.VolumeID, fact.ReplicaId, fact.Epoch, h.cfg.ReplicaID) return @@ -833,7 +848,7 @@ func (h *Host) applyFact(fact *control.AssignmentFact) { // G2: fence our own replica listener at this epoch before the adapter // can turn Healthy and the frontend serves IO, so a deposed primary that // still reaches us cannot get its writes applied (or counted) here. - if err := h.fenceSelf(selfRolePrimary, info.Epoch); err != nil { + if err := h.fenceSelfWithPeers(selfRolePrimary, info.Epoch, len(fact.Peers) > 0); err != nil { // Fail closed, as for an UpdateReplicaSet failure: the frontend // stays gated and master's stream replay redelivers the fact. h.log.Printf("blockvolume: volume %s could not fence its own replica listener at epoch %d: %v — NOT applying to adapter (fail-closed)", diff --git a/seaweed-block/core/transport/replica.go b/seaweed-block/core/transport/replica.go index 5757d6b69d..58667246b1 100644 --- a/seaweed-block/core/transport/replica.go +++ b/seaweed-block/core/transport/replica.go @@ -239,6 +239,8 @@ func (r *ReplicaListener) Stop() { // FIN/RST conns from a dead process; on localhost in-process tests, // nothing closes them, and Stop's wg.Wait would block forever. // +// Role withdrawal may also use this after FenceAsPrimary has drained all +// admitted mutations: idle peer connections must not hold a withdrawn endpoint. // Safe to call multiple times. Idempotent. // // This seam exists to make the restart-catch-up component test @@ -279,6 +281,15 @@ func (r *ReplicaListener) acceptLoop() { } } r.mu.Lock() + // Join admission with StopHard's connection snapshot. A connection + // accepted just before Close must not escape the shutdown snapshot. + select { + case <-r.stopCh: + r.mu.Unlock() + _ = conn.Close() + return + default: + } r.conns[conn] = struct{}{} r.mu.Unlock() r.wg.Add(1) From 79b3ee78d59204e7712b118fc884fabe6bf09fa2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 21:50:32 -0800 Subject: [PATCH 12/16] test: qualify replication exchanges and admitted-operation withdrawal --- .../replication_ingress_binary_test.go | 149 +++++++- .../replication_ingress_withdrawal_test.go | 356 ++++++++++++++++++ 2 files changed, 498 insertions(+), 7 deletions(-) create mode 100644 seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go diff --git a/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go b/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go index d9edda999b..ab3d0422d3 100644 --- a/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go +++ b/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go @@ -3,9 +3,12 @@ package main_test import ( + "bytes" "context" + "encoding/binary" "encoding/json" "errors" + "io" "net" "net/http" "os" @@ -15,7 +18,9 @@ import ( "testing" "time" + "github.com/seaweedfs/seaweed-block/core/recovery" control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/storage" "github.com/seaweedfs/seaweed-block/core/transport" "google.golang.org/grpc" ) @@ -119,16 +124,19 @@ func TestBinaryReplicationIngressFollowsAssignedSlots(t *testing.T) { } done := make(chan error, 1) go func() { done <- child.Wait() }() + exited := false t.Cleanup(func() { - child.Process.Signal(syscall.SIGTERM) - select { - case <-done: - case <-time.After(5 * time.Second): - child.Process.Kill() + if !exited { + child.Process.Signal(syscall.SIGTERM) select { case <-done: - case <-time.After(3 * time.Second): - t.Error("child reap timeout") + case <-time.After(5 * time.Second): + child.Process.Kill() + select { + case <-done: + case <-time.After(3 * time.Second): + t.Error("child reap timeout") + } } } log.Close() @@ -214,6 +222,7 @@ func TestBinaryReplicationIngressFollowsAssignedSlots(t *testing.T) { } c.Close() } + want := ingressProtocolPositive(t, data, dual, mode) excluded := fact(5, nil) excluded.ReplicaId = "r2" m.facts <- excluded @@ -225,6 +234,132 @@ func TestBinaryReplicationIngressFollowsAssignedSlots(t *testing.T) { return errors.Is(e, syscall.ECONNREFUSED) }) ingressRefused(t, dual) + // Reopen through the public recovery API only after the binary has + // fully stopped. Exact bytes must survive the wire barrier and close. + _ = child.Process.Signal(syscall.SIGTERM) + select { + case err := <-done: + exited = true + if err != nil { + t.Fatal(err) + } + case <-time.After(8 * time.Second): + t.Fatal("binary close did not settle") + } + store, err := storage.OpenWALStore(filepath.Join(root, "v1.bin")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err = store.Recover(); err != nil { + t.Fatal(err) + } + for lba, payload := range want { + got, err := store.Read(lba) + if err != nil || !bytes.Equal(got, payload) { + t.Fatalf("recovered LBA%d bytes differ: %v", lba, err) + } + } + t.Logf("%s supporting protocol/barrier and exact recovered bytes PASS", mode) }) } } + +func ingressProtocolPositive(t *testing.T, data, dual, mode string) map[uint32][]byte { + t.Helper() + a := bytes.Repeat([]byte{0xA7}, 4096) + want := map[uint32][]byte{0: a, 1: make([]byte, 4096), 2: make([]byte, 4096)} + c, err := net.DialTimeout("tcp", data, time.Second) + if err != nil { + t.Fatal(err) + } + defer c.Close() + _ = c.SetDeadline(time.Now().Add(5 * time.Second)) + lineage := transport.RecoveryLineage{Epoch: 4, SessionID: 1, EndpointVersion: 4, FrontierHint: 1} + if err = transport.WriteMsg(c, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: lineage, LBA: 0, LSN: 1, Data: a})); err != nil { + t.Fatal(err) + } + if err = transport.WriteMsg(c, transport.MsgBarrierReq, transport.EncodeLineage(lineage)); err != nil { + t.Fatal(err) + } + kind, payload, err := transport.ReadMsg(c) + if err != nil || kind != transport.MsgBarrierResp { + t.Fatalf("legacy barrier kind=%d err=%v", kind, err) + } + ack, err := transport.DecodeBarrierResp(payload) + if err != nil || !ack.Lineage.Equivalent(lineage) || ack.AchievedLSN != 1 { + t.Fatalf("legacy barrier %+v %v", ack, err) + } + if mode != "dual-lane" { + return want + } + d, err := net.DialTimeout("tcp", dual, time.Second) + if err != nil { + t.Fatal(err) + } + defer d.Close() + _ = d.SetDeadline(time.Now().Add(5 * time.Second)) + start := make([]byte, 36) + binary.BigEndian.PutUint64(start, 2) + binary.BigEndian.PutUint64(start[8:], 1) + binary.BigEndian.PutUint64(start[16:], 2) + binary.BigEndian.PutUint32(start[24:], 64) + binary.BigEndian.PutUint64(start[28:], 4) + ingressDualWrite(t, d, 1, start) + want[1] = bytes.Repeat([]byte{0xB8}, 4096) + want[2] = bytes.Repeat([]byte{0xC9}, 4096) + for lba := uint32(0); lba < 64; lba++ { + block := make([]byte, 4096) + if lba == 0 { + copy(block, a) + } + if lba == 1 { + copy(block, want[1]) + } + p := make([]byte, 4+4096) + binary.BigEndian.PutUint32(p, lba) + copy(p[4:], block) + ingressDualWrite(t, d, 2, p) + } + ingressDualWrite(t, d, 3, nil) + if err = recovery.WriteWALEntryFrame(d, recovery.WALKindSessionLive, 2, 2, want[2]); err != nil { + t.Fatal(err) + } + ingressDualWrite(t, d, 5, nil) + for i := 0; i < 4; i++ { + var hdr [5]byte + if _, err = io.ReadFull(d, hdr[:]); err != nil { + t.Fatal(err) + } + n := binary.BigEndian.Uint32(hdr[1:]) + if n > 1024 { + t.Fatal("oversize recovery response") + } + p := make([]byte, n) + if _, err = io.ReadFull(d, p); err != nil { + t.Fatal(err) + } + if hdr[0] == 7 { + if len(p) != 20 || binary.BigEndian.Uint64(p) != 2 { + t.Fatal("invalid base batch ack") + } + continue + } + if hdr[0] != 6 || len(p) != 8 || binary.BigEndian.Uint64(p) != 2 { + t.Fatalf("invalid recovery completion %d %x", hdr[0], p) + } + return want + } + t.Fatal("no recovery completion") + return nil +} +func ingressDualWrite(t *testing.T, c net.Conn, kind byte, p []byte) { + t.Helper() + b := make([]byte, 5+len(p)) + b[0] = kind + binary.BigEndian.PutUint32(b[1:], uint32(len(p))) + copy(b[5:], p) + if _, err := c.Write(b); err != nil { + t.Fatal(err) + } +} diff --git a/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go b/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go new file mode 100644 index 0000000000..dc412c1342 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go @@ -0,0 +1,356 @@ +package main + +import ( + "bytes" + "encoding/binary" + "errors" + "fmt" + "io" + "log" + "net" + "strings" + "sync" + "sync/atomic" + "syscall" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/storage" + "github.com/seaweedfs/seaweed-block/core/transport" +) + +// The storage wrapper parks an actual wire-dispatched effect AFTER admission. +// It embeds the real storage implementation; no listener/gate is mocked. +type ingressParkedStore struct { + storage.LogicalStorage + operation string + entered, resume, finished chan struct{} + once, release sync.Once + active atomic.Int32 + closed atomic.Bool +} + +func (s *ingressParkedStore) effect(op string) func() { + if s.closed.Load() { + panic("receiver used released store") + } + s.active.Add(1) + parked := false + if op == s.operation { + s.once.Do(func() { parked = true; close(s.entered); <-s.resume }) + } + return func() { + s.active.Add(-1) + if parked { + close(s.finished) + } + } +} +func (s *ingressParkedStore) ApplyEntry(lba uint32, p []byte, lsn uint64) error { + done := s.effect("apply") + defer done() + return s.LogicalStorage.ApplyEntry(lba, p, lsn) +} +func (s *ingressParkedStore) WriteExtentDirect(lba uint32, p []byte) error { + done := s.effect("base") + defer done() + return s.LogicalStorage.WriteExtentDirect(lba, p) +} +func (s *ingressParkedStore) Sync() (uint64, error) { + done := s.effect("sync") + defer done() + return s.LogicalStorage.Sync() +} +func (s *ingressParkedStore) unblock() { s.release.Do(func() { close(s.resume) }) } +func (s *ingressParkedStore) Close() error { + if s.active.Load() != 0 { + return fmt.Errorf("store still has %d active effects", s.active.Load()) + } + s.closed.Store(true) + return s.LogicalStorage.Close() +} + +// The inherited dual bridge does not expose a join handle. Its caller logs +// AFTER Serve returns; observe that exact connection's exit before releasing +// our store. This is an observed test-owner join, not a production guarantee. +type ingressExitWitness struct { + io.Writer + peer string + once sync.Once + done chan struct{} +} + +func (w *ingressExitWitness) Write(p []byte) (int, error) { + n, e := w.Writer.Write(p) + if strings.Contains(string(p), "replica Serve exit remote="+w.peer+" ") { + w.once.Do(func() { close(w.done) }) + } + return n, e +} +func ingressAwait(t *testing.T, what string, c <-chan struct{}) { + t.Helper() + select { + case <-c: + case <-time.After(4 * time.Second): + t.Fatal(what) + } +} +func ingressPair(t *testing.T) (string, string) { + t.Helper() + for i := 0; i < 100; i++ { + a, e := net.Listen("tcp", "127.0.0.1:0") + if e != nil { + t.Fatal(e) + } + x := a.Addr().String() + y, e := deriveDualLaneAddr(x) + if e != nil { + a.Close() + continue + } + b, e := net.Listen("tcp", y) + a.Close() + if e == nil { + b.Close() + return x, y + } + } + t.Fatal("no available port pair") + return "", "" +} +func ingressFrame(t *testing.T, c net.Conn, k byte, p []byte) { + t.Helper() + b := make([]byte, 5+len(p)) + b[0] = k + binary.BigEndian.PutUint32(b[1:], uint32(len(p))) + copy(b[5:], p) + if _, e := c.Write(b); e != nil { + t.Fatal(e) + } +} +func ingressStart(t *testing.T, c net.Conn) { + t.Helper() + p := make([]byte, 36) + binary.BigEndian.PutUint64(p, 1) + binary.BigEndian.PutUint64(p[8:], 1) + binary.BigEndian.PutUint64(p[16:], 1) + binary.BigEndian.PutUint32(p[24:], 4) + binary.BigEndian.PutUint64(p[28:], 1) + ingressFrame(t, c, 1, p) +} +func ingressBase(t *testing.T, c net.Conn, p []byte) { + t.Helper() + b := make([]byte, 4+len(p)) + copy(b[4:], p) + ingressFrame(t, c, 2, b) +} +func ingressWireClosed(t *testing.T, c net.Conn) { + t.Helper() + _ = c.SetReadDeadline(time.Now().Add(2 * time.Second)) + var b [1]byte + _, err := c.Read(b[:]) + if err == nil { + t.Fatal("unexpected successful wire outcome after withdrawal") + } + if n, ok := err.(net.Error); ok && n.Timeout() { + t.Fatal("wire did not settle") + } + t.Logf("explicit wire failure after withdrawal: %v", err) +} +func ingressClosedPort(t *testing.T, addr string) { + t.Helper() + c, e := net.DialTimeout("tcp", addr, time.Second) + if c != nil { + c.Close() + } + if !errors.Is(e, syscall.ECONNREFUSED) { + t.Fatalf("withdrawn endpoint %s accepted connection: %v", addr, e) + } +} + +func TestReplicationIngressWithdrawalDrainsAdmittedEffects(t *testing.T) { + for _, lane := range []string{"legacy", "dual"} { + t.Run(lane, func(t *testing.T) { + op := "apply" + if lane == "dual" { + op = "base" + } + s := &ingressParkedStore{LogicalStorage: storage.NewBlockStore(4, 4096), operation: op, entered: make(chan struct{}), resume: make(chan struct{}), finished: make(chan struct{})} + addr, dual := ingressPair(t) + r := &replicationIngress{addr: addr, store: s, dualLane: true} + if err := r.AdmitAsReplica(1); err != nil { + t.Fatal(err) + } + target := addr + if lane == "dual" { + target = dual + } + c, err := net.DialTimeout("tcp", target, time.Second) + if err != nil { + t.Fatal(err) + } + _ = c.SetDeadline(time.Now().Add(8 * time.Second)) + witness := &ingressExitWitness{Writer: log.Writer(), peer: c.LocalAddr().String(), done: make(chan struct{})} + if lane == "dual" { + log.SetOutput(witness) + defer log.SetOutput(witness.Writer) + } + defer func() { + s.unblock() + c.Close() + r.Stop() + if !s.closed.Load() { + _ = s.Close() + } + }() + payload := bytes.Repeat([]byte{0xD3}, 4096) + listener := r.listener + if lane == "legacy" { + l := transport.RecoveryLineage{Epoch: 1, SessionID: 1, EndpointVersion: 1, FrontierHint: 1} + if err = transport.WriteMsg(c, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: l, LBA: 0, LSN: 1, Data: payload})); err != nil { + t.Fatal(err) + } + } else { + ingressStart(t, c) + ingressBase(t, c, payload) + } + ingressAwait(t, "storage operation was not admitted", s.entered) + // Queue a second mutation on the already-open connection. It must + // never reach storage after the first admitted effect drains. + later := bytes.Repeat([]byte{0xF5}, 4096) + if lane == "legacy" { + l := transport.RecoveryLineage{Epoch: 1, SessionID: 1, EndpointVersion: 1, FrontierHint: 1} + if err = transport.WriteMsg(c, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: l, LBA: 1, LSN: 2, Data: later})); err != nil { + t.Fatal(err) + } + } else { + p := make([]byte, 4+len(later)) + binary.BigEndian.PutUint32(p, 1) + copy(p[4:], later) + ingressFrame(t, c, 2, p) + } + + withdrawn := make(chan error, 1) + go func() { withdrawn <- r.FenceAsPrimaryWithPeers(2, false) }() + // Public gate refusal is the fence-arrival witness. This cannot be a + // scheduler-only negative: the new role is installed while our effect lives. + end := time.Now().Add(3 * time.Second) + for { + release, err := listener.EnterDualLane(1) + if err != nil { + break + } + release() + if time.Now().After(end) { + t.Fatal("withdrawal never closed admission") + } + time.Sleep(time.Millisecond) + } + select { + case e := <-withdrawn: + t.Fatalf("withdrawal completed before effect release: %v", e) + default: + } + if s.active.Load() != 1 { + t.Fatal("effect no longer parked") + } + s.unblock() + ingressAwait(t, "effect did not return", s.finished) + select { + case err = <-withdrawn: + if err != nil { + t.Fatal(err) + } + case <-time.After(4 * time.Second): + t.Fatal("withdrawal did not settle") + } + ingressWireClosed(t, c) + if lane == "dual" { + ingressAwait(t, "dual receiver did not exit after cancellation", witness.done) + } + ingressClosedPort(t, addr) + ingressClosedPort(t, dual) + if release, e := listener.EnterDualLane(1); e == nil { + release() + t.Fatal("old gate accepted another frame") + } + got, err := s.Read(0) + if err != nil || !bytes.Equal(got, payload) { + t.Fatal("admitted bytes differ", err) + } + untouched, e := s.Read(1) + if e != nil || !bytes.Equal(untouched, make([]byte, 4096)) { + t.Fatal("queued post-withdrawal mutation reached storage", e) + } + if err = s.Close(); err != nil { + t.Fatal(err) + } + t.Log("admitted exact effect drained; wire failed explicitly; worker settled before store release") + }) + } +} + +// This bounded reproducer records the inherited distinction: sendAck's Sync +// is outside the counted frame. The test owner must await the receiver exit; +// ingress withdrawal alone is NOT proof that this Sync has stopped. +func TestReplicationIngressDualAckSyncNeedsOwnerSettlement(t *testing.T) { + s := &ingressParkedStore{LogicalStorage: storage.NewBlockStore(4, 4096), operation: "sync", entered: make(chan struct{}), resume: make(chan struct{}), finished: make(chan struct{})} + addr, dual := ingressPair(t) + r := &replicationIngress{addr: addr, store: s, dualLane: true} + if err := r.AdmitAsReplica(1); err != nil { + t.Fatal(err) + } + c, err := net.DialTimeout("tcp", dual, time.Second) + if err != nil { + t.Fatal(err) + } + _ = c.SetDeadline(time.Now().Add(8 * time.Second)) + witness := &ingressExitWitness{Writer: log.Writer(), peer: c.LocalAddr().String(), done: make(chan struct{})} + log.SetOutput(witness) + defer log.SetOutput(witness.Writer) + defer func() { + s.unblock() + c.Close() + r.Stop() + if !s.closed.Load() { + _ = s.Close() + } + }() + payload := bytes.Repeat([]byte{0xE4}, 4096) + ingressStart(t, c) + ingressBase(t, c, payload) + ingressFrame(t, c, 3, nil) + ingressAwait(t, "uncounted acknowledgement Sync did not start", s.entered) + withdrawn := make(chan error, 1) + go func() { withdrawn <- r.FenceAsPrimaryWithPeers(2, false) }() + select { + case err = <-withdrawn: + if err != nil { + t.Fatal(err) + } + case <-time.After(3 * time.Second): + t.Fatal("inherited uncounted Sync became a counted drain") + } + if s.active.Load() != 1 { + t.Fatal("no outstanding Sync at withdrawal return") + } + select { + case <-witness.done: + t.Fatal("receiver exited while Sync held") + default: + } + ingressWireClosed(t, c) + // Explicit owner disposition: release the parked Sync and wait for the + // caller's actual Serve-exit witness before releasing the store. + s.unblock() + ingressAwait(t, "Sync did not return", s.finished) + ingressAwait(t, "receiver did not settle", witness.done) + got, err := s.Read(0) + if err != nil || !bytes.Equal(got, payload) { + t.Fatal("base bytes differ", err) + } + if err = s.Close(); err != nil { + t.Fatal(err) + } + t.Log("INHERITED LIMIT reproduced: withdrawal returned with sendAck Sync live; test owner waited for receiver exit before store release") +} From 469edccd04372f8ffe9ec781d8c207ce0905c759 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 22:02:36 -0800 Subject: [PATCH 13/16] test: qualify replication exchanges and admitted-operation withdrawal --- .../replication_ingress_withdrawal_test.go | 388 ++++++++++++------ 1 file changed, 258 insertions(+), 130 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go b/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go index dc412c1342..c48a9e1bf2 100644 --- a/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go +++ b/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go @@ -2,12 +2,16 @@ package main import ( "bytes" + "context" "encoding/binary" "errors" "fmt" "io" "log" "net" + "os" + "os/exec" + "runtime" "strings" "sync" "sync/atomic" @@ -168,6 +172,177 @@ func ingressClosedPort(t *testing.T, addr string) { } } +// Each acquired resource is attached to this owner before the next fallible +// operation. Cleanup unblocks first, joins all started callers, then releases +// storage and restores the logger. Unknown settlement retains both resources. +type ingressTestOwner struct { + t *testing.T + store *ingressParkedStore + ingress *replicationIngress + conn net.Conn + witness *ingressExitWitness + addr, dual, lane string + withdrawalDone chan struct{} + withdrawalErr error + workerID string + cleanupOnce sync.Once + cleanupErr error +} + +func newIngressTestOwner(t *testing.T, operation, lane string) *ingressTestOwner { + t.Helper() + s := &ingressParkedStore{LogicalStorage: storage.NewBlockStore(4, 4096), operation: operation, entered: make(chan struct{}), resume: make(chan struct{}), finished: make(chan struct{})} + o := &ingressTestOwner{t: t, store: s, lane: lane} + t.Cleanup(func() { + if err := o.cleanup(); err != nil { + t.Error(err) + } + }) + o.addr, o.dual = ingressPair(t) + o.ingress = &replicationIngress{addr: o.addr, store: s, dualLane: true} + if err := o.ingress.AdmitAsReplica(1); err != nil { + t.Fatal(err) + } + return o +} +func (o *ingressTestOwner) dial() { + target := o.addr + if o.lane == "dual" { + target = o.dual + } + c, err := net.DialTimeout("tcp", target, time.Second) + if err != nil { + o.t.Fatal(err) + } + o.conn = c // ownership recorded immediately, before deadlines or assertions + _ = c.SetDeadline(time.Now().Add(8 * time.Second)) + if o.lane == "dual" { + o.witness = &ingressExitWitness{Writer: log.Writer(), peer: c.LocalAddr().String(), done: make(chan struct{})} + log.SetOutput(o.witness) + } +} +func (o *ingressTestOwner) withdraw() { + o.withdrawalDone = make(chan struct{}) + id := make(chan string, 1) + go func() { + var b [128]byte + n := runtime.Stack(b[:], false) + id <- strings.Fields(string(b[:n]))[1] + o.withdrawalErr = o.ingress.FenceAsPrimaryWithPeers(2, false) + close(o.withdrawalDone) + }() + o.workerID = <-id +} +func (o *ingressTestOwner) waitWithdrawal() { + ingressAwait(o.t, "withdrawal did not settle", o.withdrawalDone) + if o.withdrawalErr != nil { + o.t.Fatal(o.withdrawalErr) + } +} +func (o *ingressTestOwner) cleanup() error { + o.cleanupOnce.Do(func() { + o.store.unblock() + if o.conn != nil { + _ = o.conn.Close() + } + await := func(c <-chan struct{}, what string) bool { + select { + case <-c: + return true + case <-time.After(4 * time.Second): + o.cleanupErr = fmt.Errorf("UNKNOWN cleanup: %s; store/logger retained", what) + return false + } + } + if o.withdrawalDone != nil && !await(o.withdrawalDone, "withdrawal worker") { + return + } + if o.ingress != nil { + stopped := make(chan struct{}) + go func() { o.ingress.Stop(); close(stopped) }() + if !await(stopped, "ingress Stop") { + return + } + } + if o.witness != nil && !await(o.witness.done, "dual Serve exit") { + return + } + if err := o.store.Close(); err != nil { + o.cleanupErr = err + return + } + if o.witness != nil { + log.SetOutput(o.witness.Writer) + } + if os.Getenv("INGRESS_FAILURE_CASE") != "" { + if o.store.active.Load() != 0 || !o.store.closed.Load() { + o.cleanupErr = fmt.Errorf("cleanup did not release settled store") + return + } + for _, addr := range []string{o.addr, o.dual} { + c, e := net.DialTimeout("tcp", addr, time.Second) + if c != nil { + c.Close() + } + if !errors.Is(e, syscall.ECONNREFUSED) { + o.cleanupErr = fmt.Errorf("cleanup port remains open: %s %v", addr, e) + return + } + } + if o.witness != nil && log.Writer() != o.witness.Writer { + o.cleanupErr = fmt.Errorf("logger not restored") + return + } + fmt.Println("CLEANUP_SETTLED store_closed=true active=0 logger_restored=true ports_closed=true") + } + }) + return o.cleanupErr +} +func (o *ingressTestOwner) parked(payload []byte) { + if o.lane == "legacy" { + l := transport.RecoveryLineage{Epoch: 1, SessionID: 1, EndpointVersion: 1, FrontierHint: 1} + if err := transport.WriteMsg(o.conn, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: l, LBA: 0, LSN: 1, Data: payload})); err != nil { + o.t.Fatal(err) + } + } else { + ingressStart(o.t, o.conn) + ingressBase(o.t, o.conn, payload) + if o.store.operation == "sync" { + ingressFrame(o.t, o.conn, 3, nil) + } + } + ingressAwait(o.t, "storage operation was not admitted", o.store.entered) +} + +// No public wait-arrival seam exists. Observe ONLY this caller's actual +// sync.Cond wait in the production fence, using runtime's diagnostic stack. +// A skip-drain mutant must return (and fail) before we ever release the effect; +// merely closing admission is no longer accepted as a wait witness. +func ingressRequireDrainWait(t *testing.T, o *ingressTestOwner) { + t.Helper() + end := time.Now().Add(4 * time.Second) + for { + select { + case <-o.withdrawalDone: + t.Fatalf("drain skipped: withdrawal returned while admitted effect is held (active=%d)", o.store.active.Load()) + default: + } + b := make([]byte, 1<<20) + n := runtime.Stack(b, true) + for _, stack := range strings.Split(string(b[:n]), "\n\n") { + if strings.HasPrefix(stack, "goroutine "+o.workerID+" ") && + ((strings.Contains(stack, "(*ReplicaListener).fenceAndDrain") && strings.Contains(stack, "sync.(*Cond).Wait")) || + (o.lane == "legacy" && strings.Contains(stack, "(*ReplicaListener).StopHard") && strings.Contains(stack, "sync.(*WaitGroup).Wait"))) { + t.Log("withdrawal caller reached production effect drain/join wait") + return + } + } + if time.Now().After(end) { + t.Fatal("no production drain-wait witness") + } + time.Sleep(time.Millisecond) + } +} func TestReplicationIngressWithdrawalDrainsAdmittedEffects(t *testing.T) { for _, lane := range []string{"legacy", "dual"} { t.Run(lane, func(t *testing.T) { @@ -175,52 +350,16 @@ func TestReplicationIngressWithdrawalDrainsAdmittedEffects(t *testing.T) { if lane == "dual" { op = "base" } - s := &ingressParkedStore{LogicalStorage: storage.NewBlockStore(4, 4096), operation: op, entered: make(chan struct{}), resume: make(chan struct{}), finished: make(chan struct{})} - addr, dual := ingressPair(t) - r := &replicationIngress{addr: addr, store: s, dualLane: true} - if err := r.AdmitAsReplica(1); err != nil { - t.Fatal(err) - } - target := addr - if lane == "dual" { - target = dual - } - c, err := net.DialTimeout("tcp", target, time.Second) - if err != nil { - t.Fatal(err) - } - _ = c.SetDeadline(time.Now().Add(8 * time.Second)) - witness := &ingressExitWitness{Writer: log.Writer(), peer: c.LocalAddr().String(), done: make(chan struct{})} - if lane == "dual" { - log.SetOutput(witness) - defer log.SetOutput(witness.Writer) - } - defer func() { - s.unblock() - c.Close() - r.Stop() - if !s.closed.Load() { - _ = s.Close() - } - }() + o := newIngressTestOwner(t, op, lane) + o.dial() + s, r, c := o.store, o.ingress, o.conn payload := bytes.Repeat([]byte{0xD3}, 4096) + o.parked(payload) listener := r.listener - if lane == "legacy" { - l := transport.RecoveryLineage{Epoch: 1, SessionID: 1, EndpointVersion: 1, FrontierHint: 1} - if err = transport.WriteMsg(c, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: l, LBA: 0, LSN: 1, Data: payload})); err != nil { - t.Fatal(err) - } - } else { - ingressStart(t, c) - ingressBase(t, c, payload) - } - ingressAwait(t, "storage operation was not admitted", s.entered) - // Queue a second mutation on the already-open connection. It must - // never reach storage after the first admitted effect drains. later := bytes.Repeat([]byte{0xF5}, 4096) if lane == "legacy" { l := transport.RecoveryLineage{Epoch: 1, SessionID: 1, EndpointVersion: 1, FrontierHint: 1} - if err = transport.WriteMsg(c, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: l, LBA: 1, LSN: 2, Data: later})); err != nil { + if err := transport.WriteMsg(c, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: l, LBA: 1, LSN: 2, Data: later})); err != nil { t.Fatal(err) } } else { @@ -229,47 +368,24 @@ func TestReplicationIngressWithdrawalDrainsAdmittedEffects(t *testing.T) { copy(p[4:], later) ingressFrame(t, c, 2, p) } - - withdrawn := make(chan error, 1) - go func() { withdrawn <- r.FenceAsPrimaryWithPeers(2, false) }() - // Public gate refusal is the fence-arrival witness. This cannot be a - // scheduler-only negative: the new role is installed while our effect lives. - end := time.Now().Add(3 * time.Second) - for { - release, err := listener.EnterDualLane(1) - if err != nil { - break - } + o.withdraw() + ingressRequireDrainWait(t, o) + if release, err := listener.EnterDualLane(1); err == nil { release() - if time.Now().After(end) { - t.Fatal("withdrawal never closed admission") - } - time.Sleep(time.Millisecond) - } - select { - case e := <-withdrawn: - t.Fatalf("withdrawal completed before effect release: %v", e) - default: + t.Fatal("drain wait did not close admission") } if s.active.Load() != 1 { t.Fatal("effect no longer parked") } s.unblock() ingressAwait(t, "effect did not return", s.finished) - select { - case err = <-withdrawn: - if err != nil { - t.Fatal(err) - } - case <-time.After(4 * time.Second): - t.Fatal("withdrawal did not settle") - } + o.waitWithdrawal() ingressWireClosed(t, c) - if lane == "dual" { - ingressAwait(t, "dual receiver did not exit after cancellation", witness.done) + if o.witness != nil { + ingressAwait(t, "receiver did not exit", o.witness.done) } - ingressClosedPort(t, addr) - ingressClosedPort(t, dual) + ingressClosedPort(t, o.addr) + ingressClosedPort(t, o.dual) if release, e := listener.EnterDualLane(1); e == nil { release() t.Fatal("old gate accepted another frame") @@ -278,79 +394,91 @@ func TestReplicationIngressWithdrawalDrainsAdmittedEffects(t *testing.T) { if err != nil || !bytes.Equal(got, payload) { t.Fatal("admitted bytes differ", err) } - untouched, e := s.Read(1) - if e != nil || !bytes.Equal(untouched, make([]byte, 4096)) { - t.Fatal("queued post-withdrawal mutation reached storage", e) + got, err = s.Read(1) + if err != nil || !bytes.Equal(got, make([]byte, 4096)) { + t.Fatal("queued mutation reached storage", err) } - if err = s.Close(); err != nil { + if err = o.cleanup(); err != nil { t.Fatal(err) } - t.Log("admitted exact effect drained; wire failed explicitly; worker settled before store release") + t.Log("actual wait witnessed; exact effect drained; wire failed; callers settled before store/logger release") }) } } -// This bounded reproducer records the inherited distinction: sendAck's Sync -// is outside the counted frame. The test owner must await the receiver exit; -// ingress withdrawal alone is NOT proof that this Sync has stopped. +// Inherited sendAck Sync remains outside counted effects. The owner still +// joins the observed caller before releasing store/logger, on every exit. func TestReplicationIngressDualAckSyncNeedsOwnerSettlement(t *testing.T) { - s := &ingressParkedStore{LogicalStorage: storage.NewBlockStore(4, 4096), operation: "sync", entered: make(chan struct{}), resume: make(chan struct{}), finished: make(chan struct{})} - addr, dual := ingressPair(t) - r := &replicationIngress{addr: addr, store: s, dualLane: true} - if err := r.AdmitAsReplica(1); err != nil { - t.Fatal(err) - } - c, err := net.DialTimeout("tcp", dual, time.Second) - if err != nil { - t.Fatal(err) - } - _ = c.SetDeadline(time.Now().Add(8 * time.Second)) - witness := &ingressExitWitness{Writer: log.Writer(), peer: c.LocalAddr().String(), done: make(chan struct{})} - log.SetOutput(witness) - defer log.SetOutput(witness.Writer) - defer func() { - s.unblock() - c.Close() - r.Stop() - if !s.closed.Load() { - _ = s.Close() - } - }() + o := newIngressTestOwner(t, "sync", "dual") + o.dial() payload := bytes.Repeat([]byte{0xE4}, 4096) - ingressStart(t, c) - ingressBase(t, c, payload) - ingressFrame(t, c, 3, nil) - ingressAwait(t, "uncounted acknowledgement Sync did not start", s.entered) - withdrawn := make(chan error, 1) - go func() { withdrawn <- r.FenceAsPrimaryWithPeers(2, false) }() - select { - case err = <-withdrawn: - if err != nil { - t.Fatal(err) - } - case <-time.After(3 * time.Second): - t.Fatal("inherited uncounted Sync became a counted drain") - } - if s.active.Load() != 1 { - t.Fatal("no outstanding Sync at withdrawal return") + o.parked(payload) + o.withdraw() + o.waitWithdrawal() + if o.store.active.Load() != 1 { + t.Fatal("Sync not held at withdrawal return") } select { - case <-witness.done: - t.Fatal("receiver exited while Sync held") + case <-o.witness.done: + t.Fatal("receiver exited with Sync held") default: } - ingressWireClosed(t, c) - // Explicit owner disposition: release the parked Sync and wait for the - // caller's actual Serve-exit witness before releasing the store. - s.unblock() - ingressAwait(t, "Sync did not return", s.finished) - ingressAwait(t, "receiver did not settle", witness.done) - got, err := s.Read(0) + ingressWireClosed(t, o.conn) + o.store.unblock() + ingressAwait(t, "Sync did not return", o.store.finished) + ingressAwait(t, "receiver did not settle", o.witness.done) + got, err := o.store.Read(0) if err != nil || !bytes.Equal(got, payload) { t.Fatal("base bytes differ", err) } - if err = s.Close(); err != nil { + if err = o.cleanup(); err != nil { t.Fatal(err) } - t.Log("INHERITED LIMIT reproduced: withdrawal returned with sendAck Sync live; test owner waited for receiver exit before store release") + t.Log("INHERITED LIMIT: withdrawal returned with uncounted Sync live; owner joined before release") +} +func TestReplicationIngressCleanupFailureHelper(t *testing.T) { + stage := os.Getenv("INGRESS_FAILURE_CASE") + if stage == "" { + return + } + lane, op := "dual", "base" + if stage == "held-legacy" { + lane, op = "legacy", "apply" + } + if stage == "held-sync" { + op = "sync" + } + o := newIngressTestOwner(t, op, lane) + if stage == "pre-dial" { + t.Fatal("FORCED_FAILURE pre-dial") + } + o.dial() + o.parked(bytes.Repeat([]byte{0x67}, 4096)) + o.withdraw() + if op == "sync" { + o.waitWithdrawal() + } else { + ingressRequireDrainWait(t, o) + } + t.Fatal("FORCED_FAILURE " + stage) +} +func TestReplicationIngressCleanupOnForcedFailure(t *testing.T) { + for _, stage := range []string{"pre-dial", "held-legacy", "held-dual", "held-sync"} { + t.Run(stage, func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestReplicationIngressCleanupFailureHelper$", "-test.v") + cmd.Env = append(os.Environ(), "INGRESS_FAILURE_CASE="+stage) + b, err := cmd.CombinedOutput() + var exit *exec.ExitError + if !errors.As(err, &exit) || exit.ExitCode() != 1 || ctx.Err() != nil { + t.Fatalf("forced failure status: %v %s", err, b) + } + out := string(b) + if !strings.Contains(out, "FORCED_FAILURE "+stage) || !strings.Contains(out, "CLEANUP_SETTLED store_closed=true active=0 logger_restored=true ports_closed=true") || strings.Contains(out, "UNKNOWN cleanup") { + t.Fatalf("unsafe failure cleanup: %s", b) + } + t.Logf("%s expected Fatal; owned cleanup settled before process exit:\n%s", stage, b) + }) + } } From 919163c11f32a44afbf02aff5ec5dc0c2040d04a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 22:12:52 -0800 Subject: [PATCH 14/16] fix: reopen RDMA backend after a stale lineage refusal --- .../frontend/nvmerdma/failover_reopen_test.go | 154 ++++++++++++++++ .../frontend/nvmerdma/reopen_safety_test.go | 170 ++++++++++++++++++ .../core/frontend/nvmerdma/target.go | 64 +++++-- 3 files changed, 378 insertions(+), 10 deletions(-) create mode 100644 seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go create mode 100644 seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go diff --git a/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go b/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go new file mode 100644 index 0000000000..76271b6146 --- /dev/null +++ b/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go @@ -0,0 +1,154 @@ +package nvmerdma + +import ( + "bytes" + "context" + "errors" + "fmt" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/frontend" + "github.com/seaweedfs/seaweed-block/core/frontend/memback" + master "github.com/seaweedfs/seaweed-block/core/host/master" + volume "github.com/seaweedfs/seaweed-block/core/host/volume" + "github.com/seaweedfs/seaweed-block/core/lifecycle" +) + +func reopenWait(t *testing.T, what string, fn func() bool) { + t.Helper() + end := time.Now().Add(5 * time.Second) + for !fn() { + if time.Now().After(end) { + t.Fatal(what) + } + time.Sleep(time.Millisecond) + } +} + +// Real master lifecycle controller -> durable Publisher -> gRPC subscription +// -> real volume Host/adapter projection -> production memback provider -> +// the same providerBackend used by the RDMA/NBD target. No fake Backend or +// hand-set projection/epoch. This CPU control does not require RDMA hardware +// and does not claim memback durability or data replication across failover. +func TestProviderBackendReopensAfterRealMasterFailover(t *testing.T) { + m, err := master.New(master.Config{AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), Listen: "127.0.0.1:0", ControllerConfig: authority.TopologyControllerConfig{ExpectedSlotsPerVolume: 2}}) + if err != nil { + t.Fatal(err) + } + m.Start() + t.Cleanup(func() { + ctx, c := context.WithTimeout(context.Background(), 3*time.Second) + defer c() + if e := m.Close(ctx); e != nil { + t.Error(e) + } + }) + if _, err = m.Lifecycle().Volumes.CreateVolume(lifecycle.VolumeSpec{VolumeID: "v1", SizeBytes: 64 * 4096, ReplicationFactor: 2}); err != nil { + t.Fatal(err) + } + if _, err = m.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "v1", DesiredRF: 2, Candidates: []lifecycle.PlacementCandidate{{VolumeID: "v1", ServerID: "s1", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}, {VolumeID: "v1", ServerID: "s2", ReplicaID: "r2", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { + t.Fatal(err) + } + h, err := volume.New(volume.Config{MasterAddr: m.Addr(), ServerID: "s1", VolumeID: "v1", ReplicaID: "r1", DataAddr: "127.0.0.1:19101", CtrlAddr: "127.0.0.1:19102", HeartbeatInterval: time.Hour, EnableT1Readiness: true}) + if err != nil { + t.Fatal(err) + } + h.Start() + t.Cleanup(func() { + if e := h.Close(); e != nil { + t.Error(e) + } + }) + transition := func(r1, r2 bool, want string, minEpoch uint64) { + t.Helper() + for i, ready := range []bool{r1, r2} { + id := i + 1 + obs := authority.Observation{ServerID: fmt.Sprintf("s%d", id), ObservedAt: time.Now().UTC(), Server: authority.ServerFact{Reachable: ready, Eligible: ready}, Slots: []authority.SlotFact{{VolumeID: "v1", ReplicaID: fmt.Sprintf("r%d", id), DataAddr: fmt.Sprintf("127.0.0.1:19%d01", id), CtrlAddr: fmt.Sprintf("127.0.0.1:19%d02", id), Reachable: ready, Eligible: ready, ReadyForPrimary: ready, EvidenceScore: uint64(20 - i*10)}}} + if err := m.ObservationHost().Ingest(obs); err != nil { + t.Fatal(err) + } + } + if _, err := m.RunLifecycleProductTick(); err != nil { + t.Fatal(err) + } + reopenWait(t, "authority did not fail over to "+want, func() bool { + line, ok := m.Publisher().VolumeAuthorityLine("v1") + return ok && line.ReplicaID == want && line.Epoch >= minEpoch + }) + reopenWait(t, "host projection did not follow "+want, func() bool { + p := h.ProjectionView().Projection() + if want == "r1" { + return p.Healthy && p.Epoch >= minEpoch + } + return !p.Healthy + }) + line, _ := m.Publisher().VolumeAuthorityLine("v1") + t.Logf("real publisher authority: %s epoch%d", line.ReplicaID, line.Epoch) + } + transition(true, true, "r1", 1) + provider := memback.NewProvider(h.ProjectionView()) + adapters := map[string]*providerBackend{} + for _, op := range []string{"read", "write", "sync", "demoted"} { + b := &providerBackend{provider: provider, volumeID: "v1"} + ctx, c := context.WithTimeout(context.Background(), time.Second) + n, e := b.Write(ctx, 0, []byte("epoch-one")) + c() + if e != nil || n != 9 { + t.Fatal("initial write", n, e) + } + adapters[op] = b + } + transition(false, true, "r2", 2) + ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) + n, err := adapters["demoted"].Write(ctx, 0, []byte("forbidden")) + cancel() + if err == nil || n != 0 { + t.Fatalf("demoted backend wrote bytes: %d %v", n, err) + } + if !errors.Is(err, frontend.ErrStalePrimary) && !errors.Is(err, frontend.ErrNotReady) { + t.Fatal("unexpected refusal", err) + } + transition(true, false, "r1", 3) + // Seed the NEW lineage using a fresh, real provider handle. Memback does not + // retain old-lineage bytes; this is an availability/rebinding assertion. + ctx, cancel = context.WithTimeout(context.Background(), time.Second) + defer cancel() + fresh, err := provider.Open(ctx, "v1") + if err != nil { + t.Fatal(err) + } + want := []byte("new-primary") + if n, err = fresh.Write(ctx, 0, want); err != nil || n != len(want) { + t.Fatal(n, err) + } + for _, op := range []string{"read", "write", "sync"} { + t.Run(op, func(t *testing.T) { + b := adapters[op] + switch op { + case "read": + got := make([]byte, len(want)) + n, e := b.Read(ctx, 0, got) + if e != nil || n != len(got) || !bytes.Equal(got, want) { + t.Fatalf("cached RDMA read failed after r1->r2->r1: n%d err%v bytes%q", n, e, got) + } + case "write": + data := []byte("rebound-io!") + n, e := b.Write(ctx, 0, data) + if e != nil || n != len(data) { + t.Fatalf("cached RDMA write failed after failback: n%d err%v", n, e) + } + got := make([]byte, len(data)) + n, e = fresh.Read(ctx, 0, got) + if e != nil || n != len(data) || !bytes.Equal(got, data) { + t.Fatal("new-lineage exact write bytes differ", n, e) + } + case "sync": + if e := b.Sync(ctx); e != nil { + t.Fatalf("cached RDMA sync failed after failback: %v", e) + } + } + }) + } +} diff --git a/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go b/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go new file mode 100644 index 0000000000..b6924cfc37 --- /dev/null +++ b/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go @@ -0,0 +1,170 @@ +package nvmerdma + +import ( + "bytes" + "context" + "errors" + "fmt" + "io" + "sync" + "sync/atomic" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend" +) + +type reopenScriptBackend struct { + read func([]byte) (int, error) + writeN int + writeErr error + writes atomic.Int32 + closes atomic.Int32 +} + +func (b *reopenScriptBackend) Read(_ context.Context, _ int64, p []byte) (int, error) { + if b.read != nil { + return b.read(p) + } + return len(p), nil +} +func (b *reopenScriptBackend) Write(context.Context, int64, []byte) (int, error) { + b.writes.Add(1) + return b.writeN, b.writeErr +} +func (b *reopenScriptBackend) Sync(context.Context) error { return nil } +func (b *reopenScriptBackend) Identity() frontend.Identity { return frontend.Identity{} } +func (b *reopenScriptBackend) SetOperational(bool, string) {} +func (b *reopenScriptBackend) Close() error { b.closes.Add(1); return nil } + +type reopenScriptProvider struct { + mu sync.Mutex + backends []frontend.Backend + opens int +} + +func (p *reopenScriptProvider) Open(context.Context, string) (frontend.Backend, error) { + p.mu.Lock() + defer p.mu.Unlock() + p.opens++ + if p.opens > len(p.backends) { + return nil, fmt.Errorf("unexpected extra open") + } + return p.backends[p.opens-1], nil +} +func (p *reopenScriptProvider) count() int { p.mu.Lock(); defer p.mu.Unlock(); return p.opens } + +func TestProviderBackendDoesNotReplayAmbiguousWrites(t *testing.T) { + for _, tc := range []struct { + name string + n int + err error + }{{"partial-stale", 2, frontend.ErrStalePrimary}, {"transport", 0, io.ErrUnexpectedEOF}, {"partial-deadline", 2, context.DeadlineExceeded}, {"not-ready", 0, frontend.ErrNotReady}} { + t.Run(tc.name, func(t *testing.T) { + backend := &reopenScriptBackend{writeN: tc.n, writeErr: tc.err} + provider := &reopenScriptProvider{backends: []frontend.Backend{backend}} + b := &providerBackend{provider: provider, volumeID: "v1"} + n, err := b.Write(context.Background(), 0, []byte("data")) + if n != tc.n || !errors.Is(err, tc.err) { + t.Fatalf("outcome changed n%d err%v", n, err) + } + if provider.count() != 1 || backend.writes.Load() != 1 || backend.closes.Load() != 0 { + t.Fatal("ambiguous write replayed or borrowed backend closed") + } + }) + } +} +func TestProviderBackendStaleRetryIsBounded(t *testing.T) { + one := &reopenScriptBackend{writeErr: fmt.Errorf("wrapped: %w", frontend.ErrStalePrimary)} + two := &reopenScriptBackend{writeErr: frontend.ErrStalePrimary} + provider := &reopenScriptProvider{backends: []frontend.Backend{one, two}} + b := &providerBackend{provider: provider, volumeID: "v1"} + if n, err := b.Write(context.Background(), 0, []byte("data")); n != 0 || !errors.Is(err, frontend.ErrStalePrimary) { + t.Fatal(n, err) + } + if provider.count() != 2 || one.writes.Load() != 1 || two.writes.Load() != 1 || one.closes.Load() != 0 || two.closes.Load() != 0 { + t.Fatal("retry not bounded or borrowed backend closed") + } +} +func TestProviderBackendLateStaleReadKeepsNewHandle(t *testing.T) { + entered, release, done := make(chan struct{}), make(chan struct{}), make(chan struct{}) + var once sync.Once + var calls atomic.Int32 + old := &reopenScriptBackend{read: func([]byte) (int, error) { + if calls.Add(1) == 1 { + close(entered) + <-release + } + return 0, frontend.ErrStalePrimary + }} + fresh := &reopenScriptBackend{read: func(p []byte) (int, error) { return copy(p, []byte("fresh")), nil }} + provider := &reopenScriptProvider{backends: []frontend.Backend{old, fresh}} + b := &providerBackend{provider: provider, volumeID: "v1"} + var firstErr error + first := make([]byte, 5) + go func() { defer close(done); _, firstErr = b.Read(context.Background(), 0, first) }() + t.Cleanup(func() { + once.Do(func() { close(release) }) + select { + case <-done: + case <-time.After(3 * time.Second): + t.Error("read worker unsettled") + } + }) + select { + case <-entered: + case <-time.After(3 * time.Second): + t.Fatal("old request never entered") + } + second := make([]byte, 5) + if n, err := b.Read(context.Background(), 0, second); err != nil || n != 5 || !bytes.Equal(second, []byte("fresh")) { + t.Fatal(n, err) + } + once.Do(func() { close(release) }) + select { + case <-done: + case <-time.After(3 * time.Second): + t.Fatal("old request did not settle") + } + if firstErr != nil || !bytes.Equal(first, []byte("fresh")) || provider.count() != 2 || old.closes.Load() != 0 || fresh.closes.Load() != 0 { + t.Fatal("late refusal evicted the new handle or closed borrowed state", firstErr, provider.count()) + } +} + +type reopenProviderFunc func(context.Context, string) (frontend.Backend, error) + +func (f reopenProviderFunc) Open(ctx context.Context, v string) (frontend.Backend, error) { + return f(ctx, v) +} +func TestProviderBackendOpenHasBoundAndHonorsCancellation(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + entered, done := make(chan bool, 1), make(chan error, 1) + provider := reopenProviderFunc(func(c context.Context, _ string) (frontend.Backend, error) { + deadline, ok := c.Deadline() + entered <- ok && time.Until(deadline) <= 5*time.Second + <-c.Done() + return nil, c.Err() + }) + b := &providerBackend{provider: provider, volumeID: "v1"} + go func() { _, err := b.Read(ctx, 0, make([]byte, 1)); done <- err }() + select { + case bounded := <-entered: + if !bounded { + cancel() + <-done + t.Fatal("readiness Open has no finite bound") + } + case <-time.After(3 * time.Second): + t.Fatal("Open not entered") + } + cancel() + select { + case err := <-done: + if !errors.Is(err, context.Canceled) { + t.Fatal(err) + } + case <-time.After(3 * time.Second): + t.Fatal("caller cancellation ignored") + } +} diff --git a/seaweed-block/core/frontend/nvmerdma/target.go b/seaweed-block/core/frontend/nvmerdma/target.go index a19f5bce4e..dd721bdb02 100644 --- a/seaweed-block/core/frontend/nvmerdma/target.go +++ b/seaweed-block/core/frontend/nvmerdma/target.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" "sync" + "time" "github.com/seaweedfs/seaweed-block/core/frontend" ) @@ -78,26 +79,40 @@ type providerBackend struct { provider frontend.Provider volumeID string - mu sync.Mutex - backend frontend.Backend + mu sync.Mutex + backend frontend.Backend + generation uint64 } -func (b *providerBackend) get(ctx context.Context) (frontend.Backend, error) { +func (b *providerBackend) get(ctx context.Context) (frontend.Backend, uint64, error) { b.mu.Lock() defer b.mu.Unlock() if b.backend != nil { - return b.backend, nil + return b.backend, b.generation, nil } - backend, err := b.provider.Open(ctx, b.volumeID) + // NBD supplies a target-lifetime context, not a per-request deadline. + // Bound readiness waits even while this target is demoted. + openCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + backend, err := b.provider.Open(openCtx, b.volumeID) if err != nil { - return nil, fmt.Errorf("nvmerdma: open backend: %w", err) + return nil, 0, fmt.Errorf("nvmerdma: open backend: %w", err) } b.backend = backend - return backend, nil + b.generation++ + return backend, b.generation, nil } func (b *providerBackend) Read(ctx context.Context, offset int64, p []byte) (int, error) { - backend, err := b.get(ctx) + backend, generation, err := b.get(ctx) + if err != nil { + return 0, err + } + n, err := backend.Read(ctx, offset, p) + if n != 0 || !errors.Is(err, frontend.ErrStalePrimary) { + return n, err + } + backend, err = b.reopen(ctx, generation) if err != nil { return 0, err } @@ -105,7 +120,15 @@ func (b *providerBackend) Read(ctx context.Context, offset int64, p []byte) (int } func (b *providerBackend) Write(ctx context.Context, offset int64, p []byte) (int, error) { - backend, err := b.get(ctx) + backend, generation, err := b.get(ctx) + if err != nil { + return 0, err + } + n, err := backend.Write(ctx, offset, p) + if n != 0 || !errors.Is(err, frontend.ErrStalePrimary) { + return n, err + } + backend, err = b.reopen(ctx, generation) if err != nil { return 0, err } @@ -113,9 +136,30 @@ func (b *providerBackend) Write(ctx context.Context, offset int64, p []byte) (in } func (b *providerBackend) Sync(ctx context.Context) error { - backend, err := b.get(ctx) + backend, generation, err := b.get(ctx) + if err != nil { + return err + } + err = backend.Sync(ctx) + if !errors.Is(err, frontend.ErrStalePrimary) { + return err + } + backend, err = b.reopen(ctx, generation) if err != nil { return err } return backend.Sync(ctx) } + +// Stale-primary is a pre-effect lineage refusal. Retry once through Provider's +// current readiness/identity gate; never close the borrowed backend. Generation +// matching prevents a delayed old refusal from evicting a newer open handle. +func (b *providerBackend) reopen(ctx context.Context, generation uint64) (frontend.Backend, error) { + b.mu.Lock() + if b.generation == generation { + b.backend = nil + } + b.mu.Unlock() + backend, _, err := b.get(ctx) + return backend, err +} From f5b1523b8aa81f478c02866f62399bbdc678e677 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 22:27:14 -0800 Subject: [PATCH 15/16] fix: reopen RDMA backend after a stale lineage refusal --- .../frontend/nvmerdma/failover_reopen_test.go | 2 +- .../frontend/nvmerdma/reopen_safety_test.go | 88 +++++++++++++++++++ .../core/frontend/nvmerdma/target.go | 81 +++++++++++++---- 3 files changed, 151 insertions(+), 20 deletions(-) diff --git a/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go b/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go index 76271b6146..1f9583335b 100644 --- a/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go +++ b/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go @@ -107,7 +107,7 @@ func TestProviderBackendReopensAfterRealMasterFailover(t *testing.T) { if err == nil || n != 0 { t.Fatalf("demoted backend wrote bytes: %d %v", n, err) } - if !errors.Is(err, frontend.ErrStalePrimary) && !errors.Is(err, frontend.ErrNotReady) { + if !errors.Is(err, frontend.ErrStalePrimary) && !errors.Is(err, frontend.ErrNotReady) && !errors.Is(err, context.DeadlineExceeded) { t.Fatal("unexpected refusal", err) } transition(true, false, "r1", 3) diff --git a/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go b/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go index b6924cfc37..a0d4e66606 100644 --- a/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go +++ b/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go @@ -168,3 +168,91 @@ func TestProviderBackendOpenHasBoundAndHonorsCancellation(t *testing.T) { t.Fatal("caller cancellation ignored") } } + +// A held readiness Open must not serialize other callers' cancellation budgets. +func TestProviderBackendQueuedOpenCancellation(t *testing.T) { + entered, release := make(chan struct{}), make(chan struct{}) + var once sync.Once + var opens atomic.Int32 + b := &providerBackend{provider: reopenProviderFunc(func(ctx context.Context, _ string) (frontend.Backend, error) { + if opens.Add(1) == 1 { + close(entered) + } + select { + case <-release: + return &reopenScriptBackend{}, nil + case <-ctx.Done(): + return nil, ctx.Err() + } + })} + first := make(chan error, 1) + go func() { _, _, err := b.get(context.Background()); first <- err }() + t.Cleanup(func() { + once.Do(func() { close(release) }) + select { + case <-first: + case <-time.After(6 * time.Second): + t.Error("opener unsettled") + } + }) + <-entered + const callers = 8 + results := make(chan error, callers) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + for i := 0; i < callers; i++ { + go func() { _, _, err := b.get(ctx); results <- err }() + } + cancel() + timer := time.NewTimer(time.Second) + defer timer.Stop() + for i := 0; i < callers; i++ { + select { + case err := <-results: + if !errors.Is(err, context.Canceled) { + t.Errorf("queued error %v", err) + } + case <-timer.C: + t.Fatal("queued callers blocked behind Open instead of their own cancellation") + } + } + if opens.Load() != 1 { + t.Fatalf("concurrent opens: %d", opens.Load()) + } +} + +func TestProviderBackendQueuedOpenSharesDeadline(t *testing.T) { + entered := make(chan struct{}) + var opens atomic.Int32 + b := &providerBackend{provider: reopenProviderFunc(func(ctx context.Context, _ string) (frontend.Backend, error) { + if opens.Add(1) == 1 { + close(entered) + } + <-ctx.Done() + return nil, ctx.Err() + })} + const callers = 8 + results := make(chan error, callers+1) + ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + go func() { _, _, err := b.get(ctx); results <- err }() + <-entered + for i := 0; i < callers; i++ { + go func() { _, _, err := b.get(ctx); results <- err }() + } + timer := time.NewTimer(2 * time.Second) + defer timer.Stop() + for i := 0; i <= callers; i++ { + select { + case err := <-results: + if !errors.Is(err, context.DeadlineExceeded) { + t.Errorf("deadline: %v", err) + } + case <-timer.C: + t.Fatal("queued budgets accumulated") + } + } + if opens.Load() != 1 { + t.Fatalf("waiters opened serially: %d", opens.Load()) + } +} diff --git a/seaweed-block/core/frontend/nvmerdma/target.go b/seaweed-block/core/frontend/nvmerdma/target.go index dd721bdb02..340491d6a9 100644 --- a/seaweed-block/core/frontend/nvmerdma/target.go +++ b/seaweed-block/core/frontend/nvmerdma/target.go @@ -82,29 +82,68 @@ type providerBackend struct { mu sync.Mutex backend frontend.Backend generation uint64 + opening *backendOpen +} + +// backendOpen publishes its result by closing done. Only the opener writes it. +type backendOpen struct { + done chan struct{} + backend frontend.Backend + generation uint64 + err error } func (b *providerBackend) get(ctx context.Context) (frontend.Backend, uint64, error) { - b.mu.Lock() - defer b.mu.Unlock() - if b.backend != nil { - return b.backend, b.generation, nil - } - // NBD supplies a target-lifetime context, not a per-request deadline. - // Bound readiness waits even while this target is demoted. + // Start the readiness budget before coordination, never after waiting for a lock. openCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() - backend, err := b.provider.Open(openCtx, b.volumeID) - if err != nil { - return nil, 0, fmt.Errorf("nvmerdma: open backend: %w", err) + if err := openCtx.Err(); err != nil { + return nil, 0, err + } + b.mu.Lock() + if b.backend != nil { + backend, generation := b.backend, b.generation + b.mu.Unlock() + return backend, generation, nil + } + flight := b.opening + if flight == nil { + flight = &backendOpen{done: make(chan struct{})} + b.opening = flight + // Provider.Open may wait for readiness. Never hold the cache lock across it. + // One flight owns that wait; other callers retain their own cancellation. + go func() { + backend, err := b.provider.Open(openCtx, b.volumeID) + b.mu.Lock() + if err == nil { + b.backend = backend + b.generation++ + flight.backend = backend + flight.generation = b.generation + } else { + flight.err = fmt.Errorf("nvmerdma: open backend: %w", err) + } + b.opening = nil + close(flight.done) + b.mu.Unlock() + }() + } + b.mu.Unlock() + select { + case <-openCtx.Done(): + return nil, 0, openCtx.Err() + case <-flight.done: + if err := openCtx.Err(); err != nil { + return nil, 0, err + } + return flight.backend, flight.generation, flight.err } - b.backend = backend - b.generation++ - return backend, b.generation, nil } func (b *providerBackend) Read(ctx context.Context, offset int64, p []byte) (int, error) { - backend, generation, err := b.get(ctx) + readinessCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + backend, generation, err := b.get(readinessCtx) if err != nil { return 0, err } @@ -112,7 +151,7 @@ func (b *providerBackend) Read(ctx context.Context, offset int64, p []byte) (int if n != 0 || !errors.Is(err, frontend.ErrStalePrimary) { return n, err } - backend, err = b.reopen(ctx, generation) + backend, err = b.reopen(readinessCtx, generation) if err != nil { return 0, err } @@ -120,7 +159,9 @@ func (b *providerBackend) Read(ctx context.Context, offset int64, p []byte) (int } func (b *providerBackend) Write(ctx context.Context, offset int64, p []byte) (int, error) { - backend, generation, err := b.get(ctx) + readinessCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + backend, generation, err := b.get(readinessCtx) if err != nil { return 0, err } @@ -128,7 +169,7 @@ func (b *providerBackend) Write(ctx context.Context, offset int64, p []byte) (in if n != 0 || !errors.Is(err, frontend.ErrStalePrimary) { return n, err } - backend, err = b.reopen(ctx, generation) + backend, err = b.reopen(readinessCtx, generation) if err != nil { return 0, err } @@ -136,7 +177,9 @@ func (b *providerBackend) Write(ctx context.Context, offset int64, p []byte) (in } func (b *providerBackend) Sync(ctx context.Context) error { - backend, generation, err := b.get(ctx) + readinessCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + backend, generation, err := b.get(readinessCtx) if err != nil { return err } @@ -144,7 +187,7 @@ func (b *providerBackend) Sync(ctx context.Context) error { if !errors.Is(err, frontend.ErrStalePrimary) { return err } - backend, err = b.reopen(ctx, generation) + backend, err = b.reopen(readinessCtx, generation) if err != nil { return err } From 66163442fe79aa162256a52d43d8da70d48799a2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 22:35:48 -0800 Subject: [PATCH 16/16] fix: reopen RDMA backend after a stale lineage refusal --- .../core/frontend/nvmerdma/reopen_safety_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go b/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go index a0d4e66606..c239af21ba 100644 --- a/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go +++ b/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go @@ -236,7 +236,13 @@ func TestProviderBackendQueuedOpenSharesDeadline(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) defer cancel() go func() { _, _, err := b.get(ctx); results <- err }() - <-entered + select { + case <-entered: + case <-ctx.Done(): + t.Fatalf("initial Open did not enter before caller deadline: %v", ctx.Err()) + case <-time.After(2 * time.Second): + t.Fatal("initial Open did not enter") + } for i := 0; i < callers; i++ { go func() { _, _, err := b.get(ctx); results <- err }() }