From 19eb65a3b5274ff32b88c9d59df078d278f39cc7 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 15:41:25 -0800 Subject: [PATCH] test: pin collection to observed-dead operation incarnations --- .../snapshot_operation_volume_delete_test.go | 42 +++++++++++++++++++ seaweed-block/docs/design/invariants.md | 4 +- .../docs/design/snapshot-operation-index.md | 8 ++-- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/seaweed-block/core/frontend/chunkstore/snapshot_operation_volume_delete_test.go b/seaweed-block/core/frontend/chunkstore/snapshot_operation_volume_delete_test.go index cb5c923ca0..6532514949 100644 --- a/seaweed-block/core/frontend/chunkstore/snapshot_operation_volume_delete_test.go +++ b/seaweed-block/core/frontend/chunkstore/snapshot_operation_volume_delete_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "path" "strconv" "strings" "testing" @@ -190,3 +191,44 @@ func TestSnapshotOperationClosedVolumeRefusesReceipts(t *testing.T) { } } } + +// A GC pass has observed only this store's creation incarnation dead. A sibling +// under the same volume's metadata parent is not authority to broaden its sweep. +func TestSnapshotOperationDeadGCSparesUnobservedIncarnation(t *testing.T) { + ctx := context.Background() + catalog, filer, _, _, volume := rerunFixture(t) + store, err := catalog.Store(volume) + if err != nil { + t.Fatal(err) + } + op, _, err := store.CreateSnapshotOperation(ctx, "issued", "create", "daily", strings.Repeat("a", 64)) + if err != nil { + t.Fatal(err) + } + sibling := path.Join(store.root, "operations", volume.ID.String()+"-0000000000000002") + // Persist real, valid receipt/index bytes as an unobserved sibling. Neither + // a matching volume tag nor a familiar filename is proof it is dead. + for _, name := range []string{operationIndexName, operationReceiptName(op.Sequence)} { + entry, err := filer.LookupEntry(ctx, store.operationDirectory(), name) + if err != nil { + t.Fatal(err) + } + if err := filer.CreateEntry(ctx, sibling, entry, true); err != nil { + t.Fatal(err) + } + } + for i := 0; i < 2; i++ { + if _, err := catalog.DeleteVolume(ctx, volume, okDeleteAuthority{}); err != nil { + t.Fatal(err) + } + } + entries, err := filer.ListEntries(ctx, store.operationDirectory(), "", "", 128) + if err != nil || len(entries) != 0 { + t.Fatalf("observed-dead incarnation not collected: %d %v", len(entries), err) + } + for _, name := range []string{operationIndexName, operationReceiptName(op.Sequence)} { + if _, err := filer.LookupEntry(ctx, sibling, name); err != nil { + t.Fatalf("GC swept unobserved incarnation %s: %v", name, err) + } + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 2f8b5f971d..90e244f07e 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1336,8 +1336,8 @@ Notes: | `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-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 | -| `INV-SNAP-OP-ADMISSION-CLOSE-001` | Admission checks HEAD after receipt publication and refuses a deleting/deleted or absent volume. Closed incarnations cannot answer retained operation queries; their terminal receipt bytes are not rewritten by closing. | M9 admission and observation | `checkSnapshotOperationAdmission`, `readOperationIndex`, create/delete admission | `TestSnapshotOperationAdmissionRechecksHeadAfterPublication`, `TestSnapshotOperationClosedVolumeRefusesReceipts` | SnapVolDel per-incarnation refinement; exported row numbers pending | STUB | -| `INV-SNAP-OP-END-001` | Operation metadata is scoped to full VolumeID and creation generation. Late writes in a closed incarnation grant no authority. Dead-incarnation GC is idempotent and cannot affect a replacement; it does not promise no later writes. | M9 live incarnation to dead and GC | `operationDirectory`, `readOperationIndex`, `deleteSnapshotOperations` | `TestSnapshotOperationDeleteFencesPausedPublications`, `TestSnapshotOperationVolumeDeleteCleanupReruns`, `TestSnapshotOperationVolumeDeleteSparesForeignReceipt` | SnapVolDel per-incarnation refinement; exported row numbers pending | STUB | +| `INV-SNAP-OP-ADMISSION-CLOSE-001` | Admission checks HEAD after receipt publication and refuses a deleting/deleted or absent volume. Closed incarnations cannot answer retained operation queries; their terminal receipt bytes are not rewritten by closing. | M9 admission and observation | `checkSnapshotOperationAdmission`, `readOperationIndex`, create/delete admission | `TestSnapshotOperationAdmissionRechecksHeadAfterPublication`, `TestSnapshotOperationClosedVolumeRefusesReceipts` | SnapVolDel rows 257-260 (per-incarnation) | STUB | +| `INV-SNAP-OP-END-001` | Operation metadata is scoped to full VolumeID and creation generation. Late writes in a closed incarnation grant no authority. Dead-incarnation GC is idempotent and cannot affect a replacement; it does not promise no later writes. | M9 live incarnation to dead and GC | `operationDirectory`, `readOperationIndex`, `deleteSnapshotOperations` | `TestSnapshotOperationDeleteFencesPausedPublications`, `TestSnapshotOperationVolumeDeleteCleanupReruns`, `TestSnapshotOperationVolumeDeleteSparesForeignReceipt`, `TestSnapshotOperationDeadGCSparesUnobservedIncarnation` | SnapVolDel rows 257-260 (per-incarnation) | STUB | | `INV-SNAP-OP-CRASH-001` | A durable snapshot intent survives holder SIGKILL before publication and completes once after restart; after publication, restart settles its original receipt without another cut. | M9 operation recovery (planned) | Process-owned create executor; native crash qualification pending | `TestSnapshotOperationIntentAndPublicationCrashBoundaries`, `TestSnapshotOperationKillReceiptRejectsOrdinaryExit` (`cmd/blockvolume/snapshot_operation_crash_integration_test.go`) | SnapOps.Start/Publish/Settle; rows 211–219 (native red receipt owed) | STUB | | `INV-SNAPK-RETAIN-META-001` | Reachability, removal and the volume delete never read a snapshot's retention facts (source guard); the policy entry beside VOLUME changes by one conditional update and is read only by retain. | M9 snap → idle | `core/frontend/chunkstore/layout` `head.go` `SnapshotMeta`; `core/frontend/chunkstore` `retain_b.go` | `TestSnapshotMeta_WrittenOnceByTheCommit`, `TestGuard_SafetyIgnoresSnapshotMeta`, `TestBCatalog_RetainKeepsTheOldBehaviour`, `TestBCatalog_RetentionPolicyIsConditional` | — (the snapshot kernel model is not in this repository) | ACTIVE | | `INV-SNAPK-HEAD-BOUND-001` | HEAD stays inline: at most 10 snapshots, names at most 64 bytes, 4 labels, 4 dependents per snapshot and 16 per HEAD, refused where they enter with the cure; Encode refuses a HEAD above 64 KiB. A snapshot past 10 is refused before its cut: nothing is written. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `check`, `Encode`; `snapshots.go` `AddDependent`; `commit.go` `Commit`; `core/frontend/durable/provider_layout_snapshot.go` `SnapshotVolume`; `core/host/volume/chunk_control.go` `chunkErrorCode`; `core/host/volume/chunk_scheduled_snapshot.go` `ScheduledSnapshot` | `TestHead_SizeAtTheSnapshotCap`, `TestHead_BoundsRefused`, `TestChunkSnapshotPastTheLimitIsRefusedWithHEADUnchanged`, `TestScheduledSnapshotAtTheLimitStillPublishes`, `TestChunkSnapshotRefusalsAreTyped`, `TestLayoutProviderSnapshotVolume` | — (the snapshot kernel model is not in this repository) | ACTIVE | diff --git a/seaweed-block/docs/design/snapshot-operation-index.md b/seaweed-block/docs/design/snapshot-operation-index.md index 938d0bcbb8..962cba87e3 100644 --- a/seaweed-block/docs/design/snapshot-operation-index.md +++ b/seaweed-block/docs/design/snapshot-operation-index.md @@ -139,9 +139,11 @@ GC without changing the replacement's receipt. The old flat-directory layout fails those same controls. This is a development-only receipt path change; the earlier flat-directory -Draft data is not adopted or migrated. The per-incarnation SnapVolDel model -rows are pending their exported numbers; the earlier bounded-drain rows do not -prove this refinement. Whole-unit and native qualification remain separate. +Draft data is not adopted or migrated. SnapVolDel rows 257-260 cover the per-incarnation refinement (safe, shared-path, +missing-recheck and sweep-by-volume controls). Rows 254-256 are superseded; +NoOrphanAfterEnd is not its target. GC visits only the incarnation whose own +HEAD was observed deleted, never every child of the operations parent; a sibling +without that death observation stays untouched. Whole-unit and native qualification remain separate. ## CLI-owned catalog attempt boundary