Skip to content

fix(storage-postgres): return UpdateTable before the GSI backfill finishes - #708

Open
LeeroyHannigan wants to merge 13 commits into
mainfrom
fix/654-pg-async-gsi-build
Open

LeeroyHannigan wants to merge 13 commits into
mainfrom
fix/654-pg-async-gsi-build

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • 1a9b9a63b4 merges main. crates/storage-postgres/src/lib.rs conflicted 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.
  • 5b70d1f282 and 49fc116934 fix 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, a BatchExecuteStatement that named a CREATING index failed as a whole call, and an ExecuteStatement answered the backfilling text before authorization. 5b70d1f282 changes 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.
  • 15d43da4a5 makes the tests in gsi_async_build.rs, gsi_build_slots.rs and gsi_build_task.rs fail instead of skipping when the connection string is empty and EXTENDDB_TEST_PG_REQUIRED holds any value but 0. The tests in gsi_online_build.rs already failed in that case. The four files now take base_conn from crates/storage-postgres/tests/common/stream_disable_fixture.rs.
  • 17a11a4f8d makes the four files also take ACCOUNT, REGION and shipped_migrations from stream_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.
  • In this description, the text about a test list in integration.yml and 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 at 15d43da4a5, 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:

  1. UpdateTable returns once it commits the catalog row, with the index CREATING. UpdateTable detaches the build task instead of awaiting it. The build task backfills and flips the row to ACTIVE when the backfill commits.
  2. Query and Scan on a CREATING index answer ValidationException "Cannot read from backfilling global secondary index: {name}". Before, they answered "The table does not have the specified index".
  3. DeleteTable while a GSI is CREATING answers ResourceInUseException with the measured message. It does so on a deletion-protected table too, where the service gives the same answer ahead of the protection refusal. Before, it deleted an unprotected table under the running build.
  4. One server process runs at most four GSI builds at once (GSI_BUILD_SLOTS in crates/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:

  • TableStatus is ACTIVE in the UpdateTable response and for the whole build. The service reports UPDATING until Backfilling turns true, 16 to 39 s after the call, then ACTIVE.
  • GSI descriptions have no Backfilling member. The service reports Backfilling false in the UpdateTable response and until that point, then true until the index is ACTIVE.
  • After a Delete of the creating index, the index is gone at once. The response no longer lists it, and a Query naming it gets "The table does not have the specified index". The service refused that Delete in the allocation phase. In the backfilling phase it accepted it and showed the index DELETING for about 5 s, and a Query meanwhile got the backfilling text.
  • For the first seconds after Backfilling turns 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 Update carrying the index's throughput as well, and the service accepted it. I compared ExtendDB without the GSI Update, 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.md section 6.2 and the module doc of data/gsi_build.rs now describe the build task.

Not changed

PostgreSQL refuses UpdateTable with a GSI Update action 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_id in crates/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 commit 5b70d1f282 changes no PostgreSQL file and applies to the head of #454 unchanged. A merge of this PR's head into the head of #454 conflicts in crates/storage-postgres/src/data/ddl.rs, crates/storage-postgres/src/update_table.rs, tests/rust/src/gsi_on_hash_only_table.rs and tests/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 client ReadTimeoutError at 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:

  • UpdateTable returned 200 in under 100 ms with TableStatus UPDATING, the new index CREATING and Backfilling false.
  • TableStatus returned to ACTIVE 16 to 39 s after the call (16.3, 24.3, 24.4, 26.2, 26.2 and 38.5 s). The index stayed CREATING, with Backfilling true. The service's own messages call the first stage the resource allocation phase and the second the backfilling phase.
  • On the 2,000-item tables the index became ACTIVE 16 min 39 s and 16 min 33 s after the call. ItemCount and IndexSizeBytes stayed 0 until then.

Answers while the index was CREATING:

Request Allocation phase Backfilling phase
Query or Scan on the index ValidationException "The table does not have the specified index: gsi1" ValidationException "Cannot read from backfilling global secondary index: gsi1"
PutItem, UpdateItem 200 200 (PutItem)
UpdateTable adding a second GSI LimitExceededException "Subscriber limit exceeded: Only 1 online index can be created or deleted simultaneously per table" the same
UpdateTable deleting the creating GSI ResourceInUseException "Attempt to change a resource which is still in use: Index creation is in resource allocation phase. Retry deletion during backfilling phase or when the index is active. Table: {table} Index: gsi1" 200; the index went DELETING and was gone about 5 s later
UpdateTable enabling a stream ResourceInUseException "Attempt to change a resource which is still in use: Can't change stream status when an index is being created. Table: {table} Indexes: [gsi1]" 200
UpdateTable to PROVISIONED billing, with table throughput and a GSI Update carrying the index's throughput ResourceInUseException "Attempt to change a resource which is still in use: Index is being created but is not backfilling yet. Table: {table} Index: gsi1" 200
DeleteTable ResourceInUseException "Attempt to change a resource which is still in use: Cannot delete table while indexes are being created, updated, or deleted." the same
DeleteTable on the deletion-protected table the same ResourceInUseException. With no index change running, the same table answered ValidationException "Resource cannot be deleted as it is currently protected against deletion. Disable deletion protection first." the same ResourceInUseException

The 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 Backfilling turned 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's test-hooks feature (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_gsis on 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 through dispatch. It also sends the same read of an index the table does not have. The reads are a two-statement BatchExecuteStatement, a BatchExecuteStatement with COUNT(*), and an ExecuteStatement. 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.yml runs 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_gsi in gsi_online_build.rs and gsi_stale_writer.rs, and the two tests in catalog_nul_index_writes.rs and catalog_nul_names.rs that add a GSI, through wait_active in catalog_nul_support. In the wire suite, these are update_table_attribute_definitions and gsi_on_hash_only_table, through a new test_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:

  • UpdateTable awaiting the build again: update_table_returns_while_the_backfill_runs fails with "UpdateTable waited for the held backfill instead of returning".
  • data/ddl.rs as before this change: the same test fails because the read answered IndexNotFound.
  • delete_table.rs as before this change: the same test fails because DeleteTable answered Ok.
  • The deletion-protection check ahead of the CREATING check again: delete_table_of_a_protected_table_during_a_build_is_in_use fails because DeleteTable answered the protection refusal during the build.
  • Every build failure treated as transient: a_build_that_fails_every_time_removes_the_index fails because the index stayed CREATING.
  • Every build failure treated as permanent: a_build_that_fails_for_a_passing_reason_stays_creating fails because the build task removed the index.
  • The ownership lock dropped before the build task starts: the_recovery_sweep_leaves_a_running_build_alone fails because the sweep started a second build and did not return.
  • The waiting build task taking a slot of its own instead of one of the engine's: both slot tests fail. The second build wrote 256 rows while the first held the only slot.
  • The recovery worker taking no slot: the_recovery_sweep_waits_for_a_free_slot fails the same way.
  • The waiting build task building without taking ownership: both slot tests fail. In one, the second build ran without its ownership lock. In the other, the sweep published nothing.
  • UpdateTable waiting for a slot: both slot tests fail because UpdateTable did not return within 10 s.
  • The waiting build task building without reading its index row again: a_waiting_build_leaves_an_index_a_peer_published fails. The task held the published index's ownership lock to build it a second time.
  • The engine's build slots unbounded (Semaphore::MAX_PERMITS permits): an_engine_runs_at_most_gsi_build_slots_builds fails because the fifth build wrote its first page.
  • The PostgreSQL lookup and the four PartiQL index lookups as at d0ee181: reads_of_a_creating_index_through_the_engine fails on the two-statement batch, which answered the backfilling ValidationException as a whole call.
  • The four PartiQL index lookups are target_schema, check_read, projected_call_error and 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.
  • The PartiQL lookup with a backfilling index treated as a failed read: the same test fails on the two-statement batch.
  • The backfilling refusal answered with the missing-index text: the same test fails on the Query.
  • base_conn in gsi_async_build.rs as before 15d43da4a5, with EXTENDDB_TEST_PG_REQUIRED=1 and no connection string: its three tests skip and pass. With 15d43da4a5, every test of the four files fails.

Results

On this branch, against PostgreSQL 16 with pgvector in a local container:

  • Every storage-level test target of the crate, release build, as the CI step runs it (cargo test --release -p extenddb-storage-postgres --tests), at 15d43da4a5: 491 passed, 5 failed, 2 ignored. The 5 failures are filesystem backup store tests in backup_restore.rs and catalog_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's run-postgres-storage-tests job passed these tests on d0ee181.
  • The lib tests of extenddb-storage and extenddb-engine at 15d43da4a5: 290 and 933 passed, 0 failed.
  • At 15d43da4a5, cargo fmt --all -- --check passed on 1.97.0. So did cargo clippy --all-targets -- -D warnings for extenddb-storage, extenddb-engine and extenddb-storage-postgres, and for the engine also with --features extenddb-engine/backup-test-hooks. cargo +1.91.1 check --all-targets of the three crates gave no warnings.
  • The Python GSI tests (test_gsi_async, test_gsi_attribute_definitions, test_gsi_online_backfill, test_multipart_gsi, test_table_operations, and tests/python/test_warm_throughput_updates.py) against a release server built from 15d43da4a5: 62 passed, 0 failed.
  • The wire tests that this PR changes, gsi_on_hash_only_table and update_table_attribute_definitions in tests/rust, against the same server: 6 passed, 0 failed.
  • 17a11a4f8d changes only four test files of extenddb-storage-postgres. At this head, the tests of those four files gave 24 passed, 0 failed, in a dev build with EXTENDDB_TEST_PG_REQUIRED=1. With no connection string, all 24 failed. The fmt check passed. cargo clippy -p extenddb-storage-postgres --all-targets -- -D warnings gave no warnings, also with --features extenddb-engine/backup-test-hooks. So did cargo +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 was 1c0523c90, and it did not have the waiting build's re-read of its index row or the last two gsi_build_slots tests.

CI ran on d0ee181, the head before 1a9b9a63b4. 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 to StorageError. The build task's design is in docs/design/04-component-storage.md section 6.2.

Checklist

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

ADR / RFC: n/a

Breaking changes

  • UpdateTable with a GSI Create returns with the index CREATING. A client that reads the index right after UpdateTable returns has to wait for it to be ACTIVE, as on the service.
  • Query and Scan on a CREATING index answer ValidationException "Cannot read from backfilling global secondary index: {name}". DeleteTable while a GSI is CREATING answers ResourceInUseException.
  • A build failure no longer comes back in the UpdateTable response. A deterministic failure removes the index, and a transient one leaves it CREATING for the recovery worker.
  • One server process runs at most four GSI builds at once. A further build waits for a slot with its index CREATING.

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.

…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.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

#454 (opened 22 October) changes the same function, fetch_index_info_by_table_id in crates/storage-postgres/src/data/ddl.rs, to refuse a read of a CREATING GSI. It reports the two phases the service has, where this PR has one. A merge of this PR's head d0ee1816e into #454's head conflicts in crates/storage-postgres/src/data/ddl.rs, crates/storage-postgres/src/update_table.rs, tests/rust/src/gsi_on_hash_only_table.rs and tests/rust/src/test_base.rs, where both add wait_for_index_active. Whichever merges second drops its copy of the refusal. If that is this PR, it calls extenddb_storage::gsi_backfill::creating_read_refusal with the GsiBackfills record from #454 instead of its one-phase arm, and keeps one wait_for_index_active.

@LJMart11 LJMart11 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at d0ee181. PostgreSQL storage tests passed (318 tests). One PartiQL batch finding is left inline. The PR body also says the new test files are listed in the integration workflow, but that step runs the crate's full --tests suite and lists no files.

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" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

Required 1: fixed in 5b70d1f282 and 49fc116934, with the details in the thread on ddl.rs:591. A PartiQL read of a CREATING index now gets the answers main gives for an index the table does not have. Query and Scan keep the backfilling text.

Docs 1: I fixed the body. The PostgreSQL storage-level step runs every test target of the crate with --tests, so the body no longer describes a list. The Results line now gives the storage-level count at 15d43da4a5. #690 merged on 24 November, so the paragraph about it is gone. The merge of main in 1a9b9a63b4 keeps #690's catalog-check hook and this PR's GSI build hooks in crates/storage-postgres/src/lib.rs.

On the three items you could not check:

  • PartiQL reads of a backfilling index: the service's answer is not measured. The body's measurements cover Query and Scan only. After 49fc116934, this PR changes no PartiQL answer, and the body now says so.
  • A base-binary server and a head-binary server on one catalog: 1.0 does not support this setup. README.md and the upgrade manual say that more than one server on one catalog is not supported in 1.0. The two-engine tests cover the build ownership lock that the recovery worker takes.
  • The wire suite and the Python suite against a release server: CI ran both on d0ee181, against a PostgreSQL server that the build-postgres job built with cargo build --release. run-rust-integration and the three run-integration shards passed. The body now also gives two local runs against a release server built from 15d43da4a5. The Python GSI tests that the body lists gave 62 passed, and the two wire test files that the PR changes gave 6 passed.

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 demohan self-assigned this Nov 27, 2026

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@LJMart11

LJMart11 commented Dec 3, 2026

Copy link
Copy Markdown

Checked at 17a11a4 against the list from d0ee181. The head moved again to 3126e91; this reviewer stops after two rounds and leaves the rest to a person.

Fixed:

  • item 1 — Fixed in 5b70d1f (engine) and 49fc116 (PostgreSQL). ddl.rs:592 now returns StorageError::IndexBackfilling, and the four PartiQL lookups go through common::statement_index (partiql/common.rs:76), which reads it as a missing index. reads_of_a_creating_index_through_the_engine (gsi_async_build.rs:660) passes at the head. With IndexBackfilling dropped from the statement_index arm, that test fails at gsi_async_build.rs:728 on the allowed two-statement BatchExecuteStatement: left Err(ValidationException("Cannot read from backfilling global secondary index: gidx")), right Ok with a per-statement ValidationError plus the base-table Item. With ddl.rs:592 returning IndexNotFound, it fails at :748 and update_table_returns_while_the_backfill_runs fails at :459. With the create_table.rs:151 mapping changed to the missing-index text, it fails at :748 (left 'The table does not have the specified index: gidx', right the backfilling text).
  • item 2 — The PR body no longer describes a file list. It says the step runs every test target with --tests, which matches .github/workflows/integration.yml:790 (cargo test --release -p extenddb-storage-postgres --tests, with EXTENDDB_TEST_PG_REQUIRED: "1" at :736).

Disputed: none.

Needs-human: none.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

storage-postgres: UpdateTable awaits the GSI backfill inside the request, so large tables time out at the client

3 participants