Repository navigation
feat(migrations): the startup policy, serve --migrate and [server] catalog_upgrade - #741
LeeroyHannigan wants to merge 32 commits into
Conversation
[server] catalog_upgrade sets what serve does with a catalog that is behind the binary. refuse, the default in a production build, exits 3 as before. apply, the default in a dev build, migrates the catalog and then serves. serve --migrate sets apply for one run, and EXTENDDB__SERVER__CATALOG_UPGRADE sets it from the environment. Every other status is refused under both values with the code it had, and no value serves a catalog the binary cannot use. Under apply the server migrates through run_with_lock, which migrate --yes now calls too: it takes the migration lock, waiting up to [server] catalog_upgrade_lock_timeout (60 s by default, at most a day) for another migration and for running servers, reads the status again under the lock, runs detect for every pending code body, takes the SQLite copy, applies the migrations and releases the lock. A catalog that another process migrated while this one waited is served as it is. When the lock is still held at the timeout, the status is read once more: a catalog that is current by then is served, and any other exits 6. Under apply serve does not read the notes migrate --yes checks before it takes the lock, so a body that fails on a table the role does not own stops the run with the same note. serve reads the status, and under apply runs the migrations, before it forks, on a current-thread runtime it shuts down first, so in daemon mode the exit code and the message reach the invoking shell. After the fork the server reads the status again and registers, and exits 6 when a migration holds the lock. While it migrates it prints a line on stderr for each step, each starting with "catalog migration: ", and one every 5 s until the run ends. A server's refusal of a catalog behind it ends with "or start this server with --migrate". The SQLite factory no longer migrates a Behind catalog in a dev build: the startup policy does that before the factory runs. An in-memory SQLite database is created by its server and is not read before it starts. MongoCatalogMigrations can name its databases, so the integration tests run the policy on databases of their own. init writes both keys, commented out, into the config it generates.
… line A dev server applies a catalog's pending migrations before it serves, which on a large database takes longer than the launcher's startup timeout. The server prints a line on stderr for each step of the run, each starting with "catalog migration: ", and one every 5 s while it goes on. The launcher now counts startupTimeoutMs, 15 s by default, from the later of its start and the last such line, so it waits for a server that reports progress and gives up on one that prints nothing. The wait moves to startup.js, which the package ships. The launcher test runs a stand-in server that answers /health after 20 s: with a progress line every 2 s it is waited for, and with none the wait ends at 15 s.
On each backend the catalog lock script puts the catalog behind the release binary and checks that serve exits 3 with a message that names --migrate. In daemon mode the exit code and the message reach the invoking process. The script then holds the migration lock and checks that serve --migrate waits until catalog_upgrade_lock_timeout and exits 6. Once the lock is free serve --migrate applies the migration and serves. The SQLite script also checks catalog_upgrade = "apply" in the config file, EXTENDDB__SERVER__CATALOG_UPGRADE=apply and serve --migrate in daemon mode. It checks that serve --migrate writes nothing to a current catalog, exits 5 with nothing written on a catalog that needs a person, and that two serve --migrate started together on a released catalog migrate it once, with one copy. devtools/run-mongodb-tests runs the startup policy tests against its replica set and the PostgreSQL job without pgvector runs them too.
The upgrade manual describes the startup policy: [server] catalog_upgrade and its defaults, serve --migrate, the environment variables, the steps serve takes under apply, the progress lines, and the statuses serve refuses under both values. It gives the recipes for a single host, for Docker Compose, which needs no change, and for Kubernetes: one replica with the Deployment strategy Recreate and a migration Job applied in the same release, with the reasons the recipe uses no Helm pre-upgrade hook and does not migrate in the pod. It lists the exit codes of serve, which in daemon mode reach the invoking shell. The deployment guide gives the Kubernetes recipe, and its upgrade checklist names serve --migrate. docker/README.md says what the serving container does with a catalog behind its image. The admin guide lists the two keys, and the sample config, the process lifecycle in the architecture guide and the troubleshooting entry for exit 6 follow the change.
MongoCatalogMigrations now overrides release: it deletes the lock document through the client that took the lock, on the caller's runtime, and sets an atomic released flag, so dropping the lock afterwards does nothing. Before, the release in run_with_lock dropped the lock, and Drop blocked the runtime's thread, connected a new client on a thread of its own and ignored a failed delete. A failed delete left the document until its lease ended, up to 60 s, and the server serve --migrate starts after its run found the document when it registered and exited 6.
… a run The startup policy's run under apply changes in these ways. - When the status read under the lock is Current or AheadCompatible, the server releases the lock and serves the catalog without calling the backend's run, so on PostgreSQL it makes no pgvector attempt and opens no runner session. run_with_lock takes a WhenCurrent argument for this: Release on the server's path, and Run for migrate --yes, which keeps its pgvector attempt on every run. - After a run that applied nothing, the status is read again, and a catalog ahead of this binary by additive migrations gets the warning that migrate --yes prints after such a run. - Before it takes the lock, the server checks the status notes that migrate --yes checks (before_lock). A note that refuses runs stops the server with exit 1 and the same notes before any change, and the refusal names serve with --migrate or catalog_upgrade = "apply", which before_lock now takes as an argument. Notes that do not refuse are printed as progress lines. The PostgreSQL ownership note names both commands. - A dev build refuses, before the server starts, an uninitialized store that its server would refuse, as Uninitialized with exit 1. The new CatalogMigrations::server_creates_catalog says which stores: on SQLite, a database file that holds tables. In daemon mode the refusal and its message now reach the invoking shell; before, the factory refused the file after the fork, and the shell saw exit 1 with no message. - A progress line comes before the first status read, which runs detect for every pending code body, and before the status read that follows a wait that reached the lock timeout. - The PostgreSQL pgvector notice names the full command, extenddb migrate --yes --pg-user <role>, so the notice is correct when serve prints it. The doc comments now say that the lines of what a run did come when the run ends, with a heartbeat line every 5 s while it goes on. The startup unit tests pass std::slice::from_ref to the fake, as clippy's cloned_ref_to_slice_refs requires, and cover each change: a dev build refuses every status its server cannot serve, the fallback after a wait serves a catalog ahead by additive migrations, a run on a catalog found current under the lock calls no backend run, and a refusing note stops the run before the lock. The PostgreSQL ownership test checks the server's refusal too.
…ts shutdown serve now starts in this order: the config checks, the refusal of daemon mode on a platform without it, the catalog check, the bind, the banner and the fork. The platform check used to come after the catalog check, so serve without --foreground on such a platform read the status, and under apply migrated, before it failed. The bind used to come before the catalog check, so during a long migration the kernel accepted connections that got no answer until the server started. A port conflict is still reported before the fork, and the banner still follows the bind. The catalog check runs under a stderr subscriber built as the one migrate --yes uses, set with tracing::subscriber::with_default for the check alone, so the warnings the backends log during a run reach stderr and the global default stays free for the server. Before, the run came before the server installed its subscriber, and PostgreSQL's lock retry warnings and Cassandra's lease warnings were dropped. The check times the shutdown of its runtime. When the shutdown reaches its 10 s cap, a blocking thread may still be running, and a lock that thread holds would stay held in the child after a fork. In daemon mode serve then prints the cause on stderr and exits 1 instead of forking. Each line of a progress message is printed with the "catalog migration: " prefix, so a message that spans lines counts as progress on each line. The check takes its inputs in ServeStart, and its core takes the backend and the output, so the tests run it on a fake. They cover --migrate over catalog_upgrade = "refuse", the prefix on every line, the exit code of a refusal, which is never 0, the cap on the shutdown, the bound of a day on catalog_upgrade_lock_timeout, and the prefix the npm launcher matches in packaging/npm/startup.js.
…ng ones The four two_servers_started_together tests ran two prepare_to_serve calls and never started a server, and counted a run whose first status read already saw the catalog current as one that waited for the lock. They are now two_prepare_to_serve_runs_under_apply_migrate_once, with migrate_a_legacy_catalog_once at the end on Cassandra. Each holds the lock as another process until both runs wait for it, then frees it, and asserts that one run applied the migrations and the other took the lock after it and applied nothing: a report with no step. New tests on PostgreSQL: a zero lock timeout exits 6 at once through the server's run and through the run migrate --yes makes, while another session holds the migration key or the serving key; and a run that waits for both keys exits 6 once one timeout has passed in all. New tests on SQLite, in process: a catalog another process migrates during the wait is served with nothing written and no backend run, and a dev build's policy refuses a file that holds another program's tables with the refusal the factory gives.
Each /health probe has a 1 s limit that starts before the connect. The old limit started once the socket connected, so a probe of a port that is bound but does not accept waited for the agent's socket timeout instead: 5 s with Node 22, measured against a listener with a full accept queue. start() stops the server before it rejects, because the caller has no handle to a server that failed to start. When the server exits first, the error carries its exit code as exitCode and its signal as signal. The error is built on "close", after the server's stderr has ended, so it holds the last lines the server printed. A new onProgress option receives each catalog migration line while the server starts. extenddb start writes those lines to its stderr and exits with the server's exit code. test/start.test.js runs start() and extenddb start against test/fake-server.js through a replaced child_process.spawn, with startupTimeoutMs unset. A server that reports progress for 20 s is waited for, one that prints nothing is given up on at 15 s and stopped, and the exit code and the signal reach the error. The silent stand-in answers after 60 s, so a deadline check that runs late still ends in a timeout. The scenario that called waitForStartup directly leaves test/launcher.test.js. The launcher workflow and the npm build matrix run the new file. The README says when the startup timeout counts from, documents onProgress and the error's fields, and says that a migrated database keeps the copy taken before the migration beside it.
…ipts Each lock script checks that serve --migrate waits at least the 3 s set in EXTENDDB__SERVER__CATALOG_UPGRADE_LOCK_TIMEOUT and less than 30 s, so a serve that ignored the setting and waited the 60 s default fails. The MongoDB check of that wait also looks for the lock in the output, and its two exit 3 checks have different names. The SQLite script compares the database's content, read with iterdump, before and after serve --migrate exits 5, so a write left in the WAL fails the check. On a current catalog the check is named for what it compares: serve --migrate adds no ledger row and takes no copy. Of two serve --migrate started together, exactly one serves, and the other finds nothing to apply or exits 6; an exit 1 from it fails the check. Each script stops, in its cleanup, a daemon a check left running, found through the daemon's PID file and only when that PID runs the binary under test. Daemon mode runs go through run_split, which reports a command still running after 120 s as a failed check. healthy() gives each curl probe a 2 s limit. The integration workflow's comment names both ports the SQLite script uses.
The upgrade manual's part on applying migrations at startup becomes its own section after the rollback procedure, outside the region where a merge with pull request #523 conflicts. It says that under apply serve reads the PostgreSQL ownership notes before it takes the lock and exits 1 on them, and that catalog_upgrade_lock_timeout bounds all the waits of a run together on every backend, with 0 making one attempt. It says that a catalog found current under the lock is served with nothing written, what two servers started together do on each backend, which progress lines serve prints and when, that serve binds its port after the catalog check, and that SQLite servers from 0.1.14 on are detected. The Kubernetes recipe in the upgrade manual and in the deployment guide runs the preview first and migrate --yes only on exit 3, so the Job of a release with nothing to apply succeeds when the new pod registers first. Both say that the Job's --lock-timeout has to be longer than the old pod takes to stop, and that a pod that exited 3 is restarted after its CrashLoopBackOff delay, which grows up to 5 minutes. The reason against a Helm pre-upgrade hook covers 1.0 and the upgrade from 0.1.x. The architecture guide's process lifecycle binds the port after the catalog check. ADR-0023 describes the startup policy. The admin guide names the statuses serve refuses under both values, the troubleshooting entry says what exit 6 means for serve, and the two install guides run migrate --yes.
AppliedStep gained an outcome field in 86154f6, on the branch this one is stacked on, after these tests were written.
… name main() also assigns a local pid_file, the path of the daemon's PID file, so the call that stops the daemon raised "TypeError: 'str' object is not callable" in CI's "Check serve and migrate on one catalog" step. The function is imported as pid_file_for, as the Cassandra check does.
Main merged #666 and #681, which add migration 5, drop_continuous_backups, on every backend. The architecture guide keeps this branch's text on catalog_upgrade and --migrate, drops the release's migration number as main did, and adds main's sentence on what a server that refuses its catalog prints. The admin guide keeps this branch's text with main's example of a catalog at migration 4 that needs migration 5. The upgrade manual's status paragraph keeps this branch's serve --migrate route with main's migrations 1 to 5 and its note on migration 5, and main's last rollback paragraph now comes before this branch's section on applying migrations at startup. The MongoDB startup tests expect six steps and migration 5 after a run on a released catalog.
crates/config/src/lib.rs: main added the backup module (#671) at the end of the file, where this branch adds the catalog_upgrade module and its re-exports. The result declares both. docs/manuals/05-admin-guide.md: main rewrote the region row of the [server] table (CreateBackup is refused under a region outside the ARN class). This branch adds the catalog_upgrade and catalog_upgrade_lock_timeout rows below it. The result keeps main's region row and this branch's two rows. docs/manuals/07-upgrade-manual.md: in the Current Status paragraph main counts migrations 1 to 6 and names migration 6, the backup catalog index. This branch adds the serve --migrate alternative to the migrate --yes step and says that a server refuses pending migrations by default. The result keeps main's count and its migration 6 sentence with this branch's clause and link.
main's migration 6 adds one step to the migration of a 0.1.14 catalog. apply_migrates_a_released_catalog_and_refuse_writes_nothing and two_prepare_to_serve_runs_under_apply_migrate_once expected 6 applied steps and a catalog at version 5. They now expect 7 steps, the count main's lock test uses, and a catalog at MigrationId::LATEST.
.github/workflows/integration.yml runs migrations_name_escape from main and migrations_startup from this branch. crates/app/src/init_helpers.rs writes the request_timeout_secs line from main and the catalog_upgrade lines from this branch. crates/config/src/lib.rs keeps request_timeout_secs from main and both catalog_upgrade fields from this branch. crates/server/src/serve.rs keeps the catalog_refusal call from main. The next commit restores the serve --migrate line there. devtools/catalog_checks.py keeps with_filesystem_store from main and pid_file and kill_daemon from this branch. devtools/check-cassandra-catalog-lock and check-postgres-catalog-lock import the helpers of both sides. devtools/run-mongodb-tests runs migrations_spill and metrics_store from main and migrations_startup from this branch. docs/manuals/01-architecture-guide.md keeps the step numbers of this branch and the shutdown steps of main. docs/manuals/05-admin-guide.md keeps the region row, request_timeout_secs and migration numbers of main, with the catalog_upgrade rows and serve --migrate text of this branch. docs/manuals/07-upgrade-manual.md keeps migrations 7 to 12 from main and the serve --migrate text from this branch. packaging/npm/index.js keeps the version check, deadline and numeric timeout of main. waitForStartup from this branch replaces waitHealthy, with onProgress and the stop after a failed start. packaging/npm/README.md describes the release check and time budget of main and the progress lines and failed start of this branch. packaging/npm/test/launcher.test.js keeps the release check notes of main and the start.test.js note of this branch.
Main moved the catalog refusal of serve into catalog_refusal, which the backup list and purge commands call too. This branch marked the refusal of serve with AdviceFor::for_server, so that a catalog behind the binary also names serve --migrate. catalog_refusal now takes a serving flag and calls for_server when it is true. serve passes true. The backup commands pass false and keep the message they print on main.
Main added migrations 7 to 12. Its MongoDB lock test now expects 13 applied steps for a released catalog (#823). The two startup tests of this branch still expected 7, the count that the lock test had before. They now expect 13.
Main gave start() one deadline for the version check of the binary and the health wait. It also changed the timeout message to name the startup timeout. This branch replaced waitHealthy with waitForStartup, which counted its timeout from the spawn and kept the old message. waitForStartup now takes the time that start() began. The first wait gets the time that the version check left, and each progress line still restarts the timeout. A wait with no progress line fails with the message from main. Test 10 of launcher.test.js no longer kills the fake server, because start() now stops it. start.test.js expects the message from main. Its header says that the version check needs EXTENDDB_BINARY.
Main refuses a request_timeout_secs outside 1 to 86400 in serve_inner (#355). This branch reads the catalog before the fork and, under apply, migrates it. A server with such a value therefore migrated the catalog and then refused to start. check_request_timeout_secs is now public, and extenddb serve calls it beside the lock timeout check, before the catalog check. A server that cannot start migrates nothing. serve_inner keeps its own call, because serve is a public function.
On main, the refusal of serve names the data store that the catalog records in its backup clause. catalog_refusal (#672) reads it with data_store_name. On PostgreSQL that is the data database. The catalog check of this branch prints the refusal before the fork, and it built the advice on a target without that name. On PostgreSQL its refusal said "and its data database" and did not give the name. When the check fails, it now reads data_store_name before its runtime stops. It builds the advice on a target with that name, as catalog_refusal does.
The comment in start() from main says that start() takes about one startupTimeoutMs, because the version check and the health wait share one deadline. On this branch, each catalog migration line that the server prints restarts the wait. The comment now says so, as the README and the JSDoc of start() do.
devtools/check-cassandra-catalog-lock keeps the description of the refused --forget from main. It also keeps the description of the startup policy checks from this branch. docs/manuals/07-upgrade-manual.md keeps the release names 0.1.14 and 0.1.15 from main in two paragraphs. It also keeps the text about serve --migrate and catalog_upgrade from this branch in the same paragraphs.
…icy text Main renamed the release that brings the migration ledger from 1.0 to 0.1.15 in its messages and docs (#1068). The text that this branch adds still used the old names. The progress line that serve prints for a catalog with no ledger now says "a release before 0.1.15", as the status and migrate messages do. The upgrade manual's section on migrations at startup now names 0.1.15, or 0.1.14 and earlier releases, instead of 1.0 and 0.1.x. The Helm note in the deployment guide and a Cassandra test comment change in the same way. The note about one server per catalog says "this release", as the other notes on main do.
crates/storage/src/migrations/mod.rs keeps the LockedStores export from main and the WhenCurrent and run_with_lock exports from this branch. crates/storage-mongodb/src/migrations/commands.rs keeps locked_stores from main and the release of the lock with its own client from this branch. crates/storage-sqlite/src/migrations/serve_tests.rs keeps the key ring and encryption key tests from main and the startup policy tests and the collide helper from this branch.
… secret row test Main adds a test of the stores under the migration lock to crates/storage-mongodb/tests/secret_rows.rs. The test names MongoCatalogMigrations as a unit value. On this branch MongoCatalogMigrations has a field for the database names of a shared test server, and MongoCatalogMigrations::new() gives the two databases of a deployment. The test now calls new(), so it compiles again.
Main encrypts the data_database_connection_string row of a PostgreSQL catalog that has a key ring. migrate opens that row with the KEK that [auth.encryption] key_file names. The Kubernetes recipe of this branch gave the migration Job the serving Secret only. The upgrade manual and the deployment guide now cover PostgreSQL with key_file set: the Job also mounts the KEK Secret, as the Deployment does. It sets EXTENDDB__AUTH__ENCRYPTION__KEY_FILE and the securityContext of the Deployment too.
Main encrypts the data_database_connection_string row of a PostgreSQL catalog that has a key ring. The migration backend opens the row with the key on its target (Target::key_source), and migrate puts the KEK there. The startup check of serve read the status with Target::at, which carries the catalog key. On PostgreSQL with [auth.encryption] key_file set and a key ring, that status read refused the catalog, and serve exited 1 under both values of catalog_upgrade. serve now reads the KEK through the file rule before the check, on PostgreSQL only, and the check puts it on its target. The status reads, the lock and a run under apply then open the row. serve still sets up the locked key store after the fork, with the slots of the credential cache.
…_key_source d925cfa gave the catalog check of serve the KEK on PostgreSQL with a copy of the backend dispatch of util::status_key_source. It did not call the helper, because the helper sets up the locked key store, and serve sets up that store after the fork. status_key_source now takes a locked_store argument. migrate and verify pass true and keep the store setup. serve passes false, so its behaviour does not change.
On this branch, serve checks the catalog before it sets up the locked key store. Under catalog_upgrade = "apply" it also migrates the catalog first. On PostgreSQL with key_file set, the check reads the KEK file and unwraps the DEK into unlocked memory to open the connection string row. The troubleshooting entry on the locked key store said that serve sets up the store before it reads the catalog. It now gives the order of this branch. The security model said that the server reads the KEK file once at startup. It now names the read for the catalog check and the memory that holds the DEK during that check.
docs/manuals/07-upgrade-manual.md keeps the 1.0.0 paragraph that main (#1107) adds to Current Status. It also keeps the serve --migrate clause that this branch adds to the next paragraph.
demohan
left a comment
There was a problem hiding this comment.
The startup policy never migrates a catalog the operator did not ask to migrate at b52be83, and no path measured started a server on a catalog it cannot serve, ran a migration twice or lost a write. On SQLite and PostgreSQL, a catalog behind (0.1.14 fixtures) makes serve exit 3 in the foreground and as a daemon with nothing written and the message naming --migrate; --migrate, catalog_upgrade = "apply" in the file or the environment, and --migrate over an environment refuse apply and serve; an environment refuse over a file apply exits 3; a current catalog serves under both values and --migrate adds no ledger row; an additive catalog ahead is served with a warning and a breaking one exits 4; a step that fails exits 1 naming the steps applied, and a later run applies the rest; a catalog an older release wrote to after migrating exits 5; a running older server makes the startup migration wait its timeout and exit 6 with the ledger unchanged; and SIGTERM during the copy leaves the catalog untouched. Over 5 SQLite, 12 PostgreSQL and 6 Cassandra two-server runs nothing migrated twice; SQLite survived 17 kill points with data equal to a clean run, PostgreSQL killed mid-run applied the rest once, and Cassandra waited out the lock row's TTL and applied once; the workers start after the migration and the registration. The dev build's apply default migrates only what main's dev SQLite factory already did. Each policy branch, the key, both defaults and the flag have a test that fails when broken, fmt, both clippy invocations, the unit tests and the 1.91.1 build are clean, and CI is green on 60 of 60. Migrations 1 to 12 and RELEASED_THROUGH = 12 are the same here and on main.
The branch conflicts with main at 222d80a in storage-sqlite/src/lib.rs, storage-sqlite/src/migrations/mod.rs, devtools/run-mongodb-tests and docs/troubleshooting.md, since #1009 moved the factory to server_backend.rs and prepare_for_serve to file_database.rs. Beyond the hunks, the resolution needs the Behind if dev arm removed from file_database.rs (a resolution that only re-exports holds_tables still compiles and keeps a second migration path in the dev factory, though the existing test then fails), holds_tables made pub(crate), status_key_source(&app_config, true) at cmd_catalog_check.rs:78 (#690), file_database::migrate_holding in serve_tests.rs:394, and sqlx::AssertSqlSafe at storage-postgres/tests/migrations_startup.rs:250. With those, the merge passes fmt, clippy, the 1.94.0 build, the unit tests, migrations_startup and check-sqlite-catalog-lock.
I will approve once main is merged with those edits, a waiting serve --migrate releases the lock as soon as it finds the catalog current, and tests hold the KEK fix on PostgreSQL and the MongoDB lock release.
| timeout: Duration, | ||
| when_current: WhenCurrent, | ||
| ) -> Result<RunReport, MigrationError> { | ||
| let lock = migrations.lock(target, timeout).await?; |
There was a problem hiding this comment.
The status is read only after lock(), and lock() includes the wait for running servers (storage-cassandra/src/migrations/commands.rs:157-162, PostgreSQL take_migration_keys), so a serve --migrate that waits holds the lock on a catalog that is already current for its whole timeout. On Cassandra with a 30 s timeout, in 4 of 6 runs the waiter served 23.7 to 31 s after start; at +6 s verify printed OK: Current while it still held the migration_lock row, and a plain serve started then exited 6 with "a migration holds the catalog's migration lock", 2 of 2. On PostgreSQL the window did not open in 12 runs on the same path. Under WhenCurrent::Release, reading the status once the key or row is held and before the wait for servers, and releasing at once when it is Current or AheadCompatible, would close it. Related and smaller: on PostgreSQL the server that applied the migrations exited 6 in 3 of 3 runs while the other held the lock only to find the catalog current, and the message calls that holder "extenddb migrate"; on SQLite the second waits out the whole catalog_upgrade_lock_timeout (60 s, twice) printing "in progress" though nothing migrates, and in 2 of 5 runs the migrator then exited 6 at the factory's flock, which the manual describes.
| // On PostgreSQL the check opens the data connection string row of a | ||
| // catalog with a key ring with the KEK, as `migrate` does. The locked key | ||
| // store is not set up here, because `serve` sets it up after the fork. | ||
| let key_source = crate::util::status_key_source(&app_config, false)?; |
There was a problem hiding this comment.
No test holds the KEK fix on PostgreSQL (d925cfa, c8e3a04): with KeySource::CatalogKey here no test fails, and no CI job starts serve with key_file. At this head on PostgreSQL 16 it is right: healthy on a current catalog, exit 3 with one migration pending, healthy after --migrate. The same holds for the MongoDB release through the lock's own client at storage-mongodb/src/migrations/commands.rs:173 (de4b0bf): with drop(lock) back, migrations_startup and migrations_locks pass three of three. The request-timeout check before the catalog check (line 122), serving=true at serve.rs:457 and the data store name in the refusal (serve_catalog.rs:135) are untested too, though right when run.
| /// behind this binary. Every other status a server cannot serve is refused | ||
| /// under both values. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] | ||
| #[serde(rename_all = "lowercase")] |
There was a problem hiding this comment.
Optional. config 0.14.1 matches the value without regard to case, so Apply, APPLY and ApPlY apply and REFUSE refuses, rename_all has no effect, and the manual's "refuses any other value" (07-upgrade-manual.md:263) is not quite so; a bad value gets enum CatalogUpgrade does not have variant constructor always, which names neither the key nor its values. Every start prints "catalog migration: reading the catalog status", where the manual says these lines appear while it migrates, and on SQLite an additive catalog ahead prints its warning twice. The manual at line 278 says only PostgreSQL prints lines without the prefix, but SQLite prints --- Copying the database ... and --- Copied the database in 0.4 s too, and packaging/npm/README.md's "Nothing removes the copy" does not hold: a later run removed it. catalog.rs is now 674 lines and serve_tests.rs 845.
navareamol
left a comment
There was a problem hiding this comment.
I ran this head on SQLite: the unit tests of the storage, config, app and SQLite crates pass (772), and devtools/check-sqlite-catalog-lock passes all its checks, including the daemon mode refusal and two serve --migrate started together.
-
The branch does not merge with main. A merge conflicts in storage-sqlite/src/lib.rs, storage-sqlite/src/migrations/mod.rs, devtools/run-mongodb-tests, docs/troubleshooting.md, packaging/npm/README.md, packaging/npm/index.js and packaging/npm/test/launcher.test.js. The 60 green checks ran before main moved, so they say nothing about the merged tree. Can you merge main and rerun CI on the result?
-
A wrong catalog_upgrade value gives an error that does not name the setting. With catalog_upgrade = "bogus", serve exits 1 with "enum CatalogUpgrade does not have variant constructor bogus", and with the environment variable set to an empty string the message ends after "variant constructor". The lock timeout error next to it names the key and the limit. I think this one should say that catalog_upgrade takes refuse or apply. Is that reasonable?
The points already in the earlier review still apply, and I did not re-measure them.
I will approve once main is merged with CI green on the result and the catalog_upgrade error names the setting and its two values.
Summary
The third PR of the catalog migration work, after #681: what
servedoes at startup with a catalog that is behind the binary.[server] catalog_upgradesets it.refuse, the default in a production build, exits 3 as before, and the message now ends with "or start this server with --migrate".apply, the default in a dev build, migrates the catalog and then serves.serve --migratesetsapplyfor one run, andEXTENDDB__SERVER__CATALOG_UPGRADEsets it from the environment. Every other status is refused under both values with the code it had.applythe server migrates through the same locked run asmigrate --yes: it waits up to[server] catalog_upgrade_lock_timeout(60 s by default) for another migration and for running servers, reads the status again under the lock, and serves a catalog that another process migrated meanwhile. A catalog found current under the lock is served without calling the backend's run. A lock still held at the timeout exits 6.servereads the status, and underapplymigrates, before it forks, so in daemon mode the exit code and the message reach the invoking shell. While it migrates it prints a line on stderr for each step and one every 5 s, each starting with "catalog migration: ". The catalog check runs before the bind.serverefuses a[server] request_timeout_secsoutside 1 to 86400 before the catalog check, so that refusal comes before any migration.serve_catalog.rsbuilds the refusal advice itself instead of callingcatalog_refusal.catalog_refusalreads the installed migrations and takes the wholeAppConfigand a&'static strrelease. The check takes itsCatalogMigrationsas an argument, so that its tests can pass a fake.onProgress, stops a server that fails to start, and reports its exit code or signal.serve --migrate,catalog_upgradeand the deployment recipes, Kubernetes included.Merge of #1003
7ae70ec07mergesmainata60c2b9f3(#1003). It keeps the exports and the lock code of both sides, and the tests of both sides inserve_tests.rs. The follow-ups:e80511a35buildsMongoCatalogMigrationswithnew()in the secret row test of main, so that test compiles.17410e473: on PostgreSQL withkey_fileset, the Kubernetes migration Job mounts the KEK Secret, as the Deployment does.d925cfa06gives the catalog check ofservethe KEK on PostgreSQL. Without it, the status read refused every PostgreSQL catalog with a key ring, andserveexited 1 under both values ofcatalog_upgrade.c8e3a04b4reads that KEK throughutil::status_key_source, which now takes alocked_storeargument.migrateandverifypass true, andservepasses false.8d6c8ce15changes two pages of feat(auth): wrap the credential encryption key with a KEK kept outside the catalog #1003 that gave the old startup order.On PostgreSQL with
[auth.encryption] key_fileset,servereads the KEK through the file rule before the catalog check. The check needs it to open the encrypteddata_database_connection_stringrow. The locked key store does not exist yet. The DEK that the check unwraps therefore sits in a heap buffer, and the check wipes that buffer after the read.require_locked_memorydoes not cover this read. The server reads the KEK file again after the fork.I measured this on 2026-11-18 against PostgreSQL 16 in a container. I ran
initandencryption-key switchon a new catalog, and the configuration setkey_file. Built at17410e473,serve --foregroundexits 1 at the catalog check with "the catalog has a key ring, so its data_database_connection_string row is encrypted". Built at8d6c8ce15, it passes the check, and/healthanswers 200.#690 adds a call of
status_key_sourcetocatalog-check. Whichever of #690 and #741 merges second passestruein that call.Testing
clippy (1.97.0) and rustfmt pass on the changed crates, and their unit tests pass (
extenddb-storage301,extenddb-app113,extenddb-config28). The integration jobs and the lock check scripts run in CI.