Repository navigation
3.x.x: let migrate --offline-indexes build 013's and 024's indexes with a plain parallel CREATE INDEX in one transaction when no instance is live - #745
Merged
Conversation
Codex Review SummaryThis 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. |
…th a plain parallel CREATE INDEX in one transaction when no instance is live The W1 cutover's migrate step runs with every frontend stopped, yet 013 and 024 build their indexes the online way: CREATE INDEX CONCURRENTLY reads the share ledger twice and waits out every older snapshot, and DROP INDEX CONCURRENTLY runs statement by statement. The plan puts the gain of building them plainly at about 3.7 down to 1.5 to 2 minutes of outage, to be measured in the pair rehearsal. `qbit-prism-server migrate --offline-indexes [--index-build-workers N] [--index-build-memory SIZE]` runs each index migration's plan in one transaction instead. N defaults to 4, at most PostgreSQL's 1024. SIZE is a maintenance_work_mem as PostgreSQL writes it, checked before connecting; without it the run takes 2GB, or the server's setting when that is higher. A build's sort takes about that much in all, divided among its leader and workers. The transaction takes the migration lock and sets a 5 s lock timeout, the workers and the memory for itself. Before any DDL it refuses an instance that has not reported drained or stopped and a live legacy writer lease, naming plain migrate, which builds CONCURRENTLY and records without stopping frontends, as the way out. It then locks the migration's tables ACCESS EXCLUSIVE in name order, runs each rendered definition verbatim as a plain build, drops with a plain DROP INDEX, verifies the declared set and records the version as it commits. Only a lock timeout reads as a transaction still holding a table; any other failure, in the guards or the table lock, surfaces as itself. An interrupted migration rolls back whole, so no invalid index and no partial drop remain while the migrations recorded before it stay recorded, and a rerun without the flag builds concurrently. The switch is the operator CLI's alone. MigrateOptions carries it beside #743's share-hash backfill mode, so migrate takes --defer-share-hashes and --offline-indexes together, as the W1 cutover's migrate step runs them: the recent range is mapped first, before 013 drops the index that serves it, and 013 and 024 then build offline with the backfill pending. Ledger::connect_migrate takes the options, or a ShareHashBackfill alone as before, through #743's shared operator connect; every other connect passes the default, so frontends with PRISM_POSTGRES_INIT_SCHEMA=1 run the same loop and stay on CONCURRENTLY. 013's SQL and registration are unchanged and no migration number is taken. Both modes share the preflight plan, the step loop and the record, and the legacy lease refusal is factored out of migrate_schema. Six gated index_trim tests watch offline runs through event triggers: the rendered definitions run verbatim in the transaction that records the version while an append waits; a live instance or legacy lease is refused before any DDL; an open writer or reader ends the run with 55P03 and nothing changed; a terminated run rolls back whole, after which a start without the flag builds concurrently; the operator's build memory is taken even below the server's, which is otherwise never lowered; and a lock timeout inside the guards reads as itself. A gated share_hash_backfill test runs the cutover's migrate step, both flags in one run on a populated 2.x.x source: the recent range is mapped at fence 2, 013 and 024 build offline with nothing concurrent, and a frontend then starts and serves. Unit tests pin the statements, the lock failure classification and the memory parser, and config_cli pins the flags. The docs describe the mode, its worker and memory needs and starting frontends only after migrate returns, and the isolated-restore runbooks pass the flag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke
force-pushed
the
RobertClarke/rc5-offline-index-builds
branch
from
October 7, 2026 23:08
6995506 to
118b512
Compare
This was referenced Oct 8, 2026
RobertClarke
added a commit
that referenced
this pull request
Oct 8, 2026
…n throttled batches, and let the evidence export and self-check read it pending migrate --defer-share-hashes leaves migration 2's share-hash backfill pending at share_hash_backfill_pending = 2 while frontends serve. The new qbit-prism-server backfill-share-hashes maps the rest and records 2. Plain migrate on such a database now takes the same path, at the default throttle, instead of rc.4's unthrottled batches, with or without #745's --offline-indexes, which changes only how 013 and 024 build. A Throttle bounds every batch: at most --max-batch share_seq values (5,000), one statement in a transaction of its own, cancelled at --statement-timeout-ms (2 s, at most 5 s) and retried at half its size, and a rest of took * (1 - d) / d after each, where d is --duty-cycle (0.5). Every native append updates the cluster row under ORDER_LOCK, and a snapshot held on the primary keeps that row's dead versions (#738), so no statement holds one longer than its timeout, and none is held between batches. Each bound is checked in one place, which the flags' parsers call before anything connects. The chunked double-credit check that runs before 2 is recorded keeps to the same throttle. A batch or chunk that times out at its smallest size says to run backfill-share-hashes with a smaller --max-batch, or else a larger --statement-timeout-ms up to the cap; plain migrate's error names that command, as migrate takes no throttle flags. While frontends serve, the transaction that records 2 waits at most 2 s for the migration lock or the cursor table's lock, and its statements keep to the throttle's timeout. An attempt that waits longer is rolled back, holding nothing, logged, and tried again after a backoff from 2 s doubling to 30 s, 20 times, about ten minutes in all. The run then stops, naming what held it and to run backfill-share-hashes again, which goes straight to the double-credit check and the record. The record of a backfill before anything serves is unchanged. The command refuses, before it maps anything, a backfill that does not permit serving, and it shares A1's checks under the runners' lock: the fence and the claim, 017's conversion bound, the frozen end and the double-credit refusal. On a database whose backfill has finished it maps nothing and succeeds, so a retry after a lost reply is safe. It prints what it did as JSON, already_complete included. The recovery evidence export now reads a database at fence 2, as every start does. It exports the cursor as one share_hashes_deferred record in place of the partial mapping, and the summarizer marks the share_hashes kind deferred with it and says so in a note. The preamble, which every parallel session runs, reads only the catalog, and the cursor is read last, after the integrity report, so an export holds the cursor table's lock only until it commits, right after. The refusal of a cursor at fence 1 names migrate --defer-share-hashes to serve and plain migrate to finish; one that a build before #669 started, with no fence, names plain migrate alone. A complete export's summary is unchanged, and the parallel export and summarizer stay byte-identical to the serial ones. The export checks each capability's value against the highest that startup accepts, from one declaration that a unit test compares with NATIVE_CAPABILITIES. self-check samples the backfill beside the heartbeats, in one read of the cursor and its fence under one 5 s deadline, and reports it in a share_hash_backfill field with a warning line, never as a failure: "pending" with the fence and the cursor, or "unknown" with why it could not be read, a connection failure's text withheld. The field is absent only when the read succeeded and nothing is pending. The start gate's warning, migrate --defer-share-hashes's output and the share-archive refusals while the backfill is pending name backfill-share-hashes as the way to finish it. The migration guide and the ledger runbook describe when and how to run it after go-live, its throttle, how to watch it, the record's retries, and how to compare evidence while it is pending. The recovery test helpers now refuse an export script edited after the test binary was built. The serial export runs the copy compiled in, while the parallel exporter and the summarizer read the file, so a full suite whose script changed under it compared two scripts' exports: the deferred export test once failed so, at the line the edit had moved. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke
added a commit
that referenced
this pull request
Oct 8, 2026
…n throttled batches, and let the evidence export and self-check read it pending (#746) migrate --defer-share-hashes leaves migration 2's share-hash backfill pending at share_hash_backfill_pending = 2 while frontends serve. The new qbit-prism-server backfill-share-hashes maps the rest and records 2. Plain migrate on such a database now takes the same path, at the default throttle, instead of rc.4's unthrottled batches, with or without #745's --offline-indexes, which changes only how 013 and 024 build. A Throttle bounds every batch: at most --max-batch share_seq values (5,000), one statement in a transaction of its own, cancelled at --statement-timeout-ms (2 s, at most 5 s) and retried at half its size, and a rest of took * (1 - d) / d after each, where d is --duty-cycle (0.5). Every native append updates the cluster row under ORDER_LOCK, and a snapshot held on the primary keeps that row's dead versions (#738), so no statement holds one longer than its timeout, and none is held between batches. Each bound is checked in one place, which the flags' parsers call before anything connects. The chunked double-credit check that runs before 2 is recorded keeps to the same throttle. A batch or chunk that times out at its smallest size says to run backfill-share-hashes with a smaller --max-batch, or else a larger --statement-timeout-ms up to the cap; plain migrate's error names that command, as migrate takes no throttle flags. While frontends serve, the transaction that records 2 waits at most 2 s for the migration lock or the cursor table's lock, and its statements keep to the throttle's timeout. An attempt that waits longer is rolled back, holding nothing, logged, and tried again after a backoff from 2 s doubling to 30 s, 20 times, about ten minutes in all. The run then stops, naming what held it and to run backfill-share-hashes again, which goes straight to the double-credit check and the record. The record of a backfill before anything serves is unchanged. The command refuses, before it maps anything, a backfill that does not permit serving, and it shares A1's checks under the runners' lock: the fence and the claim, 017's conversion bound, the frozen end and the double-credit refusal. On a database whose backfill has finished it maps nothing and succeeds, so a retry after a lost reply is safe. It prints what it did as JSON, already_complete included. The recovery evidence export now reads a database at fence 2, as every start does. It exports the cursor as one share_hashes_deferred record in place of the partial mapping, and the summarizer marks the share_hashes kind deferred with it and says so in a note. The preamble, which every parallel session runs, reads only the catalog, and the cursor is read last, after the integrity report, so an export holds the cursor table's lock only until it commits, right after. The refusal of a cursor at fence 1 names migrate --defer-share-hashes to serve and plain migrate to finish; one that a build before #669 started, with no fence, names plain migrate alone. A complete export's summary is unchanged, and the parallel export and summarizer stay byte-identical to the serial ones. The export checks each capability's value against the highest that startup accepts, from one declaration that a unit test compares with NATIVE_CAPABILITIES. self-check samples the backfill beside the heartbeats, in one read of the cursor and its fence under one 5 s deadline, and reports it in a share_hash_backfill field with a warning line, never as a failure: "pending" with the fence and the cursor, or "unknown" with why it could not be read, a connection failure's text withheld. The field is absent only when the read succeeded and nothing is pending. The start gate's warning, migrate --defer-share-hashes's output and the share-archive refusals while the backfill is pending name backfill-share-hashes as the way to finish it. The migration guide and the ledger runbook describe when and how to run it after go-live, its throttle, how to watch it, the record's retries, and how to compare evidence while it is pending. The recovery test helpers now refuse an export script edited after the test binary was built. The serial export runs the copy compiled in, while the parallel exporter and the summarizer read the file, so a full suite whose script changed under it compared two scripts' exports: the deferred export test once failed so, at the line the edit had moved. The record of 2 while frontends serve retried a failed attempt without asking whether it had committed. An attempt can commit and still fail: its COMMIT's reply lost with the connection, or cut short after the commit was written. A retry then met the cursor that commit had dropped, failed on the missing table, and reported a finished backfill as failed. Now every failed attempt is followed, before anything else, by a read of what it left, in one statement of a fresh transaction under the record's own timeouts: whether 2 is recorded, and whether the cursor table exists. With 2 recorded and the cursor gone the backfill is done: the run logs that the attempt's reply was lost or cancelled but 2 is recorded, and succeeds as any finished run does. With 2 unrecorded and the cursor in place nothing committed, and a wait past a lock or statement timeout is retried as before. Either other state was made by hand, since the one transaction that records 2 drops the cursor in the same commit, and is refused loudly rather than retried. A read that fails too stops the run, naming backfill-share-hashes, which finds 2 recorded or records it. The statement timeout still covers the COMMIT. Under synchronous replication a COMMIT waits for the standby with its xid running and its locks held, which #738 rules out for long, and a cancelled wait leaves the commit local, which PostgreSQL reports as done with a warning. The re-check covers every way an attempt can fail after its commit, and a comment by the record's transaction says why. A gated lib test injects the failure through a test-only fault hook, in the pattern of the candidate claims' faults: keyed by schema, it lets the first record attempt commit and then return PostgreSQL's 57014. The run reports the backfill done, with 2 recorded and the cursor and the fence gone. A unit test pins the four states the read can find. The migration guide and the ledger runbook say what the run does after a lost reply. Every read of the share-hash cursor took any 42P01 for the cursor dropped since its look-up, by the transaction that records 2, and read it as nothing pending. But the read can miss another relation it needs: self-check's reads the fence from qbit_prism_schema_capabilities, so a database with its cursor beside a missing capability table, a damaged one self-check should diagnose, read as one whose backfill had finished, and self-check omitted both the field and the warning. Now a 42P01 reads as nothing pending only if the cursor is gone when it is looked up again, in one short statement. Otherwise the read's own error goes on, and self-check reports the backfill as unknown with it. Both readers of the cursor, self-check's and the one every start and migrate makes, go through that one place. The record of 2 has no such shortcut: its re-check after a failed attempt reads the catalog and the migration history, and a failure there stops the run. self-check's backfill test in ledger_postgres renames the capability table beside a pending cursor and requires state unknown with the missing relation named, and the warning. A gated lib test drops the cursor between its look-up and its read, through a test-only fault the record test's hook now shares, and requires both readers to read nothing pending. The lib tests move to share_hashes/postgres_tests.rs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke
added a commit
that referenced
this pull request
Oct 8, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.5: rc.4 plus #737's fixes in #742 (fatal-state clear accepts a tip that only grew, takes --timeout-seconds, and runs the integrity report under its own statement timeout) and #744 (migration 026: the report computes each set once); the deferred share-hash backfill in #743 and #746 (migrate --defer-share-hashes, then the throttled backfill-share-hashes after go-live); #745 (migrate --offline-indexes, which composes with --defer-share-hashes); the cutover tooling merged after rc.4's tag (#728, #732, #736, #740); and #747, a test-only fix for #724. Both Cargo.lock files move only their workspace-member entries. doc/release-notes-3.0.0-rc.5.md, dated 2026-10-08, covers: - the changes, with the report's estimated 57 to 29 s since 026, the migrate --defer-share-hashes command measured on the pair at 5 min 06 s (539d6c9, before #745), backfill-share-hashes' throttle, record of 2 and safe rerun, the evidence scripts' changes, and the offline index builds' estimated gain; - upgrading: migrate is needed again (a binary-only upgrade refuses "missing migration(s) 26", and this export refuses a database without 026), the cutover's migrate step with both flags, and finishing the backfill after go-live under #738's snapshot rule, with self-check only at low share rates. Rolling back to rc.4 at fence 2 goes only by finishing the backfill first or from the pre-migrate backup or physical copy, and each rc.4 refusal is quoted where it applies: a start meets the cursor first and says to run migrate, which rc.4's migrate refuses. The rules still in force: #737's statement timeout for rc.4's tools, 026 or not, #738's snapshot rule, and fatal-state clear --timeout-seconds, whose bound ends before the commit; - the same evidence set as rc.4's, with each PR's merge SHA, the pair's serving evidence carried, and the rehearsal's full measurements left to the cutover's go/no-go record; - the known issues: rc.4's, minus #737's F1, F2, F4 and F5, plus #737's open part, #738 (its fix planned for rc.6), #739, #741, #731 and #734, with #582 closed and #712 and #724 updated. docs/prism-rust-migration.md now says how earlier candidates refuse a database at fence 2: a start with the backfill's own refusal, whose advice to run migrate holds only for this release, and their migrate, or a start with PRISM_POSTGRES_INIT_SCHEMA=1, with the fence. The development-line notes name 3.0.0-rc.5, and they and the 3.0.0 notes link all five candidates' notes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
PR-B of PRISM rc.5 (design: section B of
rc5-plan-u3.md, "(d2) plain parallelCREATE INDEXfor 013 (and 024) when no instance is live").The W1 cutover's migrate step runs with every frontend stopped, yet 013 and 024 build their indexes the online way:
CREATE INDEX CONCURRENTLYreads the share ledger twice and waits out every older snapshot, andDROP INDEX CONCURRENTLYruns statement by statement. This adds an opt-in offline build for that case:qbit-prism-server migrate --offline-indexes [--index-build-workers N] [--index-build-memory SIZE] # N defaults to 4. SIZE defaults to 2GB, or the server's maintenance_work_mem when that is higher.With the flag, each index migration (013, then 024) runs its usual plan in one transaction, with a plain parallel
CREATE INDEXof each rendered definition and a plainDROP INDEX, and records its version as that transaction commits. Without it, nothing changes:migrateand every frontend build concurrently as before.It composes with #743's
--defer-share-hashes. The W1 cutover's migrate step runsqbit-prism-server migrate --defer-share-hashes --offline-indexes:A gated test runs exactly that. The plan expects the outage to drop from about 3.7 min to 1.5 to 2 min. That is unmeasured; the pair rehearsal should measure it (below).
No migration number is taken. Migration 013's SQL and its registration (
NATIVE_MIGRATIONS,ONLINE_MIGRATIONS,derive_online) are byte-identical.Design
The opt-in is the operator CLI's alone.
Command::Migrate { offline_indexes, index_build_workers, index_build_memory }. There is no environment variable, because compose frontends run the same online-migration loop withPRISM_POSTGRES_INIT_SCHEMA=1, and they must stay onCONCURRENTLY.--index-build-workers(default 4) is limited to0..=1024, PostgreSQL's limit formax_parallel_maintenance_workers.--index-build-memorytakes a size as PostgreSQL writes one, parsed and bounded as PostgreSQL parsesmaintenance_work_mem:B,kB,MB,GBorTB(case-sensitive;kBwithout one);So
migraterefuses a bad size before it connects, not after the migrations ahead of the build. PostgreSQL also takes an exponent such as1e3MB; the parser refuses that, which is only stricter.Both options
requires = "offline_indexes".Plumbing, composed with #743.
pub struct MigrateOptions { pub share_hashes: ShareHashBackfill, pub index_build: IndexBuildMode }:share_hashesuses 3.x.x: let migrate --defer-share-hashes serve with 002's share-hash backfill pending once it has mapped the recent range #743's type unchanged.Defaultis every connect's:ShareHashBackfill::InitializeandIndexBuildMode::Concurrent.From<ShareHashBackfill>gives that backfill mode with concurrent builds.Ledger::connect_migrate(url, impl Into<MigrateOptions>)goes through 3.x.x: let migrate --defer-share-hashes serve with 002's share-hash backfill pending once it has mapped the recent range #743's sharedconnect_as_operator. So its existing callers, which pass aShareHashBackfillalone, are unchanged, andmigratepasses both modes.connect_as_operatorandconnect_innertake the options:options.share_hashesgoes tomigrate_schema;options.index_buildgoes toapply_online_migration.connect,connect_with_metrics,connect_toolandconnect_operatorpassMigrateOptions::default().migrate's CLI builds the options from--defer-share-hashes(Defer, otherwiseFinish) and--offline-indexes/--index-build-*.IndexBuildMode { Concurrent, Offline { workers: u16, memory_kb: Option<u32> } }lives inonline.rs. Both types arepub, re-exported fromledger, because the gated integration tests callconnect_migrate.online.rs.applykeeps the session setup (statement and lock timeouts 0), the runner lock and therecorded()short-circuit, then dispatches on the mode. Both modes share the rest:plan(), the preflight factored out ofapply;run_plan(), the one Keep/Build/Rebuild/Drop/Dropped step loop. Only a concurrent step's changes go into the progress the refusals report; an offline step's roll back with its transaction;record():verify_declared, the version's insert and the commit.The modes differ only in their setup and statements:
apply_concurrentlyruns the plan on the session, then records in a fresh transaction underMIGRATION_LOCK.apply_offlinedoes everything in one transaction:MIGRATION_LOCK. That wait has no timeout, as in the online runners' record step.lock_timeout5 s,max_parallel_maintenance_workersto the requested workers, andmaintenance_work_memto--index-build-memory. Without that flag it is 2GB, unless the server's is higher, in which case the server's is kept.refuse_unquiesced_instances, which keepsqbit_prism_instanceslocked until commit) and a live legacy writer lease (refuse_live_legacy_lease, factored out ofmigrate_schemaunchanged).qbit-prism-server migrate, which builds CONCURRENTLY and records without stopping frontends.LOCK TABLE … IN ACCESS EXCLUSIVE MODEon the distinct tables, in name order.lock_failure).CREATE INDEXprefix check, and a plainDROP INDEXafterdrop_planned's re-lookup.The run logs the workers it asked for,
maintenance_work_mem,max_parallel_workersandmax_worker_processesbefore it builds. Each build'sindex builtline carries itselapsed_ms.Anything that ends an offline migration's transaction before its commit rolls that migration back whole: no invalid index, no partial drop, no record. The migrations the same
migraterecorded before it stay recorded, and the messages say so. A rerun without the flag falls back toCONCURRENTLY. 016/017 and the fingerprint don't notice the build mode: the swap checks onlyto_regclassandindrelid, andpg_get_indexdefrenders a plain build the same way as a concurrent one. 024 gets the mode for free.Memory. A build's sort takes about
maintenance_work_memin all, not that much per worker. PostgreSQL treats it as the limit of the whole parallel utility command and divides it among the leader and the workers, each needing at least 32 MB or the build launches fewer workers. I checked this on PG16 withtrace_sort: with 64MB and 4 workers requested, the build launched 1 worker, each participant's sort gotworkMem = 32768kB, and the leader's merge used 65536 kB. The docs say so and ask the operator to size--index-build-memoryto the memory the database host has free.Docs.
docs/prism-rust-migration.md:migratereturns;migrateas the way out of a refusal or of a built-but-unrecorded leftover while frontends serve;--index-build-memoryand the memory need.time qbit-prism-server migrategains--offline-indexes.docs/prism-ledger-ops.md:time qbit-prism-server migrategains--offline-indexes.online.rsmodule doc (header and offline paragraph),OnlineMigration::Indexes,ONLINE_MIGRATIONS,IndexBuildMode,MigrateOptionsandconnect_migrate, plus a call-site comment inconnect_inner.Tests
New gated tests in
tests/support/index_trim.rs(listed intest/prism-gated-tests.txt). They watch an offline run through a probe of two event triggers in the fixture database. The probe records each index the test schema creates or drops, withcurrent_query()and the build settings in force, in a table whose rows commit or roll back with the statement's transaction. It can hold a statement, still inside the run's transaction, until the test releases it.migration_013_offline_builds_plain_indexes_in_one_transaction_with_every_instance_stoppedqbit_share_ledger. An append waits on it (pg_blocking_pids).xminof 13's record, in plan order with the expected text and the settings5s 3 2GB: build, the rebuild's drop and build, and four plain drops. 024's build shares 24's record.migration_013_offline_refuses_a_live_instance_or_legacy_lease_before_any_ddlmigration_013_offline_fails_fast_behind_an_open_writer_and_changes_nothing55P03and the lock-timeout text, after at least the 5 s lock timeout and within the test's 60 s cap.migration_013_offline_rolls_back_a_partial_run_wholemigration_013_offline_takes_the_operators_build_memory_and_otherwise_never_lowers_the_serversmaintenance_work_memis set to 3GB.memory_kb64MB they see 64MB.migration_013_offline_reports_a_lock_timeout_in_its_guards_as_itselfqbit_prism_instances. The run fails with 55P03 under "could not check for live instances and legacy writers", never as a live instance.Unit tests:
an_offline_build_runs_the_rendered_definition_verbatimpins the offline and concurrent statements, the drop statements and the default mode.only_a_lock_timeout_reads_as_a_transaction_holding_the_tablecovers 55P03 against 40P01, 57014, 57P01, 42P01 and none.index_build_memory_is_parsed_and_bounded_as_postgres_does(intools.rs): sizes in kilobytes with fractions, whitespace and every unit; case-sensitive units refused; the 1MB..2147483647kB bounds.config_cli.rs:migrate --offline-indexes --index-build-workers 8andmigrate --offline-indexes --index-build-memory 1.5GBreach PostgreSQL (database_only_cli_commands_reach_postgres_without_reading_seeds).offline_indexes_is_a_switch_of_migrate_alonepins the switch's refusals and help.index_build_memory_is_checked_before_connecting:2gb, and512kB;migrate --helpdocuments the flag.The cutover's migrate step, in
tests/support/share_hash_backfill.rs, built on #743's 2.x.x fixtures and the probe:migrate_defer_share_hashes_with_offline_indexes_permits_serving_in_one_run.MigrateOptions { share_hashes: Defer, index_build: Offline }once on a populated 2.x.x source.initializethen leaves the backfill alone, passes the start gate and appends a share.Also:
migrate_takes_the_deferred_backfill_and_the_offline_indexes_together, parses both flags into one command;config_clireaches PostgreSQL withmigrate --defer-share-hashes --offline-indexes.T1 to T6 pass as they were. The only change to them is mechanical: the
offline()helper and T5's constructor gainedmemory_kb: Nonefor the new field. T1, T4 and T7 create event triggers, so like the failover tests (ALTER SYSTEM) they need the test role to be a superuser, which CI'sprism_testis.Existing tests are unchanged and stay green, since the default stays
CONCURRENTLY:index_trim,fanout_lane_plan,config_cliand theonline.rsunit tests.Local gates on the rebased commit:
GATES3
Mutation checks, one per safety property (each restored,
git diffverified identical afterwards):CONCURRENTLYofflineCREATE INDEX CONCURRENTLY cannot run inside a transaction block)lock_timeout0)requires = "offline_indexes"from--index-build-workers--index-build-workers 8alone gets past clap)LOCK TABLEfailure to the lock-timeout text (fix 2)only_a_lock_timeout_reads_as_a_transaction_holding_the_table(40P01 read as a lock timeout)maintenance_work_mem, even for--index-build-memory(fix 1)connect_innerdrops the index build mode (always concurrent)connect_innerdrops the share-hash mode (alwaysFinish)M1 to M10 ran on the review round's commit,
69955066. The rebase changed none of the code they mutate. M1, M3, M5 and M6 are the checks the fixes touch, and M8 is the new one for fix 2. M2 and M4 were re-targeted at the refactored code. M9 and M10 cover fixes 3 and 1. M11 and M12 ran on the rebased commit and check that the composed options reach both runners.Review
A
/code-review highof the first version found nine items.Fixed:
maintenance_work_memcould not be lowered.--index-build-memory(above) sets it. The "never lower a larger server setting" rule now applies only when the flag is absent (T7, the parser unit test, the config_cli test). The memory need is documented as aboutmaintenance_work_memper build in all; see Memory above for why it is not × (workers + 1).LOCK TABLEfailure read as a lock timeout. Only 55P03 does now; anything else surfaces as itself under a neutral context (lock_failure, its unit test, mutation M8).run_planand onerecord, behaviour-identical: theindex_trimandfanout_lane_plantests and T1–T6 pass as they were.OnlineMigration::Indexes' doc and the module header mention the offline mode, and the offline path checks theCREATE INDEXprefix instead of building and discarding a concurrent statement.Declined:
migratewithout stopping frontends. So the offline refusal's message now says exactly that: "…or run plainqbit-prism-server migrate, which builds CONCURRENTLY and records without stopping frontends", and the docs repeat it.IndexBuildModedirectly instead ofMigrateOptions. The struct is deliberate: at the rebase onto PR-A1, itsShareHashBackfillbecomes a second field.connect_migrateduplicatesconnect_operator's arguments. Resolved at the rebase onto 3.x.x: let migrate --defer-share-hashes serve with 002's share-hash backfill pending once it has mapped the recent range #743:connect_migrateandconnect_operatorboth go through 3.x.x: let migrate --defer-share-hashes serve with 002's share-hash backfill pending once it has mapped the recent range #743's sharedconnect_as_operator, which takes the options.Risks
qbit_share_ledgerfor the whole build. Every append and read waits for it, so it is safe only behind the guard. The guard refuses unquiesced instances and a live legacy lease before any DDL. The 5 s lock timeout turns a missed writer, a running export or a reader into a fast failure that changes nothing.import-auditsorself-checkis not refused by name. Its open transaction on the table ends the run at the lock timeout. If it is between transactions, its next statement waits for the build or fails on its own timeouts. The docs and the flag's help say to stop every frontend and tool.PRISM_POSTGRES_INIT_SCHEMA=1it waits on the migration lock until its 5 s lock timeout. Otherwise the start gate finds 13 unrecorded. So start frontends only aftermigratereturns (documented). A drained instance that is still running blocks onqbit_prism_instancesfor the run's duration, so its heartbeats fail meanwhile.maintenance_work_mem: 2GB by default, or the server's when that is higher. Size it to the host's free memory with--index-build-memory.max_worker_processesandmax_parallel_workers, at least 32 MB of the memory each. Otherwise the build silently uses fewer workers or none: slower, not wrong.migrate --offline-indexesstill takes the session runner lock first. If a frontend's concurrent runner is mid-build, the offline run waits for it, then finds the version recorded, as plainmigratedoes today.What the pair rehearsal should measure
time qbit-prism-server migrate --offline-indexesagainst plainmigrateon the same restore. That gives the migrate total and the outage delta the plan expects, about 3.7 min down to 1.5 to 2 min.index builtelapsed_msfor 013's two indexes and 024's, and thedropped replaced indexlines.workers,max_parallel_workers,max_worker_processesandmaintenance_work_mem, to confirm the parallel workers were really granted. If they weren't, compare with--index-build-workers2, 4 and 8, the server's slots, and--index-build-memory(it needs at least 32 MB per participant).--index-build-memoryfrom that for the production run.migratereturned come up normally, and thatself-checkand the recovery evidencecmppass afterwards (the index set and fingerprint are unchanged).Merge order and local suite
origin/3.x.x=539d6c91. That is 3.x.x: let fatal-state clear accept a tip that only extended during its run, and bound its integrity report by its own deadline (#737) #742 (fatal-state clear), on 3.x.x: let migrate --defer-share-hashes serve with 002's share-hash backfill pending once it has mapped the recent range #743 (d838cfd7, the deferred share-hash backfill), on 3.x.x: compute the carry-forward integrity report's mismatches and drift once each, as migration 026 (#737) #744 (1a4e353c, migration 026).ledger.rs,connect.rs,tools.rsandconfig_cli.rs, resolved as described under Plumbing. Everything else merged cleanly. 026 needed nothing here, because this PR's tests take the required versions fromREQUIRED_SCHEMA_VERSIONS.MigrateOptionsliterals in the offline tests gainedshare_hashes: ShareHashBackfill::Finish(plainmigrate's mode). 3.x.x: let migrate --defer-share-hashes serve with 002's share-hash backfill pending once it has mapped the recent range #743's parse test gained..for the new fields.tests/*.rsbutlive_regtest, 4 threads, fresh database,b-full.sh):FULL_SUITE_RESULTS
🤖 Generated with Claude Code