From c50b3d190ffcdf5a5cac4d91c81339733d889fd0 Mon Sep 17 00:00:00 2001 From: pingqiu-cpu Date: Thu, 3 Dec 2026 16:36:25 -0800 Subject: [PATCH] fix(master): retire spec-removed volume metadata after deletion (#1019) Merge note (batch b9; pull_request_target spec-trace workflow has a startup_failure, so its checks run locally): - One Test run (47234365908) succeeded (go test (linux), process-level tests (real binaries)) on the integration tree b9d12608 = main d2f0fa54 + #1019 #1020 #1024 in this order; these squash merges reproduce that tree, verified after the last one. - spec-trace-check.sh and public-text-check.sh, run with main's scripts against this head and body: both exit 0. - Code review ACCEPT on 2b7bae7a: at a cluster-spec start, a placement whose volume left the spec and seed and holds no work is pruned; a deleted volume's authority record and placement are retired only after a committed deletion reservation, no live workspace lease and a fresh HEAD read showing the volume deleted or absent, and its tombstone is kept forever; cluster checks never probe deleting or deleted volumes. - Model check PASS against the delete-retirement model (two volumes, master restart, late writer; all configurations pass). Linux: the fresh-host half-retirement witness and the focused tests pass under the race detector. - Code read ACCEPT confirmed on d231931b after the repo-wide Linux run (go test -short ./... exit 0, 52 packages ok). --- seaweed-block/.github/model-code-trace.tsv | 6 + .../blockmaster/cluster_spec_orphan_test.go | 175 +++++++ .../blockmaster/cluster_volume_cli_test.go | 3 +- seaweed-block/cmd/blockmaster/main.go | 39 +- seaweed-block/cmd/sw-block/shell_check.go | 17 + .../cmd/sw-block/shell_deleting_test.go | 116 +++++ seaweed-block/core/authority/authority.go | 8 + .../core/authority/authority_store.go | 4 +- .../core/authority/authority_store_file.go | 23 + .../authority/workspace_delete_guard_test.go | 5 + .../core/authority/workspace_retirement.go | 40 ++ .../authority/workspace_retirement_test.go | 144 ++++++ seaweed-block/core/host/master/host.go | 10 + .../core/host/master/journal_isolation.go | 3 + .../core/host/master/observation_snapshot.go | 3 + .../core/host/master/product_loop.go | 6 + .../core/host/master/spec_retirement.go | 171 ++++++ .../core/host/master/spec_retirement_test.go | 488 ++++++++++++++++++ .../lifecycle/layout_identity_guard_test.go | 5 + seaweed-block/core/ops/observation.go | 3 + seaweed-block/docs/design/invariants.md | 4 + seaweed-block/docs/time-bounds.tsv | 1 + 22 files changed, 1266 insertions(+), 8 deletions(-) create mode 100644 seaweed-block/cmd/blockmaster/cluster_spec_orphan_test.go create mode 100644 seaweed-block/cmd/sw-block/shell_deleting_test.go create mode 100644 seaweed-block/core/authority/workspace_retirement.go create mode 100644 seaweed-block/core/authority/workspace_retirement_test.go create mode 100644 seaweed-block/core/host/master/spec_retirement.go create mode 100644 seaweed-block/core/host/master/spec_retirement_test.go diff --git a/seaweed-block/.github/model-code-trace.tsv b/seaweed-block/.github/model-code-trace.tsv index ef8739da24..f0f562ab52 100644 --- a/seaweed-block/.github/model-code-trace.tsv +++ b/seaweed-block/.github/model-code-trace.tsv @@ -13,6 +13,8 @@ cmd/sw-block/volume_backup.go RestoreCommand.Run cmd/sw-block/volume_backup.go RestoreCommand.Start cmd/sw-block/volume_verbs.go CutTime.CliGiveUp cmd/sw-block/volume_verbs.go CutTime.Poll +core/authority/authority.go DeleteRetire.Retire +core/authority/authority_store_file.go DeleteRetire.Retire core/authority/workspace.go HolderInterface.ForcedMove core/authority/workspace.go HolderInterface.PlannedMove core/authority/workspace.go MoveAdmission.Ack @@ -30,6 +32,7 @@ core/authority/workspace_delete_reservation.go MoveAdmission.DelCheck core/authority/workspace_delete_reservation.go MoveAdmission.Reserve core/authority/workspace_lease_view.go HolderInterface.Grant core/authority/workspace_lease_view.go HolderInterface.Regrant +core/authority/workspace_retirement.go DeleteRetire.Retire core/engine/apply.go ReplicationPeer.Reconcile core/frontend/chunkstore/catalog_b.go CleanBatch.Publish core/frontend/chunkstore/catalog_b.go CleanBatch.Request @@ -190,12 +193,15 @@ core/host/master/format_gate.go FormatGate.Grant core/host/master/format_gate.go FormatGate.Place core/host/master/format_gate.go FormatGate.Report core/host/master/format_gate.go FormatGate.Retire +core/host/master/journal_isolation.go DeleteRetire.HostRetire core/host/master/layout_ready.go VolumeCreate.Place +core/host/master/observation_snapshot.go DeleteRetire.HostRetire core/host/master/probe_round.go FencingRound.Deliver core/host/master/probe_round.go FencingRound.Open core/host/master/product_loop.go FencingRound.Decide core/host/master/product_loop.go Promotion.Decide core/host/master/services.go FormatGate.Report +core/host/master/spec_retirement.go DeleteRetire.ReadOK core/host/master/store_attestation.go ReplicationPeer.Attest core/host/master/workspace_binding.go FormatGate.Grant core/host/master/workspace_service.go FormatGate.Place diff --git a/seaweed-block/cmd/blockmaster/cluster_spec_orphan_test.go b/seaweed-block/cmd/blockmaster/cluster_spec_orphan_test.go new file mode 100644 index 0000000000..14d1e954f8 --- /dev/null +++ b/seaweed-block/cmd/blockmaster/cluster_spec_orphan_test.go @@ -0,0 +1,175 @@ +package main + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "runtime" + "strings" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/host/master" + "github.com/seaweedfs/seaweed-block/core/lifecycle" +) + +// Manual run 2: a placement-only restore target was never created, then +// removed from the spec. A new start must not retain that unused intent. +func TestClusterSpecImportRemovesUnusedPlacementMissingFromSpec(t *testing.T) { + h, err := master.New(master.Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir()}) + if err != nil { + t.Fatal(err) + } + defer func() { + h.Start() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + _ = h.Close(ctx) + }() + intent := func(id string) lifecycle.PlacementIntent { + return lifecycle.PlacementIntent{VolumeID: id, DesiredRF: 1, Slots: []lifecycle.PlacementSlotIntent{{ServerID: "s1", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}} + } + if err := importLifecyclePlacementIntents(h, []lifecycle.PlacementIntent{intent("unused"), intent("kept")}); err != nil { + t.Fatal(err) + } + // The next import is the complete desired spec; neither volume has been + // created, assigned, bound, or queued because this host has not started. + if err := importLifecyclePlacementIntents(h, []lifecycle.PlacementIntent{intent("kept")}); err != nil { + t.Fatal(err) + } + if err := h.PruneUnusedSpecPlacements(context.Background(), []string{"kept"}); err != nil { + t.Fatal(err) + } + if _, ok := h.Lifecycle().Placements.GetPlacement("unused"); ok { + t.Fatal("spec-removed unused restore target still has its placement") + } + if _, ok := h.Lifecycle().Placements.GetPlacement("kept"); !ok { + t.Fatal("current spec placement was removed") + } +} + +func TestClusterSpecCleanupKeepsRecordsBindingsAuthorityAndSeed(t *testing.T) { + ctx := context.Background() + dir := t.TempDir() + disk, err := authority.NewFileAuthorityStore(dir) + if err != nil { + t.Fatal(err) + } + if err := disk.Put(authority.DurableRecord{VolumeID: "line", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1, WriteSeq: 1, DataAddr: "127.0.0.1:19001", CtrlAddr: "127.0.0.1:19002"}); err != nil { + t.Fatal(err) + } + _ = disk.Close() + h, err := master.New(master.Config{Listen: "127.0.0.1:0", AuthorityStoreDir: dir, LifecycleStoreDir: t.TempDir()}) + if err != nil { + t.Fatal(err) + } + defer func() { + h.Start() + closeCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + _ = h.Close(closeCtx) + }() + var intents []lifecycle.PlacementIntent + for _, id := range []string{"line", "record", "bound", "reserved", "spec", "seed", "unused"} { + intents = append(intents, lifecycle.PlacementIntent{VolumeID: id, DesiredRF: 1, Slots: []lifecycle.PlacementSlotIntent{{ServerID: "s1", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}) + } + if err := importLifecyclePlacementIntents(h, intents); err != nil { + t.Fatal(err) + } + if _, err := h.Lifecycle().Volumes.CreateVolume(lifecycle.VolumeSpec{VolumeID: "record", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatal(err) + } + if err := h.Lifecycle().WorkspaceBindings.Register(lifecycle.WorkspaceBinding{VolumeID: "bound", ServerID: "s1", DataAddr: "127.0.0.1:19011", CtrlAddr: "127.0.0.1:19012"}); err != nil { + t.Fatal(err) + } + if _, err := h.Lifecycle().Deletions.Admit("reserved", "delete"); err != nil { + t.Fatal(err) + } + if _, err := h.Lifecycle().Deletions.Commit("reserved", "delete"); err != nil { + t.Fatal(err) + } + if err := h.PruneUnusedSpecPlacements(ctx, []string{"spec", "seed"}); err != nil { + t.Fatal(err) + } + for _, id := range []string{"line", "record", "bound", "reserved", "spec", "seed"} { + if _, ok := h.Lifecycle().Placements.GetPlacement(id); !ok { + t.Errorf("removed %s which still holds work or remains desired", id) + } + } + if _, ok := h.Lifecycle().Placements.GetPlacement("unused"); ok { + t.Fatal("unused placement remains") + } + if !h.Lifecycle().Deletions.CommittedSnapshot("reserved") { + t.Fatal("committed tombstone lost") + } +} + +// The subprocess executes run(): it loads both actual files, imports, prunes, +// and reaches ready before we reopen the persisted placement store. +func TestClusterSpecStartupPrunesParsedSpecAndSeedUnion(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Linux daemon signals and lifecycle directory fsync") + } + for _, mode := range []string{"spec-and-seed", "empty-spec", "no-spec"} { + t.Run(mode, func(t *testing.T) { + root := t.TempDir() + dir := filepath.Join(root, "lifecycle", "placements") + store, err := lifecycle.OpenPlacementIntentStore(dir) + if err != nil { + t.Fatal(err) + } + intent := func(id string) lifecycle.PlacementIntent { + return lifecycle.PlacementIntent{VolumeID: id, DesiredRF: 1, Slots: []lifecycle.PlacementSlotIntent{{ServerID: "s1", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}} + } + if _, err := store.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "unused", DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: "unused", ServerID: "s1", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { + t.Fatal(err) + } + spec := filepath.Join(root, "spec.yaml") + text := "nodes:\n - server_id: s1\n data_addr: 127.0.0.1:9201\n ctrl_addr: 127.0.0.1:9202\nvolumes: []\n" + if mode == "spec-and-seed" { + text = strings.Replace(text, "volumes: []", "volumes:\n - id: spec\n replication_factor: 1\n placements:\n - server_id: s1\n replica_id: r1", 1) + } + if err := os.WriteFile(spec, []byte(text), 0600); err != nil { + t.Fatal(err) + } + extra := []string{"--lifecycle-product-loop-interval", "0"} + if mode == "spec-and-seed" { + seed := filepath.Join(root, "seed.json") + raw, err := json.Marshal([]lifecycle.PlacementIntent{intent("seed")}) + if err != nil { + t.Fatal(err) + } + if err := os.WriteFile(seed, raw, 0600); err != nil { + t.Fatal(err) + } + extra = append(extra, "--lifecycle-placement-seed", seed) + } + if mode == "no-spec" { + topo := filepath.Join(root, "topology.yaml") + if err := os.WriteFile(topo, []byte("volumes:\n - volume_id: other\n slots:\n - replica_id: r1\n server_id: s1\n"), 0600); err != nil { + t.Fatal(err) + } + extra = append(extra, "--cluster-spec", "", "--topology", topo) + } + daemon := startClusterImportCLI(t, root, spec, extra...) + daemon.stop() + reloaded, err := lifecycle.OpenPlacementIntentStore(dir) + if err != nil { + t.Fatal(err) + } + _, kept := reloaded.GetPlacement("unused") + if kept != (mode == "no-spec") { + t.Fatalf("unused placement kept=%t mode=%s", kept, mode) + } + if mode == "spec-and-seed" { + for _, id := range []string{"spec", "seed"} { + if _, ok := reloaded.GetPlacement(id); !ok { + t.Fatalf("parsed %s was pruned", id) + } + } + } + }) + } +} diff --git a/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go b/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go index 3784e9c8c7..a0a48cc23d 100644 --- a/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go +++ b/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go @@ -45,13 +45,14 @@ type clusterImportProcess struct { stop func() } -func startClusterImportCLI(t *testing.T, root, spec string) *clusterImportProcess { +func startClusterImportCLI(t *testing.T, root, spec string, extra ...string) *clusterImportProcess { t.Helper() if runtime.GOOS == "windows" { t.Skip("native daemon signal control") } tmp := t.TempDir() args := []string{"--authority-store", filepath.Join(root, "authority"), "--lifecycle-store", filepath.Join(root, "lifecycle"), "--cluster-spec", spec, "--listen", "127.0.0.1:0", "--expected-slots-per-volume", "1", "--lifecycle-product-loop-interval", "5ms", "--t0-print-ready"} + args = append(args, extra...) argsPath := filepath.Join(tmp, "args.json") data, _ := json.Marshal(args) if e := os.WriteFile(argsPath, data, 0600); e != nil { diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index 1869007ac9..b73a2e6987 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -363,14 +363,38 @@ func run(f flags) int { return 1 } } + var seedPlacements []lifecycle.PlacementIntent if f.lifecyclePlacementSeed != "" { - if err := importLifecyclePlacementSeed(h, f.lifecyclePlacementSeed); err != nil { + var err error + seedPlacements, err = importLifecyclePlacementSeed(h, f.lifecyclePlacementSeed) + if err != nil { fmt.Fprintln(os.Stderr, "blockmaster:", err) _ = h.Close(context.Background()) return 1 } } + if f.clusterSpec != "" { + var desired []string + for _, p := range clusterImport.Placements { + desired = append(desired, p.VolumeID) + } + for _, p := range seedPlacements { + desired = append(desired, p.VolumeID) + } + if err := h.PruneUnusedSpecPlacements(context.Background(), desired); err != nil { + fmt.Fprintln(os.Stderr, "blockmaster:", err) + _ = h.Close(context.Background()) + return 1 + } + } + + if err := h.ReconcileDeletedSpecVolumes(context.Background()); err != nil { + fmt.Fprintln(os.Stderr, "blockmaster:", err) + _ = h.Close(context.Background()) + return 1 + } + if f.printReadyLine { _ = json.NewEncoder(os.Stdout).Encode(readyLine{ Component: "blockmaster", @@ -462,20 +486,23 @@ func importLifecycleNodeInventory(h *master.Host, nodes []lifecycle.NodeRegistra return nil } -func importLifecyclePlacementSeed(h *master.Host, path string) error { +func importLifecyclePlacementSeed(h *master.Host, path string) ([]lifecycle.PlacementIntent, error) { stores := h.Lifecycle() if stores == nil { - return fmt.Errorf("--lifecycle-placement-seed requires --lifecycle-store") + return nil, fmt.Errorf("--lifecycle-placement-seed requires --lifecycle-store") } raw, err := os.ReadFile(path) if err != nil { - return fmt.Errorf("read lifecycle placement seed %q: %w", path, err) + return nil, fmt.Errorf("read lifecycle placement seed %q: %w", path, err) } var intents []lifecycle.PlacementIntent if err := json.Unmarshal(raw, &intents); err != nil { - return fmt.Errorf("parse lifecycle placement seed %q: %w", path, err) + return nil, fmt.Errorf("parse lifecycle placement seed %q: %w", path, err) } - return importLifecyclePlacementIntents(h, intents) + if err := importLifecyclePlacementIntents(h, intents); err != nil { + return nil, err + } + return intents, nil } func importLifecyclePlacementIntents(h *master.Host, intents []lifecycle.PlacementIntent) error { diff --git a/seaweed-block/cmd/sw-block/shell_check.go b/seaweed-block/cmd/sw-block/shell_check.go index f7372a790f..6ec2e3f33f 100644 --- a/seaweed-block/cmd/sw-block/shell_check.go +++ b/seaweed-block/cmd/sw-block/shell_check.go @@ -157,6 +157,10 @@ func (s inspectionShell) checkObservation(ctx context.Context, o *inspectionObse continue } iv := inspectedVolume{evidence: v} + if v.Status == ops.ObservationStatusDeleting || v.Status == ops.ObservationStatusDeleted { + o.volumes = append(o.volumes, iv) + continue // no lease/status RPC of a deleted holder can delay another volume's checks + } iv.lease, iv.leaseErr = client.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: v.VolumeID}) iv.local = primaryInspectionHost(v) != "" && primaryInspectionHost(v) == s.serverID if iv.local && v.Status != ops.ObservationStatusStopped { @@ -331,12 +335,15 @@ func (o *inspectionObservation) each(local bool, run func(inspectedVolume) check } state := "ok" allNotApplicable, allStopped := true, true + allDeleting, allDeleted := true, true cure, plain := "", false // the failing volumes' cause-specific cure; plain: one failed for the check's own reason parts := []string{} for _, v := range o.volumes { var f checkFinding if v.evidence.Status == ops.ObservationStatusStopped { f = stoppedFinding + } else if v.evidence.Status == ops.ObservationStatusDeleting || v.evidence.Status == ops.ObservationStatusDeleted { + f = checkFinding{Status: v.evidence.Status, Finding: "volume deletion admitted; no serving checks apply"} } else if local && !v.local { host := primaryInspectionHost(v.evidence) if host == "" { @@ -354,6 +361,12 @@ func (o *inspectionObservation) each(local bool, run func(inspectedVolume) check if f.Status != "stopped" { allStopped = false } + if f.Status != ops.ObservationStatusDeleting { + allDeleting = false + } + if f.Status != ops.ObservationStatusDeleted { + allDeleted = false + } if f.Status == "FAIL" { state = "FAIL" if f.Cure != "" && cure == "" { @@ -370,6 +383,10 @@ func (o *inspectionObservation) each(local bool, run func(inspectedVolume) check state = "not applicable" } else if state == "ok" && allStopped { state = "stopped" + } else if state == "ok" && allDeleting { + state = ops.ObservationStatusDeleting + } else if state == "ok" && allDeleted { + state = ops.ObservationStatusDeleted } if plain { cure = "" // a volume failed for the check's own reason: its own cure applies diff --git a/seaweed-block/cmd/sw-block/shell_deleting_test.go b/seaweed-block/cmd/sw-block/shell_deleting_test.go new file mode 100644 index 0000000000..27feaddb79 --- /dev/null +++ b/seaweed-block/cmd/sw-block/shell_deleting_test.go @@ -0,0 +1,116 @@ +package main + +import ( + "bytes" + "context" + "encoding/json" + "net" + "net/http" + "net/http/httptest" + "strings" + "sync" + + "github.com/seaweedfs/seaweed-block/core/ops" + "github.com/seaweedfs/seaweed-block/core/rpc/control" + "google.golang.org/grpc" + "google.golang.org/protobuf/proto" + "testing" +) + +// Manual run 3: an intentionally deleting/deleted old volume must not +// manufacture a failure when checking the remaining healthy volume. +func TestClusterCheckDoesNotProbeDeletingOrDeletedVolumes(t *testing.T) { + for _, state := range []string{"deleting", "deleted"} { + for _, local := range []bool{false, true} { + o := &inspectionObservation{volumes: []inspectedVolume{ + {evidence: ops.VolumeEvidence{VolumeID: "kept", Status: ops.ObservationStatusOK}, local: true}, + {evidence: ops.VolumeEvidence{VolumeID: "gone", Status: state}, local: true}, + }} + calls := 0 + f := o.each(local, func(v inspectedVolume) checkFinding { + calls++ + if v.evidence.VolumeID == "gone" { + return checkFinding{Status: "FAIL", Finding: "deleted holder has no lease or status endpoint"} + } + return checkFinding{Status: "ok", Finding: "healthy"} + }) + if f.Status == "FAIL" || calls != 1 || !strings.Contains(f.Finding, "gone: "+state) { + t.Fatalf("state=%s local=%v calls=%d result=%+v", state, local, calls, f) + } + } + } +} + +// Exercise runShell -> master collection -> lease/status collection, not only each. +type deletingCollectionServer struct { + inspectionControlServer + mu sync.Mutex + leases map[string]int +} + +func (s *deletingCollectionServer) GetClusterStatus(ctx context.Context, q *control.GetClusterStatusRequest) (*control.ClusterStatusResponse, error) { + r, err := s.inspectionControlServer.GetClusterStatus(ctx, q) + live := r.Volumes[0] + r.Volumes = nil + for _, state := range []string{ops.ObservationStatusDeleting, ops.ObservationStatusDeleted} { + v := proto.Clone(live).(*control.VolumeEvidence) + v.VolumeId, v.Status = state, state + r.Volumes = append(r.Volumes, v) + } + r.Volumes = append(r.Volumes, live) // retired entries must not starve this last live entry + return r, err +} +func (s *deletingCollectionServer) QueryWorkspace(ctx context.Context, q *control.WorkspaceVolume) (*control.WorkspaceStatus, error) { + s.mu.Lock() + s.leases[q.VolumeId]++ + s.mu.Unlock() + return s.inspectionControlServer.QueryWorkspace(ctx, q) +} +func TestClusterCheckCollectionSkipsDeletedRPCsAndKeepsLiveFailures(t *testing.T) { + ln, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + defer ln.Close() + backend := &deletingCollectionServer{leases: map[string]int{}} + srv := grpc.NewServer() + control.RegisterClusterEvidenceServiceServer(srv, backend) + control.RegisterWorkspaceServiceServer(srv, backend) + go func() { _ = srv.Serve(ln) }() + defer srv.Stop() + var mu sync.Mutex + requests := map[string]int{} + holder := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + id := r.URL.Query().Get("volume") + mu.Lock() + requests[id]++ + mu.Unlock() + if r.URL.Path == "/status" { + _ = json.NewEncoder(w).Encode(map[string]any{"VolumeID": id, "ReplicaID": "r2", "Epoch": 2, "FrontendPrimaryReady": false, "Version": "test-rev"}) + return + } + http.Error(w, "live durable read failed", http.StatusInternalServerError) + })) + defer holder.Close() + var out, errs bytes.Buffer + exit := runShell([]string{"-master", ln.Addr().String(), "-server-id", "host-b", "-status-addr", holder.URL, "-c", "cluster.check -o json"}, strings.NewReader(""), &out, &errs) + rows := requireInspectionOutput(t, out.Bytes()) + if exit != 1 { + t.Fatalf("live failure suppressed: exit=%d output=%s stderr=%s", exit, &out, &errs) + } + if row := rows["volume.frontend"]; row.Status != "FAIL" || !strings.Contains(row.Finding, "v1:") { + t.Fatalf("live frontend failure lost: %+v", row) + } + backend.mu.Lock() + defer backend.mu.Unlock() + mu.Lock() + defer mu.Unlock() + for _, id := range []string{"deleting", "deleted"} { + if backend.leases[id] != 0 || requests[id] != 0 { + t.Fatalf("%s lease=%d HTTP=%d", id, backend.leases[id], requests[id]) + } + } + if backend.leases["v1"] != 1 || requests["v1"] != 2 { + t.Fatalf("live collection missing: lease=%v HTTP=%v", backend.leases, requests) + } +} diff --git a/seaweed-block/core/authority/authority.go b/seaweed-block/core/authority/authority.go index ff98906fde..389d1a1425 100644 --- a/seaweed-block/core/authority/authority.go +++ b/seaweed-block/core/authority/authority.go @@ -786,6 +786,14 @@ func (p *Publisher) applyWithWorkspaceMove(ask AssignmentAsk, grant *workspaceGr // setStateLocked records the state of key k and indexes it under its // volume. It is the only writer of p.state. p.mu held. func (p *Publisher) setStateLocked(k subKey, st assignmentState) { + if !st.present { + delete(p.state, k) + delete(p.replicas[k.volumeID], k.replicaID) + if len(p.replicas[k.volumeID]) == 0 { + delete(p.replicas, k.volumeID) + } + return + } p.state[k] = st r := p.replicas[k.volumeID] if r == nil { diff --git a/seaweed-block/core/authority/authority_store.go b/seaweed-block/core/authority/authority_store.go index 86856bce45..0c6decf3da 100644 --- a/seaweed-block/core/authority/authority_store.go +++ b/seaweed-block/core/authority/authority_store.go @@ -37,7 +37,9 @@ import ( // // The authority line never expires by wall-clock judgment. Optional Workspace // lease time gates serving and forced moves; it never erases the last authored -// line. Only Publisher can mint its replacement. +// line. Only Publisher can mint its replacement. A permanent deletion +// reservation permits Publisher to retire the record after a fresh, post-lease +// deleted/absent HEAD proof; that reservation continues to forbid all reuse. type DurableRecord struct { // EnvelopeVersion is the envelope version the store writes the record // in (0: storeEnvelopeVersion). Not part of the body or its checksum: a diff --git a/seaweed-block/core/authority/authority_store_file.go b/seaweed-block/core/authority/authority_store_file.go index 8c5fd96a42..a1f17cf1e6 100644 --- a/seaweed-block/core/authority/authority_store_file.go +++ b/seaweed-block/core/authority/authority_store_file.go @@ -386,3 +386,26 @@ func (s *FileAuthorityStore) Close() error { s.closed = true return nil } + +// RetireDeletedVolume is called only by Publisher under a permanent delete +// reservation. Removal is idempotent; an uncertain sync keeps the in-memory +// line until retry, while the reservation prevents grants across a restart. +func (s *FileAuthorityStore) RetireDeletedVolume(volume string) error { + s.mu.Lock() + defer s.mu.Unlock() + if s.closed { + return fmt.Errorf("authority_store: closed") + } + if volume == "" { + return fmt.Errorf("authority_store: empty retirement volume") + } + if err := os.Remove(s.volumePath(volume)); err != nil && !os.IsNotExist(err) { + return fmt.Errorf("authority_store: retire: %w", err) + } + dir, err := os.Open(s.dir) + if err != nil { + return err + } + defer dir.Close() + return dir.Sync() +} diff --git a/seaweed-block/core/authority/workspace_delete_guard_test.go b/seaweed-block/core/authority/workspace_delete_guard_test.go index 321d3f1bdf..25b8046b8b 100644 --- a/seaweed-block/core/authority/workspace_delete_guard_test.go +++ b/seaweed-block/core/authority/workspace_delete_guard_test.go @@ -17,6 +17,11 @@ func TestDeletionReservationGuardSites(t *testing.T) { "applyWithWorkspaceMove": true, "MoveWorkspace": true, "RenewWorkspaceLease": true, "firstWorkspaceGrant": true, "regrantWorkspaceLease": true, + // Retirement reads the permanent reservation before removing authority; + // it never clears the flag or increases validity. The causal controls + // are TestRetirementKeepsReservationAndWaitsForLiveLease and the + // post-unlink/restart witnesses in workspace_retirement_test.go. + "RetireDeletedWorkspace": true, // Format level 0's horizon extender rechecks the reservation. "extendWorkspaceLease": true, } diff --git a/seaweed-block/core/authority/workspace_retirement.go b/seaweed-block/core/authority/workspace_retirement.go new file mode 100644 index 0000000000..c7cd4115e6 --- /dev/null +++ b/seaweed-block/core/authority/workspace_retirement.go @@ -0,0 +1,40 @@ +package authority + +import ( + "context" + "fmt" +) + +// RetireDeletedWorkspace removes only authority metadata after the master's +// fresh post-lease HEAD proof. The permanent reservation is never removed. +func (p *Publisher) RetireDeletedWorkspace(ctx context.Context, volume string) error { + p.mu.Lock() + defer p.mu.Unlock() + if err := ctx.Err(); err != nil { + return err + } + if !p.deleteReserved[volume] { + return fmt.Errorf("authority retire: committed deletion reservation required") + } + if err := p.liveLeaseLocked(volume); err != nil { + return err + } + if p.store != nil { + retired, ok := p.store.(interface{ RetireDeletedVolume(string) error }) + if !ok { + return fmt.Errorf("authority retire: store cannot retire records") + } + if err := retired.RetireDeletedVolume(volume); err != nil { + return err + } + } + for r := range p.replicas[volume] { + p.setStateLocked(subKey{volumeID: volume, replicaID: r}, assignmentState{}) + } + delete(p.workspace, volume) + delete(p.writeSeqByVolume, volume) + delete(p.workspaceUncertain, volume) + delete(p.lostRanges, volume) + p.refreshLeaseViewLocked(volume) + return nil +} diff --git a/seaweed-block/core/authority/workspace_retirement_test.go b/seaweed-block/core/authority/workspace_retirement_test.go new file mode 100644 index 0000000000..9d3f9504ff --- /dev/null +++ b/seaweed-block/core/authority/workspace_retirement_test.go @@ -0,0 +1,144 @@ +package authority + +import ( + "context" + "errors" + "os" + "runtime" + "testing" + "time" +) + +type retireStore struct { + deleteGrantStore + retired int + fail error +} + +func (s *retireStore) RetireDeletedVolume(string) error { s.retired++; return s.fail } + +func TestRetirementKeepsReservationAndWaitsForLiveLease(t *testing.T) { + ctx := context.Background() + bareStore := &retireStore{} + bare := newLeasePublisher(t, bareStore, 30*time.Second, newTestClock()) + if err := bare.RetireDeletedWorkspace(ctx, "unreserved"); err == nil || bareStore.retired != 0 { + t.Fatalf("unreserved absence retired: %v writes=%d", err, bareStore.retired) + } + clock := newTestClock() + store := &retireStore{} + p := newLeasePublisher(t, store, 30*time.Second, clock) + bindAndGrant(t, p, "v", "r") + if err := p.RetireDeletedWorkspace(ctx, "v"); err == nil { + t.Fatal("retired without permanent reservation") + } + if err := p.ReserveWorkspaceDeletion(ctx, "v", nil); err != nil { + t.Fatal(err) + } + if err := p.RetireDeletedWorkspace(ctx, "v"); err == nil || store.retired != 0 { + t.Fatalf("retired while lease live: %v writes=%d", err, store.retired) + } + clock.at(1000) + store.fail = errors.New("remove failed") + if err := p.RetireDeletedWorkspace(ctx, "v"); !errors.Is(err, store.fail) { + t.Fatal(err) + } + if _, ok := p.VolumeAuthorityLine("v"); !ok { + t.Fatal("failed retirement lost published line") + } + store.fail = nil + if err := p.RetireDeletedWorkspace(ctx, "v"); err != nil { + t.Fatal(err) + } + if _, ok := p.VolumeAuthorityLine("v"); ok { + t.Fatal("retired line remains") + } + if _, ok := p.PublishedAuthorityLines()["v"]; ok { + t.Fatal("retired lease view remains bound") + } + assertLeaseViewMatches(t, p, "retirement") + if !p.deleteReserved["v"] { + t.Fatal("retirement dropped permanent reservation") + } + if err := p.apply(AssignmentAsk{VolumeID: "v", ReplicaID: "r", DataAddr: "d", CtrlAddr: "c", Intent: IntentBind}); err == nil { + t.Fatal("retired id was rebound") + } + if err := p.NoLiveWorkspaceLease(ctx, "v"); err != nil { + t.Fatalf("resumed delete: %v", err) + } +} + +func TestFileAuthorityRetirementSurvivesReloadAndKeepsOtherRecords(t *testing.T) { + s, _ := newTempStore(t) + kept := sampleRecord("kept", "r", 2, 1, 1) + if err := s.Put(sampleRecord("gone", "r", 1, 1, 1)); err != nil { + t.Fatal(err) + } + if err := s.Put(kept); err != nil { + t.Fatal(err) + } + for i := 0; i < 2; i++ { + if err := s.RetireDeletedVolume("gone"); err != nil { + t.Fatal(err) + } + } + got, err := s.Load() + if err != nil || len(got) != 1 || got[0].VolumeID != "kept" || got[0].Epoch != kept.Epoch || got[0].WriteSeq != kept.WriteSeq { + t.Fatalf("reload after retire: %+v %v", got, err) + } +} + +// The real unlink succeeds, but its durability acknowledgement is lost. +// Publisher must keep the published line until the idempotent retry settles. +type unlinkThenErrorStore struct { + *FileAuthorityStore + uncertain bool +} + +func (s *unlinkThenErrorStore) RetireDeletedVolume(id string) error { + if s.uncertain { + if err := os.Remove(s.volumePath(id)); err != nil { + return err + } + return errors.New("injected directory-sync acknowledgement lost after unlink") + } + return s.FileAuthorityStore.RetireDeletedVolume(id) +} +func TestRetirementUncertainAfterRealUnlinkKeepsLineUntilRetry(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Linux directory fsync durability witness") + } + disk, _ := newTempStore(t) + store := &unlinkThenErrorStore{FileAuthorityStore: disk, uncertain: true} + clock := newTestClock() + p := newLeasePublisher(t, store, 30*time.Second, clock) + if err := p.apply(AssignmentAsk{VolumeID: "gone", ReplicaID: "r1", DataAddr: "127.0.0.1:9011", CtrlAddr: "127.0.0.1:9012", Intent: IntentBind}); err != nil { + t.Fatal(err) + } + if err := p.ReserveWorkspaceDeletion(context.Background(), "gone", nil); err != nil { + t.Fatal(err) + } + if err := p.RetireDeletedWorkspace(context.Background(), "gone"); err == nil { + t.Fatal("lost acknowledgement hidden") + } + if _, err := os.Stat(disk.volumePath("gone")); !os.IsNotExist(err) { + t.Fatalf("real unlink did not occur: %v", err) + } + if _, ok := p.VolumeAuthorityLine("gone"); !ok { + t.Fatal("uncertain unlink discarded in-memory line") + } + assertLeaseViewMatches(t, p, "uncertain unlink") + if !p.deleteReserved["gone"] { + t.Fatal("uncertainty lost tombstone") + } + store.uncertain = false + if err := p.RetireDeletedWorkspace(context.Background(), "gone"); err != nil { + t.Fatal(err) + } + if _, ok := p.VolumeAuthorityLine("gone"); ok { + t.Fatal("retry did not finish retirement") + } + assertLeaseViewMatches(t, p, "settled unlink") + if err := p.apply(AssignmentAsk{VolumeID: "gone", ReplicaID: "r1", DataAddr: "127.0.0.1:9011", CtrlAddr: "127.0.0.1:9012", Intent: IntentBind}); err == nil { + t.Fatal("retry lost permanent exclusion") + } +} diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 030e40237a..5e46b58a54 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -177,6 +177,16 @@ type Host struct { // RPC registration/place/move/ACK/delete and product ticks serialize here. // Order: workspaceMu -> publisher or lifecycle store locks (not reversed). workspaceMu sync.Mutex + // specDesired is configured before Start; only spec-removed names retire. + specDesired map[string]bool + // noWork contains only post-lease, monotone deleting/deleted HEAD proofs. + noWork sync.Map + // retirementMu serializes the bounded background scan and startup sweep. + // Retry times are disposable pacing, never retirement evidence. Entries + // exist only for current reserved volume records; no retirement history. + retirementMu sync.Mutex + retirementNext map[string]time.Time + retirementAfter string // bindingRetry: volumes whose binding reconcile failed, retried with the // next call's own volume (workspaceMu held). bindingRetry map[string]bool diff --git a/seaweed-block/core/host/master/journal_isolation.go b/seaweed-block/core/host/master/journal_isolation.go index c453800a35..e3526c5fdf 100644 --- a/seaweed-block/core/host/master/journal_isolation.go +++ b/seaweed-block/core/host/master/journal_isolation.go @@ -125,6 +125,9 @@ func (h *Host) volumesServedBy(server string) []string { } out := make([]string, 0, len(seen)) for v := range seen { + if _, noWork := h.noWork.Load(v); noWork { + continue + } out = append(out, v) } sort.Strings(out) diff --git a/seaweed-block/core/host/master/observation_snapshot.go b/seaweed-block/core/host/master/observation_snapshot.go index 985feabc50..2d4ff215d7 100644 --- a/seaweed-block/core/host/master/observation_snapshot.go +++ b/seaweed-block/core/host/master/observation_snapshot.go @@ -152,6 +152,9 @@ func (h *Host) observationVolumes(snapshot LifecycleSnapshot) []ops.VolumeEviden } func (h *Host) observationVolume(volumeID string, rec lifecycle.VolumeRecord, placement lifecycle.PlacementIntent) ops.VolumeEvidence { + if state, ok := h.noWork.Load(volumeID); ok { + return ops.VolumeEvidence{VolumeID: volumeID, Status: state.(string), Reason: "deletion_reserved", Conditions: []ops.ObservationCondition{{Type: "Deleting", Status: "true", Severity: "info", Reason: "deletion_reserved", Message: "delete admitted; no live lease or serving work remains"}}} + } rf := rec.Spec.ReplicationFactor if rf == 0 { rf = placement.DesiredRF diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index 53fd62319a..5ddf6766ac 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -1,9 +1,11 @@ package master import ( + "context" "fmt" "reflect" "strings" + "time" "github.com/seaweedfs/seaweed-block/core/storage" @@ -98,6 +100,9 @@ func (h *Host) SetPromotionEvidenceProvider(p PromotionEvidenceProvider) { // directive queue. It never calls Publisher.apply; Publisher remains the only // authority minter through its normal Run loop. func (h *Host) RunLifecycleProductTick() (LifecycleProductTickResult, error) { + if err := h.reconcileDeletedSpecVolumes(context.Background(), true, time.Now()); err != nil { + return LifecycleProductTickResult{}, err + } h.workspaceMu.Lock() stores := h.Lifecycle() if stores == nil { @@ -1294,6 +1299,7 @@ func (h *Host) freshCurrentSlot(volumeID, replicaID string) (authority.ReplicaCa // quorum ack every acknowledged write is on a survivor, so a volume // that served and lost its primary before the master read a ready // answer still ends creation and fails over), +// // once every initial store is attested (stage 1 holds whatever is // answered). Nothing clears it. Besides, the current // primary's own answer, when one was read, holds the volume while its diff --git a/seaweed-block/core/host/master/spec_retirement.go b/seaweed-block/core/host/master/spec_retirement.go new file mode 100644 index 0000000000..5afb224cba --- /dev/null +++ b/seaweed-block/core/host/master/spec_retirement.go @@ -0,0 +1,171 @@ +package master + +import ( + "context" + "errors" + "fmt" + "sort" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" +) + +// PruneUnusedSpecPlacements removes only placement-only entries at startup. +// A volume record, authority line, binding, reservation or uncertain authority +// recovery keeps the entry. No controller or RPC may run during this step. +func (h *Host) PruneUnusedSpecPlacements(ctx context.Context, desired []string) error { + h.workspaceMu.Lock() + defer h.workspaceMu.Unlock() + if h.started.Load() { + return fmt.Errorf("spec placement cleanup requires a host that has not started") + } + stores := h.Lifecycle() + if stores == nil { + return fmt.Errorf("spec placement cleanup requires lifecycle stores") + } + if len(h.Publisher().LoadErrors()) != 0 { + return nil + } + keep := make(map[string]bool, len(desired)) + for _, id := range desired { + keep[id] = true + } + h.specDesired = keep + for _, p := range stores.Placements.ListPlacements() { + if err := ctx.Err(); err != nil { + return err + } + id := p.VolumeID + if keep[id] || stores.Deletions.Reserved(id) { + continue + } + if _, exists := stores.Volumes.GetVolume(id); exists { + continue + } + if _, exists := h.Publisher().VolumeAuthorityLine(id); exists { + continue + } + if _, bound, err := stores.WorkspaceBindings.Get(id); err != nil { + return err + } else if bound { + continue + } + if err := stores.Placements.DeletePlacement(id); err != nil { + return err + } + } + return nil +} + +// ReconcileDeletedSpecVolumes is the startup sweep. Retirement always checks +// the lease barrier before a fresh HEAD read. A kept in-spec record reuses its +// terminal NoWork proof under the permanent tombstone; restart loses it. +func (h *Host) ReconcileDeletedSpecVolumes(ctx context.Context) error { + return h.reconcileDeletedSpecVolumes(ctx, false, time.Now()) +} + +// The product tick processes at most one eligible volume, rotating fairly. +// Nonterminal/error reads and failed local removals retry no faster than the +// configured observation freshness window. This is pacing, not a validity TTL. +func (h *Host) reconcileDeletedSpecVolumes(ctx context.Context, limited bool, now time.Time) error { + stores := h.Lifecycle() + if stores == nil || h.cfg.LayoutReadHead == nil { + return nil + } + h.retirementMu.Lock() + defer h.retirementMu.Unlock() + records := stores.Volumes.ListVolumes() + if h.retirementNext == nil { + h.retirementNext = map[string]time.Time{} + } + current := make(map[string]bool, len(records)) + for _, rec := range records { + current[rec.Spec.VolumeID] = true + } + for id := range h.retirementNext { + if !current[id] { + delete(h.retirementNext, id) + } + } + h.noWork.Range(func(key, _ any) bool { + if !current[key.(string)] { + h.noWork.Delete(key) + } + return true + }) + // Volume records are sorted; the cursor is constant-size and wraps. + start := sort.Search(len(records), func(i int) bool { return records[i].Spec.VolumeID > h.retirementAfter }) + attempted := false + for i := 0; i < len(records); i++ { + if err := ctx.Err(); err != nil { + return err + } + rec := records[(start+i)%len(records)] + id := rec.Spec.VolumeID + if !stores.Deletions.CommittedSnapshot(id) { + continue + } + proof, terminal := h.noWork.Load(id) + terminal = terminal && proof == layout.StateDeleted + // Kept records cannot retire; their terminal NoWork proof never + // changes under a permanent tombstone, so there is no remote polling. + if terminal && (h.specDesired == nil || h.specDesired[id]) { + continue + } + if limited && (attempted || now.Before(h.retirementNext[id])) { + continue + } + if err := h.Publisher().NoLiveWorkspaceLease(ctx, id); err != nil { + continue + } + attempted = true + h.retirementAfter = id + h.retirementNext[id] = now.Add(h.cfg.Freshness.EffectiveFreshnessWindow()) + readCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + head, readErr := h.cfg.LayoutReadHead(readCtx, rec.Spec) + cancel() + if readErr != nil && !errors.Is(readErr, layout.ErrHeadAbsent) { + h.log.Printf("blockmaster: deletion HEAD read deferred volume=%q layout_id=%q error=%v", id, rec.Spec.LayoutID, readErr) + continue + } + state := head.State + if errors.Is(readErr, layout.ErrHeadAbsent) { + state = layout.StateDeleted + } + var err error + if state != layout.StateDeleting && state != layout.StateDeleted { + continue + } + h.noWork.Store(id, state) + h.workspaceMu.Lock() + retire := h.specDesired != nil && !h.specDesired[id] && state == layout.StateDeleted + if retire { + // Recheck permanent local guards under the lock used by all lifecycle + // writers. Remote HEAD is monotone after the lease barrier/reservation. + if !stores.Deletions.CommittedSnapshot(id) { + h.workspaceMu.Unlock() + continue + } + err = h.Publisher().RetireDeletedWorkspace(ctx, id) + if err == nil { + err = stores.Placements.DeletePlacement(id) + } + if err == nil { + err = stores.WorkspaceBindings.DeleteVolume(id) + } + if err == nil { + err = stores.Volumes.DeleteVolume(id) + } + if err == nil { + h.noWork.Delete(id) + delete(h.retirementNext, id) + h.log.Printf("blockmaster: retired spec-removed volume metadata volume=%q head_state=%s reservation=committed", id, state) + } + } + h.workspaceMu.Unlock() + if err != nil { + h.log.Printf("blockmaster: deletion metadata retirement deferred volume=%q error=%v", id, err) + } + } + return nil +} diff --git a/seaweed-block/core/host/master/spec_retirement_test.go b/seaweed-block/core/host/master/spec_retirement_test.go new file mode 100644 index 0000000000..bca7978277 --- /dev/null +++ b/seaweed-block/core/host/master/spec_retirement_test.go @@ -0,0 +1,488 @@ +package master + +import ( + "context" + "errors" + "os" + "path/filepath" + "reflect" + "runtime" + "slices" + "sync/atomic" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" + "github.com/seaweedfs/seaweed-block/core/lifecycle" + "github.com/seaweedfs/seaweed-block/core/ops" + "github.com/seaweedfs/seaweed-block/core/rpc/control" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/status" +) + +func TestSpecRetirementReadsHeadOnlyAfterLeaseAndKeepsTombstone(t *testing.T) { + h, lc, _, _, now := neverCreatedVolume(t, false) + ctx := context.Background() + if err := h.VolumeDeleteAuthority("v", "retire").Reserve(ctx); err != nil { + t.Fatal(err) + } + h.specDesired = map[string]bool{} + var reads atomic.Int32 + headState := "absent" + h.cfg.LayoutReadHead = func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) { + reads.Add(1) + if headState == "absent" { + return layout.Head{}, layout.ErrHeadAbsent + } + return layout.Head{State: headState}, nil + } + if err := h.ReconcileDeletedSpecVolumes(ctx); err != nil { + t.Fatal(err) + } + if reads.Load() != 0 { + t.Fatal("HEAD read before no-live-lease check passed") + } + if !slices.Contains(h.volumesServedBy("node-a"), "v") { + t.Fatal("live creating lease no longer holds work") + } + // A late creating holder filled the formerly absent HEAD before its + // lease ended. Only a new post-barrier read may decide retirement. + headState = layout.StateLive + now.Add(int64(2 * time.Minute)) + if err := h.ReconcileDeletedSpecVolumes(ctx); err != nil { + t.Fatal(err) + } + if reads.Load() != 1 { + t.Fatalf("fresh post-barrier reads=%d", reads.Load()) + } + if _, ok := h.Lifecycle().Volumes.GetVolume("v"); !ok { + t.Fatal("retired from stale absent HEAD") + } + headState = "absent" + if err := h.ReconcileDeletedSpecVolumes(ctx); err != nil { + t.Fatal(err) + } + if _, ok := h.Lifecycle().Volumes.GetVolume("v"); ok { + t.Fatal("retired volume record remains") + } + if _, ok := h.Lifecycle().Placements.GetPlacement("v"); ok { + t.Fatal("retired placement remains") + } + if _, ok := h.Publisher().VolumeAuthorityLine("v"); ok { + t.Fatal("retired authority line remains") + } + if _, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || ok { + t.Fatalf("retired binding: %t %v", ok, err) + } + if !h.Lifecycle().Deletions.CommittedSnapshot("v") { + t.Fatal("tombstone removed") + } + if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "v", SizeBytes: 1 << 20, ReplicationFactor: 1}); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("recreate after retirement: %v", err) + } + if err := h.ReconcileDeletedSpecVolumes(ctx); err != nil { + t.Fatal(err) + } + if reads.Load() != 2 { + t.Fatalf("retired volume still causes HEAD reads: %d", reads.Load()) + } + if err := h.Publisher().NoLiveWorkspaceLease(ctx, "v"); err != nil { + t.Fatalf("delete cannot resume: %v", err) + } +} + +func TestSpecRetirementRequiresDeletedOrAbsentAndReadableHead(t *testing.T) { + for _, state := range []string{"live", "deleting", "deleted", "absent", "unread"} { + t.Run(state, func(t *testing.T) { + h, _, _, _, now := neverCreatedVolume(t, false) + ctx := context.Background() + if err := h.VolumeDeleteAuthority("v", "retire").Reserve(ctx); err != nil { + t.Fatal(err) + } + now.Add(int64(2 * time.Minute)) + h.specDesired = map[string]bool{} + h.cfg.LayoutReadHead = func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) { + switch state { + case "absent": + return layout.Head{}, layout.ErrHeadAbsent + case "unread": + return layout.Head{}, errors.New("remote unavailable") + case "live": + return layout.Head{}, nil + } + return layout.Head{State: state}, nil + } + if err := h.ReconcileDeletedSpecVolumes(ctx); err != nil { + t.Fatal(err) + } + _, kept := h.Lifecycle().Volumes.GetVolume("v") + wantKept := state != "deleted" && state != "absent" + if kept != wantKept { + t.Fatalf("state=%s record kept=%t want=%t", state, kept, wantKept) + } + if state == "deleting" { + v := h.observationVolume("v", lifecycle.VolumeRecord{}, lifecycle.PlacementIntent{}) + if v.Status != ops.ObservationStatusDeleting || clusterStatus([]ops.VolumeEvidence{v}, nil) != ops.ObservationStatusOK { + t.Fatalf("deleting degrades cluster: %+v", v) + } + if slices.Contains(h.volumesServedBy("node-a"), "v") { + t.Fatal("deleting with expired lease still holds work") + } + } + if !h.Lifecycle().Deletions.CommittedSnapshot("v") { + t.Fatal("retirement discarded tombstone") + } + }) + } +} + +func TestSpecRetirementDoesNotUseAbsentHeadWithoutReservation(t *testing.T) { + h, _, _, _, now := neverCreatedVolume(t, false) + now.Add(int64(2 * time.Minute)) + h.specDesired = map[string]bool{} + reads := 0 + h.cfg.LayoutReadHead = func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) { + reads++ + return layout.Head{}, layout.ErrHeadAbsent + } + if err := h.ReconcileDeletedSpecVolumes(context.Background()); err != nil { + t.Fatal(err) + } + if reads != 0 { + t.Fatalf("unreserved volume read for retirement: %d", reads) + } + if _, ok := h.Lifecycle().Volumes.GetVolume("v"); !ok { + t.Fatal("unreserved absent HEAD caused retirement") + } +} + +// Stop precisely after durable authority retirement and before deleting the +// lifecycle tail; a distinct Host must reconstruct the permanent exclusion. +func TestSpecRetirementFreshHostFinishesHalfRetiredTail(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Linux lifecycle/authority directory fsync durability witness") + } + ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second) + defer cancel() + root := t.TempDir() + authorityDir := filepath.Join(root, "authority") + lifecycleDir := filepath.Join(root, "lifecycle") + disk, err := authority.NewFileAuthorityStore(authorityDir) + if err != nil { + t.Fatal(err) + } + endpoints := map[string][2]string{ + "gone": {"127.0.0.1:9201", "127.0.0.1:9202"}, + "live": {"127.0.0.1:9211", "127.0.0.1:9212"}, + } + for _, id := range []string{"gone", "live"} { + if err := disk.Put(authority.DurableRecord{VolumeID: id, ReplicaID: "r1", Epoch: 1, EndpointVersion: 1, WriteSeq: 1, DataAddr: endpoints[id][0], CtrlAddr: endpoints[id][1]}); err != nil { + t.Fatal(err) + } + } + if err := disk.Close(); err != nil { + t.Fatal(err) + } + cfg := Config{Listen: "127.0.0.1:0", AuthorityStoreDir: authorityDir, LifecycleStoreDir: lifecycleDir, WorkspaceRPC: true, + WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { + return authority.WorkspaceHead{}, authority.ErrWorkspaceHeadUnclaimed + }, + LayoutReadHead: func(_ context.Context, spec lifecycle.VolumeSpec) (layout.Head, error) { + if spec.VolumeID != "gone" { + t.Errorf("read unreserved live HEAD %s", spec.VolumeID) + } + return layout.Head{State: layout.StateDeleted}, nil + }, + } + first, err := New(cfg) + if err != nil { + t.Fatal(err) + } + first.Start() + firstClosed := false + t.Cleanup(func() { + if !firstClosed { + closeTestMaster(t, first) + } + }) + for _, id := range []string{"gone", "live"} { + if _, err := first.Lifecycle().Volumes.CreateVolume(lifecycle.VolumeSpec{VolumeID: id, SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatal(err) + } + if _, err := first.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: id, DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: id, ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { + t.Fatal(err) + } + if err := first.Lifecycle().WorkspaceBindings.Register(lifecycle.WorkspaceBinding{VolumeID: id, ServerID: "node-a", DataAddr: endpoints[id][0], CtrlAddr: endpoints[id][1]}); err != nil { + t.Fatal(err) + } + } + liveRecord, _ := first.Lifecycle().Volumes.GetVolume("live") + liveBinding, _, err := first.Lifecycle().WorkspaceBindings.Get("live") + if err != nil { + t.Fatal(err) + } + liveLine, _ := first.Publisher().VolumeAuthorityLine("live") + if _, err := first.Lifecycle().Deletions.Admit("gone", "retire"); err != nil { + t.Fatal(err) + } + if _, err := first.Lifecycle().Deletions.Commit("gone", "retire"); err != nil { + t.Fatal(err) + } + if err := first.Publisher().ReserveWorkspaceDeletion(ctx, "gone", nil); err != nil { + t.Fatal(err) + } + if err := first.Publisher().RetireDeletedWorkspace(ctx, "gone"); err != nil { + t.Fatal(err) + } + if _, ok := first.Publisher().VolumeAuthorityLine("gone"); ok { + t.Fatal("authority prefix did not finish") + } + closeTestMaster(t, first) + firstClosed = true + fresh, err := New(cfg) + if err != nil { + t.Fatal(err) + } + fresh.specDesired = map[string]bool{"live": true} + fresh.Start() + t.Cleanup(func() { closeTestMaster(t, fresh) }) + // Tombstone recovery happens in New, before any serving/reconcile. + if _, ok := fresh.Publisher().VolumeAuthorityLine("gone"); ok { + t.Fatal("fresh Host restored removed authority") + } + if !fresh.Lifecycle().Deletions.CommittedSnapshot("gone") { + t.Fatal("fresh Host lost reservation") + } + if err := fresh.Publisher().NoLiveWorkspaceLease(ctx, "gone"); err != nil { + t.Fatalf("Publisher did not reconstruct committed tombstone: %v", err) + } + for _, id := range []string{"gone", "live"} { + if _, ok := fresh.Lifecycle().Volumes.GetVolume(id); !ok { + t.Fatalf("tail %s missing before reconcile", id) + } + if _, ok := fresh.Lifecycle().Placements.GetPlacement(id); !ok { + t.Fatalf("placement %s missing before reconcile", id) + } + if _, ok, err := fresh.Lifecycle().WorkspaceBindings.Get(id); err != nil || !ok { + t.Fatalf("binding %s missing before reconcile: %v", id, err) + } + } + conn, err := grpc.NewClient(fresh.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + t.Fatal(err) + } + defer conn.Close() + lc := control.NewLifecycleServiceClient(conn) + ws := control.NewWorkspaceServiceClient(conn) + assertExcluded := func() { + t.Helper() + if _, err := lc.CreateVolume(ctx, &control.CreateVolumeRequest{VolumeId: "gone", SizeBytes: 1 << 20, ReplicationFactor: 1}); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("recreate admitted after restart: %v", err) + } + if _, err := ws.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "gone", ReplicaId: "r1", Epoch: 1, ServerId: "node-a"}); err == nil { + t.Fatal("regrant admitted after restart") + } + } + assertExcluded() + for i := 0; i < 2; i++ { + if err := fresh.ReconcileDeletedSpecVolumes(ctx); err != nil { + t.Fatal(err) + } + } + if _, ok := fresh.Lifecycle().Volumes.GetVolume("gone"); ok { + t.Fatal("record tail not retired") + } + if _, ok := fresh.Lifecycle().Placements.GetPlacement("gone"); ok { + t.Fatal("placement tail not retired") + } + if _, ok, err := fresh.Lifecycle().WorkspaceBindings.Get("gone"); ok || err != nil { + t.Fatalf("binding tail: %t %v", ok, err) + } + assertExcluded() + if !fresh.Lifecycle().Deletions.CommittedSnapshot("gone") { + t.Fatal("reconcile removed tombstone") + } + gotRecord, ok := fresh.Lifecycle().Volumes.GetVolume("live") + if !ok || !reflect.DeepEqual(gotRecord, liveRecord) { + t.Fatal("unrelated volume record changed") + } + gotBinding, ok, err := fresh.Lifecycle().WorkspaceBindings.Get("live") + if err != nil || !ok || !reflect.DeepEqual(gotBinding, liveBinding) { + t.Fatal("unrelated binding changed") + } + gotLine, ok := fresh.Publisher().VolumeAuthorityLine("live") + if !ok || !reflect.DeepEqual(gotLine, liveLine) { + t.Fatal("unrelated authority changed") + } + if !slices.Contains(fresh.volumesServedBy("node-a"), "live") { + t.Fatal("unrelated live work disappeared from host census") + } +} + +// A pacing clock is supplied only to the background-scan implementation; +// authority's lease clock and all proof guards remain the production ones. +func retirementScanHost(t *testing.T, ids ...string) (*Host, string) { + t.Helper() + if runtime.GOOS == "windows" { + t.Skip("Linux lifecycle directory fsync") + } + root := t.TempDir() + h, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: filepath.Join(root, "authority"), LifecycleStoreDir: filepath.Join(root, "lifecycle")}) + if err != nil { + t.Fatal(err) + } + h.Start() + t.Cleanup(func() { closeTestMaster(t, h) }) + for _, id := range ids { + if _, err := h.Lifecycle().Volumes.CreateVolume(lifecycle.VolumeSpec{VolumeID: id, SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatal(err) + } + if _, err := h.Lifecycle().Deletions.Admit(id, "delete-"+id); err != nil { + t.Fatal(err) + } + if _, err := h.Lifecycle().Deletions.Commit(id, "delete-"+id); err != nil { + t.Fatal(err) + } + if err := h.Publisher().ReserveWorkspaceDeletion(t.Context(), id, nil); err != nil { + t.Fatal(err) + } + } + return h, root +} +func TestSpecRetirementBackgroundBoundsReadsAndCachesTerminalProof(t *testing.T) { + h, _ := retirementScanHost(t, "a", "b", "c") + h.specDesired = map[string]bool{"a": true, "b": true, "c": true} + reads := map[string]int{} + h.cfg.LayoutReadHead = func(_ context.Context, v lifecycle.VolumeSpec) (layout.Head, error) { + reads[v.VolumeID]++ + switch v.VolumeID { + case "a": + return layout.Head{State: layout.StateDeleted}, nil + case "b": + return layout.Head{State: layout.StateDeleting}, nil + default: + return layout.Head{}, errors.New("slow/unavailable filer") + } + } + if _, err := h.RunLifecycleProductTick(); err != nil { + t.Fatal(err) + } + if reads["a"]+reads["b"]+reads["c"] != 1 { + t.Fatalf("actual product tick did not enforce one-read budget: %v", reads) + } + at := time.Now() + tick := func(now time.Time) { + t.Helper() + before := reads["a"] + reads["b"] + reads["c"] + if err := h.reconcileDeletedSpecVolumes(t.Context(), true, now); err != nil { + t.Fatal(err) + } + after := reads["a"] + reads["b"] + reads["c"] + if after-before > 1 { + t.Fatalf("one background tick made %d remote reads", after-before) + } + } + for i := 0; i < 3; i++ { + tick(at) + } + if reads["a"] != 1 || reads["b"] != 1 || reads["c"] != 1 { + t.Fatalf("scan starved a volume: %v", reads) + } + for i := 0; i < 100; i++ { + tick(at.Add(time.Millisecond)) + } + if reads["a"] != 1 || reads["b"] != 1 || reads["c"] != 1 { + t.Fatalf("no-progress/error volumes polled on every tick: %v", reads) + } + later := at.Add(h.cfg.Freshness.EffectiveFreshnessWindow()) + tick(later) + tick(later) + if reads["a"] != 1 || reads["b"] != 2 || reads["c"] != 2 { + t.Fatalf("terminal proof repolled or due retry starved: %v", reads) + } + if _, ok := h.Lifecycle().Volumes.GetVolume("a"); !ok { + t.Fatal("in-spec terminal metadata retired") + } + // Pacing memory cannot retain externally removed records as history. + if err := h.Lifecycle().Volumes.DeleteVolume("c"); err != nil { + t.Fatal(err) + } + tick(later) + if _, ok := h.retirementNext["c"]; ok { + t.Fatal("retry schedule retains removed record") + } + if err := h.Lifecycle().Volumes.DeleteVolume("a"); err != nil { + t.Fatal(err) + } + tick(later) + if _, ok := h.noWork.Load("a"); ok { + t.Fatal("terminal cache retains removed record") + } + +} +func TestSpecRetirementLocalFailureDoesNotStopOtherVolumesOrProductTick(t *testing.T) { + h, root := retirementScanHost(t, "a", "b") + h.specDesired = map[string]bool{} + reads := map[string]int{} + h.cfg.LayoutReadHead = func(_ context.Context, v lifecycle.VolumeSpec) (layout.Head, error) { + reads[v.VolumeID]++ + return layout.Head{State: layout.StateDeleted}, nil + } + if _, err := h.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "a", DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: "a", ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { + t.Fatal(err) + } + path := filepath.Join(root, "lifecycle", "placements", "a.json") + backup := path + ".saved" + if err := os.Rename(path, backup); err != nil { + t.Fatal(err) + } + if err := os.Mkdir(path, 0700); err != nil { + t.Fatal(err) + } + blocker := filepath.Join(path, "blocker") + if err := os.WriteFile(blocker, []byte("inject nonempty directory removal error"), 0600); err != nil { + t.Fatal(err) + } + restore := func() { + t.Helper() + if err := os.Remove(blocker); err != nil { + t.Fatal(err) + } + if err := os.Remove(path); err != nil { + t.Fatal(err) + } + if err := os.Rename(backup, path); err != nil { + t.Fatal(err) + } + } + // A local retirement fault must neither abort the full startup sweep nor + // become the return value of the unrelated assignment/probe product tick. + if err := h.ReconcileDeletedSpecVolumes(t.Context()); err != nil { + t.Fatalf("one local fault aborted sweep: %v", err) + } + if _, ok := h.Lifecycle().Volumes.GetVolume("a"); !ok { + t.Fatal("failed removal hid retry record") + } + if _, ok := h.Lifecycle().Volumes.GetVolume("b"); ok { + t.Fatal("one fault prevented unrelated retirement") + } + if _, err := h.RunLifecycleProductTick(); err != nil { + t.Fatalf("one local fault stopped product work: %v", err) + } + if reads["a"] != 1 { + t.Fatal("failed local removal re-read terminal HEAD") + } + restore() + if err := h.reconcileDeletedSpecVolumes(t.Context(), true, time.Now().Add(h.cfg.Freshness.EffectiveFreshnessWindow())); err != nil { + t.Fatal(err) + } + if _, ok := h.Lifecycle().Volumes.GetVolume("a"); ok { + t.Fatal("due local retry did not complete") + } + if reads["a"] != 2 { + t.Fatalf("retirement retry must take a new post-lease HEAD proof: %v", reads) + } +} diff --git a/seaweed-block/core/lifecycle/layout_identity_guard_test.go b/seaweed-block/core/lifecycle/layout_identity_guard_test.go index 1a4884159a..ccdd7cffdb 100644 --- a/seaweed-block/core/lifecycle/layout_identity_guard_test.go +++ b/seaweed-block/core/lifecycle/layout_identity_guard_test.go @@ -32,6 +32,11 @@ func TestLayoutIdentityWriterAndReaders(t *testing.T) { "core/host/master/services.go CreateVolume": true, "core/host/master/services.go createLifecycleVolume": true, "core/host/master/workspace_layout_head.go WorkspaceLayoutVolume": true, + // Logs the existing record's immutable LayoutID only when a fresh + // post-lease HEAD read fails; never mints or changes the identity. + // TestSpecRetirementBackgroundBoundsReadsAndCachesTerminalProof + // covers the deferred read, and the fresh-Host witness pins its record. + "core/host/master/spec_retirement.go reconcileDeletedSpecVolumes": true, "core/launcher/k8s_renderer.go blockVolumeArgs": true, "core/launcher/k8s_renderer.go durableRoot": true, "cmd/blockvolume/main.go runVolume": true, diff --git a/seaweed-block/core/ops/observation.go b/seaweed-block/core/ops/observation.go index 409afade93..b1a8361c8a 100644 --- a/seaweed-block/core/ops/observation.go +++ b/seaweed-block/core/ops/observation.go @@ -20,6 +20,9 @@ const ( // A volume stopped on purpose: its holder released its lease cleanly // and nothing serves it. Not a fault; the cluster status ignores it. ObservationStatusStopped = "stopped" + // Deleting and deleted are intentional lifecycle states, not serving failures. + ObservationStatusDeleting = "deleting" + ObservationStatusDeleted = "deleted" // ReasonStoppedCleanly: the master recorded the holder's clean release // (its revocation ACK) for the volume's current epoch. ReasonStoppedCleanly = "stopped_cleanly" diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index eba57246c5..6557e05105 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -146,6 +146,7 @@ flowchart LR | Bound | Deleting | a deletion reservation; the id is never created again | `core/host/master/services.go` `MarkVolumeDeleting` | `INV-VOL-ID-NO-REUSE-001` | | any authority line | DeleteReserved (permanent) | the existing lifecycle reservation is committed durably; then `mu -> leaseMu` publishes the exclusion. Publication, move issue, first grant, expired re-grant and renewal check it under their writer lock. Restart reloads every committed exclusion before serving. Deleting HEAD requires the granted or restart deadline plus skew to have ended, including unclaimed grants; the check returns a refusal rather than waiting | `core/authority/workspace_delete_reservation.go` `ReserveWorkspaceDeletion`, `NoLiveWorkspaceLease`; `core/host/master/volume_delete_authority.go`; `host.go` `New` | `INV-SNAPK-DELETE-GATE-001` | | any authority line, stores still awaited (stage 1) | DeleteReserved without the holder's acknowledgement | the master's record is marked first, durably and in the lock that ends the store wait; the mark freezes the record in stage 1 (the wait never ends after it, so the primary, whose assignment keeps awaiting the stores, never serves); the reservation then skips the live-lease refusal. Deleting HEAD waits out the lease as above. Past stage 1, also while the end of creation is unrecorded (the volume may be serving), the live-lease refusal stays | `core/host/master/volume_delete_authority.go` `Reserve`; `core/host/master/store_attestation.go` `markDeleteWithoutAck`, `awaited`; `core/authority/workspace_delete_reservation.go` `ReserveNeverCreatedWorkspaceDeletion` | `INV-WS-DELETE-WITHOUT-ACK-001` | +| DeleteReserved, removed from the desired spec | Retired metadata (reservation permanent) | no live lease, then a fresh bounded HEAD read proves deleted or absent; unread/live/deleting keeps the records. Remove authority durably, then placement and bindings, then the volume record; a crash retries the remaining removals. The store and its resweep inputs are untouched | `core/host/master/spec_retirement.go` `ReconcileDeletedSpecVolumes`; `core/authority/workspace_retirement.go` `RetireDeletedWorkspace` | `INV-SPEC-DELETE-RETIRE-001` | **Volume creation phase, in blockmaster's store record** (`core/host/master/store_attestation.go`, decided by `inCreationPhase` in `core/host/master/product_loop.go`). Every replacement entry (both promotion gates, the operator's failover and planned move, the rebalance) acts only on Established. @@ -1199,6 +1200,9 @@ Notes: | `INV-CUT-TIMER-SKIP-001` | A periodic cut decided from an older last cut is skipped under the capture lock: no automatic cut follows another within the interval. | M5 periodic trigger (before Admit) | `core/storage/chunk_periodic_cut.go` `CutUnlessCutSince`; `core/frontend/durable/provider_chunk.go` `chunkLoop` | `TestChunkPeriodicCut_SkipsAfterANewerCut`, `TestChunkPeriodicCut_SkipsANewerCutWithAnOlderStamp` (`core/storage/chunk_periodic_cut_test.go`); `TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt` (`core/frontend/durable/provider_chunk_sched_test.go`) | — | ACTIVE | | `INV-CUT-TIMER-SLOT-WAIT-001` | A periodic cut refused for held host slots, pending urgent work or an earlier ticket is a wait, not a failure: no backoff or minimum spacing; it retries at the next poll in ticket order, and status reports the wait until any later cut succeeds. Other errors keep the backoff. | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `cutPolicy.after`, `chunkLoop`; `core/hostlimit/limiter.go` `ErrSlotsHeld` | `TestCutPolicy_HostSlotBusyIsAWaitNotAFailure`, `TestCutPolicy_SuccessDuringSlotWaitEndsTheWait`, `TestCutWaitSlot_StatusEndsTheWaitAfterALaterCut`, `TestCutPolicy_TicketOrderWaitBound` (`core/frontend/durable/cut_policy_test.go`); `TestTimerCutRunsSoonAfterHostSlotFrees`, `TestSlotWaitEndsWithASuccessfulDetachSeal` (`core/frontend/durable/host_slot_wait_test.go`); `TestAdmitClosedDuringPoolAcquisitionIsRevoked` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | | `INV-SNAPSHOT-ANSWER-COUNT-001` | Newly produced snapshot creation and listing answers omit the uncomputed chunk count; no manifest scan is added to answer a snapshot. | M9 snapshot answer projection (no transition change) | `core/frontend/chunkstore/control_types.go`, `api.go`; `core/host/volume/chunk_control.go` | `TestSnapshotAfter200MiBWritesOmitsUncomputedChunkCount` (`core/host/volume/snapshot_chunk_count_test.go`) | NONE (pure projection of the published snapshot; no authority or persisted format change) | STUB | +| `INV-SPEC-DELETE-RETIRE-001` | Retire spec-removed metadata only under a permanent reservation after no-live-lease and a subsequent HEAD read proves deleted or absent. Read errors, live HEAD and deleting HEAD keep the records. Retirement never removes the reservation or store data. | M4 delete retirement | `core/host/master/spec_retirement.go`; `core/authority/workspace_retirement.go`, `authority_store_file.go` | `TestSpecRetirementReadsHeadOnlyAfterLeaseAndKeepsTombstone`, `TestSpecRetirementRequiresDeletedOrAbsentAndReadableHead`, `TestSpecRetirementDoesNotUseAbsentHeadWithoutReservation`, `TestRetirementKeepsReservationAndWaitsForLiveLease`, `TestFileAuthorityRetirementSurvivesReloadAndKeepsOtherRecords`, `TestSpecRetirementBackgroundBoundsReadsAndCachesTerminalProof`, `TestSpecRetirementLocalFailureDoesNotStopOtherVolumesOrProductTick` | DeleteRetire.ReadOK; DeleteRetire.Retire; DeleteRetire.HostRetire | STUB | +| `INV-SPEC-UNUSED-PLACEMENT-001` | A spec startup prunes an undesired placement only before serving and with no volume record, authority line, binding or deletion reservation, and no skipped authority recovery. The desired spec and seed are one keep set. | M4 registration input | `cmd/blockmaster/main.go`; `core/host/master/spec_retirement.go` | `TestClusterSpecImportRemovesUnusedPlacementMissingFromSpec`, `TestClusterSpecCleanupKeepsRecordsBindingsAuthorityAndSeed` | NONE (registration-only cleanup before controller activity) | STUB | +| `INV-CHECK-DELETING-001` | A post-lease reserved volume with HEAD deleting, deleted or absent holds no serving work. Its status is informational and checks issue no lease or holder requests for it. Another volume's failures remain visible. | M9 delete observation | `core/host/master/observation_snapshot.go`, `journal_isolation.go`; `cmd/sw-block/shell_check.go` | `TestSpecRetirementRequiresDeletedOrAbsentAndReadableHead`, `TestSpecRetirementReadsHeadOnlyAfterLeaseAndKeepsTombstone`, `TestClusterCheckDoesNotProbeDeletingOrDeletedVolumes` | DeleteRetire.HostRetire | STUB | | `INV-CLI-DELETE-RETRY-001` | Only the final lease barrier after a committed volume-delete reservation permits retryable true/exit 75 at its horizon. A live-holder Reserve refusal requires stopping the volume first (not_admitted, non-retryable, exit 1). No lease guard is bypassed. | M9 delete admission result projection | `cmd/sw-block/chunk_volume_delete.go` `authorityErr`; `cmd/sw-block/chunk.go` `chunkResult` | `TestVolumeDeleteAdmissionRetryAnswer`; `TestOpsChunkVolumeDeleteRefusalSaysNothingWasPersisted` | MoveAdmission.DelRead; MoveAdmission.DelMark (unchanged guards) | STUB | | `INV-SNAPSHOT-REPLAY-FLAG-001` | A successful same-ID snapshot admission reports replayed true without changing HEAD or its retained outcome. First creation reports false; the flag decorates only the response. | M9 snapshot outcome projection | `core/host/volume/snapshot_operation.go`, `chunk_control.go`; `cmd/sw-block/snapshot_operation.go` | `TestSnapshotReplayFlagDoesNotRewriteOutcome`, `TestSnapshotCLIUsesReplayedAdmissionAnswer` | SnapOps.Poll; SnapOps.Start (no transition change) | STUB | | `INV-CLI-CATALOG-ERROR-001` | The chunk CLI reports filer/master transport failures as retryable remote_unavailable (exit 75), including census, dial, resolve and read failures; configuration refusals stay distinct. An absent v1.1 delete reports snapshot_not_found; its not_found receipt stays unchanged. | M9 client error projection; M4 census refusal, no transition change | `cmd/sw-block/chunk_transport.go` `chunkTransportFailure`; `cmd/sw-block/chunk.go` `chunkResult`; `cmd/sw-block/catalog_snapshot_operation.go` `catalogSnapshotDeleteRefusal`; `core/frontend/chunkstore/single_filer.go` `CheckSingleFiler`; `core/frontend/chunkstore/layout/delete.go` `RunMarkDeleting` | `TestOpsChunkTransportFailureMatrix`, `TestOpsChunkVerifyUnreachableCensusPreservesTransport`, `TestCheckSingleFilerKeepsTransportCause`, `TestSingleFilerConfigurationErrorDeadlineBetweenReads`, `TestCheckSingleFilerSlowDialOrdering`, `TestDialBCatalogKeepsCustomCallerDeadline`, `TestMasterCensusKeepsCustomCallerDeadline`, `TestCheckSingleFilerValidatesAllMasterAddressesBeforeCensus`; `TestOpsChunkCatalogUnavailableIsTyped`, `TestCatalogTransportClassificationKeepsDefiniteAnswers`, `TestSnapshotDeleteAbsentCLIUsesContractCodeAndKeepsReceipt` | SnapOps.Poll; r2.972 | STUB | diff --git a/seaweed-block/docs/time-bounds.tsv b/seaweed-block/docs/time-bounds.tsv index 010adf8058..c872922adf 100644 --- a/seaweed-block/docs/time-bounds.tsv +++ b/seaweed-block/docs/time-bounds.tsv @@ -199,6 +199,7 @@ core/host/master/host.go New http.Server.WriteTimeout 1 per-call NONE: no model core/host/master/host.go New http.Server.IdleTimeout 1 per-call NONE: no model row maps this file yet one HTTP request or connection core/host/master/probe_round.go roundEvidenceProvider.round time.NewTimer 1 per-call FencingRound.Deliver; FencingRound.Open one probe round's evidence wait core/host/master/services.go services.deleteHolderEvidence context.WithTimeout 1 per-call FormatGate.Report one RPC or request +core/host/master/spec_retirement.go Host.reconcileDeletedSpecVolumes context.WithTimeout 1 per-call DeleteRetire.ReadOK one fresh HEAD read after the no-live-lease barrier core/host/master/workspace_service.go services.AckWorkspaceRevoked context.WithTimeout 1 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request core/host/master/workspace_service.go services.MoveWorkspace context.WithTimeout 1 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request core/host/master/workspace_service.go services.PreviewWorkspaceMove context.WithTimeout 1 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request