diff --git a/seaweed-block/core/frontend/chunkstore/head_readers_test.go b/seaweed-block/core/frontend/chunkstore/head_readers_test.go index cd778df244..433d02afba 100644 --- a/seaweed-block/core/frontend/chunkstore/head_readers_test.go +++ b/seaweed-block/core/frontend/chunkstore/head_readers_test.go @@ -24,6 +24,10 @@ import ( // pins it. "GAP" marks a reader that takes an absent HEAD for an empty // one; a change that treats an absent HEAD as unknown flips those probes. var headReaders = map[string]string{ + "core/frontend/chunkstore/layout/delete_intent.go StageSnapshotDeletePage -> ReadHead": "refuses ErrHeadAbsent before staging (probe TestLayoutDeleteIntentAbsentHEAD)", + "core/frontend/chunkstore/layout/delete_intent.go RunDeleteSnapshotWithIntent -> ReadHead": "absence cannot settle unknown unlink (probe TestLayoutDeleteIntentAbsentHEAD and TestRunDeleteSnapshotWithIntent_InterruptAtEveryStep)", + "core/frontend/chunkstore/layout/delete_intent.go RunConsumeSnapshotDeleteIntent -> ReadHead": "absence never confirms a cursor update (probe TestLayoutDeleteIntentAbsentHEAD and TestRunConsumeSnapshotDeleteIntent_InterruptAtEveryStep)", + "core/frontend/chunkstore/layout/list_chain.go StageListPage -> ReadHead": "refuses ErrHeadAbsent before any object write (probe TestLayoutListAbsentHEAD)", "core/frontend/chunkstore/layout/list_chain.go RunPublishList -> ReadHead": "settlement absence preserves original error, never abandons pages (probe TestLayoutListAbsentHEAD and TestRunPublishList_InterruptAtEveryStep)", "core/frontend/chunkstore/layout/list_chain.go RunAdvanceList -> ReadHead": "settlement absence never confirms progress (probe TestLayoutListAbsentHEAD and TestRunAdvanceList_InterruptAtEveryStep)", diff --git a/seaweed-block/core/frontend/chunkstore/layout/delete_intent.go b/seaweed-block/core/frontend/chunkstore/layout/delete_intent.go new file mode 100644 index 0000000000..71240bfbb4 --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/layout/delete_intent.go @@ -0,0 +1,209 @@ +package layout + +import ( + "context" + "fmt" + "path" + "strings" +) + +// deleteIntentWindow is a metadata operation, including on a detached volume. +// No new holder is claimed. An idle/snap -> clean transition changes HEAD's +// generation, fencing every outstanding publication at the original base. +func deleteIntentWindow(h Head, base uint64) error { + if h.State != StateLive && h.State != StateDetached { + return ErrVolumeDeleting + } + if h.Activity.Kind == ActClean { + return ErrBusy + } + if h.Gen != base || base == ^uint64(0) { + return ErrPrecondition + } + return nil +} + +// StageSnapshotDeletePage stages immutable intent metadata without a holder +// lease or a receipt dependency. A cleaner cannot act in this same HEAD +// generation: starting one fences the publishing CAS. A write that finishes +// after that fence is merely an orphan; it cannot later authorize an unlink. +// The page generation identifies the stable attempt, independently of base; +// retries after unrelated metadata CASes reuse these same durable bytes. +func StageSnapshotDeletePage(ctx context.Context, st ListChainStore, base uint64, p ListPage) (ListRef, error) { + if p.Kind != ListSnapshotDeleteIntent { + return ListRef{}, ErrIdentity + } + raw, err := p.Encode() + if err != nil { + return ListRef{}, err + } + h, found, err := st.ReadHead(ctx) + if err != nil { + return ListRef{}, err + } + if !found { + return ListRef{}, ErrHeadAbsent + } + if err := deleteIntentWindow(h, base); err != nil { + return ListRef{}, err + } + if p.VolumeID != h.VolumeID { + return ListRef{}, ErrIdentity + } + ref, _ := p.Ref() + rel, _ := ref.Path() + if err := EnsureObject(ctx, st, rel, raw, p.Producer); err != nil { + return ListRef{}, err + } + return ref, nil +} + +// 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. +// Initial-absence admission remains the catalog's responsibility; this API +// receives the already captured (name, gen), never re-resolves a replacement. +func RunDeleteSnapshotWithIntent(ctx context.Context, st ListChainStore, base uint64, c ListCursor) (Head, error) { + if c.Kind != ListSnapshotDeleteIntent { + return Head{}, ErrIdentity + } + if err := c.check(); err != nil { + return Head{}, err + } + c = *c.clone() + h, err := runTransition(ctx, st, CauseSnapshotDeleteIntent, func(h Head) (Head, bool, error) { + next, changed, err := h.DeleteSnapshotAt(c.Target.Name, c.Target.Gen) + if err != nil || !changed { + return next, changed, err + } + if err := deleteIntentWindow(h, base); err != nil { + return Head{}, false, err + } + if h.List != nil { + return Head{}, false, ErrBusy + } + // The intent must retain the removed root, not just an operation id. + // Its complete candidate plan is authenticated before publication. + root := h.Snapshots[c.Target.Name].Root.Path() + hasRoot := false + if err := ReadListChain(ctx, st, h.VolumeID, c, func(_ ListRef, p ListPage) error { + for _, rel := range p.Entries { + hasRoot = hasRoot || rel == root + } + return nil + }); err != nil { + return Head{}, false, err + } + if !hasRoot { + return Head{}, false, fmt.Errorf("%w: delete intent omits its snapshot root", ErrMalformed) + } + next, _, err = next.StampSnapshotGenerations() + if err != nil { + return Head{}, false, err + } + next.List = c.clone() + return next, true, nil + }) + if err == nil { + return h, nil + } + // A lost reply can be settled even after the intent finished: the retained + // incarnation is gone/replaced. Never resolve that name to a new target. + observed, found, readErr := st.ReadHead(ctx) + if readErr == nil && found { + if _, changed, checkErr := observed.DeleteSnapshotAt(c.Target.Name, c.Target.Gen); checkErr == nil && !changed { + return observed, nil + } + } + return Head{}, err +} + +// pendingDeleteIntent grants continuation from the CURRENT persisted intent, +// independent of receipt lifetime, process/host and holder epoch. It never +// authorizes a namespace delete, a second snapshot unlink, or deleting live +// data. Open activity excludes intent effects; late writes retain the existing +// tag -> HEAD -> conditional mark/delete protection against a subsequent cut. +func pendingDeleteIntent(h Head, expected *ListCursor) error { + if h.State != StateLive && h.State != StateDetached { + return ErrVolumeDeleting + } + if h.Activity.Kind != ActIdle { + return ErrBusy + } + if expected == nil || expected.Kind != ListSnapshotDeleteIntent || !sameList(h.List, expected) { + return ErrPrecondition + } + return expected.check() +} + +// RunConsumeSnapshotDeleteIntent resumes one physical reclamation page solely +// from HEAD + immutable pages. The old receipt need not exist. Like other +// metadata operations it works offline; it does not claim a volume or take +// over guest writes. Every object still passes the normal live-root and +// conditional removal checks in Cleaner.removePlanned. +func RunConsumeSnapshotDeleteIntent(ctx context.Context, st ListChainStore, r *Reader) (Head, error) { + var after *ListCursor + attempted := false + h, err := runTransition(ctx, st, CauseListAdvance, func(h Head) (Head, bool, error) { + if h.List == nil { + return h, false, nil + } + before := h.List.clone() + if err := pendingDeleteIntent(h, before); err != nil { + return Head{}, false, err + } + if h.Gen == ^uint64(0) { + return Head{}, false, ErrPrecondition + } + p, err := readListPage(ctx, st, h.VolumeID, *before) + if err != nil { + return Head{}, false, err + } + if p.Next != nil { + after = before.clone() + after.Ref = *p.Next + } + cleaner := &Cleaner{st: st, os: st, r: r, session: "intent-" + before.Ref.Hash, tagParallel: 32, intent: before} + if err := cleaner.applyIntentPage(ctx, p); err != nil { + return Head{}, false, err + } + next := h.clone() + next.List = after + attempted = true + return next, true, nil + }) + if err == nil { + return h, nil + } + if attempted { + observed, found, readErr := st.ReadHead(ctx) + if readErr == nil && found && sameList(observed.List, after) && (observed.State == StateLive || observed.State == StateDetached) { + return observed, nil + } + } + return Head{}, err +} + +func (c *Cleaner) applyIntentPage(ctx context.Context, p ListPage) error { + // One bounded page, metadata first. Candidate membership is not liveness. + for _, kind := range []string{RootDir, SegDir, PoolDir} { + for _, rel := range p.Entries { + if !strings.HasPrefix(rel, kind+"/") { + continue + } + name := path.Base(rel) + var shard uint64 + if kind == PoolDir { + n, err := ParseChunkName(name) + if err != nil { + return err + } + shard = Shard(n.Index) + } + if _, err := c.Page(ctx, kind, shard, []string{name}); err != nil { + return err + } + } + } + return nil +} diff --git a/seaweed-block/core/frontend/chunkstore/layout/delete_intent_test.go b/seaweed-block/core/frontend/chunkstore/layout/delete_intent_test.go new file mode 100644 index 0000000000..69bcda6b4e --- /dev/null +++ b/seaweed-block/core/frontend/chunkstore/layout/delete_intent_test.go @@ -0,0 +1,371 @@ +package layout + +import ( + "context" + "errors" + "sort" + "testing" +) + +func deleteIntentFixture(t *testing.T) (*chainStore, ListCursor, ListPage) { + t.Helper() + s, _, _ := chainFixture(t) + s.h.Activity = Activity{Kind: ActIdle} + s.h.Current = nil + raw := []byte("old payload") + n := NameChunk(1, raw) + root, segs, err := Build(map[uint64]Ref{1: {Owner: "v1", OwnerID: s.volume, Chunk: n}}) + if err != nil { + t.Fatal(err) + } + rn, rb, err := NameRoot(root) + if err != nil { + t.Fatal(err) + } + s.put(n.Path(), raw, "old") + entries := []string{n.Path(), rn.Path()} + for sn, data := range segs { + s.put(sn.Path(), data, "old") + entries = append(entries, sn.Path()) + } + s.put(rn.Path(), rb, "old") + s.h.Snapshots = map[string]Snapshot{"daily": {Root: rn, Gen: 4}} + sort.Strings(entries) + p := ListPage{VolumeID: s.volume, Kind: ListSnapshotDeleteIntent, Producer: "delete-1", Generation: s.h.Gen + 1, Pages: 1, Target: &SnapshotTarget{Name: "daily", Gen: 4}, Entries: entries} + ref, err := p.Ref() + if err != nil { + t.Fatal(err) + } + c := ListCursor{Ref: ref, Kind: p.Kind, Producer: p.Producer, Generation: p.Generation, Target: p.Target} + return s, c, p +} + +func TestDeleteSnapshotWithIntent_Closure(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + base := s.h.Gen + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); !errors.Is(err, ErrListPageMissing) || s.updates != 0 { + t.Fatalf("unname without durable intent: %v", err) + } + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + h, err := RunDeleteSnapshotWithIntent(ctx, s, base, c) + if err != nil || h.Snapshots["daily"].Gen != 0 || !sameList(h.List, &c) || s.updates != 1 { + t.Fatalf("not one unlink+intent CAS: %+v writes%d %v", h, s.updates, err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil || s.updates != 1 { + t.Fatalf("replay: %v", err) + } +} + +func deleteIntentReader(t *testing.T, s *chainStore) *Reader { + t.Helper() + v := Volume{ID: s.volume, Name: "v1", Geometry: tableGeometry, Format: VolumeFormat} + raw, err := v.Encode() + if err != nil { + t.Fatal(err) + } + s.put(VolumeName, raw, "volume") + r, err := NewReader("/swblock/chunks", "v1", s.fetch) + if err != nil { + t.Fatal(err) + } + return r +} + +func TestConsumeSnapshotDeleteIntent_Closure(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + r := deleteIntentReader(t, s) + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + // Only durable HEAD/pages and the store remain. No receipt, owner token, + // holder identity, original CLI or process memory is supplied to resume. + h, err := RunConsumeSnapshotDeleteIntent(ctx, s, r) + if err != nil || h.List != nil { + t.Fatalf("resume: %+v %v", h.List, err) + } + for _, rel := range p.Entries { + if _, found, _ := s.Stat(ctx, rel); found { + t.Fatalf("unfinished physical work %s", rel) + } + } + if _, found, _ := s.ReadListPage(ctx, c.Ref); !found { + t.Fatal("consumer retired its own page before cursor settlement") + } +} + +func TestRunDeleteSnapshotWithIntent_InterruptAtEveryStep(t *testing.T) { + for _, after := range []bool{false, true} { + t.Run(map[bool]string{false: "before", true: "lost-reply"}[after], func(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + s.memHead.killAt, s.memHead.after = 1, after + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); !errors.Is(err, errKilled) { + t.Fatal(err) + } + _, row := s.h.Snapshots["daily"] + if row == after || (s.h.List != nil) != after { + t.Fatalf("torn row/intent: row%v intent%v", row, s.h.List != nil) + } + s.memHead.dead, s.memHead.killAt = false, 0 + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + }) + } +} + +func TestRunConsumeSnapshotDeleteIntent_InterruptAtEveryStep(t *testing.T) { + for _, after := range []bool{false, true} { + t.Run(map[bool]string{false: "before", true: "lost-reply"}[after], func(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + r := deleteIntentReader(t, s) + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + s.memHead.killAt, s.memHead.after = s.updates+1, after + if _, err := RunConsumeSnapshotDeleteIntent(ctx, s, r); !errors.Is(err, errKilled) { + t.Fatal(err) + } + if _, found, _ := s.ReadListPage(ctx, c.Ref); !found { + t.Fatal("intent page retired on unknown cursor") + } + s.memHead.dead, s.memHead.killAt = false, 0 + if h, err := RunConsumeSnapshotDeleteIntent(ctx, s, r); err != nil || h.List != nil { + t.Fatalf("resume: %+v %v", h.List, err) + } + }) + } +} + +func TestDeleteIntentOfflineAndReplacementPreserved(t *testing.T) { + for _, detached := range []bool{false, true} { + t.Run(map[bool]string{false: "same-name-replacement", true: "detached-no-holder-claim"}[detached], func(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + r := deleteIntentReader(t, s) + oldRoot := s.h.Snapshots["daily"].Root + if detached { + empty, _, _ := Build(nil) + rn, raw, _ := NameRoot(empty) + s.put(rn.Path(), raw, "current") + s.h.Current, s.h.State = &rn, StateDetached + } + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + if !detached { + next := s.h.clone() + next.Snapshots["daily"] = Snapshot{Root: oldRoot, Gen: next.Gen + 1} + if err := s.UpdateHead(ctx, s.h.Gen, next, CauseSnapshotUnchanged); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + } + h, err := RunConsumeSnapshotDeleteIntent(ctx, s, r) + if err != nil || h.List != nil { + t.Fatalf("consume: %v", err) + } + if detached { + if h.State != StateDetached || h.Epoch != me.Epoch || h.Holder != me.Holder { + t.Fatal("intent claimed ownership") + } + } else { + if h.Snapshots["daily"].Gen != base+2 { + t.Fatal("replacement incarnation changed") + } + for _, rel := range p.Entries { + if _, found, _ := s.Stat(ctx, rel); !found { + t.Fatalf("replacement lost %s", rel) + } + } + } + }) + } +} + +type intentMarkConflict struct { + *chainStore + conflicted bool +} + +func (s *intentMarkConflict) Mark(ctx context.Context, rel string, expect ObjectMeta, mark string) error { + if !s.conflicted { + s.conflicted = true + if err := s.chainStore.Mark(ctx, rel, expect, "other-executor"); err != nil { + return err + } + return ErrPrecondition + } + return s.chainStore.Mark(ctx, rel, expect, mark) +} + +func TestDeleteIntentMarkConflictKeepsUnfinishedPage(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + r := deleteIntentReader(t, s) + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + contended := &intentMarkConflict{chainStore: s} + if _, err := RunConsumeSnapshotDeleteIntent(ctx, contended, r); !errors.Is(err, ErrPrecondition) || !sameList(s.h.List, &c) { + t.Fatalf("unfinished mark advanced: %v", err) + } + if h, err := RunConsumeSnapshotDeleteIntent(ctx, contended, r); err != nil || h.List != nil { + t.Fatalf("retry: %v", err) + } +} + +func TestDeleteIntentMissingPageAndRootRefuseBeforeUnlinkOrEffects(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + r := deleteIntentReader(t, s) + base := s.h.Gen + p.Entries = p.Entries[:1] // a chunk, deliberately omit the captured root + ref, err := StageSnapshotDeletePage(ctx, s, base, p) + if err != nil { + t.Fatal(err) + } + bad := *c.clone() + bad.Ref = ref + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, bad); !errors.Is(err, ErrMalformed) || s.updates != 0 { + t.Fatalf("incomplete identity unlinked: %v", err) + } + _, c, p = deleteIntentFixture(t) // same fixed target/context; restore complete plan + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + rel, _ := c.Ref.Path() + delete(s.objs, s.full(rel)) + writes := len(s.writes) + updates := s.updates + if _, err := RunConsumeSnapshotDeleteIntent(ctx, s, r); !errors.Is(err, ErrListPageMissing) || len(s.writes) != writes || s.updates != updates { + t.Fatalf("missing page executed: %v", err) + } +} + +func TestDeleteIntentRetryKeepsDurablePagesAcrossMetadataCAS(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + writes := len(s.writes) + // An unrelated metadata write changes the CAS base, not this captured + // operation/target or its durable page bytes. + next := s.h.clone() + if err := s.UpdateHead(ctx, base, next, CauseDependentRelease); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); !errors.Is(err, ErrPrecondition) { + t.Fatalf("old base: %v", err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, s.h.Gen, c); err != nil { + t.Fatalf("retry reminted/rejected durable intent: %v", err) + } + if len(s.writes) != writes || !sameList(s.h.List, &c) { + t.Fatal("retry rewrote durable pages") + } +} + +func TestDeleteIntentCannotUseGenericListTransitions(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + if _, err := RunPublishList(ctx, s, me, c.Producer, base, c); !errors.Is(err, ErrIdentity) || s.updates != 0 { + t.Fatalf("generic publication admitted delete intent: %v", err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + if _, err := RunBeginClean(ctx, s, me, "generic"); err != nil { + t.Fatal(err) + } + called := false + if _, err := RunAdvanceList(ctx, s, me, "generic", func(context.Context, ListPage) error { called = true; return nil }); !errors.Is(err, ErrIdentity) || called || !sameList(s.h.List, &c) { + t.Fatalf("generic executor consumed delete intent: %v", err) + } +} + +func TestDeleteIntentOpenActivityRefusesEffects(t *testing.T) { + for _, activity := range []Activity{{Kind: ActSnap, Session: "cut"}, {Kind: ActClean, Session: "clean"}} { + t.Run(string(activity.Kind), func(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + r := deleteIntentReader(t, s) + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); err != nil { + t.Fatal(err) + } + s.h.Activity = activity + writes, updates := len(s.writes), s.updates + if _, err := RunConsumeSnapshotDeleteIntent(ctx, s, r); !errors.Is(err, ErrBusy) || len(s.writes) != writes || s.updates != updates || !sameList(s.h.List, &c) { + t.Fatalf("active work allowed reclamation: %v", err) + } + }) + } +} + +func TestDeleteIntentPublicationIsFencedBeforeAnOrdinarySweep(t *testing.T) { + s, c, p := deleteIntentFixture(t) + ctx := context.Background() + base := s.h.Gen + if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil { + t.Fatal(err) + } + // Publication has read durable pages, then stalls before its CAS. A + // cleaning can remove them only after its Begin changed the generation. + s.memHead.hook = func() { + if _, err := RunBeginClean(ctx, s, me, "ordinary"); err != nil { + t.Fatal(err) + } + if out, err := NewCleaner(s, nil, s, me, "ordinary").Page(ctx, ListDir, 0, []string{c.Ref.Hash}); err != nil || len(out.Names) != 1 { + t.Fatalf("sweep: %+v %v", out, err) + } + if _, err := RunEndClean(ctx, s, me, "ordinary", CauseCleanEnd); err != nil { + t.Fatal(err) + } + } + if _, err := RunDeleteSnapshotWithIntent(ctx, s, base, c); !errors.Is(err, ErrPrecondition) { + t.Fatalf("fenced publish landed: %v", err) + } + if s.h.Snapshots["daily"].Gen != 4 || s.h.List != nil { + t.Fatal("row removed after page sweep") + } +} diff --git a/seaweed-block/core/frontend/chunkstore/layout/head-write-census.json b/seaweed-block/core/frontend/chunkstore/layout/head-write-census.json index 993351ae78..790905b08f 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/head-write-census.json +++ b/seaweed-block/core/frontend/chunkstore/layout/head-write-census.json @@ -210,6 +210,15 @@ "may_change": [ "list" ] + }, + { + "cause": "snapshot-delete-intent", + "kind": "update", + "may_change": [ + "version", + "snapshots", + "list" + ] } ] } diff --git a/seaweed-block/core/frontend/chunkstore/layout/head_cause.go b/seaweed-block/core/frontend/chunkstore/layout/head_cause.go index a698f1146e..446ccde311 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/head_cause.go +++ b/seaweed-block/core/frontend/chunkstore/layout/head_cause.go @@ -9,8 +9,9 @@ type HeadWriteCause string // The census rows. A new HEAD writer needs a new row here, in the census // test and in the design's table. const ( - CauseListPublish HeadWriteCause = "list-publish" - CauseListAdvance HeadWriteCause = "list-advance" + CauseListPublish HeadWriteCause = "list-publish" + CauseListAdvance HeadWriteCause = "list-advance" + CauseSnapshotDeleteIntent HeadWriteCause = "snapshot-delete-intent" // CauseCreate: a new volume's or restore target's first HEAD. CauseCreate HeadWriteCause = "create" // CauseClaim: a holder's claim at attach (layout.Start). @@ -55,6 +56,7 @@ const ( // HeadWriteCauses is the census: every cause, in table order. var HeadWriteCauses = []HeadWriteCause{ CauseListPublish, CauseListAdvance, + CauseSnapshotDeleteIntent, CauseCreate, CauseClaim, CauseStartRollbackSnap, CauseStartRollbackClean, CauseSessionBegin, CauseSessionRollback, CauseCommit, CauseSnapshotUnchanged, CauseStopAbort, CauseCleanBegin, CauseCleanEnd, CauseSnapshotRetire, diff --git a/seaweed-block/core/frontend/chunkstore/layout/head_cause_census_test.go b/seaweed-block/core/frontend/chunkstore/layout/head_cause_census_test.go index 8ff51ecce3..c5e34fa17d 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/head_cause_census_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout/head_cause_census_test.go @@ -193,7 +193,8 @@ func causeRebound(body *ast.BlockStmt) string { // causeByName maps each census constant's name to its value. var causeByName = map[string]HeadWriteCause{ - "CauseListPublish": CauseListPublish, "CauseListAdvance": CauseListAdvance, + "CauseSnapshotDeleteIntent": CauseSnapshotDeleteIntent, + "CauseListPublish": CauseListPublish, "CauseListAdvance": CauseListAdvance, "CauseCreate": CauseCreate, "CauseClaim": CauseClaim, "CauseStartRollbackSnap": CauseStartRollbackSnap, "CauseStartRollbackClean": CauseStartRollbackClean, "CauseSessionBegin": CauseSessionBegin, "CauseSessionRollback": CauseSessionRollback, "CauseCommit": CauseCommit, diff --git a/seaweed-block/core/frontend/chunkstore/layout/kernel_table_test.go b/seaweed-block/core/frontend/chunkstore/layout/kernel_table_test.go index bb309b246d..65876b0c37 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/kernel_table_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout/kernel_table_test.go @@ -27,6 +27,7 @@ var kernelStates = []string{"absent", "unclaimed", "idle", "snap", "clean", "det // kernelEntries are the kernel's entry points (DeleteVolume is their // composition: Reserve, MarkDeleting, release, objects, MarkDeleted). var kernelEntries = []string{ + "DeleteSnapshotWithIntent", "ConsumeSnapshotDeleteIntent", "PublishList", "AdvanceList", "CreateVolume", "CreateTarget", "StartHigher", "StartHigherCannotStart", "StartOwn", "StartOwnOtherFresh", "StartOwnOtherFreshCannotStart", "StartOwnOtherOld", "Claim", "Begin", "Commit", "CommitNew", "CommitLower", "Abort", "BeginClean", "EndClean", @@ -132,6 +133,31 @@ func kernelCell(t *testing.T, state, entry string) string { src.memHead.h, src.vol = sh, &vol switch entry { + case "DeleteSnapshotWithIntent", "ConsumeSnapshotDeleteIntent": + cs := &chainStore{memHead: nv.memHead, memObjects: o} + p := ListPage{VolumeID: h.VolumeID, Kind: ListSnapshotDeleteIntent, Producer: "delete-1", Generation: h.Gen + 1, Pages: 1, Target: &SnapshotTarget{Name: "daily", Gen: 4}, Entries: []string{h.Snapshots["daily"].Root.Path()}} + ref, _ := p.Ref() + raw, _ := p.Encode() + rel, _ := ref.Path() + o.put(rel, raw, "delete-1") + cursor := ListCursor{Ref: ref, Kind: p.Kind, Producer: p.Producer, Generation: p.Generation, Target: p.Target} + if nv.memHead.h != nil { + nv.memHead.h.Version = HeadVersion1 + if sn, found := nv.memHead.h.Snapshots["daily"]; found { + sn.Gen = 4 + sn.Dependents = nil + nv.memHead.h.Snapshots["daily"] = sn + } + } + if entry == "DeleteSnapshotWithIntent" { + _, err = RunDeleteSnapshotWithIntent(ctx, cs, h.Gen, cursor) + } else { + if nv.memHead.h != nil { + nv.memHead.h.List = cursor.clone() + delete(nv.memHead.h.Snapshots, "daily") + } + _, err = RunConsumeSnapshotDeleteIntent(ctx, cs, r) + } case "PublishList", "AdvanceList": cs := &chainStore{memHead: nv.memHead, memObjects: o} p := ListPage{VolumeID: h.VolumeID, Kind: ListDrop, Producer: "s1", Generation: h.Gen + 1, Pages: 1, Entries: []string{RootName{Hash: Sum([]byte("page item"))}.Path()}} @@ -274,6 +300,9 @@ func kernelCell(t *testing.T, state, entry string) string { // source) and a claim; an unclaimed HEAD takes only the first claim and // the creates' replays. var kernelExpected = map[string]map[string]string{ + "DeleteSnapshotWithIntent": {"absent": "HeadAbsent", "unclaimed": "noop", "idle": "write", "snap": "write", "clean": "Busy", "detached": "write", "deleting": "VolumeDeleting", "deleted": "VolumeDeleting"}, + "ConsumeSnapshotDeleteIntent": {"absent": "HeadAbsent", "unclaimed": "write", "idle": "write", "snap": "Busy", "clean": "Busy", "detached": "write", "deleting": "VolumeDeleting", "deleted": "VolumeDeleting"}, + "PublishList": {"absent": "HeadAbsent", "unclaimed": "NotHolder", "idle": "NoSession", "snap": "write", "clean": "NoSession", "detached": "Detached", "deleting": "VolumeDeleting", "deleted": "VolumeDeleting"}, "AdvanceList": {"absent": "HeadAbsent", "unclaimed": "NotHolder", "idle": "NoSession", "snap": "NoSession", "clean": "write", "detached": "Detached", "deleting": "VolumeDeleting", "deleted": "VolumeDeleting"}, "CreateVolume": {"absent": "write", "unclaimed": "noop", "idle": "noop", "snap": "noop", "clean": "noop", "detached": "noop", "deleting": "VolumeDeleting", "deleted": "VolumeDeleting"}, @@ -331,6 +360,7 @@ func TestKernelTable(t *testing.T) { // kernelEntryFuncs maps each table row to the exported function it calls; // kernelComposed are exported entry points that only compose the rows. var kernelEntryFuncs = map[string]string{ + "DeleteSnapshotWithIntent": "RunDeleteSnapshotWithIntent", "ConsumeSnapshotDeleteIntent": "RunConsumeSnapshotDeleteIntent", "PublishList": "RunPublishList", "AdvanceList": "RunAdvanceList", "CreateVolume": "CreateVolume", "CreateTarget": "CreateTarget", "StartHigher": "Start", "StartOwn": "Start", "StartOwnOtherFresh": "Start", "StartOwnOtherOld": "Start", "StartHigherCannotStart": "Start", "StartOwnOtherFreshCannotStart": "Start", "Claim": "RunClaim", diff --git a/seaweed-block/core/frontend/chunkstore/layout/list_chain.go b/seaweed-block/core/frontend/chunkstore/layout/list_chain.go index 7cb258682b..74ef01a072 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/list_chain.go +++ b/seaweed-block/core/frontend/chunkstore/layout/list_chain.go @@ -38,8 +38,10 @@ func sameList(a, b *ListCursor) bool { a.Kind == b.Kind && a.Producer == b.Producer && a.Generation == b.Generation && sameTarget(a.Target, b.Target) } -// ListPageReader must bound allocation to MaxListPageBytes before returning. -// Missing is distinct from an empty, successfully completed chain. +// ListPageReader preflights declared size and rejects returned bytes above +// MaxListPageBytes. The blob adapter trusts its backend for allocation during +// GET; this interface does not promise a capped streaming read. Missing is +// distinct from an empty, successfully completed chain. type ListPageReader interface { ReadListPage(context.Context, ListRef) ([]byte, bool, error) } @@ -142,6 +144,9 @@ func StageListPage(ctx context.Context, st ListChainStore, me HolderID, session // function never abandons a session, removes pages, or turns absence at the // original generation into proof that an outstanding CAS cannot land. func RunPublishList(ctx context.Context, st ListChainStore, me HolderID, session string, base uint64, c ListCursor) (Head, error) { + if c.Kind == ListSnapshotDeleteIntent { + return Head{}, fmt.Errorf("%w: snapshot deletion requires the atomic intent transition", ErrIdentity) + } h, err := runTransition(ctx, st, CauseListPublish, func(h Head) (Head, bool, error) { if err := listSession(h, me, session, ActSnap); err != nil { return Head{}, false, err @@ -203,6 +208,9 @@ func RunAdvanceList(ctx context.Context, st ListChainStore, me HolderID, session if h.Gen == ^uint64(0) { return Head{}, false, ErrPrecondition } + if h.List.Kind == ListSnapshotDeleteIntent { + return Head{}, false, fmt.Errorf("%w: use the persisted delete-intent consumer", ErrIdentity) + } if apply == nil { return Head{}, false, fmt.Errorf("%w: list consumer needs an executor", ErrMalformed) } diff --git a/seaweed-block/core/frontend/chunkstore/layout/list_chain_test.go b/seaweed-block/core/frontend/chunkstore/layout/list_chain_test.go index b3c84f8554..12823bcfa8 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/list_chain_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout/list_chain_test.go @@ -462,4 +462,21 @@ func TestListWritesMatchExportedCensus(t *testing.T) { t.Fatal(err) } check(CauseListAdvance, before, after) + s, c, p = deleteIntentFixture(t) + r := deleteIntentReader(t, s) + before = s.h.clone() + if _, err := StageSnapshotDeletePage(ctx, s, before.Gen, p); err != nil { + t.Fatal(err) + } + after, err = RunDeleteSnapshotWithIntent(ctx, s, before.Gen, c) + if err != nil { + t.Fatal(err) + } + check(CauseSnapshotDeleteIntent, before, after) + before = s.h.clone() + after, err = RunConsumeSnapshotDeleteIntent(ctx, s, r) + if err != nil { + t.Fatal(err) + } + check(CauseListAdvance, before, after) } diff --git a/seaweed-block/core/frontend/chunkstore/layout/remove.go b/seaweed-block/core/frontend/chunkstore/layout/remove.go index a8332e0840..6814dfeb6d 100644 --- a/seaweed-block/core/frontend/chunkstore/layout/remove.go +++ b/seaweed-block/core/frontend/chunkstore/layout/remove.go @@ -12,6 +12,9 @@ import ( // authoritative HEAD view; only immutable reachability is cached between pages. // It is used serially, and never survives a cleaning session or process restart. type Cleaner struct { + // intent is set only by the persisted delete-intent consumer. Ordinary + // full-sweep cleaners retain their holder + clean-session authority. + intent *ListCursor tagParallel int st HeadStore r *Reader @@ -123,11 +126,17 @@ func (c *Cleaner) removePlanned(ctx context.Context, rels []string, kind string, if !found { return out, ErrHeadAbsent } - if err := h.holderErr(c.me); err != nil { - return out, err - } - if h.Activity != (Activity{Kind: ActClean, Session: c.session}) { - return out, fmt.Errorf("%w: HEAD has %s(%s), not clean(%s)", ErrNoSession, h.Activity.Kind, h.Activity.Session, c.session) + if c.intent != nil { + if err := pendingDeleteIntent(h, c.intent); err != nil { + return out, err + } + } else { + if err := h.holderErr(c.me); err != nil { + return out, err + } + if h.Activity != (Activity{Kind: ActClean, Session: c.session}) { + return out, fmt.Errorf("%w: HEAD has %s(%s), not clean(%s)", ErrNoSession, h.Activity.Kind, h.Activity.Session, c.session) + } } roots := HeadRoots(h) if !c.rootsRead { @@ -204,6 +213,9 @@ func (c *Cleaner) removePlanned(ctx context.Context, rels []string, kind string, } if err := c.os.Mark(ctx, rel, tag.meta, c.session); err != nil { if errors.Is(err, ErrPrecondition) { + if c.intent != nil { + return out, err + } out.After = rel continue } @@ -211,6 +223,9 @@ func (c *Cleaner) removePlanned(ctx context.Context, rels []string, kind string, } if err := c.os.DeleteMarked(ctx, rel, c.session); err != nil { if errors.Is(err, ErrPrecondition) { + if c.intent != nil { + return out, err + } out.After = rel continue } diff --git a/seaweed-block/core/frontend/chunkstore/layout_list_test.go b/seaweed-block/core/frontend/chunkstore/layout_list_test.go index d52f9897a7..fb1e738682 100644 --- a/seaweed-block/core/frontend/chunkstore/layout_list_test.go +++ b/seaweed-block/core/frontend/chunkstore/layout_list_test.go @@ -5,6 +5,7 @@ import ( "context" "errors" "path" + "sort" "testing" "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" @@ -29,6 +30,97 @@ func TestLayoutListAbsentHEAD(t *testing.T) { } } +func TestLayoutDeleteIntentAbsentHEAD(t *testing.T) { + s, f, b := layoutStoreFixture(t) + ctx := context.Background() + p := layout.ListPage{VolumeID: s.id, Kind: layout.ListSnapshotDeleteIntent, Producer: "delete-1", Generation: 1, Pages: 1, Target: &layout.SnapshotTarget{Name: "daily", Gen: 1}, Entries: []string{(layout.RootName{Hash: layout.Sum([]byte("root"))}).Path()}} + ref, _ := p.Ref() + c := layout.ListCursor{Ref: ref, Kind: p.Kind, Producer: p.Producer, Generation: p.Generation, Target: p.Target} + if _, err := layout.StageSnapshotDeletePage(ctx, s, 0, p); !errors.Is(err, layout.ErrHeadAbsent) { + t.Fatal(err) + } + if _, err := layout.RunDeleteSnapshotWithIntent(ctx, s, 0, c); !errors.Is(err, layout.ErrHeadAbsent) { + t.Fatal(err) + } + if _, err := layout.RunConsumeSnapshotDeleteIntent(ctx, s, nil); !errors.Is(err, layout.ErrHeadAbsent) { + t.Fatal(err) + } + puts, _, _ := b.counts() + if len(f.written) != 0 || puts != 0 { + t.Fatal("absent HEAD created metadata") + } +} + +func TestLayoutSnapshotDeleteIntentResumesWithoutReceipt(t *testing.T) { + s, f, _ := layoutStoreFixture(t) + ctx := context.Background() + n := layout.NameChunk(1, []byte("old")) + root, segs, err := layout.Build(map[uint64]layout.Ref{1: {Owner: "v", OwnerID: s.id, Chunk: n}}) + if err != nil { + t.Fatal(err) + } + rn, rb, err := layout.NameRoot(root) + if err != nil { + t.Fatal(err) + } + entries := []string{n.Path(), rn.Path()} + if err := s.Create(ctx, n.Path(), []byte("old"), "seed"); err != nil { + t.Fatal(err) + } + if err := s.Create(ctx, rn.Path(), rb, "seed"); err != nil { + t.Fatal(err) + } + for sn, raw := range segs { + if err := s.Create(ctx, sn.Path(), raw, "seed"); err != nil { + t.Fatal(err) + } + entries = append(entries, sn.Path()) + } + sort.Strings(entries) + v := layout.Volume{ID: s.id, Name: "v", Geometry: layout.Geometry{SizeBytes: 64 * 4096, BlockSize: 4096, ChunkBytes: 4 * 4096}, Format: layout.VolumeFormat} + vr, err := v.Encode() + if err != nil { + t.Fatal(err) + } + if err := f.CreateEntry(ctx, s.root, layoutEntry(layout.VolumeName, vr), true); err != nil { + t.Fatal(err) + } + h := layout.Unclaimed(s.id, nil) + h.Version = layout.HeadVersion1 + h.Snapshots = map[string]layout.Snapshot{"daily": {Root: rn, Gen: 1}} + if err := s.UpdateHead(ctx, 0, h, layout.CauseCreate); err != nil { + t.Fatal(err) + } + p := layout.ListPage{VolumeID: s.id, Kind: layout.ListSnapshotDeleteIntent, Producer: "delete-1", Generation: 2, Pages: 1, Target: &layout.SnapshotTarget{Name: "daily", Gen: 1}, Entries: entries} + ref, err := layout.StageSnapshotDeletePage(ctx, s, 1, p) + if err != nil { + t.Fatal(err) + } + c := layout.ListCursor{Ref: ref, Kind: p.Kind, Producer: p.Producer, Generation: p.Generation, Target: p.Target} + h, err = layout.RunDeleteSnapshotWithIntent(ctx, s, 1, c) + if err != nil || h.List == nil || len(h.Snapshots) != 0 { + t.Fatalf("unlink/intent: %+v %v", h, err) + } + // A fresh adapter/reader has no receipt store or original executor state. + reopened, err := NewLayoutStore(s.f, s.b, s.root, s.id) + if err != nil { + t.Fatal(err) + } + r, err := layout.NewReader("/blocks", "v", reopened.Fetch) + if err != nil { + t.Fatal(err) + } + h, err = layout.RunConsumeSnapshotDeleteIntent(ctx, reopened, r) + if err != nil || h.List != nil || h.Holder != "" || h.Epoch != 0 { + t.Fatalf("resume claimed or incomplete: %+v %v", h, err) + } + for _, rel := range entries { + if _, found, err := reopened.Stat(ctx, rel); err != nil || found { + t.Fatalf("not reclaimed %s: %v %v", rel, found, err) + } + } +} + func TestLayoutStoreListPageDataBeforeEntryAndBoundedRead(t *testing.T) { s, f, b := layoutStoreFixture(t) ctx := context.Background() diff --git a/seaweed-block/docs/design/immutable-list-pages.md b/seaweed-block/docs/design/immutable-list-pages.md index 97ecb83b6f..e015c6c00f 100644 --- a/seaweed-block/docs/design/immutable-list-pages.md +++ b/seaweed-block/docs/design/immutable-list-pages.md @@ -108,3 +108,53 @@ shared helper; already stamped entries keep their generation. General snapshot producer/binding integration, complete restore ancestry, volume-delete cursor, final queue layout, driver activation and release qualification remain separate required work before the v1.1 declaration. + +## Snapshot deletion owns an intent before removing its row + +The dormant delete seam is separate from the generic session API: + +```mermaid +sequenceDiagram + participant Catalog + participant Store + participant HEAD + participant LaterExecutor + Catalog->>Store: StageSnapshotDeletePage (captured name/gen, durable pages) + Catalog->>HEAD: RunDeleteSnapshotWithIntent (one CAS: remove exact row + name intent) + Note over Catalog,HEAD: receipt may retire after this step + LaterExecutor->>HEAD: read current snapshot-delete intent, require idle live/detached + LaterExecutor->>Store: authenticate page; live roots; conditional mark/delete + LaterExecutor->>HEAD: CAS continuation only after effects finish +``` + +The target is the retained `(name, publishing gen)` in this volume, never a +new lookup by name. Its root must occur in the authenticated candidate chain. +The chain's producer/generation is a stable attempt identity, independent of +the HEAD CAS base: a retry after an unrelated metadata write reuses durable +pages and the original target. 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 +leave an unlinked row without its reclamation facts. After publication, +`RunConsumeSnapshotDeleteIntent` needs only current HEAD and its immutable +pages, not the receipt, original host or holder lease. It can resume offline +on live/detached volumes and never claims a volume or changes its holder epoch. +Open snapshot or cleaning activity refuses these effects. Candidate membership +is not liveness: every removal still checks tags before current HEAD roots, +then conditionally marks and deletes. A conflicting mark or delete leaves +the intent page pending for retry; routine full-sweep skip behavior is unchanged. +This is an explicit additional authority branch inside `Cleaner.removePlanned`, +not a weakening of the holder's routine cleaning guard. + +Before publication, an ordinary cleaner must begin at a later HEAD generation; +that fences an outstanding delete CAS before it can name swept pages. An +unsettled upload finishing after the fence is merely an orphan. After +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 +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 35ad2d0499..bf00cfd1ce 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -583,6 +583,8 @@ 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 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` | | snap(s) | idle, current = root | holder at HEAD's epoch (epoch, server and claim id); activity is snap(s); the previous manifest builds to HEAD's current root; the new own chunks, every segment and the root are present; a new snapshot name records bounded retention facts once, while replay preserves them | commit.go `Head.Commit`, `RunCommit` | `INV-SNAPK-COMMIT-REACH-001`, `INV-SNAPK-TXN-INTERRUPT-001`, `INV-SNAPK-SNAPSHOT-META-001` | @@ -1222,7 +1224,7 @@ Notes: | `INV-SCHEDULE-DUE-NOW-001` | The local opt-in due-now request queues only a running configured schedule, using its existing worker and admission. A cancelled or ended snapshot worker refuses even while the aggregate background group remains alive. | M9 scheduled capture (K: HEAD) | `core/frontend/durable/chunk_snapshot_schedule.go`; `core/host/volume/chunk_control.go` | `TestScheduledSnapshotDueNowUsesExistingLoop`, `TestScheduledSnapshotDueNowRefusesEndedWorkerWithBackgroundAlive` (`core/frontend/durable/snapshot_due_now_test.go`); `TestChunkScheduleNowRunsOnlyThroughEnabledLocalControl` (`core/host/volume/chunk_schedule_now_test.go`) | EngineAdapter.StartStop; CommitReach WCommit (ordinary capture) | ACTIVE | | `INV-CLEAN-METADATA-001` | Cleaning preserves Current and snapshot roots and their segments. Dependents keep their snapshot in HEAD. Unnamed roots go before segments and chunks; reuse defeats conditional removal. | M9 clean | `core/frontend/chunkstore/layout/remove.go`; `core/frontend/chunkstore/clean_b.go` | `TestCleanerMetadataRetainsCurrentSnapshotAndDependent`, `TestCleanerMetadataReuseDefeatsLateMarkAndDelete`, `TestCleanerRecreatesRemovedRootBeforeRenamingIt` (`core/frontend/chunkstore/layout/clean_metadata_test.go`); `TestCleaningInterruptsAfterMetadataBeforeChunks` (`core/frontend/chunkstore/clean_cursor_test.go`) ; `TestCleaningSegmentResumeReplansRootsBeforeRemovingSegments` (`core/frontend/chunkstore/clean_cursor_test.go`) | CommitReach rows 65-70; CommitReach2 rows 71-75 (CPlan, CView, CIssueMark/LandMark, CIssueDel/LandDel; model-code trace) | ACTIVE | | `INV-CLEAN-CURSOR-001` | Every new session scans roots first, preserves segment/chunk progress, and wraps after the final shard. Each page validates HEAD after parallel tags; reachability caches a conservative root set only within that session. | M9 clean (liveness) | `core/frontend/chunkstore/clean_b.go`; `core/frontend/chunkstore/layout/remove.go` | `TestCleaningCursorResumesAfterTimeoutAndWraps` (`core/frontend/chunkstore/clean_cursor_test.go`); `TestCleanerReachableOncePerShardAndRechecksHead`, `TestCleanerPlansTagsInBoundedParallelBeforeHead` (`core/frontend/chunkstore/layout/clean_scale_test.go`) | CommitReach rows 65-70; CommitReach2 rows 71-75 (CPlan, CView, CIssueMark/LandMark, CIssueDel/LandDel; model-code trace) | ACTIVE | -| `INV-SNAPK-REMOVE-MARK-001` | A content-named object is removed only inside the holder's own cleaning, when no root in HEAD names it: tags read first, HEAD read and validated after, then a mark conditional on the tag and a delete conditional on the mark. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` `remove.go` `Cleaner.removePlanned` | `TestRemoveUnreachable_RemovesOnlyWhatNoRootNames`, `TestCleaningPass_InterruptAtEveryStep`, `TestHolderFunctions_RefuseAStaleHolder` | CommitReach rows 65-70; CommitReach2 rows 71-75 (CPlan, CView, CIssueMark/LandMark, CIssueDel/LandDel; model-code trace) | ACTIVE | +| `INV-SNAPK-REMOVE-MARK-001` | Routine full-sweep removal requires the holder's own cleaning and no live HEAD root: tags precede HEAD validation, then mark conditional on the tag and delete conditional on the mark. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` `remove.go` `Cleaner.removePlanned` | `TestRemoveUnreachable_RemovesOnlyWhatNoRootNames`, `TestCleaningPass_InterruptAtEveryStep`, `TestHolderFunctions_RefuseAStaleHolder` | CommitReach rows 65-70; CommitReach2 rows 71-75 (CPlan, CView, CIssueMark/LandMark, CIssueDel/LandDel; model-code trace) | ACTIVE | | `INV-SNAPK-REMOVE-STOP-001` | A reuse of an object after the plan, or after the mark, makes the remover's mark or delete fail its condition, however late it lands; an unreadable root stops the pass before any write; an open snapshot refuses it. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` `remove.go` `Cleaner.removePlanned` | `TestRemoveUnreachable_ASuccessorAfterTheHeadViewDefeatsTheMark`, `TestRemoveUnreachable_ASuccessorBeforeTheHeadViewStopsThePass`, `TestRemoveUnreachable_AReuseAfterThePlanDefeatsTheMark`, `TestRemoveUnreachable_AReuseDefeatsALateMarkOrDelete`, `TestRemoveUnreachable_NothingRemovedOnAPartialView`, `TestRemoveUnreachable_RefusedOutsideItsCleaning` | CommitReach rows 65-70; CommitReach2 rows 71-75 (CPlan, CView, CIssueMark/LandMark, CIssueDel/LandDel; model-code trace) | ACTIVE | | `INV-SNAPK-REMOVE-CONVERGE-001` | A name a cleaning marked and did not delete (the remover died in between) is planned again by the next cleaning: the re-mark replaces the old mark, so the dead remover's late delete fails, and every unreachable name goes once a cleaning completes. | M9 clean → clean | `core/frontend/chunkstore/layout` `remove.go` `Cleaner.removePlanned` | `TestRemoveUnreachable_ReclaimsAnAbandonedMark`, `TestCleaningPass_InterruptAtEveryStep`, `TestLayoutStoreCleaningReclaimsAnAbandonedMark` | CommitReach rows 65-70; CommitReach2 rows 71-75 (CPlan, CView, CIssueMark/LandMark, CIssueDel/LandDel; model-code trace) | ACTIVE | | `INV-SNAPK-REMOVE-GUARD-001` | A source scan requires DeleteMarked as Cleaner.removePlanned's only removal, each immediately after an if on its Mark's error that leaves: an unconditional delete, an ignored mark, a reused mark or another method fails. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` (source scan of `remove.go`) | `TestGuard_WritersTransitionsAndRemovers`, `TestGuard_Controls` | CommitReach rows 65-70; CommitReach2 rows 71-75 (CPlan, CView, CIssueMark/LandMark, CIssueDel/LandDel; model-code trace) | ACTIVE | @@ -1276,6 +1278,15 @@ Notes: | `INV-LIST-PUBLISH-001` | A list publication names only durable authenticated pages of its open session; an unknown reply never abandons their protection. | M9 snap -> snap | `list_chain.go` `StageListPage`, `RunPublishList` | `TestPublishList_Closure`, `TestRunPublishList_InterruptAtEveryStep`, `TestListSessionEndedDuringPageWriteCannotPublish` | PageChain 246-250; NoDangling | DORMANT | | `INV-LIST-CURSOR-001` | The persisted list cursor advances only after its authenticated page's idempotent effects finish; a missing page never completes work. | M9 clean -> clean | `list_chain.go` `RunAdvanceList` | `TestAdvanceList_Closure`, `TestRunAdvanceList_InterruptAtEveryStep`, `TestListMissingConsumerPageNeverCompletes` | PageChain 246,251-253; NoLostWork | DORMANT | | `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 | + +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 +dormant snapshot-intent branch instead requires the exact current HEAD intent, +idle activity and live/detached state, with the same live-root and conditional +mutation order. It cannot remove namespaces or unname another snapshot. It +requires separate review/activation; no production driver reaches it yet. These three list rows are dormant until producer/consumer driver wiring and final queue-layout/format review. They do not declare by-change cleaning active. diff --git a/seaweed-block/docs/spec/README.md b/seaweed-block/docs/spec/README.md index b6b0e6061c..2f8a917a2c 100644 --- a/seaweed-block/docs/spec/README.md +++ b/seaweed-block/docs/spec/README.md @@ -705,7 +705,8 @@ configurations are unchanged. The recorded Linux run passed safe_chain (150,260 states), seven must-violate mutations and four reachability witnesses; coverage exit 0. This records the model owner's run, not a rerun by this PR. Configurations and expected results are committed in `pagechain/cfg`. -Trace: [model to code](pagechain/model-code-trace.tsv), rows 246-253. +Trace: [model to code](pagechain/model-code-trace.tsv), keyed to the committed +`safe_chain`, `mut_*` and `wit_*` configurations. The model abstracts effect execution as idempotent completion and relies on conditional HEAD and object writes. The Go adapter/consumer controls are a diff --git a/seaweed-block/docs/spec/pagechain/model-code-trace.tsv b/seaweed-block/docs/spec/pagechain/model-code-trace.tsv index fea76b3a3a..f38da0ab47 100644 --- a/seaweed-block/docs/spec/pagechain/model-code-trace.tsv +++ b/seaweed-block/docs/spec/pagechain/model-code-trace.tsv @@ -7,3 +7,6 @@ row model transition code control 251 PageChain CAdvance CResolve CRetire layout/list_chain.go RunAdvanceList; layout/remove.go TestRunAdvanceList_InterruptAtEveryStep 252 PageChain CApply CAdvance layout/list_chain.go RunAdvanceList TestAdvanceList_Closure 253 PageChain CRead layout/list_chain.go readListPage TestListMissingConsumerPageNeverCompletes +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