Skip to content

fix: match data relations by catalog id in catalog-check, so --fix keeps live tables - #690

Merged
LeeroyHannigan merged 46 commits into
mainfrom
fix/652-catalog-check-ids
Nov 24, 2026
Merged

LeeroyHannigan merged 46 commits into
mainfrom
fix/652-catalog-check-ids

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

demohan reviewed 62787ee78 on 19 November. The section "Changes after the 19 November review" below lists the fixes for that review, up to 4c1818682. The commits after 4c1818682:

  • 7309bc737 merges main at 1d3be632f. No file conflicted.
  • 5e36eaafb: rows_being_created_or_deleted_are_not_reported_missing sets the index and vector index rows back to ACTIVE before it moves the table to DELETING and CREATING. CreateTable inserts the index rows ACTIVE under a table row that can be CREATING, and DeleteTable leaves them ACTIVE. With table_settled && removed from the expected of the index rows, all 16 tests passed before this commit. Now this test fails, with the gsi1, lsi1 and vec1 relations reported missing.
  • 59b48d4b4: the drop classifies SQLSTATE 42P01 with undefined_table in data/ddl.rs, beside lock_not_available. catalog_check.rs no longer has its own 42P01 constant or its copy of sqlstate. The drop keeps its own SET LOCAL lock_timeout. set_lock_timeout_until in data/ddl.rs sets the time left to a deadline, so a 1 s deadline gives 999 ms or less. The drop's error text says more than 1000 ms.
  • 9754d3a1f: data_pool and test_data_database_connection share two helpers. data_connection_row reads the connection string row as the server reads it, and connect_data connects to the data database. Each caller keeps its own errors. The data database check of verify now connects with the options of the catalog-check data pool: two connections at most and statement logging off. It runs no statement on that pool.
  • ea52779a1: four asserts compare the whole message. One is the key ring refusal in key_ring_rows.rs. Three are in catalog_check/fix.rs: the Kept reason, the held relation text and the budget text.
  • b8dca1a73: the binary test removes its config directory in a Drop guard, so a failed run does not leave the directory under CARGO_TARGET_TMPDIR.
  • 66b97c411: the troubleshooting entry says "index changes in flight" in place of "GSI additions in flight", because the lock waits for every open write to indexes.
  • 75c9a06c9: five doc comments of this branch put PostgreSQL and GetItem in backticks. The pedantic clippy run then gives no warning on a line of this branch.
  • This description: the toolchain is 1.91.1, and the Gates ran at 75c9a06c9. The loop section names the production changes after 90d429449. A new section lists the conflicts with fix(storage-postgres): return UpdateTable before the GSI backfill finishes #708, fix(storage): store U+0000 in strings on PostgreSQL and MongoDB #368 and feat: add StartBulkPutItems and the bulk operation APIs #874 and their resolutions.

What

The relation names belong to the storage backend, so the comparison moved there.

  • DiagnosticsStore (crate extenddb-storage) gains check_storage_relations(key) and drop_orphaned_relations(key, orphaned), with defaults that report the backend does not support them. key is the key that test_data_database_connection takes. On PostgreSQL it opens the encrypted connection string row of a catalog with a key ring. Other backends are untouched.
  • The PostgreSQL store implements both in a new data/catalog_check.rs. Expected names come from table_storage_relations, the list DeleteTable drops, for the rows of tables, indexes and vector_indexes in any status, through the crate's own naming functions. The data relations are listed from pg_class by the _ddb_ prefix the naming functions now share. The listing keeps the relations that unqualified names reach on the data database (pg_table_is_visible), which is how the server and the drop resolve them.
  • The check lists the relations, reads the catalog, lists the relations again and reads the catalog a second time. A relation is reported orphaned when both listings have it and no row names it. A relation is reported missing when the second listing lacks it and both catalog reads name it. Each read must name it from a row that, with its table, is in neither CREATING nor DELETING. When the first listing has a relation that the first read does not name, the check waits for the transactions that write indexes to end. Then it reads the catalog again before it compares (see the lock section below). A check that finds each listed relation named takes no lock. If the index changes in flight do not finish within 30 s, the command prints an error that says so and exits with status 1. No check prints a result then.
  • --fix waits for the indexes writers the same way, reads the catalog under that lock, and releases the lock before it drops anything. Then the command drops each reported relation that the read does not name, with DROP TABLE without IF EXISTS. Each drop runs in a transaction of its own with a lock timeout of 1 s. That is the bound that SYNC_DROP_LOCK_TIMEOUT sets for the server's own synchronous drops. The command prints Dropped, or Already gone when another session dropped the relation first (SQLSTATE 42P01). It prints Kept with the reason, or FAILED with the error. For a relation another session holds longer than 1 s, the error reads another session held a lock on it for more than 1000 ms, so it was kept; run the command again. If the index writers do not finish within 30 s, the command reports that, drops nothing and says to run it again.
  • A catalog without data_database_connection_string, or with an empty value, is refused. Without a key ring the message is "No data database connection string in settings. Run extenddb init." With a ring it is the refusal of the server, which names extenddb encryption-key set-data-connection. Both store methods refuse it, so the command does not look for data relations in the catalog's own database. The data pool and the diagnostics store's catalog pool connect with statement logging off. A read or a drop that waits on a lock then adds no slow-statement line to the report. extenddb verify gets its diagnostics store from the same factory, so on PostgreSQL it no longer prints slow-statement lines for its reads through that store either.
  • In a catalog with a key ring, the DEK of the ring encrypts the row. The PostgreSQL store reads it through data_connection_string, the reader that the data database check of verify uses, with the key that the command passes. That key is the KEK of [auth.encryption] key_file when it is set, else the catalog key, which opens no such row. A catalog with a ring and no key_file is therefore refused before the command connects to the data database. With key_file set, the command sets up the locked key store and reads the KEK file before it reads the catalog, as serve and verify do. A KEK file that the file rule refuses then stops the command on a catalog without a ring too.
  • cmd_catalog_check.rs calls the store for checks 1 and 2 and reports each missing relation with the table or index that owns it. The command no longer prints "Connected to data database.". It prints "Compared data relations with the catalog." after the comparison. Checks 3 and 4, the PID refusal, the counting and the exit code are unchanged.
  • docs/troubleshooting.md: the entry from feat(storage): SnapshotEngine, a consistent table snapshot on every backend [backup/restore 4/4] #395 told operators not to use --fix. It now describes the check, what it waits for, the reports that can be wrong while a server runs (below) and the drop outcomes. It says that --fix treats each _ddb_ relation that unqualified names reach on the data database as this deployment's, and its manual query uses the same filter.

