diff --git a/seaweed-block/core/frontend/chunkstore/layout/delete_intent.go b/seaweed-block/core/frontend/chunkstore/layout/delete_intent.go index ab9b40111f..a4dce5affe 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/delete_intent.go +++ b/seaweed-block/core/frontend/chunkstore/layout/delete_intent.go @@ -79,7 +79,7 @@ func adoptDeleteIntentPage(ctx context.Context, st ListChainStore, volume Volume if err != nil { return err } - writer := fmt.Sprintf("delete-intent/%d/%s", base, ref.Hash) + writer := deleteIntentWriter(base, ref) for round := 0; round < maxEnsureRounds; round++ { meta, found, err := st.Stat(ctx, rel) if err != nil { @@ -116,6 +116,12 @@ func adoptDeleteIntentPage(ctx context.Context, st ListChainStore, volume Volume return fmt.Errorf("%w: delete intent page kept moving during adoption", ErrPrecondition) } +func deleteIntentWriter(base uint64, ref ListRef) string { + // The page hash binds its producer, generation and bytes. The CAS base + // makes the protection tag fresh when that stable page is re-adopted. + return fmt.Sprintf("delete-intent/%d/%s", base, ref.Hash) +} + // RunDeleteSnapshotWithIntent removes a retained incarnation and publishes // its independently resumable reclamation intent in ONE HEAD CAS. Receipt // retirement is not an input to this transition or to the intent consumer. @@ -148,7 +154,18 @@ func RunDeleteSnapshotWithIntent(ctx context.Context, st ListChainStore, base ui for _, rel := range p.Entries { hasRoot = hasRoot || rel == root } - return adoptDeleteIntentPage(ctx, st, h.VolumeID, base, ref) + if err := adoptDeleteIntentPage(ctx, st, h.VolumeID, base, ref); err != nil { + return err + } + rel, _ := ref.Path() + meta, found, err := st.Stat(ctx, rel) + if err != nil { + return err + } + if !found || meta.Volume != h.VolumeID || meta.Session != deleteIntentWriter(base, ref) || meta.Mark != "" { + return ErrPrecondition + } + return nil }); err != nil { return Head{}, false, err } diff --git a/seaweed-block/core/frontend/chunkstore/layout/delete_intent_test.go b/seaweed-block/core/frontend/chunkstore/layout/delete_intent_test.go index 35c7a3196c..2090fc58d3 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/delete_intent_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout/delete_intent_test.go @@ -521,3 +521,39 @@ func TestDeleteIntentStagingNeverRevertsPublishedTags(t *testing.T) { t.Fatal("restaging undid publication protection") } } + +type changedAfterIntentAdoption struct { + *chainStore + change string +} + +func (s *changedAfterIntentAdoption) Reuse(ctx context.Context, rel string, meta ObjectMeta, writer string) error { + if err := s.chainStore.Reuse(ctx, rel, meta, writer); err != nil { + return err + } + switch s.change { + case "missing": + delete(s.objs, s.full(rel)) + case "writer": + s.objs[s.full(rel)].meta.Session = "other-attempt" + case "marked": + s.objs[s.full(rel)].meta.Mark = "interference" + } + return nil +} + +func TestDeleteIntentPublicationChecksAdoptedPageMetadata(t *testing.T) { + for _, change := range []string{"missing", "writer", "marked"} { + t.Run(change, func(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + if _, err := StageSnapshotDeletePage(ctx, s, s.h.Gen, p); err != nil { + t.Fatal(err) + } + changed := &changedAfterIntentAdoption{chainStore: s, change: change} + if _, err := RunDeleteSnapshotWithIntent(ctx, changed, s.h.Gen, c); !errors.Is(err, ErrPrecondition) || s.updates != 0 || s.h.Snapshots["daily"].Gen != 4 { + t.Fatalf("published without this attempt's unmarked page: %v", err) + } + }) + } +} diff --git a/seaweed-block/docs/design/immutable-list-pages.md b/seaweed-block/docs/design/immutable-list-pages.md index 527ad031af..49584c3d04 100644 --- a/seaweed-block/docs/design/immutable-list-pages.md +++ b/seaweed-block/docs/design/immutable-list-pages.md @@ -135,7 +135,11 @@ page bytes and the original target. Before publication, every page is conditionally adopted with a writer tag specific to its page hash and current CAS base, clearing old removal marks. This metadata update invalidates both a delayed Mark planned at an earlier base and a delayed DeleteMarked from that -cleaning. Admission of a new request against an absent +cleaning. The publishing transition then explicitly checks every page is +present, belongs to the full volume ID, carries this attempt's writer tag and +has no removal mark; a failed check refuses the HEAD write. The page hash in +that tag binds its immutable producer/generation, and the CAS base makes it +fresh for a refreshed attempt. Admission of a new request against an absent name and receipt ownership remain catalog responsibilities. The unlink and intent publication are one HEAD write. Losing its reply cannot @@ -163,8 +167,10 @@ publication, page retirement uses current-chain reachability as before. Missing pages and unfinished effects never advance the intent. A same-name replacement is preserved both by the retained target and by current live-root checks. -PageChain rows 246-253 cover publication and effect/cursor ordering; SnapDelete -241-245 cover incarnation identity. The offline consumer refinement and its +StaleClean rows 159-161 cover conditional adoption and stale removal (including +the no-metadata-change Reuse mutant); PageChain rows 246-253 cover publication +and effect/cursor ordering; SnapDelete 241-245 cover incarnation identity. +The offline consumer refinement and its new authority branch require exact-head model/code review before activation. No product delete driver calls this seam yet. The one-slot admission capacity, remaining producer wiring and Linux/race qualification remain outstanding. diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index c622824e9a..a1e0a0160c 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -583,7 +583,7 @@ stateDiagram-v2 | snap(s), list slot empty | snap(s), list cursor published | same full holder, open session and original base generation; every referenced page durable and authenticated; unknown reply retains session and pages | `list_chain.go` `StageListPage`, `RunPublishList` | `INV-LIST-PUBLISH-001` | | clean(c), current list page | clean(c), next continuation or none | exact observed cursor CAS only after authenticated page effects succeed; failed reads and failed effects leave cursor unchanged | `list_chain.go` `RunAdvanceList` | `INV-LIST-CURSOR-001` | | clean(c), stored list page | clean(c), unreached page removed | tags before HEAD; current clean session; spare all current-chain pages; conditional mark then delete | `remove.go` `Cleaner.Page` | `INV-LIST-RETIRE-001` | -| idle/snap, retained snapshot | same activity, row removed and intent published | one CAS removes only the captured name/gen and names its durable candidate chain; clean activity refuses | `delete_intent.go` `RunDeleteSnapshotWithIntent` | `INV-SNAPSHOT-DELETE-INTENT-001` | +| idle/snap, retained snapshot | same activity, row removed and intent published | one CAS removes only captured name/gen and names its durable chain; each page present, this attempt's tag, unmarked; clean activity refuses | `delete_intent.go` `RunDeleteSnapshotWithIntent` | `INV-SNAPSHOT-DELETE-INTENT-001`, `INV-SNAPSHOT-DELETE-ADOPT-001` | | idle live/detached, persisted delete intent | idle live/detached, next intent page or none | receipt-independent continuation from current HEAD; live-root and conditional effect guards; cursor follows completed effects | `delete_intent.go` `RunConsumeSnapshotDeleteIntent` | `INV-SNAPSHOT-DELETE-CONSUME-001` | | idle | snap(s) | caller is the holder at HEAD's epoch (epoch, server and claim id); HEAD present; snap(s) again is a replay, any other activity is refused | head.go `Head.Begin`, `runTransition` | `INV-SNAPK-HEAD-WRITE-001`, `INV-SNAPK-BEGIN-001` | | snap(s) | idle | holder at HEAD's epoch (epoch, server and claim id); activity is snap(s); over idle it succeeds without a write and means only that no activity remains; before resuming a failed stop, abort its still-open session and re-read HEAD: only matching live/idle resumes, detached goes Down, absent/unknown stays stopped | head.go `Head.Abort`; durable/provider_layout.go `settleLayoutStop` | `INV-SNAPK-ABORT-001` | @@ -1280,7 +1280,7 @@ Notes: | `INV-LIST-RETIRE-001` | List-page removal requires a clean session and the existing conditional mark/delete order; every page reached by HEAD is spared, including shared tails. | M9 clean removal | `remove.go` `Cleaner.removePlanned` | `TestListSweepSpareSessionAndReachableTail`, `TestListSharedTailSurvivesAbandonedChainAndResumes`, `TestLayoutStoreListPublishConsumeAndRetire` | PageChain 246,248-251; NoDangling | DORMANT | | `INV-SNAPSHOT-DELETE-INTENT-001` | Removing a captured snapshot incarnation and publishing its durable intent are one HEAD CAS; an unrelated metadata retry keeps the same target and durable pages. | M9 metadata delete | `delete_intent.go` `RunDeleteSnapshotWithIntent` | `TestDeleteSnapshotWithIntent_Closure`, `TestRunDeleteSnapshotWithIntent_InterruptAtEveryStep`, `TestDeleteIntentRetryKeepsDurablePagesAcrossMetadataCAS` | SnapDelete 241-245; PageChain 246-249 | DORMANT | | `INV-SNAPSHOT-DELETE-CONSUME-001` | Only current persisted delete intent authorizes offline reclamation; live roots remain protected, failed effects retain the cursor, and receipt retirement cannot erase work. | M9 idle intent continuation | `delete_intent.go`; `remove.go` `Cleaner.removePlanned` | `TestConsumeSnapshotDeleteIntent_Closure`, `TestDeleteIntentOfflineAndReplacementPreserved`, `TestDeleteIntentMarkConflictKeepsUnfinishedPage`, `TestLayoutSnapshotDeleteIntentResumesWithoutReceipt` | PageChain 246,251-253; offline authority refinement awaits model/code read | DORMANT | -| `INV-SNAPSHOT-DELETE-ADOPT-001` | Publication adopts every intent page with a CAS-base-specific tag after Stat and HEAD validation; stale cleaners and adopters cannot remove or retag a newly published page, and staging never restores old tags. | M9 delete intent publication | `delete_intent.go` `adoptDeleteIntentPage`, `StageSnapshotDeletePage` | `TestDeleteIntentRefreshedBaseFencesDelayedCleanerMark`, `TestDeleteIntentRefreshedBaseFencesDelayedCleanerDelete`, `TestDeleteIntentAdoptionCannotRestoreStaleTags`, `TestDeleteIntentStagingNeverRevertsPublishedTags` | PageChain NoDangling; conditional object adoption refinement awaits model/code read | DORMANT | +| `INV-SNAPSHOT-DELETE-ADOPT-001` | Publication adopts every intent page with a fresh CAS-base tag and checks it is present, this attempt's and unmarked; stale cleaners/adopters cannot remove or retag a published page, and staging never restores old tags. | M9 delete intent publication | `delete_intent.go` `adoptDeleteIntentPage`, `RunDeleteSnapshotWithIntent`, `StageSnapshotDeletePage` | `TestDeleteIntentRefreshedBaseFencesDelayedCleanerMark`, `TestDeleteIntentRefreshedBaseFencesDelayedCleanerDelete`, `TestDeleteIntentAdoptionCannotRestoreStaleTags`, `TestDeleteIntentStagingNeverRevertsPublishedTags`, `TestDeleteIntentPublicationChecksAdoptedPageMetadata` | StaleClean 159-161; exact-head refinement read required | DORMANT | The routine full-sweep scope of `INV-SNAPK-REMOVE-MARK-001` is explicit here: its holder/session guard and all existing controls remain unchanged. The new diff --git a/seaweed-block/docs/spec/pagechain/model-code-trace.tsv b/seaweed-block/docs/spec/pagechain/model-code-trace.tsv index 87c0ad27b9..456ab5a07e 100644 --- a/seaweed-block/docs/spec/pagechain/model-code-trace.tsv +++ b/seaweed-block/docs/spec/pagechain/model-code-trace.tsv @@ -10,4 +10,4 @@ row model transition code control 246 PageChain WritePage Send Deliver layout/delete_intent.go StageSnapshotDeletePage RunDeleteSnapshotWithIntent TestDeleteSnapshotWithIntent_Closure; TestRunDeleteSnapshotWithIntent_InterruptAtEveryStep; TestDeleteIntentPublicationIsFencedBeforeAnOrdinarySweep 252 PageChain CApply CAdvance layout/delete_intent.go RunConsumeSnapshotDeleteIntent; layout/remove.go TestDeleteIntentMarkConflictKeepsUnfinishedPage; TestRunConsumeSnapshotDeleteIntent_InterruptAtEveryStep; TestLayoutSnapshotDeleteIntentResumesWithoutReceipt 253 PageChain CRead layout/delete_intent.go RunConsumeSnapshotDeleteIntent TestDeleteIntentMissingPageAndRootRefuseBeforeUnlinkOrEffects -246 PageChain NoDangling (conditional object adoption refinement) layout/delete_intent.go adoptDeleteIntentPage TestDeleteIntentRefreshedBaseFencesDelayedCleanerMark; TestDeleteIntentAdoptionCannotRestoreStaleTags; TestDeleteIntentStagingNeverRevertsPublishedTags +159-161 StaleClean conditional adoption and stale removals (separate from PageChain Sweep) layout/delete_intent.go adoptDeleteIntentPage RunDeleteSnapshotWithIntent TestDeleteIntentRefreshedBaseFencesDelayedCleanerMark; TestDeleteIntentRefreshedBaseFencesDelayedCleanerDelete; TestDeleteIntentAdoptionCannotRestoreStaleTags; TestDeleteIntentStagingNeverRevertsPublishedTags; TestDeleteIntentPublicationChecksAdoptedPageMetadata