diff --git a/seaweed-block/cmd/sw-block/chunk_b.go b/seaweed-block/cmd/sw-block/chunk_b.go index c5f205954e..816da3db4d 100644 --- a/seaweed-block/cmd/sw-block/chunk_b.go +++ b/seaweed-block/cmd/sw-block/chunk_b.go @@ -265,6 +265,13 @@ func chunkSnapshotDelete(args []string, stdout, stderr io.Writer) int { if noWait && requestID == "" { return errors.New("--no-wait requires --request-id") } + // An explicit --gen names one incarnation: 0 names none, and is + // refused here, before any read or write (it is not "no pin"). + explicitGen := false + c.fs.Visit(func(f *flag.Flag) { explicitGen = explicitGen || f.Name == "gen" }) + if explicitGen && pin == 0 { + return errors.New("--gen must name a publishing generation (name@gen, >= 1)") + } if requestID == "" { if autoID, err = newSnapshotDeleteRequestID(); err != nil { return err diff --git a/seaweed-block/cmd/sw-block/snapshot_delete_route_test.go b/seaweed-block/cmd/sw-block/snapshot_delete_route_test.go index 5e4d0460ae..5e4e9050bf 100644 --- a/seaweed-block/cmd/sw-block/snapshot_delete_route_test.go +++ b/seaweed-block/cmd/sw-block/snapshot_delete_route_test.go @@ -194,6 +194,40 @@ func TestSnapshotDeleteExplicitIdentityOnAV0HeadIsRefused(t *testing.T) { } } +// An explicit --gen 0 names no incarnation: on a version-0 and on a +// version-1 HEAD it is refused before any read or write, the HEAD unchanged +// and no write under the operation tree (it is not the unpinned delete). +func TestSnapshotDeleteExplicitGenZeroIsRefusedBeforeAdmission(t *testing.T) { + ctx := context.Background() + for _, v1 := range []bool{false, true} { + t.Run(map[bool]string{false: "v0 head", true: "v1 head"}[v1], func(t *testing.T) { + mem := newMemChunkStore() + v := cliVolume(t, mem, "v1", "daily") + cat, _ := chunkstore.NewBCatalog(mem, mem, defaultChunkPathCLI) + st, _ := cat.Store(v) + if v1 { + toVersion1(t, st) + } + before, _, err := st.ReadHead(ctx) + if err != nil { + t.Fatal(err) + } + counting := useCountingStore(t, mem, 1) + code, out, logs := runChunk(cliArgs("snapshot-delete", volArgs("volume", v), []string{"--name", "daily", "--gen", "0"})...) + if code == 0 || !strings.Contains(out+logs, "--gen must name a publishing generation") { + t.Fatalf("--gen 0: code=%d out=%s logs=%s; want refused before admission", code, out, logs) + } + after, _, err := st.ReadHead(ctx) + if err != nil || after.Gen != before.Gen || len(after.Snapshots) != 1 { + t.Fatalf("--gen 0 changed the HEAD: before %+v after %+v %v", before, after, err) + } + if n := counting.writes.Load(); n != 0 { + t.Fatalf("--gen 0 attempted %d writes under the operation tree, want 0", n) + } + }) + } +} + // An old client's name-only delete (the v1.0 call) of a version-1 HEAD's // snapshot refuses typed and writes nothing. func TestSnapshotDeleteOldClientNameOnlyRefusesAV1Head(t *testing.T) { diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 5777a5f33a..f55d8b2c19 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1368,6 +1368,7 @@ Notes: | `INV-SNAP-OP-FINGERPRINT-001` | A retained operation ID reused with changed snapshot intent refuses before any cut or HEAD write. | M9 operation admission (planned) | `CreateSnapshotOperation` canonical fingerprint; create executor wired; delete executor pending | `TestSnapshotOperationSameIDChangedIntentRefusesBeforeWrite` (`core/host/volume/snapshot_operation_red_test.go`) | SnapOps.Send; rows 211–219 | STUB | | `INV-SNAP-OP-READMIT-001` | A create whose HEAD publication applied before its answer was lost reconciles that original outcome on re-admission; later removal cannot cause another execution under its retained operation ID. | M9 operation re-admission (planned) | `SnapshotOperationBinding`, `LayoutStore.GuardSnapshotOperations`; create executor and compact index wired; native qualification pending | `TestSnapshotOperationLostPublishAnswerReadmitDeleteCannotRepublish`, `TestSnapshotOperationRemovalBeforeReadmitKeepsPublishedOutcome` (`core/host/volume/snapshot_operation_red_test.go`) | SnapOps.Send/Publish/Settle/Delete; rows 211–219 (persisted-stall removal controls included; concurrent-owner controls pending) | STUB | | `INV-SNAP-OP-CLI-001` | Snapshot observation preserves the printed operation ID across retries, polling, interruption and no-wait submission; observing an operation never admits another identity. | M9 operation observation (planned) | `chunkObserveSnapshot`, holder asynchronous create executor | `TestSnapshotOperationCLIUsesPrintedIDForAsyncObservation`, `TestSnapshotOperationCLIInterruptThenResumeUsesPrintedID` (`cmd/sw-block/snapshot_operation_red_test.go`, `cmd/sw-block/snapshot_operation_interrupt_unix_test.go`) | SnapOps.Send/Start; rows 211–219 (server crash controls owed) | STUB | +| `INV-SNAP-DELETE-HOLDER-RESUME-001` | A holder delete operation that meets an earlier delete's unconsumed intent (busy) or a moved HEAD kicks the cleaning and resumes its own admitted operation, within a bound, to its terminal receipt: no second admission, never left stalled by its request. | M9 holder delete execution | `core/host/volume/chunk_control.go` `deleteSnapshotOperation` | `TestSnapshotDeleteHolderResumesAfterThePreviousIntentIsConsumed` | SnapDelete rows 241-245 | ACTIVE | | `INV-SNAP-DELETE-NAME-001` | The name-only delete primitive (an old client's) refuses a v1.1 HEAD without a HEAD write. Retries in one CLI invocation keep its request id and resolved incarnation, so a lost reply never deletes a replacement; a new invocation resolves the name again (--gen pins it). | M9 legacy delete admission | `layout.RunDeleteSnapshot`; catalog, CLI and host delete routes | `TestSnapshotDeleteOldClientNameOnlyRefusesAV1Head`, `TestSnapshotDeleteAfterALostLegacyReplyIsANewIntent`, `TestSnapshotDeleteHolderAfterALostLegacyReplyIsANewIntent`, `TestSnapshotDeletePublicOperationKeepsTargetAcrossRecreation`, `TestSnapshotDeletePublicNoWaitResumesSameAdmission`, `TestSnapshotDeletePublicAbsentHeadRefuses` | SnapDelete row 242; rows 241-245 | STUB | | `INV-SNAP-DELETE-LOGICAL-001` | A delete receipt succeeds only after its retained target is proven absent. Actual unlink and its durable reclamation intent publish in one HEAD CAS; physical continuation depends on HEAD/pages, not the receipt. | M9 delete running to succeeded | `snapshotDeleteLogicalStep`, `RunDeleteSnapshotWithIntent` | `TestSnapshotDeleteLogicalCommitKeepsIndependentIntent`, `TestSnapshotDeleteLogicalCommitResumesAcrossLostAnswers`, `TestSnapshotDeleteLogicalCommitSparesReplacement` | SnapDelete rows 241-245; PageChain rows 246-253 | STUB | | `INV-SNAP-DELETE-EXECUTOR-001` | A catalog delete attempt reads its issued handle before work, takes ownership by receipt CAS, and persists uncertain work as stalled. It never infers terminal success from a callback return; terminal replay reads the same incarnation. | M9 delete attempt transport | `BCatalog.RunSnapshotDeleteOperation`; CLI execution seam | `TestSnapshotDeleteCatalogResumesDurableIntentOnAnotherExecutor`, `TestSnapshotDeleteCatalogRefusesWrongIntentBeforeWork`, `TestSnapshotDeleteCatalogCannotInferSuccessFromWorkReturn`, `TestSnapshotDeleteOfflineCLILeavesProgressInFiler` | SnapDelete retained target; SnapOps owner/state refinement; V8 completion adapter and public command activation owed | STUB |