The lock on indexes

Each relation name comes from a UUID that the request inserting its catalog row generates for that row. For a table and the GSIs, LSIs and vector indexes created with it, that request is in create_table.rs, which restore also uses. For a GSI or vector index added later, it is in update_table.rs. No path inserts a row for an id it did not generate, so a row inserted later cannot name a relation that exists already. The recovery paths in gsi_build.rs and vector_index.rs create a relation only for a row that has committed.

CreateTable and a vector index add commit the catalog rows first and create the relations after. A GSI add in UpdateTable is the only path that commits its relation before its row. It inserts the index row, creates and commits the relation on the data database, and then commits the catalog transaction. That transaction holds ROW EXCLUSIVE on indexes from the insert to its end. A SHARE lock on indexes is granted only after each such add whose relation exists has committed or rolled back. A catalog read taken after the grant sees the rows of those that committed. No row names a relation that this read does not name, and no row inserted later can name it.

The command requests the lock in attempts of 100 ms, 50 ms apart, for up to 30 s. While an attempt waits, new writes to indexes queue behind it. A server write therefore waits on the command for at most 100 ms plus the one catalog read that the lock is held for. The command holds no other lock while it waits, so it cannot take part in a deadlock. The next statement of the GSI add, an update of its tables row, does not wait on the command. The transaction runs at READ COMMITTED whatever default_transaction_isolation the database, role or connection sets. It sets its lock timeout with SET LOCAL, which takes no snapshot, so the read after the grant sees rows committed during the wait.

Servers do not hold migrate's advisory lock, so taking it would not exclude a running CreateTable or UpdateTable.

#708 (fix/654-pg-async-gsi-build), the fix for #654, stops UpdateTable from waiting for the GSI build. It leaves the order of insert, create and commit of the add as it is, so the lock covers a GSI add there too. Its cleanup of a failed build removes the CREATING row, waits GRACE_PUBLISH (1 s) and then drops the relation, in the order that main uses. A check in that second therefore reports the relation orphaned. The conflict of the two branches is under "Conflicts with other open PRs" below.

Reports that can be wrong while a server runs

