11 KiB
Immutable cleaning and intent list pages
This Draft integrates the immutable codec with the existing filer/blob store, HEAD CAS and cleaning exclusion. It is dormant: no cut/restore/delete driver calls the producer or consumer yet, and no automatic cleaner policy changes. This is not the final format declaration or the complete V8 producer wiring.
Version 1 is compact canonical JSON with keys in this order:
version, volume_id, kind, producer, generation, pages, next?, target?, entries.
Each reference is {hash, pages}. A snapshot target is {name, gen}.
Kinds are drop, upload-intent, and snapshot-delete-intent; the last
requires a captured nonzero snapshot incarnation. The enclosing full volume
ID binds it to its volume. The producer is an opaque identifier, not authority.
The object name is SHA-256 of swblock:list-page:v1 followed by a NUL and
the exact canonical bytes, stored under lists/<lowercase hex hash>.
The decoder checks the reference hash, full volume ID and remaining-page
count. Entries are strictly sorted unique canonical owned root/segment/chunk
paths, not HEAD, VOLUME, another list or arbitrary paths. Consumers must still
check live roots and retain the existing Stat/HEAD/conditional Mark/Delete
ordering; listing a name gives no right to remove it.
Format ceilings (not time limits): 1 MiB per encoded page, 4,096 entries per page, 4,096 pages per chain, 256 producer bytes. A tail has pages=1 and no next; a non-tail has pages=next.pages+1. One read/encode allocates one bounded page, not a volume-sized chain. A producer reaching a ceiling must refuse before its effect, never truncate or omit required work. These explicit ceilings are proposed for format review and must be confirmed before declaration.
ReadListChain validates producer/kind/target/generation consistency across pages, holding one bounded page at a time. The consumer advances progress only after completing the page executor's idempotent effects. An unread continuation must remain reachable until retirement is authorized. Neither an absent page nor malformed metadata may mean empty/completed work.
Fixed files in layout/testdata/list-page-v1 cover a drop page, upload intent,
and a two-page snapshot-delete intent. Their independent SHA-256 names are
pinned in tests. Negative controls exercise truncation, unknown/duplicate
fields, kind confusion, identity/hash mismatch, counts, canonical ordering,
forbidden paths and size/entry limits. Unknown newer versions are refused.
The fallback cleaner stays a full mark/sweep until a separately reviewed switch, made safe for reachable list/intent objects. Nothing in this codec starts that switch or weakens existing reclamation protections.
Publication, continuation and retirement
sequenceDiagram
participant Producer
participant Store
participant HEAD
participant Consumer
Producer->>Store: StageListPage (data before exclusive entry, session-owned)
Producer->>Store: read and validate complete chain
Producer->>HEAD: CAS base generation + open snap session -> list cursor
Note over Producer,HEAD: unknown reply retains ownership; reread/retry same attempt
Consumer->>Store: read authenticated current page under clean session
Consumer->>Consumer: finish idempotent, independently guarded effects
Consumer->>HEAD: CAS observed continuation -> next page or none
Note over Consumer,HEAD: lost reply settled from HEAD before success
Consumer->>Store: tags -> current HEAD reachability -> conditional mark/delete
HEAD has one optional list field, containing ref, kind, producer,
generation, and optional captured target. It is a serialized admission
slot: a second outstanding chain is refused, never overwrites unfinished
work. The slot is bounded and admitted only in version 1; a legacy encoding
cannot carry it. This slot is for reviewing the chain integration, not an
approval of final multi-producer queue capacity. The version remains 1;
all v1.1 fields belong to the final schema, never to ext.
Pages are staged by the already-open snap session. The original base HEAD generation and the full holder identity gate publication. Ending a session while an upload runs may leave an orphan, but its publication cannot land afterward. No failed/unknown publish path discards pages or ends its session. A replay that observes its exact live cursor settles a landed send even if a resend was refused. Otherwise the error remains unknown/refused, with no cleanup side effect.
ConsumeListPage authenticates one page, invokes an idempotent executor,
and advances only after that executor returns success. The executor must
use existing authority, reachability and conditional mutation rules; a list
is a set of candidates, not permission to remove an object or a snapshot.
A crash or refused cursor CAS can repeat that page's effects. Only a
confirmed persisted continuation is progress. Page retirement is separate:
Cleaner.Page(ListDir, ...) reads tags before HEAD, requires the existing
clean session, walks the current live chain and conditionally marks/deletes
only unreached pages. An open snap session refuses cleaning altogether,
protecting unsettled publication. A shared tail remains live even if an
abandoned attempt also contains it. A missing/corrupt live continuation
stops retirement, never means empty or complete.
Storage uses ordinary data-first exclusive filer objects with session and volume metadata. Reads check declared inline/blob sizes before payload fetch; the blob interface returns one object, so a dishonest blob backend that returns more than its declared size can allocate before the final size check. No stronger streaming allocation guarantee is claimed. Existing full-volume deletion remains the authority for namespace removal; this slice does not replace its sweep with the dormant list consumer.
Model trace: PageChain rows 246-253 (NoDangling, NoLostWork). Seven
mutations cover premature HEAD publication, loss of session protection,
unsettled abandonment, membership-based retirement, retirement before
cursor settlement, cursor before effects, and absent-as-end. Tests also
cover session end during upload and shared-tail continuation after restart.
The list publishing CAS also stamps legacy snapshot entries through the
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:
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
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. 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
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. A refreshed-base retry additionally adopts every page; a base fence alone cannot invalidate an earlier cleaner's outstanding conditional object operations. Adoption orders Stat -> validate current HEAD/base -> conditional Reuse, so an old adopter cannot read a new tag and then restore an old one. Staging only creates missing entries and never changes existing tags; a delayed staging request cannot undo adoption. 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.
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.
The generic StageListPage rejects snapshot-delete intent before any HEAD or
object I/O, just as generic publication and consumption reject that kind. Its
ordinary EnsureObject adoption must never restore a snapshot-intent producer
tag after dedicated publication protected it. The held-generic-staging control
crosses snap end, cleaner planning and refreshed publication and proves this
door cannot recreate an earlier cleaner's removal authority.