layout: remove pool names no root reaches, inside the lease

RemoveUnreachable is the cleaning's removal step for one pool shard: for
the holder with its own clean(session) open, it deletes each candidate
chunk that no root in HEAD (current or any snapshot) names in this
volume's pool, and checks its own lease immediately before every delete.
HEAD is read once after BeginClean: no commit can add a root while the
cleaning is open, and a claim that voids it waits for this lease to end,
which the next check sees. An unreadable root or segment stops the pass
before any delete; a lapsed lease stops it before the next one; an open
snapshot refuses it.

The package guard now allows Delete/Remove names only in
RemoveUnreachable and requires a lease check before every delete in the
same block (controls: no check, check after the delete, one check
before the loop). The HEAD reader enumeration classifies its read, and
the ledger gains the removal row and the read path's row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-24 15:45:51 -08:00
1 parent 4a86e06748
commit c7900bb57c
5 files changed
+516 -11

No files matched your search

@@ -40,6 +40,7 @@ var headReaders = map[string]string{
"core/frontend/chunkstore/share_guard.go beginShare -> ReadHead": "refuses outcome_unknown: the HEAD to share is no longer current",
"core/frontend/chunkstore/usage.go Usage -> ReadHead": "GAP: reports an empty image, no error (probe Usage)",
"core/frontend/chunkstore/verify.go readHead -> LookupEntry": "finding ROOT_INVALID (probe Verify)",
"core/frontend/chunkstore/layout/remove.go RemoveUnreachable -> ReadHead": "refuses ErrHeadAbsent and deletes nothing (probe LayoutRemoval)",
"core/frontend/chunkstore/layout/head.go runTransition -> ReadHead": "refuses ErrHeadAbsent and writes nothing; no layout transition creates a HEAD (probe LayoutTransition)",
"core/frontend/chunkstore/verify.go run -> LookupEntry": "finding ROOT_INVALID (probe Verify)",
"core/frontend/chunkstore/volume_delete.go DeleteVolume -> ReadHead": "operator delete writes a deleting HEAD from nothing and completes (probe DeleteVolume)",
@@ -264,6 +265,19 @@ func TestHeadReaders_AbsentHeadProbes(t *testing.T) {
t.Fatalf("layout transition over an absent HEAD wrote %d times", st.updates)
}
})
t.Run("LayoutRemoval", func(t *testing.T) {
r, err := layout.NewReader("/swblock/chunks", "v1", func(context.Context, string) ([]byte, bool, error) { return nil, false, nil })
if err != nil {
t.Fatal(err)
}
pool := &countingPool{}
if _, err := layout.RemoveUnreachable(ctx, &absentLayoutHead{}, r, pool, okLease{}, layout.HolderID{Epoch: 1, Holder: "h"}, "c", 0, []layout.ChunkName{layout.NameChunk(1, []byte("x"))}); !errors.Is(err, layout.ErrHeadAbsent) {
t.Fatalf("layout removal over an absent HEAD: %v; want ErrHeadAbsent", err)
}
if pool.deletes != 0 {
t.Fatalf("layout removal over an absent HEAD deleted %d objects", pool.deletes)
}
})
t.Run("ForkReplay", func(t *testing.T) {
f, b := headReaderForkFixture(t)
c, err := NewCatalog(manifestFilerBlobs{f, gcBlobs{b}}, catBase)
@@ -297,3 +311,11 @@ func (a *absentLayoutHead) UpdateHead(context.Context, uint64, layout.Head) erro
a.updates++
return nil
}
type countingPool struct{ deletes int }
func (p *countingPool) DeleteObject(context.Context, string) error { p.deletes++; return nil }
type okLease struct{}
func (okLease) StillHeld(context.Context) error { return nil }
@@ -123,9 +123,10 @@ func owners(m map[string]bool) []string {
// - Lease, claim half: OldLeaseEnded is used only in RunClaim, and
// RunClaim, when it is declared, uses it.
// - Every declared exported Run function goes through runTransition.
// - Pool: no name starting with Delete or Remove is used yet; the
// removal that comes with cleaning must bring its lease re-check and
// its own row here.
// - Pool: a name starting with Delete or Remove is used only in
// RemoveUnreachable, and there every delete is preceded, in the same
// loop body, by the remover's own lease check (StillHeld); see
// removerOrderFindings.
//
// These are syntactic checks of this package's own files: they see any
// use of these names, but not a store effect reached through a name they
@@ -167,13 +168,81 @@ func guardFindings(code map[string]map[string]bool, decl, tests map[string]bool)
}
for name, by := range code {
if strings.HasPrefix(name, "Delete") || strings.HasPrefix(name, "Remove") {
bad = append(bad, strings.Join(owners(by), ", ")+" uses "+name+": a store remover needs its lease re-check and its own guard row")
for _, fn := range owners(by) {
if fn != "RemoveUnreachable" {
bad = append(bad, fn+" uses "+name+": only RemoveUnreachable removes, after its lease re-check")
}
}
}
}
sort.Strings(bad)
return bad
}
// removerOrderFindings checks the removal half of the time premise in the
// sources: in RemoveUnreachable, every statement that deletes
// (DeleteObject) sits in a block where an earlier statement checks the
// remover's own lease (StillHeld).
func removerOrderFindings(t *testing.T, srcs map[string]string) []string {
t.Helper()
uses := func(n ast.Node, name string) bool {
found := false
ast.Inspect(n, func(n ast.Node) bool {
if sel, ok := n.(*ast.SelectorExpr); ok && sel.Sel.Name == name {
found = true
}
return !found
})
return found
}
var bad []string
for fname, src := range srcs {
file, err := parser.ParseFile(token.NewFileSet(), fname, src, 0)
if err != nil {
t.Fatal(err)
}
for _, d := range file.Decls {
fn, ok := d.(*ast.FuncDecl)
if !ok || fn.Body == nil || fn.Name.Name != "RemoveUnreachable" {
continue
}
deletes := 0
ast.Inspect(fn.Body, func(n ast.Node) bool {
blk, ok := n.(*ast.BlockStmt)
if !ok {
return true
}
for i, st := range blk.List {
if _, isBlock := st.(*ast.BlockStmt); isBlock || !uses(st, "DeleteObject") {
continue
}
if _, nested := st.(*ast.RangeStmt); nested {
continue // its body is checked as its own block
}
if _, nested := st.(*ast.ForStmt); nested {
continue
}
deletes++
checked := false
for _, prev := range blk.List[:i] {
if uses(prev, "StillHeld") {
checked = true
}
}
if !checked {
bad = append(bad, "RemoveUnreachable deletes without a lease check before it in the same block")
}
}
return true
})
if deletes == 0 {
bad = append(bad, "RemoveUnreachable is declared and has no delete: the scan is broken")
}
}
}
return bad
}
// declared returns the names of the functions the sources declare.
func declared(t *testing.T, srcs map[string]string) map[string]bool {
t.Helper()
@@ -196,7 +265,7 @@ func TestGuard_WritersTransitionsAndRemovers(t *testing.T) {
src := packageSources(t, false)
code := refs(t, src)
tests := declared(t, packageSources(t, true))
if bad := guardFindings(code, declared(t, src), tests); len(bad) != 0 {
if bad := append(guardFindings(code, declared(t, src), tests), removerOrderFindings(t, src)...); len(bad) != 0 {
t.Fatalf("guard: %s", strings.Join(bad, "\n"))
}
st := reflect.TypeOf((*HeadStore)(nil)).Elem()
@@ -229,14 +298,50 @@ func TestGuard_Controls(t *testing.T) {
"runTransition alias": {src: `func w(ctx context.Context, st HeadStore) { f := runTransition; _, _ = f(ctx, st, nil) }`, want: "uses runTransition; transitions are exported"},
"untested transition": {src: `func RunZz(ctx context.Context, st HeadStore) (Head, error) { return runTransition(ctx, st, nil) }`, want: "has no TestZz_Closure"},
"lease wait outside claim": {src: `func w(ctx context.Context, l LeaseWait) error { return l.OldLeaseEnded(ctx, 1) }`, want: "only RunClaim claims"},
"remover": {src: `type p interface{ DeleteObject(context.Context, string) error }
func w(ctx context.Context, x p) error { return x.DeleteObject(ctx, "o") }`, want: "a store remover"},
"remover outside RemoveUnreachable": {src: `type p interface{ DeleteObject(context.Context, string) error }
func w(ctx context.Context, x p) error { return x.DeleteObject(ctx, "o") }`, want: "only RemoveUnreachable removes"},
"removal without lease check": {file: "remove.go", src: `type p interface{ DeleteObject(context.Context, string) error }
type l interface{ StillHeld(context.Context) error }
func RemoveUnreachable(ctx context.Context, x p, h l, names []string) error {
for _, n := range names {
if err := x.DeleteObject(ctx, n); err != nil {
return err
}
}
return nil
}`, want: "deletes without a lease check"},
"lease check after the delete": {file: "remove.go", src: `type p interface{ DeleteObject(context.Context, string) error }
type l interface{ StillHeld(context.Context) error }
func RemoveUnreachable(ctx context.Context, x p, h l, names []string) error {
for _, n := range names {
if err := x.DeleteObject(ctx, n); err != nil {
return err
}
if err := h.StillHeld(ctx); err != nil {
return err
}
}
return nil
}`, want: "deletes without a lease check"},
"lease check once before the loop": {file: "remove.go", src: `type p interface{ DeleteObject(context.Context, string) error }
type l interface{ StillHeld(context.Context) error }
func RemoveUnreachable(ctx context.Context, x p, h l, names []string) error {
if err := h.StillHeld(ctx); err != nil {
return err
}
for _, n := range names {
if err := x.DeleteObject(ctx, n); err != nil {
return err
}
}
return nil
}`, want: "deletes without a lease check"},
"claim without lease wait": {src: `func RunClaim(ctx context.Context, st HeadStore, lease LeaseWait, me HolderID) (Head, error) {
return runTransition(ctx, st, func(h Head) (Head, bool, error) { return h, false, nil })
}`, want: "does not wait for the old lease", file: "claim.go"},
"transition not through runTransition": {src: `func RunZz(ctx context.Context, st HeadStore) (Head, error) { h, _, err := st.ReadHead(ctx); return h, err }`, want: "does not go through runTransition"},
"remover method value": {src: `type p interface{ RemoveName(string) }
func w(x p) { f := x.RemoveName; f("o") }`, want: "a store remover"},
func w(x p) { f := x.RemoveName; f("o") }`, want: "only RemoveUnreachable removes"},
} {
srcs := packageSources(t, false)
file := c.file
@@ -244,7 +349,7 @@ func w(x p) { f := x.RemoveName; f("o") }`, want: "a store remover"},
file = "zz_control.go"
}
srcs[file] = "package layout\n\nimport \"context\"\n\nvar _ context.Context\n\n" + c.src + "\n"
bad := guardFindings(refs(t, srcs), declared(t, srcs), tests)
bad := append(guardFindings(refs(t, srcs), declared(t, srcs), tests), removerOrderFindings(t, srcs)...)
if !strings.Contains(strings.Join(bad, "\n"), c.want) {
t.Errorf("control %q: findings %q; want one containing %q", name, bad, c.want)
}
@@ -0,0 +1,105 @@
package layout
import (
"context"
"errors"
"fmt"
"sort"
)
// ErrLeaseLost: the remover's own lease is no longer valid; nothing more
// is removed.
var ErrLeaseLost = errors.New("layout: remover's lease is not valid")
// LeaseHeld is the remover's half of the time premise: it returns nil only
// while the caller's own lease is valid. Remove calls it immediately before
// every delete.
type LeaseHeld interface {
StillHeld(ctx context.Context) error
}
// Pool deletes one object of the volume by its path relative to the volume
// root; deleting an absent object succeeds.
type Pool interface {
DeleteObject(ctx context.Context, rel string) error
}
// RemoveUnreachable is transition 7 for one pool shard: for the holder
// with clean(session) open at HEAD's epoch, every candidate chunk of shard
// that no root in HEAD (current and every snapshot) names in this
// volume's pool is deleted, each delete preceded by a check of the
// remover's own lease. HEAD is read once, after BeginClean: while clean is
// open no commit can add a root, and a claim that voids the cleaning waits
// for this lease to end, which the check before every delete sees. It
// returns the names it deleted, in index order.
func RemoveUnreachable(ctx context.Context, st HeadStore, r *Reader, pool Pool, lease LeaseHeld, me HolderID, session string, shard uint64, candidates []ChunkName) ([]ChunkName, error) {
if lease == nil || pool == nil || r == nil {
return nil, errors.New("layout: removal needs a reader, a pool and a lease check")
}
h, found, err := st.ReadHead(ctx)
if err != nil {
return nil, err
}
if !found {
return nil, ErrHeadAbsent
}
if !h.heldBy(me) {
return nil, fmt.Errorf("%w: HEAD epoch %d holder %q", ErrNotHolder, h.Epoch, h.Holder)
}
if h.Activity != (Activity{Kind: ActClean, Session: session}) {
return nil, fmt.Errorf("%w: HEAD has %s(%s), not clean(%s)", ErrNoSession, h.Activity.Kind, h.Activity.Session, session)
}
live, err := reachable(ctx, r, h, shard)
if err != nil {
return nil, err
}
sorted := append([]ChunkName(nil), candidates...)
sort.Slice(sorted, func(a, b int) bool { return sorted[a].Index < sorted[b].Index })
var removed []ChunkName
for _, c := range sorted {
if Shard(c.Index) != shard || live[c] {
continue
}
if err := lease.StillHeld(ctx); err != nil {
return removed, fmt.Errorf("%w: %v", ErrLeaseLost, err)
}
if err := pool.DeleteObject(ctx, c.Path()); err != nil {
return removed, fmt.Errorf("layout: delete %s: %w", c, err)
}
removed = append(removed, c)
}
return removed, nil
}
// reachable returns this volume's chunk names in shard that any root in h
// names. A root or segment that cannot be read is an error: nothing is
// removed on a partial view.
func reachable(ctx context.Context, r *Reader, h Head, shard uint64) (map[ChunkName]bool, error) {
roots := map[RootName]bool{}
if h.Current != nil {
roots[*h.Current] = true
}
for _, s := range h.Snapshots {
roots[s.Root] = true
}
live := map[ChunkName]bool{}
for rn := range roots {
img, err := r.Open(ctx, rn)
if err != nil {
return nil, err
}
seg, ok, err := img.Segment(ctx, shard)
if err != nil {
return nil, err
}
if !ok {
continue
}
for _, ref := range seg.Chunks {
if ref.Owner == r.vol {
live[ref.Chunk] = true
}
}
}
return live, nil
}
@@ -0,0 +1,269 @@
package layout
import (
"context"
"errors"
"fmt"
"path"
"testing"
)
const removeBase = "/swblock/chunks" // volRoot = removeBase/v1
// objPool is a volume's objects for removal tests: Fetch reads them, Pool
// deletes them, with an optional kill point counted over deletes.
type objPool struct {
objs map[string][]byte
deletes []string
killAt int
after bool
dead bool
}
func (o *objPool) fetch(_ context.Context, p string) ([]byte, bool, error) {
if o.dead {
return nil, false, errKilled
}
b, ok := o.objs[p]
return b, ok, nil
}
func (o *objPool) DeleteObject(_ context.Context, rel string) error {
if o.dead {
return errKilled
}
o.deletes = append(o.deletes, rel)
kill := len(o.deletes) == o.killAt
if kill && !o.after {
o.dead = true
return errKilled
}
delete(o.objs, path.Join(volRoot, rel))
if kill {
o.dead = true
return errKilled
}
return nil
}
type fakeHeld struct {
calls int
lostAt int // the n-th call (1-based) and later fail; 0 = never
}
func (l *fakeHeld) StillHeld(context.Context) error {
l.calls++
if l.lostAt > 0 && l.calls >= l.lostAt {
return errors.New("lease lapsed")
}
return nil
}
// removeFixture: HEAD clean(c1) at epoch 3; the current root names chunks
// 0 and 3, the snapshot "daily" an older image naming chunks 0 and 2 (all
// in shard 0); chunks 5 and 7 are in the pool but no root names them, and
// chunk 10001 (shard 1) is unreferenced too.
func removeFixture(t *testing.T) (*objPool, *Head, []ChunkName, []ChunkName) {
t.Helper()
objs := map[string][]byte{}
cur := manifest(ref("v1", 0, "a"), ref("v1", 3, "b"))
old := manifest(ref("v1", 0, "a"), ref("v1", 2, "c"))
curRoot := writeImage(t, objs, cur, map[uint64][]byte{0: []byte("a"), 3: []byte("b")})
oldRoot := writeImage(t, objs, old, map[uint64][]byte{0: []byte("a"), 2: []byte("c")})
var orphans []ChunkName
for i, d := range map[uint64]string{5: "e", 7: "f", 10001: "g"} {
c := NameChunk(i, []byte(d))
objs[path.Join(volRoot, c.Path())] = []byte(d)
orphans = append(orphans, c)
}
h := &Head{Gen: 7, Epoch: 3, Holder: "srv-a", Activity: Activity{Kind: ActClean, Session: "c1"}, Current: &curRoot,
Snapshots: map[string]Snapshot{"daily": {Root: oldRoot}}}
live := []ChunkName{cur[0].Chunk, cur[3].Chunk, old[2].Chunk}
return &objPool{objs: objs}, h, live, orphans
}
func removeShard0(t *testing.T, st HeadStore, o *objPool, l LeaseHeld, session string, cands []ChunkName) ([]ChunkName, error) {
t.Helper()
r, err := NewReader(removeBase, "v1", o.fetch)
if err != nil {
t.Fatal(err)
}
return RemoveUnreachable(context.Background(), st, r, o, l, me, session, 0, cands)
}
func inPool(o *objPool, c ChunkName) bool { _, ok := o.objs[path.Join(volRoot, c.Path())]; return ok }
// Only names no root in HEAD reaches are removed: the current root's and
// a snapshot's chunks stay, shard 0's orphans go, the shard-1 orphan is
// not touched by a shard-0 pass; the lease is checked before every delete.
func TestRemoveUnreachable_RemovesOnlyWhatNoRootNames(t *testing.T) {
o, h, live, orphans := removeFixture(t)
l := &fakeHeld{}
cands := append(append([]ChunkName(nil), live...), orphans...)
removed, err := removeShard0(t, &memHead{h: h}, o, l, "c1", cands)
if err != nil {
t.Fatal(err)
}
if len(removed) != 2 || removed[0].Index != 5 || removed[1].Index != 7 {
t.Fatalf("removed %v; want chunks 5 and 7", removed)
}
for _, c := range live {
if !inPool(o, c) {
t.Fatalf("reachable chunk %s was removed", c)
}
}
if l.calls != len(o.deletes) {
t.Fatalf("lease checks %d for %d deletes; want one before each", l.calls, len(o.deletes))
}
if err := reachableMissing(h, o.objs); err != nil {
t.Fatalf("after removal HEAD reaches a missing object: %v", err)
}
for _, c := range orphans {
if c.Index == 10001 && !inPool(o, c) {
t.Fatal("a shard-1 name was removed by a shard-0 pass")
}
}
}
// No name is removed while a snapshot is open (or without a cleaning, or
// by another holder, or over an absent HEAD).
func TestRemoveUnreachable_RefusedOutsideItsCleaning(t *testing.T) {
for name, tc := range map[string]struct {
edit func(*Head)
want error
}{
"snapshot open": {func(h *Head) { h.Activity = Activity{Kind: ActSnap, Session: "s1"} }, ErrNoSession},
"idle": {func(h *Head) { h.Activity = Activity{Kind: ActIdle} }, ErrNoSession},
"other cleaning": {func(h *Head) { h.Activity = Activity{Kind: ActClean, Session: "c2"} }, ErrNoSession},
"newer epoch": {func(h *Head) { h.Epoch = 4; h.Holder = "srv-b" }, ErrNotHolder},
} {
o, h, _, orphans := removeFixture(t)
tc.edit(h)
if _, err := removeShard0(t, &memHead{h: h}, o, &fakeHeld{}, "c1", orphans); !errors.Is(err, tc.want) || len(o.deletes) != 0 {
t.Errorf("%s: %v, %d deletes; want %v and none", name, err, len(o.deletes), tc.want)
}
}
o, _, _, orphans := removeFixture(t)
if _, err := removeShard0(t, &memHead{}, o, &fakeHeld{}, "c1", orphans); !errors.Is(err, ErrHeadAbsent) || len(o.deletes) != 0 {
t.Errorf("absent HEAD: %v, %d deletes", err, len(o.deletes))
}
}
// A lease that lapses mid-pass stops the removal before the next delete.
func TestRemoveUnreachable_StopsWhenTheLeaseLapses(t *testing.T) {
o, h, _, orphans := removeFixture(t)
removed, err := removeShard0(t, &memHead{h: h}, o, &fakeHeld{lostAt: 2}, "c1", orphans)
if !errors.Is(err, ErrLeaseLost) || len(removed) != 1 || len(o.deletes) != 1 {
t.Fatalf("lease lapsing before the second delete: removed %v, %v; want one delete then ErrLeaseLost", removed, err)
}
}
// A root or segment HEAD names that cannot be read stops the pass before
// any delete: nothing is removed on a partial view.
func TestRemoveUnreachable_NothingRemovedOnAPartialView(t *testing.T) {
o, h, _, orphans := removeFixture(t)
delete(o.objs, path.Join(volRoot, h.Snapshots["daily"].Root.Path()))
if _, err := removeShard0(t, &memHead{h: h}, o, &fakeHeld{}, "c1", orphans); !errors.Is(err, ErrMissing) || len(o.deletes) != 0 {
t.Fatalf("unreadable snapshot root: %v, %d deletes; want ErrMissing and none", err, len(o.deletes))
}
}
// cleaningPass is the whole cleaning operation as the holder runs it after
// a (re)start: a cleaning of its own left open is ended first, then
// BeginClean, the removal of shard 0, EndClean.
func cleaningPass(st *memVolume, o *objPool, session string, cands []ChunkName) error {
ctx := context.Background()
h, found, err := st.ReadHead(ctx)
if err != nil {
return err
}
if !found {
return ErrHeadAbsent
}
if h.Activity.Kind == ActClean && h.heldBy(me) {
if _, err := RunEndClean(ctx, st, me, h.Activity.Session); err != nil {
return err
}
}
if _, err := RunBeginClean(ctx, st, me, session); err != nil {
return err
}
r, err := NewReader(removeBase, "v1", o.fetch)
if err != nil {
return err
}
if _, err := RemoveUnreachable(ctx, st, r, o, &fakeHeld{}, me, session, 0, cands); err != nil {
return err
}
_, err = RunEndClean(ctx, st, me, session)
return err
}
// Interrupt at every step of the cleaning operation: killed at each of its
// writes (BeginClean, every delete, EndClean), before the write applies
// and after it applied with its reply lost; at no point does HEAD reach a
// missing object, and the restarted holder ends idle with every orphan of
// shard 0 removed and every reachable object present.
func TestCleaningPass_InterruptAtEveryStep(t *testing.T) {
fresh := func() (*memVolume, *objPool, []ChunkName, []ChunkName) {
o, h, live, orphans := removeFixture(t)
h.Activity = Activity{Kind: ActIdle}
return &memVolume{head: &memHead{h: h}, objects: o.objs}, o, live, orphans
}
v, o, live, orphans := fresh()
cands := append(append([]ChunkName(nil), live...), orphans...)
if err := cleaningPass(v, o, "c1", cands); err != nil {
t.Fatal(err)
}
steps := len(v.writes) + len(o.deletes)
if steps != 4 {
t.Fatalf("the cleaning made %d writes; want 4 (BeginClean, two deletes, EndClean)", steps)
}
// Kill points: HEAD writes are counted by memVolume, deletes by objPool;
// step k is the k-th write of either kind in run order.
order := []string{"head", "delete", "delete", "head"}
for k := range order {
for _, after := range []bool{false, true} {
t.Run(fmt.Sprintf("step%d %s/after=%t", k+1, order[k], after), func(t *testing.T) {
v, o, live, orphans := fresh()
nth := 0
for _, kind := range order[:k+1] {
if kind == order[k] {
nth++
}
}
if order[k] == "head" {
v.killAt, v.after = nth, after
} else {
o.killAt, o.after = nth, after
}
if err := cleaningPass(v, o, "c1", cands); !errors.Is(err, errKilled) {
t.Fatalf("killed run: %v", err)
}
if err := reachableMissing(v.head.h, o.objs); err != nil {
t.Fatalf("after the kill HEAD reaches a missing object: %v", err)
}
v.dead, v.killAt, o.dead, o.killAt = false, 0, false, 0
if err := cleaningPass(v, o, "c2", cands); err != nil {
t.Fatalf("re-run: %v", err)
}
if v.head.h.Activity.Kind != ActIdle {
t.Fatalf("activity after the re-run: %+v", v.head.h.Activity)
}
for _, c := range orphans {
if c.Index != 10001 && inPool(o, c) {
t.Fatalf("orphan %s still present", c)
}
}
for _, c := range live {
if !inPool(o, c) {
t.Fatalf("reachable %s removed", c)
}
}
if err := reachableMissing(v.head.h, o.objs); err != nil {
t.Fatal(err)
}
})
}
}
}
+6 -2
View File
@@ -530,6 +530,7 @@ stateDiagram-v2
clean --> idle: Claim(e), c void
idle --> clean: BeginClean(c)
clean --> idle: EndClean(c)
clean --> clean: RemoveUnreachable(shard)
```
| From | To | Guard | Enforced in | Protects |
@@ -540,10 +541,11 @@ stateDiagram-v2
| any | idle at epoch e | e above HEAD's epoch (the same epoch and server is a replay); every older holder's lease has ended, checked after the read and before the update | claim.go `Head.Claim`, `RunClaim` (`LeaseWait.OldLeaseEnded`) | `INV-SNAPK-CLAIM-LEASE-001` |
| idle | clean(c) | holder at HEAD's epoch; activity idle (clean(c) again is a replay) | clean.go `Head.BeginClean` | `INV-SNAPK-CLEAN-EXCL-001` |
| clean(c) | idle | holder at HEAD's epoch; activity clean(c); over idle it succeeds without a write | clean.go `Head.EndClean` | `INV-SNAPK-CLEAN-EXCL-001` |
| clean(c) | clean(c), names removed | holder at HEAD's epoch with clean(c) open (HEAD read once, after BeginClean); a name is deleted only if no root in HEAD (current or snapshot) names it in this volume's pool; the remover's own lease is checked before every delete | remove.go `RemoveUnreachable` (`LeaseHeld.StillHeld`) | `INV-SNAPK-REMOVE-LEASE-001` |
## Part B. Invariant ledger
337 rows: 266 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 322 new.
339 rows: 268 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 324 new.
The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger.
@@ -1083,7 +1085,7 @@ Notes:
| ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status |
|---|---|---|---|---|---|---|
| `INV-SNAPK-NAME-CANONICAL-001` | A chunk is named by its index and the SHA-256 of its bytes under `pool/<index/10000>/`; a segment and a root are named by the SHA-256 of their canonical encoding, and decoding refuses any bytes the encoder would not write, so an object has one encoding and one name. | Content-named layout (no state transition) | `core/frontend/chunkstore/layout` `layout.go` `ParseChunkName`, `DecodeSegment`, `DecodeRoot` | `TestParseChunkName_RoundTripAndRefusals`, `TestDecodeSegment_RefusesNonCanonical`, `TestRoot_Refusals`, `TestBuild_ShardsAndIncrementalReuse` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-HEAD-WRITE-001` | HEAD changes only by one conditional update on its generation through `runTransition`; no path in the package creates a HEAD, and an absent HEAD is refused. A source scan refuses any other use of `UpdateHead`, a transition without its closure and interrupt tests, and any store remover. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `runTransition`; `HeadStore` (read and conditional update only) | `TestGuard_WritersTransitionsAndRemovers`, `TestGuard_Controls`, `TestRunBegin` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-HEAD-WRITE-001` | HEAD changes only by one conditional update on its generation through `runTransition`; no path in the package creates a HEAD, and an absent HEAD is refused. A source scan refuses any other use of `UpdateHead`, a transition without its closure and interrupt tests, and any store remover other than the lease-checked RemoveUnreachable. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `runTransition`; `HeadStore` (read and conditional update only) | `TestGuard_WritersTransitionsAndRemovers`, `TestGuard_Controls`, `TestRunBegin` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-HEAD-CODEC-001` | HEAD is canonical JSON with at most 100 snapshots and sorted unique dependents; unknown fields, non-canonical bytes and names that are not valid UTF-8 are refused at encode and decode, and the next HEAD is checked before it is written. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `Head.check`, `Head.Encode`, `DecodeHead` | `TestHead_GoldenEncodingRoundTrip`, `TestHead_Refusals`, `TestHead_RefusesInvalidUTF8` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-BEGIN-001` | Begin opens snap(s) only for the holder at HEAD's epoch and only from idle; a re-run of the open session writes nothing; killed at its write and re-run, it ends in snap(s) at one generation step. | M9 idle → snap | `core/frontend/chunkstore/layout` `head.go` `Head.Begin`, `RunBegin` | `TestBegin_Closure`, `TestRunBegin_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-ABORT-001` | Abort closes the holder's own snap(s) and changes nothing else; after its own crash a holder rolls the open session back before beginning another; over idle Abort writes nothing and its success never says whether the work was committed. | M9 snap → idle (Abort) | `core/frontend/chunkstore/layout` `head.go` `Head.Abort`, `RunAbort` | `TestAbort_Closure`, `TestAbort_IdleMeansNoActivityRemains`, `TestAbort_RollBackAfterOwnCrash`, `TestRunAbort_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
@@ -1091,6 +1093,8 @@ Notes:
| `INV-SNAPK-TXN-INTERRUPT-001` | A snapshot transaction killed at any of its writes (Begin, each object, Commit), before the write or after it applied with its reply lost, never leaves HEAD reaching a missing object, and the restarted holder (roll back, new session, base recomputed from HEAD) ends at the committed image. | M9 idle → snap → idle | `core/frontend/chunkstore/layout` `head.go`, `commit.go` (the transitions above) | `TestSnapshotSession_InterruptAtEveryStep`, `TestReachableMissing_Controls`, `TestAbort_AfterCommitLeavesTheCommit` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-CLAIM-LEASE-001` | A claim takes HEAD only at a newer epoch and only after every older holder's lease has ended (checked after the read, before the update); it voids any open session or cleaning, so the old holder's commit, abort and begin are refused. | M9 any → idle (Claim) | `core/frontend/chunkstore/layout` `claim.go` `RunClaim`, `Head.Claim` | `TestClaim_Closure`, `TestRunClaim_WaitsForTheOldLease`, `TestRunClaim_VoidsTheOldSession`, `TestRunClaim_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-CLEAN-EXCL-001` | A cleaning and a snapshot exclude each other through HEAD's one activity field, so no name is removed while a snapshot is open; a claim voids an open cleaning. | M9 idle → clean → idle | `core/frontend/chunkstore/layout` `clean.go` `Head.BeginClean`, `Head.EndClean` | `TestBeginClean_Closure`, `TestEndClean_Closure`, `TestEndClean_IdleMeansNoActivityRemains`, `TestClean_ExcludesSnapshot`, `TestRunBeginClean_InterruptAtEveryStep`, `TestRunEndClean_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-READ-MISSING-001` | A read resolves root, segment, chunk; an index the root does not name is zeros; a root, segment or chunk the root reaches but the store lacks is ErrMissing, never zeros; bytes that do not hash to their name are ErrCorrupt; a foreign chunk is read from its owner's pool. | Content-named layout (read path, no state transition) | `core/frontend/chunkstore/layout` `read.go` `Reader.Open`, `Image.Segment`, `Image.Chunk` | `TestRead_AbsentIndexIsZeros`, `TestRead_ForeignChunkFromSourcePool`, `TestRead_MissingObjectIsAnErrorNeverZeros`, `TestRead_FetchFailureAndCorruption`, `TestRead_SegmentOfAnotherShardRefused` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-REMOVE-LEASE-001` | A pool name is removed only inside the holder's own cleaning, only when no root in HEAD names it, and only after the remover's own lease is checked immediately before that delete; a lapsed lease stops the pass, an unreadable root or segment stops it before any delete, and a snapshot open on the volume refuses it. A source scan requires the lease check before every delete in the same block and refuses any other remover. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` `remove.go` `RemoveUnreachable` | `TestRemoveUnreachable_RemovesOnlyWhatNoRootNames`, `TestRemoveUnreachable_RefusedOutsideItsCleaning`, `TestRemoveUnreachable_StopsWhenTheLeaseLapses`, `TestRemoveUnreachable_NothingRemovedOnAPartialView`, `TestCleaningPass_InterruptAtEveryStep`, `TestGuard_Controls` | — (the snapshot kernel model is not in this repository) | ACTIVE |
| `INV-SNAPK-STALE-HOLDER-001` | Every transition refuses an older epoch of the same server and the same epoch held by another server, in idle, snap and clean; a new transition must be added to the table. | M9 every transition | `core/frontend/chunkstore/layout` `Head.heldBy` and each transition | `TestTransitions_RefuseAStaleHolder` | — (the snapshot kernel model is not in this repository) | ACTIVE |
Notes: