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..9a49dbb074 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) { + continue // never placed again (see importLifecycleVolumes) + } plan := lifecycle.PlacementPlan{ VolumeID: intent.VolumeID, DesiredRF: intent.DesiredRF, 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..ab3d0422d3 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/replication_ingress_binary_test.go @@ -0,0 +1,365 @@ +//go:build subprocess && !windows + +package main_test + +import ( + "bytes" + "context" + "encoding/binary" + "encoding/json" + "errors" + "io" + "net" + "net/http" + "os" + "os/exec" + "path/filepath" + "syscall" + "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" +) + +// 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() }() + exited := false + t.Cleanup(func() { + if !exited { + 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() + } + want := ingressProtocolPositive(t, data, dual, mode) + 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) + // 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..c48a9e1bf2 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/replication_ingress_withdrawal_test.go @@ -0,0 +1,484 @@ +package main + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "io" + "log" + "net" + "os" + "os/exec" + "runtime" + "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) + } +} + +// 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) { + op := "apply" + if lane == "dual" { + op = "base" + } + 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 + 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) + } + o.withdraw() + ingressRequireDrainWait(t, o) + if release, err := listener.EnterDualLane(1); err == nil { + release() + 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) + o.waitWithdrawal() + ingressWireClosed(t, c) + if o.witness != nil { + ingressAwait(t, "receiver did not exit", o.witness.done) + } + ingressClosedPort(t, o.addr) + ingressClosedPort(t, o.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) + } + got, err = s.Read(1) + if err != nil || !bytes.Equal(got, make([]byte, 4096)) { + t.Fatal("queued mutation reached storage", err) + } + if err = o.cleanup(); err != nil { + t.Fatal(err) + } + t.Log("actual wait witnessed; exact effect drained; wire failed; callers settled before store/logger release") + }) + } +} + +// 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) { + o := newIngressTestOwner(t, "sync", "dual") + o.dial() + payload := bytes.Repeat([]byte{0xE4}, 4096) + o.parked(payload) + o.withdraw() + o.waitWithdrawal() + if o.store.active.Load() != 1 { + t.Fatal("Sync not held at withdrawal return") + } + select { + case <-o.witness.done: + t.Fatal("receiver exited with Sync held") + default: + } + 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 = o.cleanup(); err != nil { + t.Fatal(err) + } + 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) + }) + } +} 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..52e05da0cc --- /dev/null +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -0,0 +1,129 @@ +package main + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "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" + "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) +// 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 ( + 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") + 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) + } + 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 == "" || 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 { + return exit + } + defer closeFn() + conn, err := grpc.NewClient(master, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return chunkResult("volume-delete", nil, err, stdout, stderr) + } + defer conn.Close() + admit := &masterAdmission{lc: control.NewLifecycleServiceClient(conn), token: requestID} + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + res, err := cat.DeleteVolume(ctx, volumeID, admit) + if err != nil { + return volumeDeletePartial(res, err, stdout, stderr) + } + return chunkResult("volume-delete", res, nil, stdout, stderr) +} + +// 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 (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 { + 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 new file mode 100644 index 0000000000..535811e3a3 --- /dev/null +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete_test.go @@ -0,0 +1,158 @@ +package main + +import ( + "context" + "encoding/json" + "strings" + "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" +) + +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() + 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", "v3"} { + 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) + } + // v3 has a snapshot. + 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) + } + + 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) + } + } + + 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 + } + 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 refused delete: %v", err) + } + + // 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 _, 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) + } +} diff --git a/seaweed-block/core/frontend/chunkstore/catalog.go b/seaweed-block/core/frontend/chunkstore/catalog.go index a94aa1f2ae..c8577c41a1 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. @@ -396,6 +399,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 } @@ -498,6 +502,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 && 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) } @@ -844,6 +856,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 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 { + return SnapshotInfo{}, refuseDeleted(vol, "it cannot be snapshotted") + } headEnt, err := headEntry(head) if err != nil { @@ -1160,6 +1181,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 @@ -1171,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) { + // 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 } @@ -1184,6 +1213,16 @@ 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 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 gone { + 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) } @@ -1279,7 +1318,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) @@ -1339,16 +1378,26 @@ 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) +} + +// 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] @@ -1358,7 +1407,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 @@ -1367,10 +1416,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 b477841b8b..3fbfde5f9d 100644 --- a/seaweed-block/core/frontend/chunkstore/chunk_remote.go +++ b/seaweed-block/core/frontend/chunkstore/chunk_remote.go @@ -401,6 +401,11 @@ func (r *ChunkRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVer if err != nil { return 0, err } + 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) + } if current.Gen != expected.Gen || current.Epoch != expected.Epoch || next.RemoteLSN < current.RemoteLSN { return 0, storage.ErrChunkHeadPrecondition } @@ -524,6 +529,14 @@ 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, 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 != "" { + 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..238e860e19 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/volume_delete.go @@ -0,0 +1,482 @@ +package chunkstore + +import ( + "context" + "errors" + "path" + "strconv" + "strings" + + "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; 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 +// 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) 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" + CodeVolumeHasSnapshots = "volume_has_snapshots" + + // VolumeDeleted is the state of a deleted volume's VOLUME entry. + VolumeDeleted = "deleted" + + extVolState = "swb.volume.state" + extVolDeletedNs = "swb.volume.deleted_ns" + + // Test seams (retainHook stages) in a DeleteVolume. + 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 +// (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 + // 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 + 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). 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} + 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) + } + h, _, err := c.ReadHead(ctx, vol) + if err != nil { + return res, err + } + res.Replayed = v.State == VolumeDeleted && h.State == storage.ChunkHeadDeleted + // (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) { + 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 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), (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 + return res, err + } + return giveBack(err) + } + res.HeadMarked = true + c.hook(hookHeadMarked, vol) + // (c) + live, err := c.snapshotsBlock(ctx, vol, root) + if err != nil { + return res, err + } + if live != nil { + c.hook(hookBlocked, vol) + out, u, rerr := c.revertHeadDeleting(ctx, vol, root, gen) + switch { + case rerr != nil: + res.Uncertain = u + return res, rerr + 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) + } + res.Reverted, res.HeadMarked = true, false + return giveBack(live) + } + c.hook(hookClaimsChecked, vol) + // (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 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 + c.hook(hookCommitted, vol) + 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 + // (e) + if u, err := c.finishHeadDeleted(ctx, vol, root); err != nil { + 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 + } + res.Completed = true + return res, 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 != "" +} + +// 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.ChunkHeadPurging || 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. 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 0, false, err + } + if h.State == storage.ChunkHeadDeleting { + return h.Gen, false, nil // join this incarnation + } + if headDeletingOrDeleted(h) { + return h.Gen, false, nil + } + if headHeld(h) { + 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 + 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 0, true, catErr(CodeOutcomeUnknown, true, err, "mark HEAD of %s deleting: outcome unknown; rerun the delete", vol) + } + return h.Gen + 1, false, nil + } + return 0, false, remoteErr(nil, "HEAD of %s kept changing", vol) +} + +// 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 + } + 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 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 + } + 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: + return incarnationMoved, false, nil // another incarnation: its claims were not checked here + } + 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. +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.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) + 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) +} + +// 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 + } + 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 +} + +// 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 + } + } +} + +// 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 (or deleting) volume id. +func refuseDeleted(vol, what string) error { + 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_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..5190f32eba --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/volume_delete_test.go @@ -0,0 +1,553 @@ +package chunkstore + +import ( + "context" + "errors" + "fmt" + "path" + "strings" + "sync" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// 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). +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) + } +} + +// 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 + 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 +} + +// 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) + 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) + } + } + return f, b, c, h +} + +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 +} + +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, +// 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 +} + +// 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(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) + } +} + +// 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") + 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 _, 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) + } +} + +// 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") + 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 != hookBlocked { + return + } + c.retainHook = nil + if _, err := c.DeleteSnapshot(ctx, "v1", "s1"); err != nil { + t.Fatal(err) + } + 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 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) + } +} + +// 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) + } + if _, err := c.DeleteVolume(ctx, "w2", nil); CodeOf(err) != CodeVolumeHasSnapshots { + t.Fatalf("delete w2 with a snapshot: %v; want volume_has_snapshots", err) + } + if _, err := c.DeleteSnapshot(ctx, "w2", "w2snap"); err != nil { + t.Fatal(err) + } + res, err := c.DeleteVolume(ctx, "w2", nil) + if err != nil || res.Replayed || !res.Completed { + t.Fatalf("delete w2: %+v %v", res, err) + } + 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) + } +} + +// 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/frontend/nvmerdma/failover_reopen_test.go b/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go new file mode 100644 index 0000000000..1f9583335b --- /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) && !errors.Is(err, context.DeadlineExceeded) { + 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..c239af21ba --- /dev/null +++ b/seaweed-block/core/frontend/nvmerdma/reopen_safety_test.go @@ -0,0 +1,264 @@ +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") + } +} + +// 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 }() + 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 }() + } + 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 a19f5bce4e..340491d6a9 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,79 @@ type providerBackend struct { provider frontend.Provider volumeID string - mu sync.Mutex - backend frontend.Backend + mu sync.Mutex + backend frontend.Backend + generation uint64 + opening *backendOpen } -func (b *providerBackend) get(ctx context.Context) (frontend.Backend, error) { +// 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) { + // Start the readiness budget before coordination, never after waiting for a lock. + openCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + if err := openCtx.Err(); err != nil { + return nil, 0, err + } b.mu.Lock() - defer b.mu.Unlock() if b.backend != nil { - return b.backend, nil + backend, generation := b.backend, b.generation + b.mu.Unlock() + return backend, generation, nil } - backend, err := b.provider.Open(ctx, b.volumeID) - if err != nil { - return nil, fmt.Errorf("nvmerdma: open backend: %w", err) + 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 - return backend, nil } func (b *providerBackend) Read(ctx context.Context, offset int64, p []byte) (int, error) { - backend, 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 + } + n, err := backend.Read(ctx, offset, p) + if n != 0 || !errors.Is(err, frontend.ErrStalePrimary) { + return n, err + } + backend, err = b.reopen(readinessCtx, generation) if err != nil { return 0, err } @@ -105,7 +159,17 @@ 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) + readinessCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + backend, generation, err := b.get(readinessCtx) + 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(readinessCtx, generation) if err != nil { return 0, err } @@ -113,9 +177,32 @@ 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) + readinessCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + backend, generation, err := b.get(readinessCtx) + if err != nil { + return err + } + err = backend.Sync(ctx) + if !errors.Is(err, frontend.ErrStalePrimary) { + return err + } + backend, err = b.reopen(readinessCtx, 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 +} 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 e68f7a7645..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 { + 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 8fa4cfbf49..3bec693596 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -56,6 +56,19 @@ 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. + // held through the create (workspace_protocol.md: reservation checks + // and commits stay under workspaceMu). + s.host.workspaceMu.Lock() + 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 { + 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 { @@ -107,6 +120,132 @@ 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) + var res lifecycle.DeletionReservation + var persistErr error + err = s.host.Publisher().RecordWorkspaceDeletion(ctx, vol, bound && placed, func() error { + res, persistErr = stores.Deletions.Admit(vol, req.GetToken()) + return persistErr + }) + 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) + } + _, 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 +} + +// 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) { + 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) + +// 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) { if !s.host.cfg.FailbackRuntimeRPC { return nil, status.Error(codes.FailedPrecondition, "failback runtime RPC is disabled") @@ -180,6 +319,7 @@ func lifecycleError(op string, err error) error { if errors.Is(err, lifecycle.ErrVolumeConflict) { return status.Errorf(codes.AlreadyExists, "%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..a1a7bdb54f --- /dev/null +++ b/seaweed-block/core/host/master/volume_deleting_test.go @@ -0,0 +1,205 @@ +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" +) + +// 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, markReq("live", "d1")) + if status.Code(err) != codes.FailedPrecondition { + t.Fatalf("mark of an assigned volume: %v; want FailedPrecondition", err) + } + 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) + 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"} { + if _, err := lc.MarkVolumeDeleting(ctx, markReq(vol, "d-"+vol)); err != nil { + t.Fatalf("mark %s: %v", vol, err) + } + } + 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 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 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/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 013011dea9..5c58e320a3 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -160,6 +160,9 @@ func (h *Host) admitWorkspacePublication(ask authority.AssignmentAsk, publish fu } h.workspaceMu.Lock() defer h.workspaceMu.Unlock() + 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: no lifecycle VolumeRecord for %s; register it (CreateVolume) before publishing", ask.VolumeID) } diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index f8f977ccf7..f1e17f69a3 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 s.host.lifecycle.Deletions.Reserved(volume) { + return status.Error(codes.FailedPrecondition, "workspace: volume is being deleted") + } return nil } 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/lifecycle/deletion_reservations.go b/seaweed-block/core/lifecycle/deletion_reservations.go new file mode 100644 index 0000000000..75cd4f381d --- /dev/null +++ b/seaweed-block/core/lifecycle/deletion_reservations.go @@ -0,0 +1,255 @@ +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) { + 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 { + 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 { + 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 { + 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..d6be8a4207 --- /dev/null +++ b/seaweed-block/core/lifecycle/deletion_reservations_test.go @@ -0,0 +1,119 @@ +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") + } +} + +// 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) + } +} diff --git a/seaweed-block/core/rpc/control/control.pb.go b/seaweed-block/core/rpc/control/control.pb.go index f0aec7594d..ecaa109beb 100644 --- a/seaweed-block/core/rpc/control/control.pb.go +++ b/seaweed-block/core/rpc/control/control.pb.go @@ -2533,6 +2533,121 @@ 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"` + // 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() { + *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 "" +} + +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 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() { + *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 +} + +func (x *MarkVolumeDeletingResponse) GetState() string { + if x != nil { + return x.State + } + return "" +} + type FailbackRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2554,7 +2669,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 +2682,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 +2695,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 +2792,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 +2805,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 +2818,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 +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, 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, + 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, 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, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, + 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, 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, + 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, 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, 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, + 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, 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, 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, + 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, 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, 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, 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, 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, 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, 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, + 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, 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, + 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, 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, 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, + 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 +3521,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 +3592,27 @@ 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 + 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 @@ -3805,7 +3961,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 +3973,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 +4015,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..cb2855bebf 100644 --- a/seaweed-block/core/rpc/control/control_grpc.pb.go +++ b/seaweed-block/core/rpc/control/control_grpc.pb.go @@ -665,8 +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_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. @@ -675,6 +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 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 { @@ -703,12 +718,51 @@ 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 +} + +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 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() } @@ -722,6 +776,15 @@ 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) 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. @@ -771,6 +834,60 @@ 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) +} + +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) @@ -786,6 +903,18 @@ var LifecycleService_ServiceDesc = grpc.ServiceDesc{ MethodName: "DeleteVolume", Handler: _LifecycleService_DeleteVolume_Handler, }, + { + 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 8841d72118..1efa3f4021 100644 --- a/seaweed-block/core/rpc/proto/control.proto +++ b/seaweed-block/core/rpc/proto/control.proto @@ -84,6 +84,18 @@ service ClusterEvidenceService { service LifecycleService { rpc CreateVolume(CreateVolumeRequest) returns (CreateVolumeResponse); rpc DeleteVolume(DeleteVolumeRequest) returns (DeleteVolumeResponse); + // 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. @@ -404,6 +416,21 @@ message DeleteVolumeRequest { message DeleteVolumeResponse { } +message MarkVolumeDeletingRequest { + string volume_id = 1; + // token identifies one delete operation (chosen by the caller). + string token = 2; +} + +message MarkVolumeDeletingResponse { + // 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 { 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 7c6aa02ac4..a81d157e2f 100644 --- a/seaweed-block/core/storage/chunk_public.go +++ b/seaweed-block/core/storage/chunk_public.go @@ -27,6 +27,9 @@ const ( ChunkHeadActive = chunkHeadActive ChunkHeadDetached = chunkHeadDetached ChunkHeadAborted = chunkHeadAborted + ChunkHeadDeleting = chunkHeadDeleting + ChunkHeadPurging = chunkHeadPurging + ChunkHeadDeleted = chunkHeadDeleted ) // NewChunkIntentID returns a fresh intent id "-" for a remote @@ -44,6 +47,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 9c74e1317a..07007cfb39 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -206,6 +206,18 @@ type chunkDetachedBy struct { // 2026-11-15 17:30Z). Such a volume never attaches. const chunkHeadAborted = "aborted" +// 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. +// chunkHeadPurging is the delete's irreversible boundary (chunks still +// kept until the final tombstone). +const ( + chunkHeadDeleting = "deleting" + chunkHeadPurging = "purging" + chunkHeadDeleted = "deleted" +) + func chunkHeadIsDetached(h chunkHead) bool { return h.State == chunkHeadDetached } // chunkRemote is the remote store. Keys are non-empty valid UTF-8 strings @@ -475,6 +487,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") 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)