Repository navigation
fix(storage-mongodb): keep a DELETING table's tags until its document goes - #1446
Conversation
… goes DeleteTable removed the table's tag documents after the collection drops and before the catalog delete, so ListTagsOfResource sent in that stretch answered no tags while DescribeTable still read DELETING. DynamoDB returns the tags for the whole DELETING window. Remove the tags and the catalog document in one transaction, as the last step of the delete, as PostgreSQL and SQLite do. A table created again under the name still cannot inherit the tags. Fixes #604 Signed-off-by: Hitesh Sharma <hts@amazon.com>
LJMart11
left a comment
There was a problem hiding this comment.
Reviewed at b0e2bda. 1 finding: 1 Docs.
The change moves MongoDB DeleteTable's tag removal into one session transaction with the catalog document delete. Confirmed: while a stopped DeleteTable leaves the document DELETING, the tags stay in storage; with main's ordering put back the new live test fails with left: [], and with the tag delete dropped from the transaction it fails at the post-delete check; 20 concurrent DeleteTable calls on one table all answered DELETING and left no tags and no document (3 of 3 trials); the head merged with current main passes the MongoDB crate's unit tests (197) and live DeleteTable tests (20). Ran at the head: the crate's unit tests (190 passed, 85 ignored) and the data-engine and backup-engine live tests (20 and 56) against a MongoDB 7 replica set, plus the ListTagsOfResource-during-DELETING sequence against Amazon DynamoDB, 3 trials.
- Docs
crates/storage-mongodb/src/table_engine.rs:748— ListTagsOfResource does not return the tags while a MongoDB table reads DELETING: the engine's existence check refuses it as ResourceNotFoundException on main and on this head, and DynamoDB itself stops returning them partway through DELETING.
| .map_err(|e| StorageError::Internal(e.to_string()))?; | ||
| // Tags are keyed by the table ARN rather than table_id, so a table | ||
| // recreated with the same name would inherit any left behind. They | ||
| // go in one transaction with the table metadata: ListTagsOfResource |
There was a problem hiding this comment.
Docs
This comment and the PR body say ListTagsOfResource now returns the tags while the table reads DELETING, as DynamoDB does. On the wire it does not. tagging.rs:175 first calls table_key_info, which on MongoDB refuses any status other than ACTIVE (table_engine.rs:1393-1398), so the client gets ResourceNotFoundException on main and on this head (from the code). The new test calls the storage list_tags directly and skips that check. The reader this change affects is authorization's fetch_resource_tags (authorization_store.rs:342).
Fix: reword the comment and the body to say what the change does: aws:ResourceTag evaluation sees the tags during DELETING.
Evidence: with DeleteTable stopped as in the new test, table_key_info gave Err(TableNotFound("t")) and list_tags gave [team=a]. On DynamoDB, ListTagsOfResource returned the tags for 0.46, 1.83 and 2.12 s after DeleteTable (3 trials). It then answered ResourceNotFoundException while DescribeTable still read DELETING.
There was a problem hiding this comment.
Agreed, and confirmed at the head: handle_list_tags_of_resource goes through the table_key_info check in crates/engine/src/tagging.rs, which on MongoDB refuses any status other than ACTIVE, and PostgreSQL and SQLite refuse CREATING/DELETING the same way, so the wire answer during DELETING is ResourceNotFoundException before and after this PR. The guard predates #604, so the issue's Tags: [] premise was a storage-level reading, not a wire one.
Fixed in dc96583: the comment at table_engine.rs:748 now says the transaction keeps the tags for authorization's aws:ResourceTag reads (fetch_resource_tags) while the table reads DELETING, and that ListTagsOfResource is unaffected. The test module doc says the same. The PR body's What/Why now describe the authorization effect, say ListTagsOfResource answers ResourceNotFoundException throughout, and quote your DynamoDB measurement (tags for 0.46/1.83/2.12 s, then ResourceNotFoundException while still DELETING). No code change.
The tags kept until the catalog document goes are read by authorization's aws:ResourceTag evaluation. ListTagsOfResource is not affected: its table_key_info check refuses a table that is not ACTIVE, so it answers ResourceNotFoundException during DELETING before and after this change. Signed-off-by: Hitesh Sharma <hts@amazon.com>
LJMart11
left a comment
There was a problem hiding this comment.
Checked at dc96583 against the list from b0e2bda. 1 finding: 1 Important.
The change removes a MongoDB table's tag documents and its catalog document in one transaction at the end of DeleteTable. The earlier wording point is fixed: the comment and the body now name aws:ResourceTag evaluation, and at this head ListTagsOfResource on a DELETING table answers ResourceNotFoundException. Confirmed: with DeleteTable stopped while the table reads DELETING and the authorization cache cold, a user whose DescribeTable/DeleteTable Allow is conditioned on aws:ResourceTag/team is allowed (3 of 3 trials), while main answers AccessDeniedException (3 of 3). 8 readers polling a 20-tag table across the final delete saw 20 or 0 tags, never a partial set (3 trials). The final transaction took 70 ms with 125,050 tag documents in the collection. With main's hunk put back, the new live test fails at its DELETING assertion. The head merged with current main passes the MongoDB crate's unit tests (197) and live data-engine tests (20). At the head, the crate's unit tests (190) and the data-engine (20) and backup-engine (56) live tests pass against a MongoDB 7 replica set.
Previous items: 1 fixed.
- Important
crates/storage-mongodb/src/table_engine.rs:786— When a concurrent DeleteTable on the same name hits a write conflict, the new retry loop re-runs adelete_onekeyed only by name, so a run that lands after the table was created again deletes the new table's catalog document and leaves its tags behind.
| tags.delete_many(doc! { "resource_arn": table_arn }) | ||
| .session(&mut session) | ||
| .await?; | ||
| tables |
There was a problem hiding this comment.
Important
Chronology: this defect was already present in b0e2bda and was missed in round 1. The follow-up dc965835 corrected the prior wording finding but did not introduce this race.
When a concurrent DeleteTable on the same name loses the write conflict, the retry loop at table_engine.rs:776-803 re-runs a transaction whose delete_one at :786-789 matches only {account_id, table_name}. If the winning delete has committed and a CreateTable of that name has landed before the retry, the retry deletes the new table's catalog document. On main the loser's plain delete_one ran once, with no backoff, so the window was much narrower.
The caller gets 200 from CreateTable and from every DeleteTable. The new table then answers ResourceNotFoundException, while its tag documents stay under the ARN, so the next CreateTable of that name inherits them. From the code, the new table's data collection is orphaned too. Nothing is logged, because every delete returns Ok.
Fix: key the delete on this table's identity, as PostgreSQL does (storage-postgres/src/delete_table.rs:635, WHERE table_id = $1 AND table_status = 'DELETING'). Add table_id: desc.table_id and table_status: "DELETING" to the delete_one filter. When it deletes nothing, abort the transaction and return without deleting tags. Add a live test next to data_engine_live_tests_delete_table.rs:24 that races several deletes against an immediate CreateTable and checks that the new table survives. No migration.
Evidence: a scratch live test ran 8 concurrent delete_table calls on a tagged table, then called create_table with tag gen=new as soon as the first delete returned Ok. At this head the new table was gone in 10 of 60 trials (TableNotFound("r"), list_tags = [gen=new], 8/8 deletes Ok). With main's table_engine.rs it was gone in 0 of 60. With the TxErr::Transient arm at :800 changed to return an error instead of retrying, 0 of 40 were lost and the arm fired 277 times. Over the wire, the same sequence through the server was lost 0 of 20 times, because the HTTP round trip outlasts the retry window.
There was a problem hiding this comment.
Agreed, and thanks for the scratch test. Fixed in 86e62b7.
delete_tags_and_table_docnow deletes the catalog document by_id,table_idandtable_status: "DELETING", before the tags. When that matches nothing, another DeleteTable already removed the table and its tags, so it aborts the transaction and returnsOkwithout touching tags.- The mark-DELETING
update_oneat the top ofdelete_table_implhad the same name-only filter. A DeleteTable whosedescribe_table_implread predated the winning delete could mark the new table DELETING, and then (with the fix above) leave it stuck there. It now matchestable_idtoo. When it matches nothing, the call answers DELETING, as the concurrent deletes do. - New live test
live_delete_retry_spares_a_table_created_againnext to the existing one: 8 concurrentdelete_tablecalls on a tagged table, thencreate_tablewithgen=newas soon as the first returnsOk, 30 trials. It checks the new table is there and not DELETING, and thatlist_tagsis[gen=new].
Against a local MongoDB 7 single-node replica set:
| Run | Result |
|---|---|
| New test at 86e62b7 | 5 of 5 runs pass (150 trials) |
New test with table_engine.rs from dc96583 |
fails on trial 0, 3 of 3 runs: TableNotFound("r") |
| With only the final-delete filter fixed | fails on trial 0: the new table reads DELETING (the mark-DELETING race above) |
data_engine::live_tests:: |
21 passed |
backup_engine::live_tests:: |
57 passed |
| crate lib tests | 190 passed, 87 ignored |
cargo fmt --all -- --check and cargo +1.97.0 clippy -p extenddb-storage-mongodb --all-targets --features test-hooks -- -D warnings are clean. Not run: the over-the-wire sequence and cargo test --workspace.
A DeleteTable that lost a write conflict re-ran a catalog delete keyed by name alone. If another DeleteTable had finished and a CreateTable had reused the name before the re-run, it deleted the new table's document and its tags, which share the ARN, and left the new data collection orphaned. The mark-DELETING update had the same shape: a DeleteTable whose read predates the other delete could mark the new table DELETING and strand it. Both writes now match the table's id as well as its name, and the final delete also requires DELETING. When the final delete matches nothing, another DeleteTable already removed the table and its tags, so the transaction aborts without touching tags. When the mark matches nothing, the call answers DELETING as the concurrent deletes do. New live test races 8 DeleteTable calls against a CreateTable of the same name, 30 trials; without the fix it loses the new table on the first trial. Signed-off-by: Hitesh Sharma <hts@amazon.com>
|
Checked at Fixed:
Disputed: none. Needs-human:
|
LeeroyHannigan
left a comment
There was a problem hiding this comment.
Thanks. I read the change against main 92155f3. The transaction deletes the catalog document and the tags together, matched by table_id and DELETING. So a table that a CreateTable makes again under the name keeps its tags. The new live test fails on main, as the description shows. At this head the MongoDB live tests (data_engine::live_tests::, 21 tests, the two new ones included) passed in 3 of 3 runs on a one-node replica set. CI passed, and the branch merges with main.
This duplicates #550 (opened 25 October). Its finish_table_delete already deletes the MongoDB catalog document and the tags in one transaction, as the last step of DeleteTable. It uses the same filter and the same rule for the tags. #598 and #599 build on #550. Under code-size.md, the second of the two PRs to merge drops its copy. The two PRs differ where a second DeleteTable meets the table:
| Request on MongoDB | This PR, as on main | #550 | DynamoDB |
|---|---|---|---|
DeleteTable of a table that is DELETING |
200, and the delete runs again | ResourceInUseException, "Table is being deleted" |
ResourceInUseException, the same sentence |
| The second of two concurrent DeleteTable calls | 200 | ResourceInUseException |
ResourceInUseException |
| A DeleteTable that stopped part way | stays DELETING until a client sends DeleteTable again |
the control plane finishes it | the table always finishes deleting |
The DynamoDB answers are the measured rows in #1411 (30 November) and in #550's comments (25 October).
This needs one change before it merges. On MongoDB, a request whose policy reads aws:ResourceTag now finds the table's tags during the DELETING window, where v1.1.0 found none (LJMart11 measured it). docs/versioning.md puts such a change under Behavior Changes by Release in the upgrade manual, so it needs a v1.2.0: entry.
On the description and the commits:
- The description does not cover the third commit, 86e62b7: the
table_idmatch on the mark, its early return, and the second live test. "20 passed" is 21 at this head (mongodb-rust job 142297703032). It names neither #550 nor #598 nor #599. - The message of b0e2bda still says that ListTagsOfResource answered no tags in that stretch, and that DynamoDB returns the tags for the whole
DELETINGwindow. LJMart11 showed that both are wrong. A squash merge here keeps the commit messages, so that text would reach main.
The inline comment is smaller.
| ) | ||
| .await | ||
| .map_err(|e| StorageError::Internal(e.to_string()))?; | ||
| // Tags are keyed by the table ARN rather than table_id, so a table |
There was a problem hiding this comment.
This comment and the Why section say that a stopped DeleteTable leaves the tags while the table reads DELETING. Neither says that on MongoDB nothing finishes such a table. The document, the tags and any collection not yet dropped stay until a client sends DeleteTable again. Until then, the backend refuses a CreateTable into the name. One sentence here would say it.
There was a problem hiding this comment.
Done in ce0305b. The comment now says that nothing on MongoDB finishes a DeleteTable that stops before this step: the document, the tags and any collection not yet dropped stay until a client sends DeleteTable again, and until then a CreateTable into the name answers ResourceInUseException. I checked the last part in the code: the catalog document's _id is {account_id, table_name}, so the CreateTable insert hits the duplicate key, name_taken_error returns TableAlreadyExists, and crates/engine/src/create_table.rs maps that to ResourceInUseException. The Why section of the description has the same sentence.
…leting-window Signed-off-by: Hitesh Sharma <hts@amazon.com>
Add a v1.2.0 entry under Behavior Changes by Release in the upgrade manual: on MongoDB, a request whose policy reads aws:ResourceTag now finds a DELETING table's tags until its catalog document goes, where 1.1.0 found none for part of the window. No migration or configuration step. Say in DeleteTable's comment that nothing on MongoDB finishes a DeleteTable that stopped part way: the document, the tags and any undropped collection stay until a client sends DeleteTable again, and until then CreateTable into the name is refused. Signed-off-by: Hitesh Sharma <hts@amazon.com>
|
@LeeroyHannigan thanks. Addressed in ce0305b, after merging origin/main (it merged without conflicts):
|
LeeroyHannigan
left a comment
There was a problem hiding this comment.
Thanks. The new commit adds the v1.2.0: entry, and the comment and the description now say what a stopped DeleteTable leaves on MongoDB.
I checked the new comment against the code: the CreateTable insert fails with a duplicate key on the catalog document's _id, and crates/engine/src/create_table.rs answers ResourceInUseException for it.
I checked the entry too. At v1.1.0, DeleteTable on MongoDB removes the tags before it removes the stream state and the catalog document. ListTagsOfResource answers ResourceNotFoundException for a table that isn't ACTIVE. PostgreSQL and SQLite remove the tags and the catalog row in one transaction.
The description now covers 86e62b7, gives 21 passed, and names #550, #598 and #599. Its squash message is the one to use, because a squash with the default message would include the old text of b0e2bda.
Apart from that comment the code is the same as at 86e62b7, where the MongoDB live tests passed in 3 of 3 runs. Main merged into the branch with no conflict and CI passed at this head.
This PR still duplicates #550, as round 1 said. #550 came first (25 October) and its finish_table_delete removes the catalog document and the tags in one transaction. Whichever of the two merges second drops its copy.
…leting-window Signed-off-by: Hitesh Sharma <hts@amazon.com> # Conflicts: # docs/manuals/07-upgrade-manual.md
LeeroyHannigan
left a comment
There was a problem hiding this comment.
Approve again. d145f1b only merges main at e8b5f10. Your own change is the same in all four files against the new main, the upgrade entry included, so I checked only that merge.
CI passed at this head, 69 of 69, and the branch merges cleanly with main at b3510a9.
This still duplicates #550, which came first. Whichever of the two merges second drops its copy.
…leting-window Signed-off-by: Hitesh Sharma <hts@amazon.com> # Conflicts: # docs/manuals/07-upgrade-manual.md
LeeroyHannigan
left a comment
There was a problem hiding this comment.
Approve again. af616c7 only merges main at c8e66fb. Your own change is the same in all four files against the new main, the upgrade entry included, so I checked only that merge.
CI passed at this head, 69 of 69, and the branch merges cleanly with main at c8e66fb.
This still duplicates #550, which came first. Whichever of the two merges second drops its copy.
Main is at c057660. This branch last had main at b3510a9. Since then, #1411 and #1446 merged into main. One file conflicted: crates/storage-mongodb/src/data_engine_live_tests.rs. #1446 declares its delete_table test module where this branch declares put_race and contention. The merge keeps all three, main's first. Git merged docs/differences-from-dynamodb.md and the upgrade manual at other lines.
Main is at c057660, one PR after the last merge of main into this branch. #1446 added its v1.2.0 entry at the top of Behavior Changes by Release in docs/manuals/07-upgrade-manual.md, where this branch had its entry. The merge keeps main's entries in main's order and puts the entry of this branch after main's v1.2.0 entries. Main adds each new entry at the top, so the entry no longer conflicts with the next one.
The base now holds main at c057660. #1446 added its v1.2.0 entry at the top of Behavior Changes by Release, and the base moved its own entry after main's v1.2.0 entries. The upgrade manual conflicted where this branch had its entry. The merge takes the manual of the base and puts the entry of this branch after the entry of the base.
The base now holds main at c057660 (#1446). The upgrade manual conflicted where this branch had its v1.2.0 entry. The merge takes the manual of the base and puts the entry of this branch after the entry of the base. Git merged crates/storage-mongodb/src/table_engine.rs, where #1446 changes DeleteTable and this branch changes UpdateTable, at other lines.
Main is at c057660, 43 commits after the last merge. Thirteen files conflicted. Main's #1411 and #1446 change the same DeleteTable paths as this branch, so the merge keeps one copy of each check. #1411 refuses a second DeleteTable of a DELETING table on PostgreSQL and SQLite with StorageError::IndexesInUse and the TableBeingDeleted message. This branch refuses it with StorageError::TableBeingDeleted, which UpdateTable, MongoDB and Cassandra also raise. The merge keeps that variant, removes the second check that git placed after it in crates/storage-postgres/src/delete_table.rs, and removes deleting_refusal from crates/storage-sqlite/src/delete_table.rs. On SQLite, #1411 also re-reads the status under the write lock (refuse_if_deleting_or_gone). This branch reads the row inside the BEGIN IMMEDIATE transaction under the same lock, so the re-read goes. #1411's two concurrent DeleteTable tests stay, in one test module with this branch's tests, and expect TableBeingDeleted. #1446 removes a MongoDB table's tags and catalog document in one transaction keyed on the table id (delete_tags_and_table_doc). This branch does the same in remove_deleting_document, which the control plane also runs. The merge keeps the branch's function and adds #1446's note on aws:ResourceTag to its comment. The live test live_delete_table_keeps_tags_while_deleting finishes its stopped DeleteTable with finish_table_delete, because this branch refuses a second DeleteTable. Other conflicts: the doc comment of ErrorMessageKey::TableBeingDeleted names both measurement dates. crates/engine/src/delete_table.rs keeps the key-info drop before the storage call with #1411's deleting_description, and one test module. The engine test uses main's crate::test_context, so crates/engine/src/partiql/test_context.rs is main's. In put_item.rs, delete_item.rs and update_item.rs the queries take main's AssertSqlSafe and keep this branch's db_error. In table_snapshot.rs, conftest.py and test_table_operations.py main's test names and helpers stay, with the TableBeingDeleted variant. In docs/differences-from-dynamodb.md both rows stay. #1411's row now says that MongoDB and Cassandra refuse a second DeleteTable too. sqlx 0.9.1 (#1166) refuses a query string built at run time. Eight of this branch's queries now take AssertSqlSafe: two in ddl.rs (table_key_info and the status check) and six in the window tests.
Main is at db8a90d. This branch last had main at 3534c9e (#1009). Since then, 44 commits merged into main. Among them, #1514 released v1.1.0 without this branch, and #1166 moved to sqlx 0.9.1. Four files conflicted: - crates/storage/src/lib.rs: #1449 exports VectorItemFilter beside the transact exports that this branch extends. The merge keeps both. - crates/storage-mongodb/src/data_engine_live_tests.rs: #1446 declares its delete_table module where this branch declares token. The merge keeps both, main's first. - crates/storage-postgres/tests/twi_conflict.rs: #1166 passes the SQL of the deadlock test through sqlx::AssertSqlSafe, and this branch takes the outside transaction from outside_transaction. The merge keeps the helper and the wrapper. - docs/manuals/07-upgrade-manual.md: #1514 moved and rewrote the v1.1.0 ClientRequestToken entry of #526. This branch changed the Cassandra sentence of the old copy. The merge keeps the entry as main has it. The text of this branch is now a v1.2.0 entry after the v1.2.0 entries of main, because v1.1.0 shipped without this change. sqlx 0.9 takes SQL that is not a &'static str only in sqlx::AssertSqlSafe (#1166). The merge passes the SQL of the 11 queries that this branch adds to twi_conflict.rs in it. The SQL text does not change. Git merged these files, which both sides change, at other lines: - crates/core/src/error/mod.rs and crates/core/src/validation/mod.rs - crates/engine/src/transact_write_helpers.rs and crates/storage/src/transact.rs - tx_helpers.rs of PostgreSQL and SQLite, and crates/storage-postgres/src/data/update_item.rs - the Cassandra direct_integration.rs and docs/differences-from-dynamodb.md Since #1375, the engine stores a ClientRequestToken with each backslash doubled and each U+0000 written \0 before a backend sees it. The token code of this branch uses that stored form, as it used the token before.
Main is at b6c8595, three commits past c8e66fb: #1446, #1531 and #1466. #1446 and #1531 add two v1.2.0 entries at the top of "Behavior Changes by Release" in docs/manuals/07-upgrade-manual.md, above the entry of #1411. Git merged the file with no conflict. The order is #1531, #1446, #1411, #606, then the entry of this branch, which does not change. No other file has changes on both sides.
The base merges main at b6c8595, which brings #1446, #1531 and #1466. The base also adds 15 rows to tests/test_binary_base64.py. One file conflicted: docs/manuals/07-upgrade-manual.md. #1446 and #1531 add two v1.2.0 entries at the top of "Behavior Changes by Release", where this branch adds its entry. The merge keeps the three entries: the two entries of main first, then the entry of this branch, above the entry of #1411. Git merged tests/test_binary_base64.py at other lines. It holds the new rows of the base and the rows of this branch. No other file has changes on both sides.
The base brings main at b6c8595 through #1260, with #1446, #1531 and #1466. It also brings the 15 new rows of #1260 in tests/test_binary_base64.py. One file conflicted: docs/manuals/07-upgrade-manual.md. #1446 and #1531 add two v1.2.0 entries at the top of "Behavior Changes by Release", where this branch adds its entry. The merge keeps the two entries of main first, then the entry of this branch, then the entry of #1313. Git merged tests/test_binary_base64.py at other lines. No other file has changes on both sides.
The base brings main at b6c8595 through #1260, with #1446, #1531 and #1466, and the 15 new rows of #1260 in tests/test_binary_base64.py. The merge has no conflict. Git merged the upgrade manual, where both sides changed other lines. The base adds the two entries of main above the entry of #1313, and this branch has its entry below the entry of #1260. No other file has changes on both sides.
The base brings main at b6c8595 through #1260 and #1313, with #1446, #1531 and #1466. It also brings the 15 new rows of #1260 in tests/test_binary_base64.py. One file conflicted: docs/manuals/07-upgrade-manual.md. #1446 and #1531 add two v1.2.0 entries at the top of "Behavior Changes by Release", where this branch adds its entry. The merge keeps the two entries of main first, then the entry of this branch, then the entry of #1355. No other file has changes on both sides.
Main is at 5826e1b. This branch last had main at c8e66fb. Since then, four PRs merged into main: #1446, #1531, #1466 and #1087. One file conflicted. In docs/manuals/07-upgrade-manual.md, #1087 added its v1.2.0 entry after the other v1.2.0 entries of main, where this branch has its entry. The merge keeps the entries of main first, then the entry of this branch. Git merged crates/wasm-adapter/parity/corpus.json with no conflict: #1087 adds a Scan case, and the 15 checks that this branch changes are in other cases. The diff of this branch against main does not change in that file.
Main is at 5826e1b. This branch last had main at c8e66fb. Since then, four PRs merged into main: #1446, #1531, #1466 and #1087. One file conflicted. In docs/manuals/07-upgrade-manual.md, #1087 added its v1.2.0 entry after the other v1.2.0 entries of main, where this branch has its entry. The merge keeps the entries of main first, then the entry of this branch. Main changed no other file that this branch changes.
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466, #1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and #1531 add v1.2.0 entries at the top of "Behavior Changes by Release", and git merged them with no conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of main, where this branch has its entry. That is the one conflict. The merge keeps both entries without change: the entry of #1087 first, then the entry of this branch, before the v1.1.0 entries. Git merged five other files with no conflict: - crates/storage-cassandra/tests/direct_integration.rs: #1531 declares the update_item_retry module, and this branch declares gsi_backfilling. - crates/storage-mongodb/src/table_engine.rs: #1446 changes DeleteTable. It marks the table DELETING by table_id, and it removes the tags and the table document in one transaction. This branch changes create_table_impl_inner, index_info_by_table_id_impl and doc_to_table_description_in. - crates/storage-sqlite/src/lib.rs: #1087 declares the scan_segment_tests module, and this branch declares gsi_backfilling_tests. - crates/storage-sqlite/src/store.rs: #1087 registers extenddb_scan_segment on each connection of the pool. This branch adds the gsi_backfills field and gsi_creating_phase_delay. - crates/storage/src/lib.rs: #1087 rewrites the doc comment of scan_key_in_segment, and this branch declares the gsi_backfill module.
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466, #1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and #1531 add v1.2.0 entries at the top of "Behavior Changes by Release", and git merged them with no conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of main, where this branch has its entry. That is the one conflict. The merge keeps both entries without change: the entry of #1087 first, then the entry of this branch, before the v1.1.0 entries. Git merged four other files with no conflict: - Cargo.lock: #1087 adds crc32fast to the dependencies of extenddb-storage, and this branch adds form_urlencoded and tempfile to the dependencies of extenddb-storage-sqlite. - crates/storage-sqlite/Cargo.toml: #1087 rewrites the comments of libsqlite3-sys and sqlite-wasm-rs. This branch adds form_urlencoded and the tempfile dev-dependency. - crates/storage-sqlite/src/lib.rs: #1087 declares the scan_segment_tests module, and this branch declares file_mode and sqlite_uri. - crates/storage-sqlite/src/store.rs: #1087 registers extenddb_scan_segment on each connection of the pool, in after_connect. This branch calls file_mode::prepare before the pool connects, and it removes the mode change after the connect. The pool keeps the after_connect of main.
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466, #1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and #1531 add v1.2.0 entries at the top of "Behavior Changes by Release", and git merged them with no conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of main, where this branch has its entry. That is the one conflict. The merge keeps both entries without change: the entry of #1087 first, then the entry of this branch, before the v1.1.0 entries. No other file has changes on both sides.
What
On MongoDB,
DeleteTablenow removes a table's tag documents and its catalog document in one transaction, as the last step of the delete. Before, the tags were removed after the collection drops and before the stream cleanup and the catalog delete, so for that stretch the tags were gone from storage whileDescribeTablestill read DELETING.The reader this affects is authorization:
fetch_resource_tags(crates/storage-mongodb/src/authorization_store.rs) reads thetagscollection to evaluateaws:ResourceTag/*conditions. With this change, a request on the table while it reads DELETING (DescribeTable, a secondDeleteTable) is evaluated against the table's tags when the authorization cache loads them from storage; before, it could be evaluated with no tags, so a policy conditioned onaws:ResourceTagmatched differently.ListTagsOfResourceis not affected, on main or with this change.crates/engine/src/tagging.rschecks the table withtable_key_infobefore listing, and on MongoDB that refuses any status other than ACTIVE (PostgreSQL and SQLite refuse CREATING and DELETING the same way), so the client getsResourceNotFoundExceptionfor the whole DELETING window. The new test reads the tags through the storagelist_tags, not the wire operation.The new helper
delete_tags_and_table_docincrates/storage-mongodb/src/table_engine.rsuses the same session-transaction retry loop asbackup_catalog.rs(TxErr,commit_write_transaction,backoff_sleep). The collection drops and stream cleanup still run first and do not depend on the tags.The third commit (86e62b7) makes DeleteTable touch only the table it read. Both catalog writes now match the table's
table_idas well as its name: the mark that sets DELETING, and the final delete, which also requires DELETING. Before, a DeleteTable that lost a write conflict re-ran a delete keyed by name alone; if another DeleteTable had finished and a CreateTable had reused the name in between, the re-run deleted the new table's document and its tags (they share the ARN) and orphaned its data collection. When the mark matches nothing, another DeleteTable got there first, so the call returns early and answers DELETING as the concurrent deletes do. When the final delete matches nothing, the transaction aborts without touching tags.The upgrade manual (
docs/manuals/07-upgrade-manual.md) has av1.2.0:entry under Behavior Changes by Release for theaws:ResourceTagchange.Overlap with #550
#550 (opened 25 October) already deletes the MongoDB catalog document and the tags in one transaction, in its
finish_table_delete, with the same filter and the same rule for the tags. #598 and #599 build on #550. Undercode-size.md, whichever of #550 and this PR merges second drops its copy of that change. They differ where a second DeleteTable meets the table (the DynamoDB column is from the measured rows in #1411 and in #550's comments):DELETINGResourceInUseException, "Table is being deleted"ResourceInUseException, the same sentenceResourceInUseExceptionResourceInUseExceptionDELETINGuntil a client sends DeleteTable againSquash commit message
The message of the first commit (b0e2bda) says that ListTagsOfResource answered no tags in the stretch and that DynamoDB returns the tags for the whole DELETING window. Review measurements showed both are wrong; the Why section below has the corrected account. History is not rewritten here, so write the squash commit message from this description, not from the commit messages. A proposed title and body are in a PR comment.
Why
Fixes #604. The issue says
ListTagsOfResourceansweredTags: []in that stretch. On the wire it did not: as above, the existence check answersResourceNotFoundExceptionfor a DELETING table, and has since before the issue was filed. The storage-level gap the issue describes is real, and it shows up throughaws:ResourceTagevaluation instead. The issue also says Amazon DynamoDB returns the tags for the whole DELETING window. A review measurement (3 trials) found DynamoDB returned the tags for 0.46, 1.83 and 2.12 s afterDeleteTable, then answeredResourceNotFoundExceptionwhileDescribeTablestill read DELETING. This PR does not changeListTagsOfResource. PostgreSQL and SQLite already delete the tag rows and the catalog row in one transaction.On MongoDB nothing finishes a DeleteTable that stopped part way: the document, the tags and any collection not yet dropped stay until a client sends DeleteTable again, and until then a CreateTable into the name is refused (
ResourceInUseException, since the catalog document's_idis the account and table name).I chose one transaction over simply moving the tag
delete_manyafter the catalogdelete_one. With the second option, a delete that stops between the two writes would leave tags under the ARN, and a table created again under the same name would inherit them.CreateTableupserts tags and does not clear old ones.Testing done
data_engine::live_tests::delete_table::live_delete_retry_spares_a_table_created_again(86e62b7): races 8 DeleteTable calls against a CreateTable of the same name, 30 trials; without thetable_idmatch it loses the new table on the first trial.data_engine::live_tests::delete_table::live_delete_table_keeps_tags_while_deletingincrates/storage-mongodb/src/data_engine_live_tests_delete_table.rs. It stops aDeleteTablepartway through without a test hook: it turnsstream_shardsinto a view, so the stream cleanup'sdelete_manyfails. While the table reads DELETING, the test checks that the tags are still in storage (through the storagelist_tags). It then drops the view, deletes again, and checks that the tags are gone and that a table created again under the name has none.origin/main(89fc971) it fails:assertion failed: the tags are readable while the table is DELETING, left: [], right: [Tag { key: "team", value: "a" }].cargo test -p extenddb-storage-mongodb --lib -- --ignored --test-threads=1 data_engine::live_tests::: 21 passed (also 21 in CI's mongodb-rust job 142297703032 at 86e62b7), against a local single-node replica set (MongoDB 7.0). CI's--rust-livejob runs this filter, so it picks up the new test.cargo test -p extenddb-storage-mongodb --lib -- --ignored --test-threads=1 backup_engine::live_tests::: 56 passed. These tests calldelete_table.cargo test -p extenddb-storage-mongodb --lib: 190 passed, 85 ignored.cargo fmt --all -- --checkis clean.cargo +1.97.0 clippy -p extenddb-storage-mongodb --all-targets --features test-hooks -- -D warningsis clean.cargo fmt --all -- --checkand the clippy command above are clean.cargo fmt --all -- --checkand the clippy command above are clean, andcargo test -p extenddb-storage-mongodb --lib --features test-hooks -- --ignored data_engine::live_tests::gives 21 passed on a local single-node replica set.cargo test --workspace.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
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.