Repository navigation
fix: report Backfilling on a CREATING GSI and refuse its reads by phase - #454
LeeroyHannigan wants to merge 34 commits into
Conversation
7716312 to
8afad5f
Compare
| if idx.index_status != "ACTIVE" || effective_delay(idx, system_default) != 0 { | ||
| return Ok(true); | ||
| } | ||
| index_has_queued_rows(tx, &idx.index_id).await |
There was a problem hiding this comment.
This will be invoked on every update to an active, sync GSI. How much overhead does it introduce?
There was a problem hiding this comment.
This code is no longer in the PR. On 29 October I replaced the branch: #401 fixed the convergence bug that these commits addressed, and the PR now adds only the two CREATING phases. The branch does not change data/index.rs, where this queue probe ran, so the PR adds no work to a write to an ACTIVE GSI.
| if index_type == IndexType::Gsi && index_status != "ACTIVE" { | ||
| return Err(StorageError::Validation(format!( | ||
| "{}{index_name}", | ||
| extenddb_core::types::VECTOR_INDEX_BACKFILLING_SCAN_PREFIX |
There was a problem hiding this comment.
This message is gone with the earlier commits. A Query or Scan that names a CREATING GSI now gets the service's refusal for its phase, as measured on 2026-10-26. Before the backfill starts, the refusal is "The table does not have the specified index: ". After it starts, the refusal is "Cannot read from backfilling global secondary index: ". extenddb_storage::gsi_backfill builds both refusals, and the PR body has the table.
jcshepherd
left a comment
There was a problem hiding this comment.
Question about performance for synchronous GSIs and nit on error messaging, but overall looks reasonable.
On DynamoDB a GSI added by UpdateTable is refused to Query and Scan while it is CREATING and served once its backfill is done and it is ACTIVE (measured 2026-10-26 in us-east-1 on a 3000-item table). The table takes writes while the index builds, and the ACTIVE index has to include them. These two tests check that for the PostgreSQL build #401 made state-based. Each seeds 3000 rows, adds a KEYS_ONLY GSI with UpdateTable while four writers move index keys, insert rows and delete rows, waits for the propagation queue to drain, and checks that the index table equals the base projection row for row. Each runs ten iterations, one test with the propagation delay at 5 ms and the other at 0, where an ACTIVE index is maintained inline. Ported from #454 (gsi_creation_converges_under_concurrent_writers and its _zero_delay variant, with the helpers they use) into a new file. The UpdateTable input is built from JSON, so the file does not depend on the struct's field list.
940b769 to
cea91ba
Compare
Two runs against DynamoDB on 2026-10-26 (us-east-1) added a GSI to a 3000-item table with UpdateTable. The index stayed CREATING for 512 s and 519 s. For about the first 30 s DescribeTable reported Backfilling false, and a Query or Scan naming the index got the ValidationException "The table does not have the specified index: <name>". For the rest of the build it reported Backfilling true, and both reads got the ValidationException "Cannot read from backfilling global secondary index: <name>". Once the index was ACTIVE the member was absent and both reads were served. Before this change no backend reported the member. PostgreSQL and SQLite answered a read of a CREATING GSI with the first sentence for the whole build, and MongoDB and Cassandra served the read from the partial index. GsiDescription gains a Backfilling member that is absent when None. Each backend answers one question, whether the backfill has started, and the storage crate's gsi_backfill module derives both the member and the refusal from that answer, so DescribeTable and a read report the same phase. Each backend takes the answer from its build: - PostgreSQL and SQLite build in the server process and record no backfill progress in the catalog, so the engine keeps the index ids whose backfill has started. PostgreSQL records an id when the build task reaches its backfill, after the publish wait and the write barrier. SQLite records it before UpdateTable opens the transaction that creates the index's data table and backfills it. The record is dropped after the ACTIVE flip or when the build gives up. - MongoDB's backfill worker sets backfilling on the index document before its first batch, and the ACTIVE flip removes it. Restored indexes report no member. - On Cassandra the recovery worker writes backfill_heartbeat when it starts work on the index, after checking the row is still CREATING and before it rebuilds the data table. A later scan of the worker then finds a fresh heartbeat and leaves the index to the running build. A new test setting, gsi_creating_phase_delay_ms:<table>, lengthens each phase by the given milliseconds, so a client can observe both on a small table. It is writable through the settings API (0 to 60000) and documented with the other test settings in the admin guide. Tests: a storage test per backend walks the three states and checks the refusal in each (Cassandra stages the catalog row, since its direct tests run no worker), and tests/python/test_gsi_backfilling.py checks the member set, both refusals byte for byte, and the ACTIVE state over the wire.
On DynamoDB a GSI added by UpdateTable is refused to Query and Scan while it is CREATING and served once its backfill is done and it is ACTIVE (measured 2026-10-26 in us-east-1 on a 3000-item table). The table takes writes while the index builds, and the ACTIVE index has to include them. These two tests check that for the PostgreSQL build #401 made state-based. Each seeds 3000 rows, adds a KEYS_ONLY GSI with UpdateTable while four writers move index keys, insert rows and delete rows, waits for the propagation queue to drain, and checks that the index table equals the base projection row for row. Each runs ten iterations, one test with the propagation delay at 5 ms and the other at 0, where an ACTIVE index is maintained inline. Ported from #454 (gsi_creation_converges_under_concurrent_writers and its _zero_delay variant, with the helpers they use) into a new file. The UpdateTable input is built from JSON, so the file does not depend on the struct's field list.
gsi_can_be_added_to_a_table_with_no_sort_key waited for the table to be ACTIVE after UpdateTable and then queried the new index. On MongoDB and Cassandra UpdateTable returns while the index is still CREATING, and a CREATING index now refuses reads as the service does. On MongoDB the first Query got "ValidationException: The table does not have the specified index: hashOnlyIdx" and the test failed. Before the CREATING phases were added, MongoDB served that read from the partial index and the test's loop polled until the row appeared. The test now waits for the index itself to be ACTIVE, the way the second test in the file and gsi_update_table_attr_defs.rs already do. No other test in tests/rust or tests/ reads a GSI that UpdateTable created before waiting for that index to be ACTIVE.
… failure
A PostgreSQL GSI build that fails for a passing reason (a conflict, a
timeout, a lost connection) leaves its index CREATING for the recovery
worker, and UpdateTable still succeeds. The backfill record was a guard
local to the build loop, so that failure dropped it: the index went back
from Backfilling true to false, and a Query or Scan went back from
"Cannot read from backfilling global secondary index: <name>" to "The
table does not have the specified index: <name>", until the recovery
worker's next pass, which runs every minute and backs off up to an hour
after another failure. The service is not known to go back a phase.
The record now stays until the index leaves CREATING. The build removes
it when it publishes the index, finds the index deleted or already
published, or when remove_failed_build deletes the index after a failure
that would recur. A passing failure returns with the record in place, and
the retry records the same id again. The set no longer counts builds of
one index: an id is removed only once no build of it is needed. SQLite
keeps a record scoped to its build, because a failed SQLite build deletes
its row in the same call.
Test: a_passing_build_failure_keeps_the_index_backfilling_until_the_retry_publishes_it
locks the index's catalog row so the flip to ACTIVE waits, cancels the
waiting statement (SQLSTATE 57014, which the build treats as passing),
then checks that the UpdateTable response, ten readings before the
retry, and the readings while reconcile_creating_gsis runs until ACTIVE
report Backfilling true with the backfilling refusal. On the previous
commit it fails at its first check: the UpdateTable response reports
("CREATING", false). The test file's setup moves into a helper shared by
both tests.
The admin guide lists gsi_creating_phase_delay_ms:<table> among the settings managed with `extenddb settings set`, but the command looked keys up in KNOWN_KEYS alone and refused it with "Unknown setting". Only the management API accepted the key, through its own check for a valid table name. ops_settings now has one lookup, writable_key_validator, that returns the validator for a KNOWN_KEYS entry or for a table's phase hold. The management API's set_setting and the CLI both use it, so they accept the same keys with the same bound (0 to 60000 ms); set_setting also accepts the MongoDB test-gate keys in builds with mongodb-test-hooks, as before. The CLI's checks move into a validate function so they can be tested without a store. Test: a_table_gsi_phase_hold_is_writable_from_the_cli accepts the key with 1000 and 0, refuses 60001 as an invalid value and a two-character table name as an unknown setting. It fails when validate looks keys up in KNOWN_KEYS alone, as the command did before.
PostgreSQL and SQLite keep the ids of GSIs whose backfill has started in the process, and DescribeTable and the read path paired that set with the index's catalog row. They read the row first and the set second. A build removes its id right after it flips the row to ACTIVE, so a call whose row read landed before the flip and whose set read landed after the removal saw a CREATING row with no record, and reported Backfilling false, or the first-phase refusal "The table does not have the specified index", for an index whose backfill had finished. GsiBackfills gains snapshot(), a copy of the set. DescribeTable, DeleteTable's response and the read path on both backends take it before they read the rows they pair it with. An id is removed only after its row has left CREATING, so a set read first can be paired only with the same row or a newer one, and a call never reports an earlier phase than the call before it. On PostgreSQL the test hold inside the second phase now runs between the backfill and the flip instead of before the backfill, so a test can read the index in the window at the end of the build. The second phase is as long as before: the hold plus the backfill. Test: the_index_stays_backfilling_from_the_end_of_its_backfill_to_the_flip waits until the index table holds the table's three items, then reads the index until it is ACTIVE and fails on any reading other than the second phase. It fails when the build removes its record before the flip (the mutant that inserts backfills.finish right after the backfill): "phase 1 after the backfill wrote every item". The walk test and the passing-failure test fail under that mutant too.
The MongoDB storage tests for the phases of a GSI that UpdateTable adds need a live replica set, so they are #[ignore]d like the other live tests and their names start with live_gsi_. devtools/run-mongodb-tests runs the crate's live tests before the Rust suite, the one place in CI with a replica set, but its filter was records_live alone, so CI never selected them. The filter is now `records_live live_gsi_`; libtest runs the tests whose names contain either. With the old filter, `--list` on that command shows none of the live_gsi_ tests; with the new one it lists them.
The Cassandra recovery claim and a MongoDB backfill resumed after a restart had no test. Cassandra: the recovery worker's claim writes backfill_heartbeat before it rebuilds the index's data table and starts the backfill, which is the start of the second phase, and a later scan that finds the heartbeat fresh leaves the index to the build already running. The direct tests run no worker, so workers.rs gains a hidden entry point, recover_stale_gsi_backfills_of_table, that runs one scan limited to one table's CREATING indexes; the limit keeps the scan off the rows the tests beside it stage. The worker itself passes no limit. the_recovery_claim_starts_the_second_phase_and_a_later_scan_leaves_the_build stages the row as UpdateTable inserts it, with the table's phase hold at 3000 ms, and runs one scan. It checks that the index then reports Backfilling true with the backfilling refusal, that the heartbeat's write time is earlier than the write time of the rebuilt data table's schema row, that a second scan during the hold leaves that table in place (same table id), and that the running build publishes the index. It fails when the claim writes no heartbeat. MongoDB: a job resumed after a restart finds the backfilling mark the dead process set (ttl_worker.rs) and goes straight to its scan. live_gsi_job_resumed_after_a_restart_keeps_its_second_phase adds the index with no worker running and a 30 s phase hold, sets the mark as a worker that died would have, then starts the worker. The test fails on any reading other than the second phase before and during the resumed job, and requires the index to be ACTIVE within 15 s. It fails when the resumed job starts its first phase again, which waits the hold twice. The live test file's setup and phase reading move into helpers shared with the existing test.
… keyspace
The Cassandra recovery worker runs its catalog scan once per account
keyspace, and the scan returns the CREATING indexes of every account.
Each scan rebuilt and backfilled every stale row in the keyspace it was
given. The claim this branch added writes backfill_heartbeat on the
first attempt, so when the worker listed another account's keyspace
first, that scan claimed the index, created its data table in the other
account's keyspace, and failed the backfill there ("table items_...
does not exist"). The scan of the index's own keyspace then found the
heartbeat fresh and skipped the index. Each later pass repeated this
once the heartbeat was older than the stale threshold, so the index
stayed CREATING with Backfilling true. Main has no claim, so every scan
tried the index and the one in its own keyspace built it.
The scan now reads the account that owns the base table from its tables
row, and leaves the row alone when that account's keyspace is not the
one being scanned. The check comes before the claim, so a scan of
another keyspace no longer writes the heartbeat, creates a data table or
takes a propagation hold for the index.
The other fix would build each row in its own account's keyspace from
whichever scan reaches it first. That makes the first scan of a pass do
all the work while the other scans repeat the catalog read and build
nothing, and when the claim's UPDATE fails, a later scan in the same pass
that reads the row before the backfill's first page writes a heartbeat
starts a second build of the index. With the skip, only the scan of the index's
own keyspace can take it up, once per pass, and the claim is written
only by the attempt that builds the index.
Test: a_recovery_pass_builds_each_index_in_its_own_account_keyspace
creates a table in each of two accounts, puts three items in each, adds
gidx to both with UpdateTable, and runs one pass limited to the two
tables: the first account's keyspace, then the second's. After the
first scan the second account's index must still report Backfilling
false, with no data table for it in the first keyspace. After the
second scan both indexes must become ACTIVE with three rows in their
data tables. On the previous commit it fails at the first check: the
second account's index reports ("CREATING", true). The claim test's
index id query moves into a helper the new test shares.
…the flip The SQLite phase-walk test held the second CREATING phase before the build, so no test read the index between the build's commit and the flip to ACTIVE. A build that ended its record there, with the row still CREATING, passed the test, although DescribeTable then reported the first phase. The second hold now runs after the build commits and before the flip, as on PostgreSQL, and a record dropped before the flip fails the walk test. The snapshot() doc comment and the build's comment said the answer never goes back to the first phase. On SQLite it does on two failure paths: when the flip to ACTIVE fails, or the cleanup DELETE after a failed build fails, the record ends while the row stays CREATING until the startup reconciler rebuilds it. Both comments now say so.
CodeQL reported the two-account recovery test as cleartext logging of sensitive information: the assertion message printed the table name of a helper built from the account id. The loop now names each account "first" or "second", and the message prints that label.
3bb0c38 to
af36b96
Compare
a_recovery_pass_builds_each_index_in_its_own_account_keyspace, with its helpers activate, add_gsi, rows_in and scan, checked two things. A recovery pass over another account's keyspace leaves an index unclaimed and creates no data table there. The pass over the owner's keyspace builds it. recovery_for_one_account_leaves_the_indexes_of_other_accounts_alone in direct/index.rs, which main carries since #868, checks the same rows. The phase tests in this file check the Backfilling member after a claim. The first-phase read check in the phase test now checks the index name in the IndexNotFound error, as the PostgreSQL test does. recover_stale_gsi_backfills_of_table is now compiled only for tests, like the two worker entry points beside it. It stays separate from recover_stale_gsi_backfills_for_tests because it detaches the backfills it starts. The claim test runs a second scan while the first scan's build waits out the phase hold.
…parse fetch_index_by_name read index_status with get_by_name and treated a column that failed to read as "not CREATING". It then served the read from an index that may be partial. The other columns of the same row go through get_column, which fails the read with Internal, and DescribeTable reads index_status that way. The status read now does the same. Test: the phase test sets the row's index_status to null after the ACTIVE step and checks that the read fails with Internal. On the previous commit it resolves the index.
The PartiQL SELECT path resolves an index through the lookup this branch changes. A statement naming a CREATING GSI now gets the refusal of its phase on every backend. The wire test sends one SELECT on the index beside its Query and Scan in each phase. The answers it pins are ExtendDB's. In the first phase it is the PartiQL text for an index the table does not have, which carries no index name. In the second it is the backfilling sentence, and once the index is ACTIVE it is the three items. The service's answer to a PartiQL read of a CREATING index is not measured.
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.
… read Since #945 the reads run at LOCAL_QUORUM, and a debug build asserts that a SELECT from system_schema goes through system_read, which reads at ONE. The claim test's data_table helper read system_schema.tables with query_optional, so the test panicked on the merged tree. It now uses system_read, as the two-account test in index.rs does.
Main is at 3534c9e, one commit after the last merge (#1009, the WebAssembly build). One file conflicted: crates/storage-sqlite/src/lib.rs. In the module list, this branch adds the test module gsi_backfilling_tests after delete_table, and #1009 puts a wasm32 cfg and its comment on hooks, the next module. The merge keeps both. Main changed four other files that this branch changes, and git merged them with no overlap: crates/storage-sqlite/src/store.rs, table_helpers.rs and update_table.rs, and crates/engine/src/backup/tests.rs.
…int allows The WebAssembly job lints the browser build with -D warnings and a list of calls that trap or hang there. That list holds tokio::time::sleep. update_table_impl, which the browser build compiles, slept twice for the gsi_creating_phase_delay_ms test hold. So after the merge of main the job fails on this branch. Only the server's settings API, the settings command and tests write the hold's row, and the browser build has none of them. So there the hold is zero and the sleep never runs. Both waits now call wait_creating_phase_hold. It carries the allow of clippy::disallowed_methods with that reason, as build_vector_index does on main.
LJMart11
left a comment
There was a problem hiding this comment.
Reviewed at ece2581. Workspace tests ran on 1.91.1, including the new PostgreSQL, SQLite and settings phase tests, plus a wire run of BatchExecuteStatement through each CREATING phase on PostgreSQL. The review centres on how the backfilling refusal reaches PartiQL batch reads.
1 finding is left inline.
| #[must_use] | ||
| pub fn creating_read_refusal(index_name: &str, backfill_started: bool) -> StorageError { | ||
| if backfill_started { | ||
| StorageError::Validation(format!( |
There was a problem hiding this comment.
A BatchExecuteStatement that names a GSI in its second CREATING phase now fails as a whole call, because check_read (crates/engine/src/partiql/batch.rs:384) treats only IndexNotFound as a per-statement answer and returns this Validation error as a request fault. On a PostgreSQL server built from this head, a two-statement batch (a SELECT on the index and a SELECT of a base item by key) returned 200 with a per-statement ValidationError and the item while Backfilling was false and once ACTIVE, but answered 400 ValidationException: Cannot read from backfilling global secondary index: gsi_slow while Backfilling was true. Mapping the backfilling refusal to a per-statement error in check_read, plus a BatchExecuteStatement step in test_gsi_backfilling.py, would close this.
There was a problem hiding this comment.
f9831b5 makes the backfilling refusal the answer of the statement in a BatchExecuteStatement. check_read in crates/engine/src/partiql/batch.rs now gives that statement the backfilling sentence, as it gives a missing index the not-found sentence. The authorization of the statement read the index's key schema through target_schema in crates/engine/src/partiql/authorize.rs, which failed the call in the same way. It now finds no key schema for a backfilling GSI, as for a missing one. is_backfilling_refusal in crates/storage/src/gsi_backfill.rs tells the refusal from the other lookup errors.
tests/python/test_gsi_backfilling.py now sends your two-statement batch in each phase. The index read gets the not-found sentence, then the backfilling sentence, then the batch primary-key sentence once the index is ACTIVE. The read of the base item returns the item each time. On a SQLite server and a PostgreSQL server built from 2a75a22, it passes, beside tests/test_partiql_batch.py (171 passed on each). On a server built with the two PartiQL files of the merge before f9831b5, it fails at the batch of the second phase. That batch answers 400 ValidationException: Cannot read from backfilling global secondary index: gsi_slow. The service's answer to a PartiQL read of a CREATING index is not measured, so these answers are ExtendDB's.
#708 sends these two lookups and the other PartiQL index lookups through common::statement_index, which reads a backfilling GSI as a missing index. The PR body names that overlap.
Main is at c8e66fb. This branch last had main at 3534c9e. Since then, 42 PRs merged into main, #1482 among them, which fixes the WebAssembly build. Seven files conflicted. The merge keeps both sides in each: - crates/core/src/settings_keys.rs: #1449 adds the search_inequality_filters keys where this branch adds the GSI phase hold key. Both blocks stay, the hold first. - crates/app/src/cmd_settings.rs: #1449 imports server_setting_default and this branch imports writable_key_validator from the same module. The import names both. - crates/server/src/management/ops_settings.rs: #1449 adds the search_tests module where this branch adds its tests module. Both stay. - crates/storage-mongodb/src/lib.rs: #486 adds mod error_class where this branch adds its two GSI modules. All three stay. - crates/storage-postgres/src/delete_table.rs: #1411 refuses a table that is already DELETING before the indexes are read, where this branch built its description with the backfill set. The merge keeps the refusal of #1411 and reads the backfill set after it, before the index rows, as this branch does. - crates/storage-sqlite/src/delete_table.rs: the same change of #1411. The second hunk keeps the backfill set before the index rows and the sqlx::AssertSqlSafe query of #1166. - crates/storage-sqlite/src/table_helpers.rs: the backfill set before the catalog rows, and the sqlx::AssertSqlSafe query of #1166.
…atch In a BatchExecuteStatement, a SELECT that names a GSI whose backfill has started failed the whole call with 400 ValidationException. check_read in crates/engine/src/partiql/batch.rs answered a missing index per statement and passed every other error of the index lookup up as a request fault. The authorization of each statement read the index's key schema through target_schema in crates/engine/src/partiql/authorize.rs, which did the same. Both now take the backfilling refusal as they take a missing index. check_read gives the statement the backfilling sentence, as ExecuteStatement gets it, and target_schema finds no key schema. The other statements of the batch run. is_backfilling_refusal in crates/storage/src/gsi_backfill.rs tells that refusal from the other lookup errors. tests/python/test_gsi_backfilling.py now sends a BatchExecuteStatement of a read of the index and a read of a base item in each phase. The service's answer to a PartiQL read of a CREATING index is not measured, so the answers are ExtendDB's.
The Breaking changes section of this PR lists what a client of an existing deployment sees after the upgrade. The upgrade manual had no entry for it. The new v1.2.0 entry comes after the two v1.2.0 entries of main. It names the Backfilling member, the refusal of each CREATING phase on each backend against 1.1.0, and the per-statement refusal in a BatchExecuteStatement.
Main moved to sqlx 0.9.1 in #1166, which refuses a query string built at run time unless AssertSqlSafe wraps it. The two PostgreSQL GSI test files of this branch built their SQL with format! and passed it by reference, so after the merge of main their test targets did not compile (E0277). gsi_backfilling.rs and gsi_create_converge.rs now wrap each built string in sqlx::AssertSqlSafe, as the other test files of the crate do on main.
LJMart11
left a comment
There was a problem hiding this comment.
Checked at 2a75a22 against the list from ece2581.
The follow-up makes a BatchExecuteStatement read of a GSI whose backfill has started a per-statement error, in check_read and target_schema. Confirmed: on PostgreSQL and SQLite the batch of an index read plus a base-item read now answers 200 in each CREATING phase, with the backfilling sentence on the index statement and the item returned; removing either new arm makes the wire test fail with the whole-call 400. cargo test -p extenddb-engine -p extenddb-storage passed (981 + 296 + 1) under 1.94.0, and the head already contains the base tip.
Previous items: 1 fixed.
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466, #1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and #1531 add v1.2.0 entries at the top of "Behavior Changes by Release", and git merged them with no conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of main, where this branch has its entry. That is the one conflict. The merge keeps both entries without change: the entry of #1087 first, then the entry of this branch, before the v1.1.0 entries. Git merged five other files with no conflict: - crates/storage-cassandra/tests/direct_integration.rs: #1531 declares the update_item_retry module, and this branch declares gsi_backfilling. - crates/storage-mongodb/src/table_engine.rs: #1446 changes DeleteTable. It marks the table DELETING by table_id, and it removes the tags and the table document in one transaction. This branch changes create_table_impl_inner, index_info_by_table_id_impl and doc_to_table_description_in. - crates/storage-sqlite/src/lib.rs: #1087 declares the scan_segment_tests module, and this branch declares gsi_backfilling_tests. - crates/storage-sqlite/src/store.rs: #1087 registers extenddb_scan_segment on each connection of the pool. This branch adds the gsi_backfills field and gsi_creating_phase_delay. - crates/storage/src/lib.rs: #1087 rewrites the doc comment of scan_key_in_segment, and this branch declares the gsi_backfill module.
|
Checked at Fixed:
Disputed: none. Needs-human: none. |
Changes since the last review
d2bfa44 merges
mainat 44a7b79, which brings fix(storage-mongodb): keep a DELETING table's tags until its document goes #1446, fix(storage-cassandra): retry a lost UpdateItem version check over the PutItem and DeleteItem window #1531, ci(release): add devtools/freeze-migrations #1466, fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087, fix(bin): rerun the build script when the checked-out commit changes #768 and fix(server): ignore a TableName sent to an operation without one #1296. It is the one commit after 2a75a22, the head that LJMart11 reviewed on 3 December. Indocs/manuals/07-upgrade-manual.md, fix(storage-mongodb): keep a DELETING table's tags until its document goes #1446 and fix(storage-cassandra): retry a lost UpdateItem version check over the PutItem and DeleteItem window #1531 add v1.2.0 entries at the top of "Behavior Changes by Release", and git merged them with no conflict. fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 adds its v1.2.0 entry after the other v1.2.0 entries of main, where this PR has its entry. That is the one conflict. The merge keeps both entries without change: the entry of fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 first, then the entry of this PR, above the v1.1.0 entries. Git merged five other files that both sides change, each at other lines:crates/storage-cassandra/tests/direct_integration.rs: fix(storage-cassandra): retry a lost UpdateItem version check over the PutItem and DeleteItem window #1531 declares theupdate_item_retrymodule, and this PR declaresgsi_backfilling.crates/storage-mongodb/src/table_engine.rs: fix(storage-mongodb): keep a DELETING table's tags until its document goes #1446 changes DeleteTable. It marks the table DELETING bytable_id, and it deletes the tags and the table document in one transaction. This PR changescreate_table_impl_inner,index_info_by_table_id_implanddoc_to_table_description_in.crates/storage-sqlite/src/lib.rs: fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 declares thescan_segment_testsmodule, and this PR declaresgsi_backfilling_tests.crates/storage-sqlite/src/store.rs: fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 registersextenddb_scan_segmenton each connection of the pool. This PR adds thegsi_backfillsfield andgsi_creating_phase_delay.crates/storage/src/lib.rs: fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 rewrites the doc comment ofscan_key_in_segment, and this PR declares thegsi_backfillmodule.The lines that this PR changes against main are the same before and after the merge. The gates on d2bfa44:
cargo +1.97.0 fmt --all -- --checkis clean. The two clippy commands of.github/workflows/clippy.ymlwith-D warnings, on the whole workspace as CI runs them, are clean.write_lock_testsofextenddb-storage-sqliteand fivebackup_storetests ofextenddb-serverfail, as on main (storage-sqlite: the two write_lock_tests fail when an ancestor of the Cargo target directory is owned by another user #1414).cargo test -p extenddb-wasm-adapter, with itsparitycorpus test: 4 passed.cargo test -p extenddb-storage-postgres --test doc_version_literals: 3 passed.tests/python/test_gsi_backfilling.pyagainst a SQLite server and a PostgreSQL server built from d2bfa44 on 127.0.0.1: passed on each.python3 -m pytest --collect-only -qcollects 7348 tests intests/and 821 intests/python, with no error.deda762 merges
mainat c8e66fb, 42 PRs after the last merge, fix(core): read the latency segment clock through web_time #1482 among them. Seven files conflicted, and the merge keeps both sides in each:crates/core/src/settings_keys.rs,crates/app/src/cmd_settings.rsandcrates/server/src/management/ops_settings.rs: feat: SearchVectors inequality filters #1449 adds thesearch_inequality_filterskey, its import and its test module where this branch adds the GSI phase hold.crates/storage-mongodb/src/lib.rs: fix(mongodb): answer 503 when the key-info lookup cannot reach the backend #486 addsmod error_classwhere this branch adds its two GSI modules.crates/storage-postgres/src/delete_table.rsandcrates/storage-sqlite/src/delete_table.rs: fix(engine): describe a DELETING table with the members the service keeps #1411 refuses a table that is already DELETING before the index rows are read. This branch built the description of such a table with the backfill set there. The merge keeps the refusal of fix(engine): describe a DELETING table with the members the service keeps #1411 and reads the backfill set after it, before the index rows.crates/storage-sqlite/src/delete_table.rsandcrates/storage-sqlite/src/table_helpers.rs: the backfill set stays ahead of the catalog reads, beside thesqlx::AssertSqlSafequeries of fix(deps): move to sqlx 0.9.1 for the SQLite fix of RUSTSEC-2026-0459 #1166.f9831b5 answers LJMart11's review of 26 November. In a BatchExecuteStatement, a SELECT of a GSI whose backfill has started failed the whole call with 400.
check_readincrates/engine/src/partiql/batch.rsnow gives that statement the backfilling sentence as its own error, as it gives a missing index the not-found sentence. The authorization of the statement read the index's key schema throughtarget_schemaincrates/engine/src/partiql/authorize.rs, which failed the call the same way. It now finds no key schema for a backfilling GSI, as for a missing one.is_backfilling_refusalincrates/storage/src/gsi_backfill.rstells the refusal from the other lookup errors. The wire test sends a two-statement BatchExecuteStatement in each phase.c3d2973 adds a v1.2.0 entry for this change to
docs/manuals/07-upgrade-manual.md, after the two v1.2.0 entries of main.2a75a22 wraps the SQL that the two PostgreSQL GSI test files build in
sqlx::AssertSqlSafe. fix(deps): move to sqlx 0.9.1 for the SQLite fix of RUSTSEC-2026-0459 #1166 moved main to sqlx 0.9.1, which refuses a query string built at run time without it. So after the merge, these two test targets did not compile.In this description: The change, Overlaps with other PRs, Tests, Testing done, the Checklist and Breaking changes. fix(storage-postgres): return UpdateTable before the GSI backfill finishes #708 now also changes the PartiQL lookups of f9831b5.
What
A GSI that UpdateTable adds goes through the two CREATING phases the service has. DescribeTable reports
Backfillingfalse and then true, and a Query, Scan or PartiQL SELECT naming the index gets the refusal for its phase.Why
The PR closes no issue. Refs #1081, which asks for
TableStatusUPDATING and the new index CREATING withBackfillingfalse in the UpdateTable response and in the DescribeTable after it. This PR adds the member. On PostgreSQL and SQLite the response still reports the table and the index ACTIVE, because the build runs inside the request. The response'sTableStatusandIndexStatusremain for #1081.What the service does
Measured on the service on 2026-10-26 in us-east-1, in two runs. A GSI added by UpdateTable to a 3,000-item table stayed CREATING for 512 s on one run and 519 s on the other.
While the index is CREATING, DescribeTable lists nine members for it: Backfilling, IndexArn, IndexName, IndexSizeBytes, IndexStatus, ItemCount, KeySchema, Projection and ProvisionedThroughput.
Those runs read the index every 30 s, so the table is right at that granularity. #708's measurement of 31 October read it more often. A Query sent 0 and 2 s after
Backfillingturned true still got the not-found text. One sent about 45 s after it got the backfilling text. ExtendDB switches the refusal with the member. The wire test reads DescribeTable before and after each read and counts a reading only when both agree.What main does
GsiDescription has no Backfilling member, so no backend reports one. PostgreSQL and SQLite answer a Query or Scan of a CREATING GSI with "The table does not have the specified index" for the whole build. MongoDB and Cassandra serve the read from the partial index. On Cassandra the recovery worker drops and recreates the index's data table before it backfills (
crates/storage-cassandra/src/workers.rs). Main's lookup serves a CREATING index. A read that lands between the drop and the create queries a table that does not exist and answers InternalServerError.#401 already made PostgreSQL GSI creation converge under concurrent writers: the build is state-based, and a recovery worker finishes builds left CREATING. This change adds the two CREATING phases on top of that design. It changes neither how the build orders its writes nor when the recovery worker runs. This PR's earlier commits fixed the same convergence bug with a design of their own. Their two convergence tests are ported here.
The change
GsiDescription gains Backfilling, absent when it is None. Each backend answers one question, whether the backfill of a CREATING index has started.
extenddb_storage::gsi_backfillderives both the member and the refusal from that answer, so DescribeTable and a read report the same phase.backfillingon the index document before its first batch, and the flip to ACTIVE removes it. A job resumed after a restart finds the mark and goes straight to its scan.backfill_heartbeatwhen it takes the index up, before it rebuilds the data table. A later scan finds the heartbeat fresh and leaves the index to the build that is running. The worker scans the catalog once per account keyspace, and each scan returns the CREATING indexes of every account. A scan takes up only the indexes whose base table belongs to the keyspace's account. The heartbeat is therefore written only by the scan that builds the index. The read lookup readsindex_statuswithget_column, as it reads the other columns of the row. A row whose status cannot be read therefore fails the read with an internal error instead of being served.The read path shares its index lookup with PartiQL.
partiql/select.rs,partiql/batch.rsandpartiql/authorize.rsresolve an index throughindex_info_by_table_id. An ExecuteStatement SELECT naming a CREATING GSI therefore gets the refusal of its phase on every backend. In a BatchExecuteStatement, that refusal is the error of the statement that names the index, and the other statements run. The authorization of the statement finds no key schema for the index in either phase. Those answers are ExtendDB's. In the first phase it is the PartiQL text for an index the table does not have: "The table does not have the specified index". That text carries no index name. In the second it is the backfilling sentence. The service's answer to a PartiQL read of a CREATING index is not measured (see Not tested).A test setting,
gsi_creating_phase_delay_ms:<table>, lengthens each phase by the given milliseconds so a client can observe both phases on a small table. It is writable through the management API and withextenddb settings set, from 0 to 60000. The admin guide lists it with the other test settings.table_scoped_gate_table_name, the helper of the two MongoDB test-gate keys, parses the key. It accepts a table name of 3 to 255 characters froma-z,A-Z,0-9,.,_and-.Three changes to existing tests and CI.
gsi_can_be_added_to_a_table_with_no_sort_keyintests/rustnow waits for its new index to be ACTIVE before it queries it, because a CREATING index refuses reads on MongoDB and Cassandra. Thewait_for_index_activehelper it uses moves fromgsi_update_table_attr_defs.rstotest_base.rs, where both files call it.devtools/run-mongodb-testsnow runs thelive_gsi_storage tests with therecords_liveones, so CI selects them.One test-only entry point stays beside an existing one.
recover_stale_gsi_backfills_of_tablein the Cassandraworkers.rsruns one recovery scan limited to one table. It returns while the backfills it started run, which the claim test needs to run a second scan during the phase hold.recover_stale_gsi_backfills_for_testsscans an account's keyspace and waits for its backfills. Both are compiled only for tests.Overlaps with other PRs
fix/654-pg-async-gsi-build, opened 31 October, for issue storage-postgres: UpdateTable awaits the GSI backfill inside the request, so large tables time out at the client #654) changes the same function,fetch_index_info_by_table_idincrates/storage-postgres/src/data/ddl.rs. It refuses a Query or Scan on a CREATING GSI with the backfilling sentence for the whole build, one phase where this PR has two. Its commit 5b70d1f (25 November) also sends the PartiQL index lookups throughcommon::statement_index, which reads a backfilling GSI as a missing index. Two of them,check_readandtarget_schema, are the functions of f9831b5. This PR gives the backfilling sentence there instead, as its ExecuteStatement does. This PR came first (22 October). A merge of fix(storage-postgres): return UpdateTable before the GSI backfill finishes #708's head 3126e91 into this head conflicts in six files:crates/engine/src/partiql/authorize.rs,crates/engine/src/partiql/batch.rs,crates/storage-postgres/src/data/ddl.rs,crates/storage-postgres/src/update_table.rs,tests/rust/src/gsi_on_hash_only_table.rsandtests/rust/src/test_base.rs, where both PRs addwait_for_index_active. Whichever merges second drops its copy of the refusal and keeps one PartiQL answer for a backfilling GSI. If that is fix(storage-postgres): return UpdateTable before the GSI backfill finishes #708, it callsextenddb_storage::gsi_backfill::creating_read_refusalwith theGsiBackfillsrecord of this PR instead of its one-phase arm, and keeps onewait_for_index_active.deleting_window_data_testsincrates/storage-sqlite/src/lib.rswhere this PR declaresgsi_backfilling_tests. fix: create SQLite database files 0600 and set wider ones to 0600 when opened #691 declaresfile_modeat the same place. Each of the four conflicts with this PR there. The PR that merges second keeps both declarations.docs/manuals/07-upgrade-manual.md, above the v1.1.0 entries. fix: answer requests during a table's DELETING window as the service does #550, fix(scan): check the numbers in ExpressionAttributeValues as the service does #562, fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831, fix(engine): refuse ProjectionType and StreamViewType outside their sets #1110, fix(core): refuse a name that starts with an underscore in an expression #1131, fix(server): send Message on a SerializationException #1220, fix(server): write __type first in an error body #1249 and fix(core): send DynamoDB's text for a B value that does not decode #1260 add their entries at the same place. 23 other open PRs conflict with this PR there and with main there too. The PR that merges second keeps both entries.git merge-treecompared d2bfa44 and main with each of the 219 open PRs. This PR adds no other conflict with an open PR.bafa608c3made the same change on 29 October. The merge of 6 November took main's version. The diff against main carries fix(storage-cassandra): recover a GSI backfill only in its owner's keyspace #868's code, and that commit's message describes a change the diff no longer carries.Tests
extenddb-storagegsi_backfill::tests(6 unit tests)a_gsi_added_by_update_table_walks_both_creating_phases("CREATING", None)a_passing_build_failure_keeps_the_index_backfilling_until_the_retry_publishes_it("CREATING", false)the_index_stays_backfilling_from_the_end_of_its_backfill_to_the_flipgsi_create_converge(2 tests)gsi_backfilling_tests::a_gsi_added_by_update_table_walks_both_creating_phases[3]instead of[1, 2, 3]. A build that drops its record before the flip:[1, 3]live_gsi_added_by_update_table_walks_both_creating_phases("CREATING", None)live_gsi_job_resumed_after_a_restart_keeps_its_second_phasea_creating_gsi_reports_each_phase_and_refuses_reads_by_phaseindex_statuscannot be read fails the read("CREATING", None). A status read that treats an unreadable column as not CREATING: the read is servedthe_recovery_claim_starts_the_second_phase_and_a_later_scan_leaves_the_buildops_settingsa_gsi_phase_hold_is_writable_for_one_valid_table_namecmd_settingsa_table_gsi_phase_hold_is_writable_from_the_cliextenddb settings setaccepts the hold key within the bound and refuses an invalid table nametests/python/test_gsi_backfilling.pyOne run from the branch before the 30 October rebase is not repeated by CI. Against a Cassandra server built from that branch, a script added an index with UpdateTable in each of two accounts, 8 s apart. It ran both orders, and both indexes became ACTIVE each time. One of the orders adds the first index to the account whose keyspace the recovery worker lists last.
Merge with #395
Rebased on main at
3051e500(#395) on 30 October.lib.rs:gsi_backfillsfollows the fields feat(storage): SnapshotEngine, a consistent table snapshot on every backend [backup/restore 4/4] #395 added toPostgresEngine(snapshot_open_slots,shared_data_pooland the test-hooksdrop_attempts), in the struct and innew().table_helpers.rs: feat(storage): SnapshotEngine, a consistent table snapshot on every backend [backup/restore 4/4] #395 moved the catalog reads intobuild_table_description_on, which its snapshot engine also calls. The backfill set is read at the top of that function, before thetablesread. DescribeTable and the snapshot engine therefore both read the set before the rows.delete_table.rs: feat(storage): SnapshotEngine, a consistent table snapshot on every backend [backup/restore 4/4] #395 moved the index-row read ahead of its new early return for a table already DELETING. The backfill set is read before that read, and both of feat(storage): SnapshotEngine, a consistent table snapshot on every backend [backup/restore 4/4] #395's description builds take it. This branch's own index-row read is gone, since it was the same query in the same transaction.delete_table.rsmerged without a conflict but did not compile. feat(storage): SnapshotEngine, a consistent table snapshot on every backend [backup/restore 4/4] #395's early return for a DELETING table builds a description, so it reads the backfill set as well.DeleteTable reads the backfill set only for the description in its response. When and how the table's data is dropped is #395's code, unchanged.
Testing done
On 2a75a22, merged with main at c8e66fb, on one host:
cargo +1.97.0 fmt --all -- --checkis clean. The two clippy commands of.github/workflows/clippy.ymlwith-D warningson the seven crates this PR touches: clean.cargo +1.94.0 check --all-targetson the same crates: clean.write_lock_testsofextenddb-storage-sqliteand fivebackup_storetests ofextenddb-serverfail, as on main (storage-sqlite: the two write_lock_tests fail when an ancestor of the Cargo target directory is owned by another user #1414).cargo test -p extenddb-wasm-adapter, with itsparitycorpus test: 4 passed.gsi_backfilling(3) andgsi_create_converge(2) against PostgreSQL 16 (pgvector/pgvector:pg16) withEXTENDDB_TEST_PG_REQUIRED=1: 5 passed.tests/python/test_gsi_backfilling.pyandtests/test_partiql_batch.pyagainst a SQLite server and a PostgreSQL server built from 2a75a22: 171 passed on each.tests/python/test_gsi_backfilling.pyfails. The BatchExecuteStatement of the second phase answers 400ValidationException: Cannot read from backfilling global secondary index: gsi_slowfor the whole call.cargo test -p extenddb-storage-postgres --test doc_version_literals: passed.python3 -m pytest --collect-only -qcollects 7305 tests intests/and 821 intests/python, with no error.The runs below are from earlier rounds.
CI at
3cb02a7ce, the head before the commits of 24 November, ran on 14 November, and all 13 workflow runs were green. Among them: Test 43599472817, Integration Tests 43599472857, MongoDB Integration Tests 43599472914 and Cassandra Integration Tests 43599472860.tests/python/test_gsi_backfilling.pypassed in run-integration, run-integration-sqlite, mongodb-pytest and cassandra-pytest. The PostgreSQLgsi_backfillingandgsi_create_convergetests passed in run-postgres-storage-tests, the twolive_gsi_tests in mongodb-rust, and the Cassandragsi_backfillingtests in cassandra-storage. Thetests/rustsuite passed in cassandra-rust and mongodb-rust.On
ece2581d0, on one host:cargo fmt --all -- --check, and clippy with-D warningsas CI runs it, with both of its feature sets, on the whole workspace: clean.gsi_backfilling_testspasses.tests/python/test_gsi_backfilling.pyagainst a SQLite server built fromece2581d0: passed.devtools/run-wasm-step clippy): clean. At832afe71c, the merge before the fix, it failed on the twotokio::time::sleepcalls. It ran with the C compile of the bundled SQLite skipped, because the host has no clang, and clippy does not link.python3 -m pytest --collect-only -qcollectstests/(6,638 tests) andtests/python(673) with no error.3ab93e85b, the head before832afe71c, passed all 65 checks.On the commits of 24 November up to
14f7d0136, on one host:cargo fmt --all -- --check. Clippy with-D warningsas CI runs it, with both of its feature sets, on the nine crates this PR touches.cargo +1.91.1 check --all-targetson the same crates.cargo test --no-runintests/rust, with no warning.backup_storetests inextenddb-serverand twowrite_lock_testsinextenddb-storage-sqlitefail on that host. The SQLite two are storage-sqlite: the two write_lock_tests fail when an ancestor of the Cargo target directory is owned by another user #1414, a file-ownership condition of the host. CI's Test run at3cb02a7ceran all seven green.gsi_backfilling(3) andgsi_create_converge(2) against PostgreSQL 16 (pgvector/pgvector:pg16, CI's image) withEXTENDDB_TEST_PG_REQUIRED=1: 5 passed. With the connection string unset and the variable set, the 5 fail with the new assert. With the previousbase_conn, they passed as skips.gsi_backfilling(2) andindex::recovery_for_one_account_leaves_the_indexes_of_other_accounts_aloneagainst Cassandra 4.1 with PasswordAuthenticator: 3 passed. With the previousindex.rs, the phase test fails at its new assertion: the read is served.tests/rustgsi_on_hash_only_tableandgsi_update_table_attr_defs(6 tests) against a SQLite server built from the branch, with--test-threads=1asdevtools/run-testsruns them: 6 passed.a_gsi_phase_hold_is_writable_for_one_valid_table_nameanda_table_gsi_phase_hold_is_writable_from_the_clifail on the two-character name.python3 -m pytest --collect-only -qcollectstests/(6,638 tests) andtests/python(673) with no error.Not tested
ConsistentReadtrue on the backfilling index, and a Query whose KeyConditionExpression names a non-key attribute of it.{"Statement": "SELECT * FROM \"<table>\".\"<index>\" WHERE g = 'v'"}right after UpdateTable and again afterBackfillingturns true, and BatchExecuteStatement with the same statement. The wire test pins ExtendDB's answers.Backfillingturning true and the refusal switching on the service (see What the service does). A Query every second from UpdateTable on, with a DescribeTable between each pair, would measure it.Backfillingever returns to false after true on the service. A DescribeTable every second for the whole build would measure it.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, 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.
Backfillingis a member of the service's DescribeTable response, and the setting followsvector_allocation_phase_delay_ms, the test setting of the same shape. TheStoragetrait gains no method.GsiDescriptiongains one optional field with a serde default, so descriptions stored by earlier releases deserialise.Breaking changes
A client of an existing deployment sees four differences after the upgrade. DescribeTable lists
Backfillingon a GSI that UpdateTable added, while the index is CREATING. On MongoDB and Cassandra a Query, Scan or PartiQL SELECT naming such an index gets a ValidationException where main served the partial index. On PostgreSQL and SQLite the refusal changes once the backfill has started. It was "The table does not have the specified index: ", and it is now "Cannot read from backfilling global secondary index: ". In a BatchExecuteStatement, a SELECT of such an index gets the refusal as its own error, and the other statements run. The upgrade manual lists these changes under v1.2.0.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.