Repository navigation
impl(backups): mesh class D — fleet-queue-backup D1 export to Turso home (#13458) - #13539
Conversation
The reverse direction of the #8584 leg: bin/export_to_turso.py exports the fleet-queue-backup D1 database into its dedicated Turso home (d1-backup-fleet-queue-backup) on a weekly schedule, reusing restore_drill's proven D1 read path (keyset paging, CAST AS TEXT integer fidelity, _cf_KV excluded) and fq_common's libsql client. Wholesale replace, staged: the new copy is loaded into staging tables and verified (emitted counts, cross-checked against the source so a mid-run source move fails the run) before anything live moves; a failed import leaves the previous import intact. The swap writes the incoming record as a marker before its first rename and as the import record after live counts verify -- marker/record agreement by import_id is the commit point -- and a later run reconciles retiring tables against it (roll back an uncommitted swap, drop a committed swap's leftovers). bin/restore_drill_d1_home.py is the acceptance drill: rebuild the D1 database from the home into a local SQLite file and verify counts against the import record. Weekly systemd units (Sun 03:40) + wrapper fetching credentials by name, install-units and argument-test coverage, schedule-registry row in the same pass, README + runbook (incl. the provisioning steps for the live leg). Hermetic tests: sqlite3 is the oracle -- row-for-row copy incl. int64::MAX, wholesale replacement, failed-import and smear refusal leaving the previous import intact, and both swap-crash readings.
…3458) home_schema lists every table in the home, staging included, so _swap renamed the staging tables aside as if they were the live copy and then could not find them to rename in. Caught by the hermetic suite on its first remote run (6 errors, no such table: _d1stage_tasks).
#13458) recover_interrupted_swap built its 'live' set from every table in the home -- retiring tables included -- dropped them all, and then failed renaming the retiring tables back ('no such table: _d1retire_tasks'). The rollback now decides per live table from the marker: the marker carries the pre-swap live set (replaces), and a live table is dropped only when a retiring copy shadows it or it is an incoming table that did not exist before the swap; untouched old copies stay. New test covers the early-crash shape (one table renamed aside, the rest live, one incoming-only table already in). Caught by the hermetic suite on its second remote run: 5 of 6 export tests passed, this one errored.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 34 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc40874e12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| record = export_to_turso.read_import_record(home) | ||
| if record is None: | ||
| raise RuntimeError("Turso home has no import record; nothing to verify") |
There was a problem hiding this comment.
Verify the import generation stays stable throughout the restore
If the weekly export swaps the home while this drill is reading it, separate table/page requests can copy different import generations. The drill reads the import record only once and never checks the swap marker or rechecks import_id, so an export that changes values without changing per-table counts lets a mixed-generation database pass verification. An interrupted export after the incoming renames can likewise expose uncommitted data under the previous import record. Reject an uncommitted swap and verify that the committed generation remains unchanged through the final read before reporting success.
Useful? React with 👍 / 👎.
Refs #13458 — backup-mesh class D leg (design: #9093, record PR #13467). This PR lands the code half of the leg; the issue stays open for the live leg and the step-2 inventory (named on the issue).
What lands
The reverse of the #8584 pipeline, reusing its machinery (
fq_commonclients,restore_drill's D1 schema/read path with keyset paging and CAST-AS-TEXT integer fidelity):bin/export_to_turso.py— weekly D1 → Turso-home export for thefleet-queue-backupD1 database into the new homed1-backup-fleet-queue-backup. Staged wholesale import: load into_d1stage_tables, verify emitted counts cross-checked against D1count(*)(a disagreement means the source moved mid-run → fail, previous import intact — the Fleet unification slice 6: backups — Turso into D1, repos to Cloudflare plus mirror plus R2 #8584 smear lesson), then swap behind a commit marker in_d1_backup_home_meta(marker/recordimport_idequality is the witness), recreate indexes/views/triggers, verify live counts, write the import record with per-table counts, drop the retiring set. An interrupted swap is recovered at the next run's start: uncommitted → roll back to the recorded import; committed → clean the retiring leftovers.bin/restore_drill_d1_home.py— the restore verification: rebuilds the D1 database from the home alone into a local SQLite file (the issue's local-SQLite scratch target) and verifies counts against the import record.systemd/—run-d1-home-export.shwrapper (secrets by name from Bitwarden; fails with a clear message while the home token is unprovisioned),fleet-queue-backup-d1-home.service(TimeoutStartSec=2h) +.timer(Sun 03:40 + RandomizedDelaySec 30m, Persistent),install-units.shextended, argument tests extended.tests/test_export_to_turso.py(6) +tests/test_restore_drill_d1_home.py(3) — hermetic, sqlite-backed fakes in the established standalone pattern. They caught two real defects during development (the swap renaming its own staging tables aside; a fixture drop-order error), both fixed in-branch.doc/fleet-schedule-registry.md— new Surface 2b row for the timer (declared in repo; laptop install is part of the issue's live leg).No new dependencies (Python standard library only). No changes to
fq_common.pyorrestore_drill.py.Evidence
Full
infra/fleet-queue-backupsuite run remotely against this branch (fleet queue dispatch): fleet-command run 45230221803 — conclusion success: all 9 test files pass (38 tests: pre-existing 29 incl. the #8584 suites, plus 7 export + 3 D1-home drill tests added here) andsystemd/test-export-arguments.shreports all checks passed. Two earlier runs against this branch (45221374628, 45228755235) caught real defects in the new code — the swap renaming its own staging tables aside, and the rollback dropping the retiring set it was about to restore — both fixed in-branch with regression tests before this green run.What remains on #13458 after this PR
d1-backup-fleet-queue-backup, mint the vault tokenturso.d1-backup-fleet-queue-backup-rw-token, install the units on the laptop, first live import record posted on the issue, live restore verification.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.