diff --git a/seaweed-block/core/frontend/chunkstore/snapshot_operation_retirement_test.go b/seaweed-block/core/frontend/chunkstore/snapshot_operation_retirement_test.go new file mode 100644 index 0000000000..b467317ccb --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/snapshot_operation_retirement_test.go @@ -0,0 +1,55 @@ +package chunkstore + +import ( + "context" + "errors" + "fmt" + "strings" + "testing" +) + +// The durable bound includes accepted, running and stalled records. Reopening +// the store must not turn those records into free admission capacity. +func TestSnapshotOperationRetirementFullPendingRefusesWithoutLosingReceipt(t *testing.T) { + ctx := context.Background() + _, _, store, _ := cleanFixture(t) + fingerprint := strings.Repeat("a", 64) + var first, stalled SnapshotOperation + for i := range 4096 { + op, created, err := store.CreateSnapshotOperation(ctx, fmt.Sprintf("pending-%04d", i), "create", "daily", fingerprint) + if err != nil || !created { + t.Fatalf("admit %d: created=%v err=%v", i, created, err) + } + if i == 0 { + first = op + } + if i == 1 { + running, err := store.AdvanceSnapshotOperation(ctx, op, "running", nil, "") + if err != nil { + t.Fatal(err) + } + stalled, err = store.AdvanceSnapshotOperation(ctx, running, "stalled", nil, "") + if err != nil { + t.Fatal(err) + } + } + } + reopened, err := NewLayoutStore(store.f, store.b, store.root, store.id) + if err != nil { + t.Fatal(err) + } + _, created, err := reopened.CreateSnapshotOperation(ctx, "overflow", "create", "daily", fingerprint) + var refusal *CatalogError + if created || !errors.As(err, &refusal) || !refusal.Retryable || refusal.Code != "operation_capacity" || refusal.Message != "operation records full: 4096 pending" { + t.Fatalf("4097th pending admission must refuse without a record: created=%v err=%v", created, err) + } + if _, found, err := reopened.ReadSnapshotOperation(ctx, "overflow", "create"); err != nil || found { + t.Fatalf("refused admission persisted: found=%v err=%v", found, err) + } + for _, want := range []SnapshotOperation{first, stalled} { + got, created, err := reopened.CreateSnapshotOperation(ctx, want.ID, want.Verb, want.Name, want.Fingerprint) + if err != nil || created || got.Instance != want.Instance || got.State != want.State || got.Revision != want.Revision { + t.Fatalf("pending retry lost its retained record at capacity: got=%+v want=%+v created=%v err=%v", got, want, created, err) + } + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 0d4a96e5df..9d11feac31 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1291,6 +1291,7 @@ Notes: | `INV-SNAP-OP-RECEIPT-001` | A snapshot operation receipt survives reopening its volume store; changed intent is refused, terminal outcomes are immutable, and a stale owner or revision cannot advance the receipt. | M9 operation receipt | `LayoutStore.CreateSnapshotOperation`, `AdvanceSnapshotOperation` (create coupling and process-owned executor wired; retirement pending) | `TestSnapshotOperationReceiptSurvivesReopenAndRejectsChangedIntent`, `TestSnapshotOperationStallReadmissionFencesOldOwner`, `TestSnapshotOperationSplitPublishReadmissionSettlesOneBinding` | SnapOps run3 rows 211–219; split-publication model result and retirement owed | STUB | | `INV-SNAP-OP-TERMINAL-WRITERS-001` | Snapshot operation success settles a HEAD binding. A terminal refusal is a HEAD conflict checked before provider execution; a provider error can only stall or leave the receipt unchanged. | M9 operation terminal outcome | `LayoutStore.SettleSnapshotOperationFromHead`, `chunkControl.snapshotOperationAttempt` | `TestSnapshotOperationTerminalWriterEnumeration`, `TestSnapshotOperationAppliedAnswerFailureNeverBecomesRefused`, `TestSnapshotOperationFencedFailurePreservesPublishedBinding` | SnapOps run3 row 218; split-publication refinement pending | STUB | | `INV-SNAP-OP-WORKER-001` | A synchronous retry of an in-flight operation reads its receipt and replays a terminal outcome or refuses retryably, without starting another provider attempt. Changed intent still refuses before work. | M9 operation executor | `chunkControl.Snapshot`, `snapshotOperationInFlight`, process-local `opJobs` | `TestSnapshotOperationSynchronousRetryDoesNotDuplicateAsyncWorker` | SnapOps.Start; complete executor qualification pending | STUB | +| `INV-SNAP-OP-CAPACITY-001` | At 4096 nonterminal receipts, new snapshot-operation admission refuses retryably without a record; retained accepted and stalled operations still replay after reopening. | M9 operation admission (planned) | `LayoutStore.CreateSnapshotOperation` (durable capacity implementation pending) | `TestSnapshotOperationRetirementFullPendingRefusesWithoutLosingReceipt` | SnapOps total-record bound; pending-never-retires control (red) | STUB | | `INV-SNAP-OP-ORIGINAL-001` | Within the retained operation window, retrying a snapshot create returns its original outcome after control, catalog or retention removal, and after name reuse; it performs no new cut or HEAD write. | M9 operation replay (planned) | `chunkControl.Snapshot`, shared HEAD/receipt guard and process-owned executor; retirement pending | `TestSnapshotOperationRetryAfterRemovalKeepsOriginalOutcome`, `TestSnapshotOperationOldIDDoesNotAliasReusedName` (`core/host/volume/snapshot_operation_red_test.go`) | SnapOps.Send/Publish/Delete; rows 211–219 (first red tranche only) | STUB | | `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 wired; retirement 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 |