Repository navigation
fix(storage-postgres): return UpdateTable before the GSI backfill finishes - #708
LeeroyHannigan wants to merge 13 commits into
Conversation
…ishes The service answers UpdateTable at once with a new GSI CREATING and backfills in the background. On PostgreSQL, UpdateTable with a GSI Create spawned the index build and awaited it inside the request, so the response arrived only after every existing item was indexed, and a 20,000-item table exceeded boto3's default 60 s read timeout. The build task is now detached. UpdateTable returns once the CREATING index row is committed, and the task waits 1 s, takes a write barrier, backfills, and flips the row to ACTIVE. Writes already maintain a CREATING index, and the recovery worker already finishes a build that a restart left behind. A build that fails for a transient reason leaves the index CREATING for the recovery worker; one that would fail on every attempt is logged and its index removed. One server process runs at most GSI_BUILD_SLOTS (4) GSI builds at once, and the recovery worker's builds count toward them. UpdateTable never waits for a slot. A build that finds none waits in its task with no database session open, takes its ownership lock when a slot comes, and then builds only if the index is still CREATING, since the recovery worker of this or another server may have built it in the meantime. Without the limit, in a storage-level test, 30 UpdateTable calls in a row on 30 tables, each build held after its first page, raised the database's sessions from 11 to 42. A CREATING index answers as the service does in its backfilling phase. Query and Scan get ValidationException "Cannot read from backfilling global secondary index: <name>" where they got "The table does not have the specified index". DeleteTable gets ResourceInUseException "Attempt to change a resource which is still in use: Cannot delete table while indexes are being created, updated, or deleted.", also on a table with deletion protection on; before, it deleted an unprotected table under the build. On the service, measured on 30 October 2026, Backfilling turned true 16 to 39 s after UpdateTable, and the index went ACTIVE about 16 minutes after the call on 2,000-item tables. The new tests gsi_async_build, gsi_build_task and gsi_build_slots hold a table's backfill through a test-hooks hook and cover the response during the build, writes made during it, a restart partway through, both failure outcomes, the ownership lock that keeps the recovery sweep off a running build, DeleteTable on a protected table, the build limit, and a waiting build whose index another server's recovery sweep published. They are added to the storage-level PostgreSQL step of the integration workflow. Storage tests and two wire tests that used an index right after UpdateTable now wait for it to be ACTIVE. The design doc, the gsi_build module doc and differences-from-dynamodb.md describe the detached build and the differences from the service that remain.
.github/workflows/integration.yml conflicted. Main runs every test target of extenddb-storage-postgres with --tests, which includes this branch's new GSI build tests, so the step keeps main's command.
Main's migrations no longer seed the control_plane_delay_seconds row in settings, so the UPDATE that set it to zero in these tests changed no row. The engine kept its default delay, CreateTable left the table CREATING, and table_key_info then returned TableNotFound. The tests now insert the row or update it, as main's own tests do.
crates/storage-postgres/src/lib.rs keeps the snapshot_slot_limit field from main and the gsi_build_slots field from this branch, in the struct and in new(). crates/storage-postgres/src/update_table.rs keeps main's from_catalog_json reads of the base key schema and attribute definitions, and this branch's comment on build slots above them.
…GSI build detached On main, #474 starts the WarmThroughput UPDATING window of each GSI that UpdateTable creates again before UpdateTable describes the table for its response. Its comments give the reason as the GSI build, which UpdateTable waited for. On this branch the build runs in a task that UpdateTable does not wait for. The restart is still the last step before UpdateTable describes the table, so the response still reports the window UPDATING. The two comments in update_table.rs and the doc comment of restart_created_gsi_warm_throughput in warm_throughput.rs now say this. The docstring of test_gsi_create_with_warm_throughput_in_update_table said that ExtendDB reports the table and the new index ACTIVE at once. It now says that the table is ACTIVE and that SQLite reports the index ACTIVE. It also says that PostgreSQL, MongoDB and Cassandra report the index CREATING while they build it in the background. No code or assertion changes.
…g name tests Main's #833 added two storage tests that add a GSI with UpdateTable and expect UpdateTable to build the index before it returns. On this branch UpdateTable returns while the new index is CREATING, and a task of its own backfills the index and flips it to ACTIVE. - catalog_nul_index_writes::a_backfill_and_the_recovery_sweep_read_the_names_from_the_catalog read the rows of by_u1 right after UpdateTable and found none, because the build task had not yet backfilled the index. It now waits for the index to be ACTIVE before it reads the rows. Its comment on the ownership lock now names the build task that UpdateTable starts. - catalog_nul_names::names_with_u0000_and_u0001_round_trip_through_the_catalog called DeleteTable right after the UpdateTable that adds gsi2. DeleteTable refuses a table with a CREATING index, so the call failed with IndexesInUse. It now waits for gsi2 to be ACTIVE first. Both tests use wait_active from catalog_nul_support. It now waits for the table and each of its indexes to be ACTIVE. Its other caller waits for a restored table, and the restore flips the table and its indexes to ACTIVE in one transaction. This commit keeps every assertion of both tests.
|
#454 (opened 22 October) changes the same function, |
| let (idx_type_str, idx_id, ks_json, proj_json) = | ||
| let (idx_type_str, idx_id, idx_status, ks_json, proj_json) = | ||
| idx_row.ok_or_else(|| StorageError::IndexNotFound(index_name.to_owned()))?; | ||
| if idx_status == "CREATING" { |
There was a problem hiding this comment.
This refusal also reaches the PartiQL callers of index_info_by_table_id, which treat only IndexNotFound as an expected answer and pass any other error up as a request failure. A BatchExecuteStatement naming a CREATING index now fails as a whole call, and its other statements get no answer.
There was a problem hiding this comment.
I reproduced this through dispatch on PostgreSQL with the build held: your two-statement batch failed as a whole call with the backfilling ValidationException. With a caller allowed on the table, the base-table statement lost its item.
Fixed in 5b70d1f282 (engine) and 49fc116934 (PostgreSQL).
The refusal is now its own variant, StorageError::IndexBackfilling, and Query and Scan still answer it with the backfilling text. The four PartiQL lookups (target_schema, check_read, projected_call_error and the single SELECT) now call one helper, common::statement_index, which reads a backfilling index as a missing one. So a PartiQL read of a CREATING index gets the answers main gives for an index the table does not have. The batch stays 200, with a per-statement error for the index read and an answer for the other statement. The engine gives an ExecuteStatement the missing-index refusal only after it authorizes the statement, so a caller with no permission gets AccessDeniedException.
The new test reads_of_a_creating_index_through_the_engine in gsi_async_build.rs sends each PartiQL read to the CREATING index and to a missing one. It asserts both answers in full, for an allowed caller and for a refused one. With the production code of d0ee181, it fails on the batch.
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.
A backend can now refuse a read of a CREATING GSI with StorageError::IndexBackfilling. storage_err_to_dynamo maps the variant to ValidationException "Cannot read from backfilling global secondary index: <name>", the text the service gives a Query or Scan in the backfilling phase. Query and Scan send the variant to that mapping, so they answer with this text. The mapping takes the text from the existing constant VECTOR_INDEX_BACKFILLING_SCAN_PREFIX. The four PartiQL index lookups are target_schema in authorize.rs, check_read and projected_call_error in batch.rs, and the single SELECT in select.rs. Each one treated every error except IndexNotFound as a failure of the whole request. They now call one helper, common::statement_index, which reads IndexNotFound and IndexBackfilling as no index. So a PartiQL read of a backfilling index gets the answers for an index the table does not have. A BatchExecuteStatement gives that statement its per-statement error and answers the other statements. The engine authorizes an ExecuteStatement before it answers the refusal, so a caller with no permission gets AccessDeniedException. The service's answer to a PartiQL read of a backfilling index is not measured. No backend returns IndexBackfilling at this commit. The next commit makes the PostgreSQL lookup return it.
…lling fetch_index_info_by_table_id returned StorageError::Validation with the backfilling text for a CREATING index. The PartiQL callers of the lookup passed that error up as a failure of the whole request. A BatchExecuteStatement that named a CREATING index failed as a whole call, and its other statements got no answer. An ExecuteStatement on a CREATING index answered the backfilling text before authorization. So a caller with no permission on the table learned that the index existed. The lookup now returns StorageError::IndexBackfilling. The previous commit answers that variant with the same text for a Query or Scan, and as a missing index for a PartiQL statement. The three storage-level asserts of the refusal match the new variant. Section 6.2 of docs/design/04-component-storage.md now gives the PartiQL answer. New test reads_of_a_creating_index_through_the_engine in gsi_async_build.rs holds the build and sends three PartiQL reads through dispatch: a two-statement BatchExecuteStatement, a BatchExecuteStatement with COUNT(*), and an ExecuteStatement. Each read goes once to the CREATING index and once to an index the table does not have. Both answers must equal the answer in the test's table, for a caller that may read the table and for a caller with no permission. A Query and a Scan of the CREATING index get the backfilling text. With the production code of d0ee181, the test fails on the BatchExecuteStatement.
…PG_REQUIRED gsi_async_build.rs, gsi_build_slots.rs and gsi_build_task.rs each had a base_conn that skipped every test when EXTENDDB_TEST_PG_CONNECTION_STRING was unset, also with EXTENDDB_TEST_PG_REQUIRED set. The PostgreSQL storage-level step of integration.yml sets EXTENDDB_TEST_PG_REQUIRED so that a skip for a missing connection string fails the job. The three files and gsi_online_build.rs now take base_conn from common/stream_disable_fixture.rs and drop their own copies. That base_conn fails the test when the connection string is empty and EXTENDDB_TEST_PG_REQUIRED holds any value but 0.
…_migrations The previous commit made gsi_async_build.rs, gsi_build_slots.rs, gsi_build_task.rs and gsi_online_build.rs include common/stream_disable_fixture.rs for its base_conn. Each of the four files kept its own ACCOUNT, REGION and shipped_migrations, with the same code as the fixture's public items. So the code of each test binary had two copies of the three items. The four files now import the three items from the fixture and delete their own copies. The comment above mod fixture names the four items that each file takes from the fixture. The commit changes no test function.
|
Required 1: fixed in Docs 1: I fixed the body. The PostgreSQL storage-level step runs every test target of the crate with On the three items you could not check:
|
LJMart11
left a comment
There was a problem hiding this comment.
Checked at 17a11a4 against the list from d0ee181. Checked at 17a11a4 against d0ee181: both earlier items are fixed. The PartiQL read of a CREATING index is pinned by reads_of_a_creating_index_through_the_engine, and the PostgreSQL GSI build tests (24) plus the engine (933) and storage (290) lib tests passed.
Previous items: 1 fixed; 2 fixed.
demohan
left a comment
There was a problem hiding this comment.
UpdateTable returns with the index CREATING at 17a11a4, and the background build indexes every item once. On PostgreSQL 16, UpdateTable answers in 18 ms to 1.3 s over 11 calls whatever the table's size, and in 28 to 31 ms on 200,000-item tables where main took about 20 s; DescribeTable shows IndexSizeBytes and ItemCount 0 while CREATING, and Query and Scan get the backfilling text ahead of the ConsistentRead and key checks, as on the service in us-east-1. A second GSI Create, a Delete of another or a missing index and DeleteTable get the service's class and text. After every run the index matched the base items carrying the key, with no duplicate, missing, extra or stale row: 50,000 items with 29,200 writes during the build, six concurrent 200,000-item builds with 111,605 writes, a Delete of the building index followed at once by a Create of the same name, SIGKILL of one of two servers on one catalog mid-build (the other published an exact index 15.6 s later), a graceful stop and restart (published 9.1 s after), a build main started and this head recovered and the reverse, and a CreateBackup during a build restored. Four builds run at once, the rest wait with no rows and no lock, AccessDenied still comes first, and the 25 storage tests and eight negative controls behave as they should. fmt, clippy and the 1.91.1 check are clean.
Merged with main at 222d80a the library and server build, but the three new test files do not compile: sqlx 0.9.1 (#1166) refuses 22 dynamic queries with E0277 in gsi_async_build.rs, gsi_build_slots.rs and gsi_build_task.rs; wrapping them in sqlx::AssertSqlSafe, as main's gsi_online_build.rs:57 does, fixes it.
I will approve once main is merged and those files build, a PartiQL read of a building index answers as below, and a test deletes the index while its build runs.
crates/storage-postgres/tests/gsi_online_build.rs:785
No test deletes the index while a build runs: this one marks a finished index CREATING by hand. The behaviour is right on a server built from this head: deleted 1.5 s into a 20,000-item build, the Delete answers, a Query naming the index gets The table does not have the specified index: gsi1, the log says GSI was deleted while it was being built, and adding it again reaches ACTIVE with 20,000 rows, twice. A test that deletes during a held build would keep it so.
| /// # Errors | ||
| /// | ||
| /// A failed read of the catalog. | ||
| pub(super) async fn statement_index( |
There was a problem hiding this comment.
A PartiQL read of a CREATING index answers as if the index did not exist, and every UpdateTable now opens that window. On the service in the backfilling phase, ExecuteStatement SELECT with WHERE on the index key, on pk or with no WHERE answers Cannot read from backfilling global secondary index: gsi1, with ConsistentRead true Strongly consistent read is not supported on Global Secondary Indexes, and inside BatchExecuteStatement Select statements within BatchExecuteStatement must specify the primary key in the where clause. as for an ACTIVE index; this head and main give The table does not have the specified index on all 20 shapes, twice. The comment, design section 6.2 and the body say this was not measured. Treating a backfilling index as existing for these checks and refusing at the read would match; otherwise a differences row would say it.
| | Projected attributes across all indexes | At most 100 | Enforced on `CreateTable` (and so on `RestoreTableFromBackup`, which validates its target the same way) and on `UpdateTable`'s GSI `Create`: every `NonKeyAttributes` entry of every GSI and LSI is counted, so an attribute projected into two indexes counts twice. Over 100 is `ValidationException` ("Number of projected attributes in all indexes exceeds limit of 100, projected: <n>"; the service's text was not captured) | | ||
| | Index key validation on `UpdateItem` and transaction writes | A secondary-index key attribute must carry its declared scalar type and may not be empty. On `UpdateItem` a literal operand of the wrong type (`SET k = :v`, `ADD`, `DELETE`, `list_append` of literals) is refused on the statement, ahead of the `ConditionExpression`, naming the attribute and the index; a value computed from the item (an attribute reference, the fallback of `if_not_exists`) is refused after the condition passes with the message "The update expression attempted to update the secondary index key to unsupported type"; a key left empty is refused after the condition passes with the update-expression wording. In `TransactWriteItems` a wrong-typed key (table or index) on any member cancels the transaction with the first such member's `ValidationError` in position and `None` elsewhere; otherwise an empty index key on any member is a top-level `ValidationException`; otherwise members report their own conditions. On a `Put` member both checks come ahead of the member's condition. (Measured on the service.) | Matches on every backend. Two known shared differences: an empty index key supplied through the legacy `AttributeUpdates` parameter is reported with the update-expression wording where the service uses the `PutItem` wording naming the index; and a request whose own value exceeds 400 KB is refused for size by the service before any index-key check, where ExtendDB reports the index-key fault first. | | ||
| | `Query` on a GSI with several RANGE attributes (MongoDB and Cassandra backends) | Orders results over every RANGE attribute in key-schema order and serves a key condition on each of them (equality on every one before the last, any operator on the last) | SQLite and PostgreSQL match the service. The MongoDB and Cassandra backends filter the first RANGE attribute of such an index only: a key condition on a later RANGE attribute is refused with `ValidationException` naming the attribute and the backend. MongoDB orders results by the first RANGE attribute then the base table key. Cassandra orders a page over every RANGE attribute then the base table key, and refuses a `Query` that carries an `ExclusiveStartKey` on such an index with `ValidationException` (the cursor compares the first RANGE attribute only). Every refusal the service gives for the condition's shape (one condition per key, condition count, missing HASH attribute, RANGE gap, non-key attribute, value type) is the same on every backend. | | ||
| | `TableStatus` while a GSI added by `UpdateTable` is built (PostgreSQL) | `UPDATING` in the `UpdateTable` response and until the index reports `Backfilling` true, then `ACTIVE` while the index stays `CREATING`. The change came 16 to 39 s after the call in six builds on four tables (measured 2026-10-30) | `ACTIVE` in the response and for the whole build | |
There was a problem hiding this comment.
Optional. During the build the service shows the GSI's WarmThroughput as {12000, 4000, UPDATING}; this head shows none until ACTIVE (core/src/types/table.rs:880-884), which this list leaves out. crates/storage/src/lib.rs:272 lists IndexNotFound and TableNotFound, and PostgreSQL now also returns IndexBackfilling.
Main moved to sqlx 0.9.1 in #1166. sqlx 0.9 accepts SQL that is not a &'static str only in sqlx::AssertSqlSafe. After the merge of main, the three test files that this branch adds did not compile: gsi_async_build.rs, gsi_build_slots.rs and gsi_build_task.rs. Each of the 22 calls that passes a string built at run time now passes it in sqlx::AssertSqlSafe, in the same form as main's tests. The SQL text and the bound values do not change.
|
Checked at Fixed:
Disputed: none. Needs-human: none. |
Changes since the last review
1a9b9a63b4mergesmain.crates/storage-postgres/src/lib.rsconflicted where fix: match data relations by catalog id in catalog-check, so --fix keeps live tables #690 on main and this branch each added test-hook exports. The merge keeps all three exports.5b70d1f282and49fc116934fix the PartiQL answers for a CREATING index. The PostgreSQL lookup now refuses the read with a new variant,StorageError::IndexBackfilling. The engine answers a Query or Scan of the index with the backfilling text, as before. A PartiQL statement that reads the index gets the answers for an index the table does not have. Before, aBatchExecuteStatementthat named a CREATING index failed as a whole call, and anExecuteStatementanswered the backfilling text before authorization.5b70d1f282changes only the engine and the storage error type, and it applies to the head of fix: report Backfilling on a CREATING GSI and refuse its reads by phase #454 unchanged.15d43da4a5makes the tests ingsi_async_build.rs,gsi_build_slots.rsandgsi_build_task.rsfail instead of skipping when the connection string is empty andEXTENDDB_TEST_PG_REQUIREDholds any value but 0. The tests ingsi_online_build.rsalready failed in that case. The four files now takebase_connfromcrates/storage-postgres/tests/common/stream_disable_fixture.rs.17a11a4f8dmakes the four files also takeACCOUNT,REGIONandshipped_migrationsfromstream_disable_fixture.rs, and removes their own copies of the three items. The copies had the same code as the fixture's items. The commit changes no test function.integration.ymland the conflict with fix: match data relations by catalog id in catalog-check, so --fix keeps live tables #690 is gone. The first line under Results gives the count at15d43da4a5, and "Overlap with open pull requests" names fix: report Backfilling on a CREATING GSI and refuse its reads by phase #454.What
ExtendDB's backfill starts after a 1 s wait and a write barrier, so it has no stage that corresponds to the allocation phase. A CREATING index on PostgreSQL now answers as the service does in the backfilling phase:
GSI_BUILD_SLOTSincrates/storage-postgres/src/data/gsi_build.rs). The recovery worker's builds count toward the four. UpdateTable never waits for a slot. A build that finds none waits in its task with no database session open and its index CREATING. Slots go to waiting builds in the order they asked. Without the limit, a client that added indexes to one table after another started every build at once. Each build had a database session of its own for its ownership lock. A storage-level test ran against a local PostgreSQL 16 container. It sent 30 UpdateTable calls in a row on 30 tables of 300 items, and it held each build after its first page. With no limit, the calls left 42 sessions on the database 3 s after the last call (11 before) and 30 ownership locks held. With the limit, the same 30 calls left 16 sessions and 4 ownership locks at that point. The most seen at any sample was 18 sessions. All 30 indexes were ACTIVE 12.8 s after the test released the builds.A PartiQL statement that reads a CREATING index gets the answers it got before this change. Those are the answers for an index the table does not have. The service's answer to that read is not measured.
Differences that remain, with the service's measured answers:
Backfillingturns true, 16 to 39 s after the call, then ACTIVE.Backfillingmember. The service reportsBackfillingfalse in the UpdateTable response and until that point, then true until the index is ACTIVE.Backfillingturns true, the service still answers a Query with "The table does not have the specified index". On one table this was 0 and 2 s after. Later the service answers with the backfilling text (about 45 s after). ExtendDB answers the backfilling text for as long as the index is CREATING.The same four are rows in
docs/differences-from-dynamodb.md.These answers are unchanged and match the service's backfilling phase. A second index Create gets LimitExceededException. ExtendDB accepts a Delete of the creating index, PutItem and stream changes. It also accepts a switch to PROVISIONED billing with table throughput only. I sent the service that switch with a GSI
Updatecarrying the index's throughput as well, and the service accepted it. I compared ExtendDB without the GSIUpdate, which PostgreSQL refuses (see "Not changed"). ExtendDB also answers LimitExceededException to a Delete of a different index. On the service, I measured only a Delete of an index that did not exist, and it got LimitExceededException.Restart and failure handling uses the existing recovery worker and build ownership lock. When a build slot is free, UpdateTable takes the build's ownership lock (a session advisory lock on its own connection) before the catalog commit. The build task holds the lock for its lifetime. A build that waits for a slot takes the lock when the slot comes. Until then its CREATING row has no owner, and the recovery worker on this or another server may take the index and build it instead. Once it holds the lock, the waiting build reads the index row again and goes ahead only if the index is still CREATING. If the server stops during a build, PostgreSQL releases the lock with the connection. The recovery worker runs a pass at startup and then every 60 s. It takes ownership of each CREATING GSI whose lock is free, and it runs the build again over the partial index table. The backfill upserts, and the orphan sweep removes leftovers. A transient error leaves the index CREATING for the recovery worker. A deterministic error removes the index, as the recovery worker already did, so DescribeTable shows it gone and a later UpdateTable can create it again. The caller no longer receives that error in the UpdateTable response. The service answers UpdateTable before its backfill starts, so it cannot return a backfill failure in that response either.
I chose this over two other designs. Handing every build to the recovery worker would start a build up to 60 s late. A new persisted failed state is a state the service does not report, and it would need a catalog migration.
docs/design/04-component-storage.mdsection 6.2 and the module doc ofdata/gsi_build.rsnow describe the build task.Not changed
PostgreSQL refuses UpdateTable with a GSI
Updateaction with ValidationException "UpdateGlobalSecondaryIndex is not yet supported". It does so whether the index is CREATING or ACTIVE, as before this PR. The service accepted that action in the backfilling phase.UpdateTable holds a pool connection for its catalog transaction while it takes a second one to create a new GSI's data table. A server can use one pool for its catalog and its data. On such a server, as many concurrent GSI Creates as the pool has connections can each hold one and time out waiting for another. This PR does not change that.
This PR does not change SQLite. SQLite builds the index inside UpdateTable and answers with it ACTIVE. On a 20,000-item table the call took 0.62 s and 0.67 s in two runs of a local release build. Its response reports the index ACTIVE where the service reports CREATING.
Overlap with open pull requests
#454 changes the same function,
fetch_index_info_by_table_idincrates/storage-postgres/src/data/ddl.rs, to refuse a read of a CREATING GSI with the two phases the service has. I opened #454 first, on 22 October, and this PR on 31 October. Whichever of the two merges second drops its copy of the refusal. The engine commit5b70d1f282changes no PostgreSQL file and applies to the head of #454 unchanged. A merge of this PR's head into the head of #454 conflicts incrates/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.Why
On PostgreSQL, UpdateTable with a GSI Create spawned the index build and awaited it inside the request (
crates/storage-postgres/src/update_table.rs). So the response came back only after the build indexed every existing item. The issue reports 23 s for a 3,000-item table under load. It also reports a clientReadTimeoutErrorat boto3's default 60 s read timeout on a 20,000-item table, while the build continued in the server.DynamoDB answers UpdateTable at once with the new index CREATING and backfills in the background.
I timed this branch on a 20,000-item table on a local PostgreSQL 16 container. The backfill took 5.6 s from the UpdateTable call to the index reporting ACTIVE. Before this change, the UpdateTable response waited for the backfill to finish. The pre-change build was not timed separately on this host. With this change the call returned in 24 ms with the index CREATING. I measured both figures before I added the build limit (item 4 under "What"). A build that finds a free slot starts the way it did before.
Service behaviour
Measured on Amazon DynamoDB in us-east-1 on 30 October 2026, on four on-demand tables. Two tables had 2,000 items and two had 500 items. I created one of the 500-item tables with deletion protection on. Each measurement added a GSI with UpdateTable and polled DescribeTable every 1 or 2 s, six index builds in all:
Backfillingfalse.Backfillingtrue. The service's own messages call the first stage the resource allocation phase and the second the backfilling phase.Answers while the index was CREATING:
Updatecarrying the index's throughputThe backfilling-phase Query and Scan answers on the two 2,000-item tables came about two minutes after UpdateTable. Queries on the deletion-protected table got two answers during the build of its second index. Queries 0 and 2 s after
Backfillingturned true still got "The table does not have the specified index". Queries about 45 s after it got the backfilling text.I measured each allocation-phase answer on two tables, except DeleteTable: once on an unprotected table, and twice on the deletion-protected one. In the backfilling phase, I measured PutItem, the second Create, the stream change, the billing change and the Delete of the creating index once each. I measured Scan on two tables, Query on three, and DeleteTable five times on two tables.
Closes #654
Testing done
Tests
New
crates/storage-postgres/tests/gsi_async_build.rs, using a hook behind the crate'stest-hooksfeature (hold_gsi_backfill_for_tests) that holds one table's GSI build at its start or after a given number of backfill pages:update_table_returns_while_the_backfill_runs: with the build held, UpdateTable returns within 10 s with the index CREATING, and DescribeTable agrees. The PostgreSQL index lookup refuses a read of the index as backfilling. DeleteTable gets the ResourceInUse message and the table stays. After the test releases one page, it writes behind and ahead of the scan. The writes are a key change, a delete, an insert and an item that loses the key attribute. On release the index reaches ACTIVE and holds each base item that carries the key attribute once.a_restart_during_the_backfill_still_reaches_active: a first engine on its own runtime adds the GSI with the build held after one page. Once at least 256 rows are in the index, that runtime is shut down, and the index stays CREATING. After more writes,reconcile_creating_gsison a second engine finishes the build, and the index matches the base table with each item once.reads_of_a_creating_index_through_the_engine: with the build held, the test sends each PartiQL read of the index throughdispatch. It also sends the same read of an index the table does not have. The reads are a two-statementBatchExecuteStatement, aBatchExecuteStatementwithCOUNT(*), and anExecuteStatement. Both reads get the same answer, for a caller with permission and for one without, and the test asserts that answer in full. A Query and a Scan of the index get the backfilling text.New
crates/storage-postgres/tests/gsi_build_task.rs, for what the build task does after UpdateTable answers:a_build_that_fails_every_time_removes_the_index: the test makes one stored item undecodable. UpdateTable answers with the index CREATING, the build fails on that item, and the build task removes the index and its data table. Once the test restores the item, the same Create builds the index.a_build_that_fails_for_a_passing_reason_stays_creating: an outside transaction holds the base table's lock, so every write barrier attempt times out. The index stays CREATING with its data table, the build task releases its ownership lock, and the next recovery sweep publishes the index.the_recovery_sweep_leaves_a_running_build_alone: a recovery sweep during a held build returns at once with nothing built.delete_table_of_a_protected_table_during_a_build_is_in_use: on a deletion-protected table, DeleteTable gets the protection refusal before the build and the ResourceInUse message during it. Once the index is ACTIVE, it gets the protection refusal again.New
crates/storage-postgres/tests/gsi_build_slots.rs. Its first three tests run on an engine given one build slot, with a first table's build held after its first page:a_build_waits_for_a_free_slot_holding_no_session: UpdateTable on a second table returns within 10 s with the index CREATING. That index refuses a read as backfilling, has 0 rows after 3 s, and holds no ownership lock. Once the first index is ACTIVE, the second build starts under its own ownership lock, and both indexes end holding exactly the base items.the_recovery_sweep_waits_for_a_free_slot: a recovery sweep takes the waiting index and builds nothing while the first build holds the slot. When the slot frees, the index's own task finds the sweep owning it and leaves it, and the sweep publishes it.a_waiting_build_leaves_an_index_a_peer_published: a second engine on the same database stands in for another server. While the second build waits, that engine's recovery sweep takes the index and publishes it. The second index's build entry is then held, so a build that started there would keep its ownership lock. When the slot frees, the waiting task takes the lock, finds the index ACTIVE and releases the lock. 3 s later, no session holds an ownership lock.The fourth,
an_engine_runs_at_most_gsi_build_slots_builds, runs on an engine with its own four slots. It sends UpdateTable on five tables and holds each build after its first page. After 3 s, four builds run with one ownership lock each, and the fifth index has 0 rows and no owner. All five indexes then reach ACTIVE holding exactly the base items.The PostgreSQL storage-level step of
integration.ymlruns every test target of the crate with--tests, so the new files run there. The workflow needs no change.Tests that assumed the build was done when UpdateTable returned now wait for the index to be ACTIVE. In the storage-level tests, these are
add_gsiingsi_online_build.rsandgsi_stale_writer.rs, and the two tests incatalog_nul_index_writes.rsandcatalog_nul_names.rsthat add a GSI, throughwait_activeincatalog_nul_support. In the wire suite, these areupdate_table_attribute_definitionsandgsi_on_hash_only_table, through a newtest_base::wait_for_index_active. Without that, two wire tests failed against a server built from this branch. One got the backfilling ValidationException, and the other got LimitExceededException on its next index add.Negative controls
I ran each on the committed tree and restored the tree after the run:
update_table_returns_while_the_backfill_runsfails with "UpdateTable waited for the held backfill instead of returning".data/ddl.rsas before this change: the same test fails because the read answered IndexNotFound.delete_table.rsas before this change: the same test fails because DeleteTable answered Ok.delete_table_of_a_protected_table_during_a_build_is_in_usefails because DeleteTable answered the protection refusal during the build.a_build_that_fails_every_time_removes_the_indexfails because the index stayed CREATING.a_build_that_fails_for_a_passing_reason_stays_creatingfails because the build task removed the index.the_recovery_sweep_leaves_a_running_build_alonefails because the sweep started a second build and did not return.the_recovery_sweep_waits_for_a_free_slotfails the same way.a_waiting_build_leaves_an_index_a_peer_publishedfails. The task held the published index's ownership lock to build it a second time.Semaphore::MAX_PERMITSpermits):an_engine_runs_at_most_gsi_build_slots_buildsfails because the fifth build wrote its first page.d0ee181:reads_of_a_creating_index_through_the_enginefails on the two-statement batch, which answered the backfilling ValidationException as a whole call.target_schema,check_read,projected_call_errorand the single SELECT. Each one back to its code before this change, one at a time: the same test fails on the first read that the lookup answers.base_conningsi_async_build.rsas before15d43da4a5, withEXTENDDB_TEST_PG_REQUIRED=1and no connection string: its three tests skip and pass. With15d43da4a5, every test of the four files fails.Results
On this branch, against PostgreSQL 16 with pgvector in a local container:
cargo test --release -p extenddb-storage-postgres --tests), at15d43da4a5: 491 passed, 5 failed, 2 ignored. The 5 failures are filesystem backup store tests inbackup_restore.rsandcatalog_nul_backup_jobs.rs, which this PR does not change. On this host uid 65534 owns the system directories, so the store refuses every backup root. CI'srun-postgres-storage-testsjob passed these tests ond0ee181.extenddb-storageandextenddb-engineat15d43da4a5: 290 and 933 passed, 0 failed.15d43da4a5,cargo fmt --all -- --checkpassed on 1.97.0. So didcargo clippy --all-targets -- -D warningsforextenddb-storage,extenddb-engineandextenddb-storage-postgres, and for the engine also with--features extenddb-engine/backup-test-hooks.cargo +1.91.1 check --all-targetsof the three crates gave no warnings.test_gsi_async,test_gsi_attribute_definitions,test_gsi_online_backfill,test_multipart_gsi,test_table_operations, andtests/python/test_warm_throughput_updates.py) against a release server built from15d43da4a5: 62 passed, 0 failed.gsi_on_hash_only_tableandupdate_table_attribute_definitionsintests/rust, against the same server: 6 passed, 0 failed.17a11a4f8dchanges only four test files ofextenddb-storage-postgres. At this head, the tests of those four files gave 24 passed, 0 failed, in a dev build withEXTENDDB_TEST_PG_REQUIRED=1. With no connection string, all 24 failed. The fmt check passed.cargo clippy -p extenddb-storage-postgres --all-targets -- -D warningsgave no warnings, also with--features extenddb-engine/backup-test-hooks. So didcargo +1.91.1 check -p extenddb-storage-postgres --all-targets. The other steps above did not run again at this head.The wire suite (
tests/rust) ran on an earlier revision of this branch, against a release server: 512 passed, 0 failed. Its base was1c0523c90, and it did not have the waiting build's re-read of its index row or the last twogsi_build_slotstests.CI ran on
d0ee181, the head before1a9b9a63b4. It ran the workspace tests on Rust 1.88.0 and on stable. It also ran the integration suites on all four backends. These included the wire suite and the Python suite (without its import and export tests) against a PostgreSQL server. All of them passed. Locally I ran the steps listed under Results. Clippy ran with-D warnings, without the pedantic group. The change adds no command, flag, catalog migration or trait method. It adds one variant toStorageError. The build task's design is indocs/design/04-component-storage.mdsection 6.2.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
Breaking changes
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.