fix(consensus-db): tolerate a missing data table during migration - #392
Open
Dusk1e wants to merge 1 commit into
Open
fix(consensus-db): tolerate a missing data table during migration#392Dusk1e wants to merge 1 commit into
Dusk1e wants to merge 1 commit into
Conversation
migrate_certificates and migrate_decided_blocks open their table inside a read transaction, which fails with TableDoesNotExist when the table is not there. migrate_undecided_blocks and migrate_pending_parts open theirs inside a write transaction, which creates it, so those two already treat a missing table as an empty one. A datadir can reach the migration before the tables exist. Db::new migrates, and only afterwards does Store::open call create_tables; needs_migration records "file exists, no schema version" as v0 and asks for a migration, and redb makes the file before that version is written. A first start interrupted in between leaves a database that every later start rejects, and `db migrate` rejects it the same way, dry run included. Treat a missing table as empty in both, matching the other two.
Dusk1e
requested review from
ZhiyuCircle,
ancazamfir,
romac and
sergio-mena
as code owners
September 12, 2026 16:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
migrate_certificatesandmigrate_decided_blocksopen their table inside a read transaction:open_tableon a read transaction returnsTableDoesNotExistwhen the table isn't there. The other two table migrations,migrate_undecided_blocksandmigrate_pending_parts, open theirs inside a write transaction, which creates it, so those already treat a missing table as an empty one. The first two abort the whole migration instead.A datadir can reach the migration before the tables exist.
Db::newmigrates, and only afterwards doesStore::opencallcreate_tables.needs_migrationrecords "file exists, no schema version" as v0 and asks for a migration, andredb::Database::createmakes the file before that version is ever written — so a first start interrupted between the two leaves a database that every later start rejects with:db migratefails the same way,--dry-runincluded, sincepreview_migrateruns the same functions.The change treats a missing table as empty in both, which is what the other two already do. The added test fails on
mainwithTableDoesNotExist("certificates")and passes with the change; the rest of the crate's suite (107 tests) still passes.