The command refuses to run while it finds the server's PID file. It does not see a server started without --write-pid-file, one on another host, or one using another run_dir or port. With a server running, the reports below can be wrong, and a later run does not repeat them:

  • Orphaned: the relations of a GSI or vector index whose catalog row a server has removed. The report occurs when their drop has not committed by the second listing. This is the case for an UpdateTable that removes a GSI or vector index before its drop runs. It is also the case for a failed GSI build during its GRACE_PUBLISH second. A synchronous DeleteTable keeps its row DELETING until its data tables drop (fix(postgres): keep a deleted table DELETING until its data tables drop #504), so its relations stay named. A --fix that drops such a relation first causes the server no error, because the server's drops use IF EXISTS.
  • Missing: the relations of a table whose row is ACTIVE before its relations commit. A CreateTable inserts the row ACTIVE when control_plane_delay_seconds is 0. Otherwise the row moves from CREATING to ACTIVE once that delay (0.25 s by default) has passed since its catalog transaction began. It moves whether or not the relations have committed. --fix drops only relations reported orphaned, so a wrong missing report leads to no drop.

The command does not report a GSI or vector index stuck in CREATING. Check 4 covers tables only, and check 2 does not count a CREATING index row as expected.

Why

extenddb catalog-check expected data relations named _ddb_{account}_{table} and _ddb_{account}_{table}__gsi__{index}. The storage layer names them from catalog ids: _ddb_{table_id}, _ddb_{index_id} and _ddb_vec_{index_id} for vector indexes, which the command did not know. It also counted only tables in ACTIVE or CREATING as live.

This was measured on main 1c0523c90 on 2026-10-30, against PostgreSQL 16 with pgvector and a separate data database as extenddb init creates it. The deployment had one table with a GSI, an LSI and a vector index. The report listed all four live relations as orphaned and three names that never existed as missing. --fix dropped the four relations. GetItem then returned ResourceNotFoundException, and Query on either index returned ValidationException: The table does not have the specified index. DescribeTable still reported the table ACTIVE.

On SQLite the command exits before any check with Cannot connect to catalog: error with configuration: relative URL without a base, because it opens a PostgreSQL pool unconditionally (#177). It reports and drops nothing there, so no SQLite change is needed.

Closes #652

Merge of #1003

23e9df454 merges main at a60c2b9f3 (#1003). crates/app/src/cmd_catalog_check.rs keeps the comparison through the storage backend from this branch. crates/storage/src/diagnostics.rs keeps the key argument of test_data_database_connection from main and the two methods of this branch. The follow-ups:

At 62787ee78, against PostgreSQL 16 without pgvector and with a separate data database, --test catalog_check gave 13 passed and --test key_ring_rows gave 6 passed. With the plain SELECT of the earlier head put back into data_pool, the new test failed with "relative URL without a base", and the 13 catalog_check tests passed.

Changes after the 19 November review

demohan's review of 62787ee78 listed 11 fixes. At 75c9a06c9, all of them are in:

  • a9e49b89e: the diagnostics store's catalog pool connects with statement logging off. A catalog read that waits on a lock no longer prints a slow statement line in the report.
  • 2ae1b1983 and 9ee6fecca: the test deployment creates pgvector in its data database. With EXTENDDB_EXPECT_VECTORS=1 it fails when the server has no pgvector, so the storage test job always creates vec1.
  • 2d9801613: a test holds an indexes write past a 2 s budget. It checks the error of the check and of the drop, and that nothing was dropped. The short budget comes from with_index_lock_budget, which only test-hooks compiles.
  • 1c2ffe330: the text about index changes in progress now comes only from a 55P03 on the indexes lock attempt after the deadline. The command reports a statement timeout, a deadlock or a lock on another catalog table with the server's error.
  • ee338c591: the listing resolves names as the server does. A search_path set for the role on the data database no longer makes the check report a served table's relations missing.
  • bcdeb4798: the key ring refusal is reported as not configured, so it prints on its own, as at the merge base.
  • e516b0764 and c4e2aaa32: the troubleshooting entry says that the report also stops after 30 s, and gives the wait of each indexes write.
  • 425931239: crates/bin/tests/catalog_check.rs runs the extenddb catalog-check binary against the test deployment and checks its output and exit status. A new step of the storage test job runs it.
  • 753c44e4d: the tests fail instead of skipping when EXTENDDB_TEST_PG_REQUIRED=1 is set and the connection string is not.
  • The other commits run the drop under the same failures and add one hold helper for the test sessions that hold a lock. They also map the store factory's error once, set the job's test settings once, and format the tests.

Each code change has a test that fails without it. At ea1d0ec35, against PostgreSQL 16 with pgvector, EXTENDDB_TEST_PG_REQUIRED=1 and EXTENDDB_EXPECT_VECTORS=1, --test catalog_check gave 16 passed and --test key_ring_rows 6 passed. The binary test passed there too. Against postgres:16 without the switch, the two targets gave 16 and 6 passed. Both clippy commands of clippy.yml gave no warnings. 4c1818682 changes one test file. At that head, --test catalog_check gave 16 passed on pgvector, and clippy of the crate's tests was clean.

Conflicts with other open PRs

On 23 November, git merge-tree of 75c9a06c9 with each open PR gave these conflicts, which the PRs do not have with main. The resolution of each keeps both sides:

Testing done

The Gates and one row of the controls table name their own commit. The other runs in this section date from 2026-10-30, unless an item gives another date. They used PostgreSQL 16 with pgvector and a separate data database. They predate the merge of #1003 and #504, and none of them used a catalog with a key ring. The orphan report of two DeleteTable calls in the 2026-10-31 loop below came from the order before #504.

With a binary built from 4556ffcd4, on the deployment from the reproduction with the table recreated: the report is HEALTHY (exit 0). With a planted _ddb_00000000-0000-4000-8000-00000000dead and an unrelated operator_scratch, the report lists the planted relation only. --fix prints Dropped for it and nothing else. The four live relations and operator_scratch remain. GetItem returns the item, and Query on gsi1 and lsi1 returns 3 and 1 items.

The report and --fix loops below ran on a binary built from 90d429449, with a server running on the same deployment. They did not run again after the later production changes: c23efefe6, 7208d60df, 2d9801613, 1c2ffe330, ee338c591 (the listing moved from current_schema() to pg_table_is_visible), bcdeb4798, a9e49b89e, 2610afd55, ea1d0ec35, 59b48d4b4 and 9754d3a1f, and the merges of main in c530d9f95, 23e9df454 and 7309bc737. The command ran with a config for another port, so the PID refusal did not apply. In a loop, four traffic workers each created a table with a GSI, an LSI and a vector index, set its TTL and tagged it. Each then wrote three items, added a second GSI, queried both indexes and ran DeleteTable on the table. A fifth worker wrote items to one table.

  • Report loop: 300 runs 0.1 s apart from 20:23:52Z to 20:26:45Z, with no planted relation. All 300 exited 0 (median 466 ms, max 930 ms). The traffic made 365 CreateTable, 364 UpdateTable, 364 DeleteTable and 8,045 PutItem calls, all answered 200. 40 of the CreateTable calls took longer than 250 ms (max 480 ms), so the missing-report case above could occur during the loop. No run reported it.
  • The same report loop on 2026-10-31, against a build of fe791ce87 on a busier host: 3 of 300 runs exited 1. On that host 188 of 349 CreateTable calls took longer than 250 ms (p50 255 ms, max 808 ms). Each of the 3 runs was a case listed under "Reports that can be wrong while a server runs". Two runs reported missing relations for a table whose CreateTable took 558 ms in one run and 435 ms in the other. The third reported orphaned relations for two tables whose DeleteTable calls were between their catalog commit and their data commit. How many runs report a wrong result depends on how long CreateTable and DeleteTable take on the host. The server log has no deadlock and no error line.
  • The same loop with an earlier binary (16c62f521) had 1 run of 300 exit 1, at 20:10:56Z. That binary requested the lock in attempts of 200 ms on each run. The run that exited 1 reported the four relations of a table whose CreateTable took 308 ms as missing. A waiting lock request can hold up a CreateTable's insert into indexes for one attempt, which counts against the 0.25 s delay. The check now requests the lock only when it finds an unnamed relation.
  • --fix loop: 120 runs 0.3 s apart from 20:29:20Z to 20:31:20Z, each with a planted relation that no row names. Each run reported and dropped that relation and nothing else. No run kept or failed a drop, or reported a relation missing. The traffic made 253 CreateTable, 252 UpdateTable and 7,457 PutItem calls, all answered 200, and the server log has no deadlock and no error line.
  • A planted relation held by a psql session in ACCESS SHARE mode for 6 s: --fix printed FAILED to drop ...: another session held a lock on it for more than 1000 ms, so it was kept; run the command again: error returned from database: canceling statement due to lock timeout and exited 1 after 1.33 s. After the session ended, --fix printed Dropped.
  • With the data_database_connection_string setting absent, the report and --fix both printed Error: No data database connection string in settings. Run `extenddb init`. and exited 1.

Tests

crates/storage-postgres/tests/catalog_check/ (main.rs, report.rs, fix.rs, support.rs), run by the PostgreSQL storage-level step of integration.yml, which runs --tests. Each test initialises a deployment through PostgresBootstrapper with a separate data database. It creates a table with gsi1, lsi1 and vec1 (vec1 when pgvector is installed) and three items through the engine. Then it drives PostgresCatalogStore as the DiagnosticsStore. The deployment creates the extension in its data database. Without EXTENDDB_TEST_PG_CONNECTION_STRING the tests skip, and with EXTENDDB_TEST_PG_REQUIRED=1 they fail instead. With EXTENDDB_EXPECT_VECTORS=1, which the storage test job sets, a deployment without pgvector fails.

The check:

  • Live relations are neither orphaned nor missing.
  • A renamed GSI relation is reported missing with index gsi1 of table 123456789012/orders as its owner, and the renamed one orphaned.
  • Rows in any status keep their relations out of the orphan list.
  • With the relations removed, a table, index or vector index in CREATING or DELETING is not reported missing. An ACTIVE index or vector index of a table in CREATING or DELETING is not reported either. Once the rows are ACTIVE again, all of them are.
  • With a write to indexes left open, a check that finds each relation named finishes in under 2 s.
  • Both methods refuse a catalog without the data database setting, or with an empty one, with main's message. The planted relation stays.
  • The check is held after its first catalog read. A DeleteTable, a relation another session drops and a relation created then are not reported. The next check reports the new relation.

The drop:

  • --fix drops a planted relation and keeps an unrelated table. It keeps the relations of a table created after the check when they are passed as stale candidates. It leaves the items and index rows intact.
  • A GSI add that has inserted its row and committed its relation is in flight while the drop runs. The drop waits for it and holds no lock on tables or vector_indexes. The tables write of the add finishes in under 900 ms, and another indexes write in under 1 s. The add commits while a lock attempt waits, and the relation is kept. The test runs at the default isolation and again with the store's sessions defaulting to REPEATABLE READ.
  • The same add is in flight during the check. Its relation is not reported orphaned.
  • Another session holds a planted relation. The drop reports it FAILED with the lock message within 5 s, and a CreateTable sent meanwhile finishes within 5 s. Once the session ends, the drop succeeds.
  • A relation that another session drops after the check reported it comes back as Already gone.

crates/storage-postgres/tests/key_ring_rows.rs writes the connection string row under the DEK of a key ring. Then check_storage_relations opens the row with the KEK. With the catalog key it returns NotConfigured with the whole refusal for a catalog with a key ring.

A unit test in data/catalog_check.rs checks that a row in CREATING or DELETING, or one that is absent, does not count as settled.

Negative controls

Each mutation was applied to a clean committed tree, and the catalog_check tests were run. Then the file was restored and the tree checked clean before the next.

Mutation Tests that failed
No SHARE lock on indexes before the read the two drop-during-add tests and the check-during-add test
The lock on tables, indexes and vector_indexes, as before the two drop-during-add tests (the waiting session held a lock on tables)
No retry after an attempt times out the two drop-during-add tests and the check-during-add test
The lock requested on each check the test with an open indexes write
The transaction starts with SELECT set_config(...) and no READ COMMITTED the drop-during-add test under REPEATABLE READ (relation dropped), in 3 runs of 3
The drop ignores the names the read under the lock gives the stale-candidate test and the two drop-during-add tests
Drops without their own lock timeout the held-relation test
DROP TABLE IF EXISTS again the already-gone test
Orphans taken from the second listing the test that holds the check after its first read
Orphans without the second-listing filter the test that holds the check after its first read
Missing without the second catalog read the test that holds the check after its first read
A DELETING row counts as expected the CREATING and DELETING test
A CREATING row counts as expected the CREATING and DELETING test
At 75c9a06c9: an index row counts as expected whatever its table's status (table_settled && removed) the CREATING and DELETING test
The prefix check in the drop replaced by false the stale-candidate test
The prefix check in the drop disabled with if false && the stale-candidate test
The listing without the prefix filter 9 of the 13 tests
A catalog without the setting falls back to the catalog pool the refusal test

An earlier control, run when the test file had its first four tests, built the expected names from account and table names instead of ids. All four tests failed.

Gates

At 75c9a06c9 on 2026-11-23, against PostgreSQL 16 with pgvector, with EXTENDDB_TEST_PG_REQUIRED=1 and EXTENDDB_EXPECT_VECTORS=1:

  • cargo +1.97.0 fmt --all -- --check: clean.
  • Both clippy commands of clippy.yml on 1.97.0, with -p extenddb-storage -p extenddb-storage-postgres -p extenddb-app -p extenddb: no warnings.
  • cargo +1.97.0 clippy of the same four crates with --all-targets -- -W clippy::pedantic: no warning on a line that this branch adds.
  • cargo +1.91.1 check --locked -p extenddb-storage -p extenddb-storage-postgres -p extenddb-app -p extenddb --all-targets: clean.
  • cargo +1.97.0 test --locked --lib of extenddb-app, extenddb-storage and extenddb-storage-postgres: 105, 286 and 87 passed.
  • cargo +1.97.0 test --locked -p extenddb-storage-postgres -p extenddb --test catalog_check --test key_ring_rows: the storage catalog_check target 16 passed, key_ring_rows 6 passed, and the binary test 1 passed.

At 4c1818682, CI ran the workspace tests on Rust 1.91.1 and on stable, and the integration suites on all four backends. All of them passed.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a

Breaking changes

After the upgrade, extenddb catalog-check on PostgreSQL prints other lines: "Compared data relations with the catalog." in place of "Connected to data database.", the table or index that owns each missing relation, and an outcome for each relation that --fix handles. With [auth.encryption] key_file set, the command sets up the locked key store and reads the KEK before it reads the catalog. A KEK file that the file rule refuses then stops the command, as it stops verify and migrate. So does a host where memory locking fails while require_locked_memory is true. extenddb verify on PostgreSQL prints no slow-statement lines for its reads through the diagnostics store. DiagnosticsStore gains two methods with default bodies, so other backends compile unchanged. The change adds no command, flag or on-disk format.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

Add DiagnosticsStore::check_storage_relations and drop_orphaned_relations
with default implementations that report the backend does not support
them. The PostgreSQL store implements both from the catalog's table_id,
index_id and vector index ids through the crate's own naming functions,
so the expected names match what the engine creates. Rows in every
status count as live. The drop takes SHARE locks on tables, indexes and
vector_indexes, reads the catalog again under them, and drops only the
reported relations that no row names.
… backend

catalog-check expected relations named _ddb_{account}_{table} and
_ddb_{account}_{table}__gsi__{index}, while the storage layer names them
_ddb_{table_id}, _ddb_{index_id} and _ddb_vec_{index_id}. On PostgreSQL
every live relation was reported orphaned, every live table missing, and
--fix dropped the data tables of ACTIVE tables.

Checks 1 and 2 now call the backend's DiagnosticsStore, which derives the
expected names from the catalog ids with the engine's own naming
functions and re-checks each candidate under catalog locks before it
drops it. Missing relations are reported with the table or index that
owns them. Checks 3 and 4 are unchanged.
… engine creates

On a deployment with a separate data database, a table with a GSI, an LSI
and a vector index is neither orphaned nor missing; a planted relation no
catalog row names is dropped alone while an unrelated table and a table
created after the check are kept; a renamed index relation is reported
missing with its owner; rows in CREATING, UPDATING and DELETING count as
live. The binary is listed with the other PostgreSQL storage-level tests.
…atalog row

The troubleshooting entry told operators not to use --fix because the
command expected a different relation-naming scheme. It now describes
what the check compares, how --fix re-checks each relation under catalog
locks before dropping it, and keeps the manual comparison for inspection.
The drop locked tables, indexes and vector_indexes in SHARE mode in one
statement and kept the locks until every drop had finished. An
UpdateTable adding a GSI on a new attribute writes indexes and then
tables, so the two could deadlock and the client got a 500. A drop
waiting on a relation another session held kept every catalog write on
the server waiting for up to 30 seconds. Under REPEATABLE READ the
re-read after the lock wait used a snapshot taken before it, and the
drop removed a live GSI relation.

Only a GSI add creates a relation before its catalog row commits, and it
holds ROW EXCLUSIVE on indexes from its insert to its end; every
relation name comes from an id generated when its row is inserted. A
SHARE lock on indexes alone therefore covers every path. It is taken in
attempts of 200 ms, 50 ms apart, within the 30 second budget, in a READ
COMMITTED transaction whose first statements take no snapshot, and it is
released right after the catalog read. Each drop then runs in its own
transaction with a 1 second lock timeout and without IF EXISTS: a
relation another session dropped first is reported as already gone, one
another session holds as failed, and no notice reaches the output.

The report waits for the index writers the same way before the catalog
read that decides orphans, and reports a relation orphaned only when a
second listing still has it. It reads the catalog a second time after
that listing and reports a relation missing only when both reads expect
it and the listing lacks it. Rows in CREATING are no longer expected to
have relations.

A catalog without data_database_connection_string, or with an empty
one, is refused again with the message the command gave before.
Split the catalog_check test binary into report, fix and support
modules, keeping its name for CI. The new tests cover a GSI add whose
relation exists and whose row has not committed, against the drop at the
default isolation and at REPEATABLE READ and against the check, with the
add's table write and another index write timed; an orphan another
session holds, with a CreateTable sent while the drop waits; a relation
another session dropped first; rows in CREATING or DELETING whose
relations are gone; a catalog without the data database setting; and a
DeleteTable, a dropped orphan and a new orphan landing between the
check's first catalog read and its second listing, held there by a
test-hooks pause.
The troubleshooting entry now says that the check reads the data
database's current schema and refuses a catalog without the data
database setting, that rows in CREATING are not reported missing, and
which reports can still be wrong while a server on another host changes
tables. The --fix paragraph describes the wait for GSI additions in
flight, the one second lock wait of each drop, the Already gone outcome,
and that every _ddb_ relation in the schema is taken as this
deployment's. The manual query filters on the current schema, as the
command does.
The holder session is released only after the drop returns, so a drop
without a lock timeout of its own would keep the test waiting. A 10
second timeout around the drop makes that case fail instead.
…med relation

The report took the SHARE lock on indexes on every run. While that
request waits behind an open writer, every new write to indexes queues
behind it for up to one attempt, the index rows of a CreateTable
included. The check now reads the catalog first and waits for the index
writers only when a listed relation is unnamed, which outside a GSI add
in flight means a relation no row will name, so a check that finds every
relation named holds up no write. An attempt now lasts 100 ms instead of
200 ms.
…ng else

The drop test against a GSI add in flight now reads pg_locks while the
drop waits for its SHARE lock on indexes, and asserts that the waiting
session holds no lock on tables or vector_indexes. Before, a lock of all
three tables passed the test: each attempt's 100 ms lock timeout ends
the wait before PostgreSQL's deadlock check runs, so the add's table
write still finished in time.
The drop test committed the add after a fixed 600 ms, which fell in the
50 ms pause between two lock attempts about a third of the time. The next
attempt then started after the commit, and a snapshot taken before the
lock still saw the row, so the REPEATABLE READ case passed without the
isolation fix. The test now commits only once pg_locks shows a SHARE
request on indexes that began less than 20 ms earlier, so the commit
lands while that attempt waits.
The troubleshooting entry still said the check always waits for the GSI
additions in flight and that each lock attempt lasts 200 ms. The check
waits only when it finds a relation no row names, and an attempt lasts
100 ms. A write to indexes that queues behind the granted lock also
waits for the one catalog read the lock is held for; the entry and the
comment on the attempt length now say so.
The troubleshooting entry opened its list of the reports that can be
wrong while a server runs with a count of them. It now states the
condition and lists them.
@LeeroyHannigan LeeroyHannigan added bug Something isn't working backend:postgresql Related to the PostgreSQL backend specifically. labels Oct 31, 2026
.github/workflows/integration.yml conflicted. Main runs every test
target of extenddb-storage-postgres with --tests, so the step keeps
main's command and this branch's comment line on the catalog_check test.

Main replaced PostgresBootstrapper::run_catalog_migrations and
run_data_migrations with the migration runner. The catalog_check test
support now runs extenddb_storage_postgres::migrations::migrate on the
catalog and data databases, as main's migrate_data_db_name test does. It
sets the two delay settings with an upsert, as main's PostgreSQL tests
do, so each row exists whether or not a migration seeds it.
crates/app/src/cmd_catalog_check.rs keeps the comparison through the storage backend from this branch in place of the direct read of the data database by main (#1003). It keeps main's data_connection_text below the command.

crates/storage/src/diagnostics.rs keeps the key argument of test_data_database_connection from main and the check_storage_relations and drop_orphaned_relations methods from this branch.
Merged via the queue into main with commit 58a3206 Nov 24, 2026
64 checks passed
@LeeroyHannigan
LeeroyHannigan deleted the fix/652-catalog-check-ids branch November 24, 2026 13:53
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Main is at 018715e, three commits after the last merge (#690, #765 and
#774). One file conflicted: the docstring of
tests/test_expression_param_usage.py. #765 states that the values message
of a Scan or a Query whose AttributeValues parse has no suffix. This
branch adds the wrapped messages of the single-item writes. The merge
keeps both statements.

#765 also passes no expression parameters to the values check in
handle_scan, which merged clean. So the row of
tests/test_expression_semantics.py that sends a Scan with a
ProjectionExpression and ExpressionAttributeValues now expects the message
with no suffix. The service answered that request with the same message,
on a table that does not exist, on 24 November 2026, each request sent
twice.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Main is at 89fc971, four commits after the last merge (#690, #765, #774
and #1280). One file conflicted: the docstring of
tests/test_expression_param_usage.py. #765 states that the values message
of a Scan or a Query whose AttributeValues parse has no suffix. This
branch adds the wrapped messages of the single-item writes. The merge
keeps both statements.

#765 also passes no expression parameters to the values check in
handle_scan, which merged clean. So the row of
tests/test_expression_semantics.py that sends a Scan with a
ProjectionExpression and ExpressionAttributeValues now expects the message
with no suffix. The service answered that request with the same message,
on a table that does not exist, on 24 November 2026, each request sent
twice.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Main is at 018715e, 5 commits after the last merge (#503, #526, #690,
#765 and #774). No file has a conflict. One file changed on both sides,
and git merged it with no overlap: docs/differences-from-dynamodb.md.
#526 adds a Transactions section to it, and this branch changes the
index key validation row.

#526 puts the Return fields in the token fingerprint and gives
IdempotentParameterMismatchException the service's message. #774 picks
the message key per error. The commits after this merge bring the
branch in line with both.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Main is at 018715e, three commits after the last merge (#690, #765 and
#774). Main's #690 changes .github/workflows/integration.yml,
crates/storage-postgres/src/data/ddl.rs and docs/troubleshooting.md, and
#765 changes crates/engine/src/scan.rs. This branch changes those four
files too.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Merges main at 018715e, five commits past 6aef346:

- #503: the stream retention cutoff shape on SQLite
- #526: the Return fields on a TransactWriteItems token replay
- #690: catalog-check matches data relations by catalog id
- #765: the FilterExpression suffix in the values message
- #774: the Message key on two errors

No conflicts. None of the five changes a file of this branch. #774
changes crates/server/src/response.rs, which renders the errors this
branch's tests assert. The key on SerializationException stays message.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Merges b9baaf5 of fix/request-nesting-depth. That commit merges main
at 018715e into the other branch, five commits past 6aef346:

- #503: the stream retention cutoff shape on SQLite
- #526: the Return fields on a TransactWriteItems token replay
- #690: catalog-check matches data relations by catalog id
- #765: the FilterExpression suffix in the values message
- #774: the Message key on two errors

No conflicts. None of the five changes a file of this branch. #774
changes crates/server/src/response.rs, which renders the refusals that
this branch's tests assert. SerializationException keeps the message
key, and a refusal with an empty message still has no message key.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Merges 0986467 of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at b9baaf5. That commit merges main at
018715e, five commits past 6aef346:

- #503: the stream retention cutoff shape on SQLite
- #526: the Return fields on a TransactWriteItems token replay
- #690: catalog-check matches data relations by catalog id
- #765: the FilterExpression suffix in the values message
- #774: the Message key on two errors

No conflicts. None of the five changes a file of this branch. #774
changes crates/server/src/response.rs, which renders the refusals that
this branch's tests assert. SerializationException keeps the message
key, and a refusal with an empty message still has no message key.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Merges 0986467 of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at b9baaf5. That commit merges main at
018715e, five commits past 6aef346:

- #503: the stream retention cutoff shape on SQLite
- #526: the Return fields on a TransactWriteItems token replay
- #690: catalog-check matches data relations by catalog id
- #765: the FilterExpression suffix in the values message
- #774: the Message key on two errors

No conflicts. None of the five changes a file of this branch. #774
changes crates/server/src/response.rs, which renders the refusals and
the authentication errors that this branch's tests assert. The two
errors that get the Message key are not among them. A refusal with an
empty message still has no message key.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Merges 54ed1f2 of fix/1257-leading-zero-numbers, its merge of
fix/1195-syntax-fault-message at 0986467. That brings in
fix/request-nesting-depth at b9baaf5, which merges main at 018715e,
five commits past 6aef346:

- #503: the stream retention cutoff shape on SQLite
- #526: the Return fields on a TransactWriteItems token replay
- #690: catalog-check matches data relations by catalog id
- #765: the FilterExpression suffix in the values message
- #774: the Message key on two errors

No conflicts. None of the five changes a file of this branch. #774
changes crates/server/src/response.rs, which renders the refusals that
this branch's tests assert. SerializationException keeps the message
key, and a refusal with an empty message still has no message key.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
No conflicts. Main (#690, #765, #774) changed two of the files this branch
touches, in lines this branch does not change. It adds an undefined_table
helper in crates/storage-postgres/src/data/ddl.rs, and it changes the
diagnostics store connection and adds a test-hooks re-export in
crates/storage-postgres/src/lib.rs.
LeeroyHannigan added a commit that referenced this pull request Nov 24, 2026
Main is at 018715e, seven commits after the last merge (#432, #468,
#503, #526, #690, #765 and #774). One file conflicted:
crates/storage-postgres/src/data/mod.rs. #690 adds
STORAGE_RELATION_PREFIX where this branch imports from_catalog_json and
to_catalog_json. The merge keeps both.

Main changed seven other files this branch changes, and git merged them
with no overlap. The PostgreSQL query and query_scan modules keep this
branch's import of parse_sk and pk_to_text from data::key_text. So the
LSI index walk of #432 refuses a key that holds U+0000 as the other
reads do. The AT_TIMESTAMP seek of #468 reads sequence numbers only, so
the record escape does not apply to it. Main adds no catalog migration,
so migration 13 keeps its number.
LeeroyHannigan added a commit that referenced this pull request Nov 25, 2026
crates/storage-postgres/src/lib.rs conflicted in its test-hook exports.
Main's #690 added the export of catalog_check::test_pause, and this
branch added the exports of GSI_BUILD_SLOTS and hold_gsi_backfill_for_tests
at the same place. The merge keeps the three exports, in path order. The
other files merged without a conflict.
@robinnsc robinnsc mentioned this pull request Nov 25, 2026
6 of 8 tasks
robinnsc added a commit that referenced this pull request Nov 26, 2026
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 15
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (the version and the five platform pins),
the four license-notice files (regenerated with cargo-about 0.9.0), and
the sample `extenddb version` and `serve` output in
docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md.

This is a minor release. Since v1.0.0, main has two features (#468,
#1009) and changes that make ExtendDB answer as DynamoDB does, which
docs/versioning.md ships in a minor release. It adds no catalog
migration (RELEASED_THROUGH stays 12, the last id), no configuration
key and no backup format version.

Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468
(AT_TIMESTAMP, and the GetShardIterator answers it changes), #503,
#544, #567, #765 and #774, #588, #596, #690, #1144, #1173 and #1194,
next to the existing entries for #398 and #526. The #526 entry now
gives the old TransactWriteItems mismatch message, and the entries are
in PR order. Current Status, the General Upgrade Procedure and the
Rollback Procedure cover 1.0.0 to 1.1.0: no migrate step, and a
rollback runs the 1.0.0 binary on the same catalog, with the two
limits the manual names (#526 tokens, and 1.0.0's catalog-check
--fix). The rollback note of the KEK-file switch says that 1.0.0
serves a switched catalog.

docs/manuals/11-deployment-guide.md: a sentence about the release
before the one that carries #398 is gone.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
robinnsc added a commit that referenced this pull request Nov 26, 2026
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 15
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (the version and the five platform pins),
the four license-notice files (regenerated with cargo-about 0.9.0), and
the sample `extenddb version` and `serve` output in
docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md.

This is a minor release. Since v1.0.0, main has two features (#468,
#1009) and changes that make ExtendDB answer as DynamoDB does, which
docs/versioning.md ships in a minor release. It adds no catalog
migration (RELEASED_THROUGH stays 12, the last id), no configuration
key and no backup format version.

Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468
(AT_TIMESTAMP, and the GetShardIterator answers it changes), #486,
#503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173,
#1194 and #1375, next to the existing entries for #398, #526 and
#1166. The #526 entry now gives the old TransactWriteItems mismatch
message, and the entries are in PR order. Current Status, the General
Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no
migrate step, the #1166 checks before a PostgreSQL upgrade, and a
rollback runs the 1.0.0 binary on the same catalog, with the two
limits the manual names (#526 tokens, and 1.0.0's catalog-check
--fix). The rollback note of the KEK-file switch says that 1.0.0
serves a switched catalog.

docs/manuals/11-deployment-guide.md: a sentence about the release
before the one that carries #398 is gone.
robinnsc added a commit that referenced this pull request Nov 27, 2026
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 15
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (the version and the five platform pins),
the four license-notice files (regenerated with cargo-about 0.9.0), and
the sample `extenddb version` and `serve` output in
docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md.

This is a minor release. Since v1.0.0, main has three features (#468,
#1009, #1449) and changes that make ExtendDB answer as DynamoDB does, which
docs/versioning.md ships in a minor release. It adds no catalog
migration (RELEASED_THROUGH stays 12, the last id), no configuration
key and no backup format version.

Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468
(AT_TIMESTAMP, and the GetShardIterator answers it changes), #486,
#503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173,
#1194, #1375 and #1522, next to the existing entries for #398, #526,
#1166, #1449 and #1523. The #526 entry now gives the old
TransactWriteItems mismatch message, the #1523 heading takes the
v1.1.0: prefix, and the entries are in PR order. Current Status, the General
Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no
migrate step, the #1166 checks before a PostgreSQL upgrade, and a
rollback runs the 1.0.0 binary on the same catalog, with the two
limits the manual names (#526 tokens, and 1.0.0's catalog-check
--fix). The rollback note of the KEK-file switch says that 1.0.0
serves a switched catalog.

docs/manuals/11-deployment-guide.md: a sentence about the release
before the one that carries #398 is gone.
robinnsc added a commit that referenced this pull request Nov 27, 2026
Moves the workspace version from 1.0.0 to 1.1.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 15
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (the version and the five platform pins),
the four license-notice files (regenerated with cargo-about 0.9.0), and
the sample `extenddb version` and `serve` output in
docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md.

This is a minor release. Since v1.0.0, main has three features (#468,
#1009, #1449) and changes that make ExtendDB answer as DynamoDB does, which
docs/versioning.md ships in a minor release. It adds no catalog
migration (RELEASED_THROUGH stays 12, the last id), no configuration
key and no backup format version.

Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468
(AT_TIMESTAMP, and the GetShardIterator answers it changes), #486,
#503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173,
#1194, #1375 and #1522, next to the existing entries for #398, #526,
#1166, #1449 and #1523. The #526 entry now gives the old
TransactWriteItems mismatch message, the #1523 heading takes the
v1.1.0: prefix, and the entries are in PR order. Current Status, the General
Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no
migrate step, the #1166 checks before a PostgreSQL upgrade, and a
rollback runs the 1.0.0 binary on the same catalog, with the two
limits the manual names (#526 tokens, and 1.0.0's catalog-check
--fix). The rollback note of the KEK-file switch says that 1.0.0
serves a switched catalog.

docs/manuals/11-deployment-guide.md: a sentence about the release
before the one that carries #398 is gone.

docs/troubleshooting.md: the bus error entry names 1.0.0 as the release
that has the bug, so its line carries a version-literal-ok marker.
LeeroyHannigan added a commit that referenced this pull request Nov 27, 2026
* chore(release): bump version to 1.1.0

Moves the workspace version from 1.0.0 to 1.1.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 15
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (the version and the five platform pins),
the four license-notice files (regenerated with cargo-about 0.9.0), and
the sample `extenddb version` and `serve` output in
docs/getting-started.md and docs/manuals/04-quickstart-setup-guide.md.

This is a minor release. Since v1.0.0, main has three features (#468,
#1009, #1449) and changes that make ExtendDB answer as DynamoDB does, which
docs/versioning.md ships in a minor release. It adds no catalog
migration (RELEASED_THROUGH stays 12, the last id), no configuration
key and no backup format version.

Upgrade manual, Behavior Changes by Release: v1.1.0 entries for #468
(AT_TIMESTAMP, and the GetShardIterator answers it changes), #486,
#503, #544, #567, #765 and #774, #588, #596, #690, #963, #1144, #1173,
#1194, #1375 and #1522, next to the existing entries for #398, #526,
#1166, #1449 and #1523. The #526 entry now gives the old
TransactWriteItems mismatch message, the #1523 heading takes the
v1.1.0: prefix, and the entries are in PR order. Current Status, the General
Upgrade Procedure and the Rollback Procedure cover 1.0.0 to 1.1.0: no
migrate step, the #1166 checks before a PostgreSQL upgrade, and a
rollback runs the 1.0.0 binary on the same catalog, with the two
limits the manual names (#526 tokens, and 1.0.0's catalog-check
--fix). The rollback note of the KEK-file switch says that 1.0.0
serves a switched catalog.

docs/manuals/11-deployment-guide.md: a sentence about the release
before the one that carries #398 is gone.

docs/troubleshooting.md: the bus error entry names 1.0.0 as the release
that has the bug, so its line carries a version-literal-ok marker.

* docs(upgrade): add the v1.1.0 entry of #1290, put #1349's in order

#1290 merged after this branch was rebased. It changes the answer to a
request with no Authorization header, so it gets a v1.1.0 entry. The
merge of main put the #1349 entry after the #1523 entry. It moves to
the place of its number, beside the new #1290 entry.

---------

Co-authored-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:postgresql Related to the PostgreSQL backend specifically. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

catalog-check expects pre-id relation names; --fix drops live data tables on PostgreSQL

2 participants