Migration runner — iterion migrate epoch and the boot floor
Read it when you add a persisted-data migration, run one against a store, read the v8 census preflight, or a server or runner pod refuses to boot on its migration ledger.
Every data migration is a registered step of one runner (pkg/migrate), never a one-off script and never a backfill hidden in EnsureSchema. A ledger records, per step, what was counted, applied and verified. In v7.x the step list (pkg/migrate/epoch) is empty: the runner ships dormant and the boot floor is a no-op on every deployment.
The step contract
A step implements migrate.Step:
| Method | Receives | Contract |
|---|---|---|
Census | Source, read-only | fingerprint of the snapshot read + count of records to change; writes nothing |
Apply | Target, writable; expected | refuses (CountMismatchError) when the live count is not expected; idempotent |
Verify | Source, read-only | records still to change; 0 = done |
Requirements | — | compiled capabilities Apply needs; Boot = the floor waits for it |
The read-only Source carries an fs.FS confined to the store root (every file opened read-only) or a ReadDB that exposes reads only and refuses an aggregation ending in $out/$merge (ErrReadOnly). A step that reaches around its handle is a review defect. Fingerprint with migrate.NewFingerprint over the records in a stable order. A new handle a step needs (fleet registry, queue, blob) is a new field of Source/Target, wired by the CLI.
What the runner guarantees
--applyre-takes the census first: a different fingerprint is refused (ErrSnapshotMoved), a different count too (ErrCountMismatch), and thecensused → applyingtransition is a compare-and-swap on the entry's revision, state and census fingerprint (ErrLedgerConflictto a racer).- A step with no census is refused (
ErrNoCensus); so is one whose capability the binary does not compile in (ErrCapabilityMissing). - An apply that fails or is killed leaves the entry
applying.--applythen refuses (ErrInterrupted);--resumere-censuses what is left, takes the apply over with a new token and finishes it. Witness: a helper process killed with SIGKILL mid-apply, on both stores (KillMidApply). - Applying an applied step with nothing left is a no-op recorded as
apply-noop; records to change again are refused (ErrDrift) until a new census. --resumedoes not lease: a previous apply still alive fails its next ledger swap, but both may write meanwhile — steps are idempotent for that.- An
applyingentry belongs to its apply, running or interrupted (the ledger cannot tell them apart): its final swap expects the revision it wrote.--censusrefuses it (ErrInterrupted) rather than replace the census the apply runs under, and goes on to the next step;--applyrefuses it too. Both say "wait for it to finish, or run --resume if it stopped": only--resumewrites it, from its apply record and a live census, so it also finishes anapplyingentry that holds no census.--censusreads the entry before it counts and swaps from that read: an apply that ends while it counts makes it fail (ErrLedgerConflict) and leaves the stepapplied. --verifyrecords only on anappliedstep. On acensusedorapplyingone it reports the remaining count,pending, and records nothing, so it can watch an--applyfrom its re-census to its last swap. On anappliedstep it records: a verify that lands while--applyreplays that step makes the replay fail (ErrLedgerConflict), and the apply stops there; rerun--apply. Witness: a verify run from the apply's re-census and from its first record, a census and a second--applyfrom its first record; the apply still finishesapplied, on both stores. An apply run to its end inside a census's count leaves the stepappliedwith history[census apply-start apply-done].
The ledger — two twins, one contract
| Store | Ledger | Written |
|---|---|---|
| filesystem | <store root>/schema_migrations.json (format: 1) | under schema_migrations.json.lock, atomic rename |
| Mongo | schema_migrations collection, _id = step id | insert / filtered replace |
Both pass migratetest.LedgerContract; the runner contract and the kill witness run on both (pkg/migrate for the filesystem, pkg/store/mongo for Mongo — the package CI's mongo-conformance job already runs). A missing file or collection is an empty ledger, and nothing creates either until a step records something.
Running it
iterion migrate epoch --census # count + fingerprint, read-only on records
iterion migrate epoch --apply # apply in order, verify each at zero
iterion migrate epoch --resume # --apply, continuing an interrupted step
iterion migrate epoch --verify # exit non-zero unless all applied at zero--step <id> (repeatable) narrows the run. The store is the Mongo database when ITERION_MODE=cloud (the pod's full environment, as for migrate orgs), else the filesystem store of the working directory or --store-dir. --json prints {mode, backend, location, steps, preflight, unknown, error} (preflight: --census only, below). An unknown entry is a step the ledger records and this binary does not know; apply_recorded is true when the ledger records an apply of it, finished or not, which the boot floor refuses whatever the entry's state. The text report names such a censused entry censused after an apply, as the floor's refusal does. A cloud census opens the database without the store's EnsureSchema.
The boot floor
The cloud server and every runner pod read the ledger right after opening the Mongo store (migrationFloor.enforce, cmd/iterion/migrate_floor.go) — after the NATS stream and KV ensure (natsq.Connect) and the store's own index ensure, before the other Mongo schema ensures, the fleet registry join, the rollout epoch claim and, for a runner, the queue consumer bind — and refuse to boot when an entry is applying/applied for a step this binary does not know (a newer binary migrated the store), was applied under a capability it does not compile in, carries a state it does not know, or when a Boot step is not applied. A censused entry of an unknown step passes — a newer binary's census rehearsal must not stop the running fleet — unless the ledger records an apply of it: a census that finds records to change again on an applied step moves it to censused and keeps the apply record, so an older binary still refuses it, and a binary whose step is Boot refuses until the next --apply.
The floor guards what the steps change in Mongo. A refused process has already ensured its NATS streams and KV buckets (the queue, the rollout epoch, the fleet registry) to its own configuration, so a step that changes those is not protected by it.
The floor is read once, at boot: a process already serving when a step is applied keeps serving and writing. Run --apply only once the previous generation is drained — no fleet registry member runs a binary that does not know the step. The one-shot commands that write records into the cloud store, iterion migrate to-cloud and iterion migrate orgs, do not check the floor: run them with a binary that knows every step the ledger records.
Escape hatch: --skip-migration-floor, one flag per process — iterion server --skip-migration-floor, iterion runner --skip-migration-floor — boots that process anyway and logs each overridden refusal at error level (migration floor skipped), whatever ITERION_LOG_LEVEL says; setting it on one leaves the other's floor closed. Local mode does not check the floor.
The v8 census preflight
--census also runs the census items of pkg/migrate/preflight (v8 L6-02): named, versioned counts of what the store holds that the v8 cut must drain, answer or carry. They read through the steps' read-only Source and record nothing, the ledger included; an unchanged store gives the same report and fingerprint. --json carries them under preflight, with refs naming the records to act on. An item with nothing to count on a backend reports applies: false and why, never 0; a source that is not a run store (a root without runs/, a database without runs) fails the census. A new item implements migrate.CensusItem, joins preflight.Items(), and bumps Version() when what it counts changes.
| Item | Counts |
|---|---|
runs-to-drain | runs not terminal, plus failed_resumable, by status |
human-queue | paused_waiting_human + failed_resumable (plan A5) |
forge-gated-runs | runs to drain holding a forge publish grant on a pull request |
dlq-parked-runs | runs whose failure code is DLQ_PARKED |
run-references | records naming no live run: run-store tables, runs' links (parent_run_id, forked_from, delegation, lineage root), the platform's pointers by collection.field (board cards included); FS: run dirs without run.json, deleted ones still holding records, the same links, the pointers' local twins, .run-data-v1, worktrees/ and merges/ |
untenanted-documents | run-store documents without tenant_id (Mongo) |
pre-lineage-sessions | refresh sessions without a lineage (Mongo) |
orgs | teams with no org, or a gone one; orgs by status (Mongo) |
memory-entries | memory documents by space visibility (Mongo) |
scratch-banks | gzip'd scratch banks of parked runs (FS; the cloud keeps them in the bucket) |
fleet-registry | the nodes: NATS, out of the handle's reach, so applies: false naming the read |
Runbook: at T-weeks, T-7, T-1 and in the window
Operator steps, against prod only on the operator's go; time the census on the R1 restored dump first, since it reads every run-keyed collection.
- Drift. The cluster runs what GitOps holds: the generation check of sync liveness, and the pods'
imageIDagainst the pinned digests. - Backups as deployed. Read the applied CronJobs (the Mongo dump, the
backup.*tiers) against cloud-backup.md: schedule, destination, last success, each bucket copy starting after its dump ended. - Proof of an S3 copy. List the latest dump and copy at the destination (
rclone lsl), compare object count and a sampled checksum with the source, and keep the listing beside the census report. - Census. In a pod with the server's environment:
iterion migrate epoch --census --json > census-<date>.json. Compare fingerprints across runs: equal means nothing the items read moved. - What the census does not reach. The dead-letter streams, one page per call:
iterion remote api GET '/api/admin/dlq?limit=200&cursor=0', again withcursor=<next_cursor>until it is 0,&pool=<name>per dedicated pool, to matchdlq-parked-runsand export; the fleet registry:iterion remote api GET /api/admin/fleet, empty during--apply; from the bucket copy, the scratch banks and the run ids of the per-run key spaces, against the live runs. A test runs each named command (TestMigrateEpochCensusOperatorReadsRunAsWritten). - Gate.
human-queueat 0, its runs answered, exported or exempted by name on the v8 migration page;forge-gated-runsat 0; the DLQ exported. Every other count is carried by a step or named as a loss.
