Skip to content

fix(cassandra): fence concurrent DeleteTable with a lease - #598

Open
LeeroyHannigan wants to merge 14 commits into
fix/505-deleting-window-answersfrom
fix/553-cassandra-concurrent-delete-table
Open

LeeroyHannigan wants to merge 14 commits into
fix/505-deleting-window-answersfrom
fix/553-cassandra-concurrent-delete-table

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

The branch is at 08b7356. Eight commits sit on 7318dbc, the head of the last review. The four newest answer that review:

  • 66a3046 releases the lease when the removal fails. When a statement fails after the claim (a DeleteTable call) or the take (the control-plane sweep), remove_claimed_table moves the actor's deadline to the current time. It uses the compare-and-set of the renewal: release_delete_lease and renew_delete_lease share swap_delete_deadline. The failed call then wakes the control-plane poller, and the poller's next pass removes the table. A failure inside the sweep does not wake the poller, because the poller runs that pass.
  • bba68ad runs the claim and the removal in a task that the call awaits, as the PostgreSQL backend runs its drops. Before it, a request whose client closed the connection after the claim stopped the drops part way and left the row to the lease.
  • f77e591 adds a test that pauses a DeleteTable between its drops and its renewal while a sweep takes its row.
  • 08b7356 names the lease in the clock note of docs/cassandra-setup.md and in the doc comment of DELETE_CLAIM_LEASE_SECS. It fixes the two comments that put the tag delete last. It also rewrites the text on a stopped claim in docs/differences-from-dynamodb.md and docs/troubleshooting.md.

The four commits before them came from the earlier round:

The message of 13a2940 is no longer true at this head. It names the continuous-backup delete, a deadline skip in the abandoned-restore sweep, and tests that later commits dropped (see "Merged with main"). Whoever merges: please use the What section of this body as the squash message.

What

Two concurrent DeleteTable calls on one Cassandra table both answered 200 and both ran the deletion. DeleteTable now claims the catalog row with a lightweight transaction before its first drop. The claim is conditioned on the table id and on a status other than DELETING. It marks the row DELETING and sets status_transition_at 300 s ahead. The call whose claim applies removes the table and answers 200 with TableStatus DELETING. The other call answers 400 ResourceInUseException "Attempt to change a resource which is still in use: Table is being deleted: ", as the service does.

The control-plane sweep takes a DELETING row whose deadline has passed, with a compare-and-set on that deadline. It skips the row when the swap does not apply. The call and the sweep run the same removal, remove_claimed_table. It starts with the drops keyed on the table id, then renews the lease with the same swap. The tag delete, keyed on the ARN, comes next, and the row delete conditioned on the table id comes last. An actor whose renewal does not apply stops before the tag delete. delete_indexes_for_table now drops the index tables before it deletes their metadata, so a drop that fails leaves the metadata for the next attempt.

When a statement of the removal fails, the actor moves its deadline to the current time with the same swap. The sweep's next pass then takes the row. A failed DeleteTable also wakes the control-plane poller. The call runs the claim and the removal in a task that it awaits. So a request that its client drops after the claim does not stop the removal.

Without the swap, two actors on one claimed row both run the tag delete. The two actors can be two servers' sweeps, or a slow call and the sweep that takes the row from it. The later actor can then delete the tags of a table created under the name in between.

On main, the removal of a restore target replaced the abandoned-restore sweep. It does not take a DELETING table.

The case that depends on the lease length

An actor can renew its lease and then stall for more than 300 s before the tag delete and the row delete. During the stall, a sweep can take the row, finish, and free the name. The actor's tag delete then reaches a table created under that name in the meantime. The key of the tag rows carries no table id, so closing the case needs a schema change (#1458). The lease comes from the server's clock, and the sweep compares it with the clock of the Cassandra node. So on a server S seconds behind the node, a stall of 300 minus S seconds is enough (docs/cassandra-setup.md).

Why

Fixes #553

#553 measured the service on 2026-10-25, five rounds of five. Of two DeleteTable calls sent at once on one table, one answers 200 and the other answers ResourceInUseException with the sentence above.

Behaviour to know about

  1. A DeleteTable that fails after its claim answers 500 and moves the row's deadline to the current time. It wakes the control-plane sweep, whose next pass removes the table. A retry before that pass answers ResourceInUseException with the being-deleted sentence. A request that its client drops after the claim does not stop the removal. A DeleteTable whose server process stops after its claim leaves the row DELETING. A retry is then refused with the being-deleted sentence until the lease has passed and the sweep's next pass has removed the table. That is 300 s plus up to 60 s for the sweep's idle poll (the pass ran 60.1 s after the deadline in one measurement). Before this change a retry finished the removal at once.
  2. Data-plane requests during the delete change with the server's key-info cache. With an entry for the table they answer 200 until the base data table is dropped and 500 after it, as before. Without one they answer 404 ResourceNotFoundException for the whole delete, where they answered 200 for about 0.3 s and then 500. The 404 is the DELETING-to-not-found mapping that fix: answer requests during a table's DELETING window as the service does #550 settled for this backend (Requests during a table's DELETING window answer differently from DynamoDB #505). The service answers 200 throughout its window.
  3. CreateBackup during the delete answers 400 TableNotFoundException "Table not found: " from the claim on, where it answered 200 until the data table was dropped. CreateBackup refuses a table that is not ACTIVE with that answer on main, and the claim makes the row DELETING. The service accepts the backup for about 2 s (200, and the backup later reads AVAILABLE). It then answers TableNotFoundException while DescribeTable still reads DELETING (measured by the reviewer on 24 Nov).
  4. On this branch alone, UpdateTimeToLive during the delete answers 400 ResourceInUseException "Table is not in ACTIVE state". fix: answer requests during a table's DELETING window as the service does #550's branch answered 200. The service answers 200 for the first 0.3 to 1.2 s. It then answers 400 ResourceInUseException "Attempt to change a resource which is still in use: Table is being deleted". The reviewer measured this on 24 Nov, over 13 delays in two runs. fix: answer TTL and tag calls during a table's DELETING window #599, which is based on fix: answer requests during a table's DELETING window as the service does #550's branch too, serves UpdateTimeToLive on a DELETING row on every backend.
  5. The 200 of DeleteTable reports DELETING, and the table is already gone when the answer arrives. The delete runs inside the request, so a DescribeTable sent after it answers 404.
  6. The DeleteTable 200 carries thirteen TableDescription members, and the service's carries nine (no AttributeDefinitions, KeySchema, CreationDateTime or TableThroughputModeSummary). This is the same on every backend and is not changed here (DeleteTable's 200 and DescribeTable during DELETING carry thirteen TableDescription members; DynamoDB carries nine #602).
  7. DeleteTable on a table that is still CREATING is served here. The service refuses it with "Attempt to change a resource which is still in use: Table is being created: ". This is the same on every backend (DeleteTable on a table that is still CREATING is served; DynamoDB refuses it #603). The claim's condition (a status other than DELETING) keeps that answer on purpose.
  8. A sweep that cannot remove a row logs it, gives the row to its next pass, and goes on to the next row. Before, the sweep returned at the first row it could not remove.

docs/differences-from-dynamodb.md describes items 1, 2, 5 and 8, and docs/troubleshooting.md describes item 1.

Merged with main

Main reports point-in-time recovery (PITR) as unsupported and dropped its continuous-backup table (#335). So the continuous-backup delete and the PITR parts of the tests are gone. Main also removed the abandoned-restore sweep, so this branch's deadline skip in it and the test of that skip are gone. Main's own test of the removal of a restore target covers a DELETING restored table. The tests check a data table's existence through main's helper.

Overlaps with other PRs and merge notes

Testing done

At 08b7356, with toolchain 1.97.0 and cassandra:4.1 with PasswordAuthenticator, as in CI:

  • extenddb-storage-cassandra lib: 181 passed. --test consistency_policy: 10 passed.
  • --features test-hooks --test direct_integration, with EXTENDDB_TEST_CASSANDRA=required: the three delete modules concurrent_delete_table, delete_table_lease and deleting_window passed 16 of 16 (5, 8 and 3). The other callers of the sweep and of the removal (index::, stream_disable, transaction_ledger, index_delay_reads and the backup_engine restore-target tests) passed 40 of 40.
  • tests/python/test_deleting_window_control_plane.py on a Cassandra-backed debug server of this head, with EXTENDDB_TEST_BACKEND=cassandra: TestConcurrentDeleteTable passed. The five held-window tests skip there, because they hold the window through PostgreSQL.
  • A probe on that server, on 25 Nov: the client of a DeleteTable of a table with 8 GSIs timed out after 0.2 s. DescribeTable then read DELETING for about 4 s, and ResourceNotFoundException after that. During a second DeleteTable of a table with 8 GSIs, CreateBackup answered 277 of 277 times with 400 TableNotFoundException "Table not found: ". UpdateTimeToLive answered 241 of 241 times with 400 ResourceInUseException "Table is not in ACTIVE state", until the row was gone. Before bba68ad, the same timed-out DeleteTable left the row DELETING until the sweep removed it 351 s after the request.
  • cargo +1.97.0 fmt --all -- --check, and cargo +1.97.0 clippy -p extenddb-storage-cassandra --all-targets -- -D warnings with and without --features test-hooks: clean. cargo +1.91.1 check -p extenddb-storage-cassandra --all-targets: clean.
  • The clippy step of .github/workflows/wasm.yml for wasm32-unknown-unknown: clean. This host has no clang, so the run used a stand-in C compiler and archiver. Clippy does not link.
  • python3 -m pytest --collect-only -q of tests/ (6643 tests) and of tests/python (678): no error.
  • Not run: the whole direct_integration binary (332 tests). CI runs it.

Controls at 08b7356, each with the tests kept:

  • The release removed from remove_claimed_table: a_delete_that_fails_after_its_claim_is_finished_by_the_next_sweep fails, because the row's deadline is still 300 s ahead.
  • Main's order restored in delete_indexes_for_table, with the index metadata deleted first: the same test fails, with both index tables left after the sweep's pass.
  • The renewal check disabled: a_delete_whose_row_a_sweep_took_over_stops_at_its_renewal fails in its first case, because the newer table loses its tag. a_sweep_whose_row_was_replaced_leaves_the_newer_table_alone fails too.
  • The deadline condition removed from the compare-and-set of the renewal: a_delete_whose_row_a_sweep_took_over_stops_at_its_renewal fails in its second case, because the call deletes the row that the sweep holds. a_renewal_against_a_stale_deadline_does_not_apply fails too.
  • The claim and the removal run inline, not in a task: a_delete_whose_request_is_dropped_after_its_claim_still_removes_the_table fails, with the row still there after 60 s.
  • A client DeleteTable takes no claim: 6 of the 13 tests of concurrent_delete_table and delete_table_lease fail. Among them are two_concurrent_delete_tables_have_one_winner, a_table_created_during_a_delete_keeps_its_tags and a_tag_written_during_the_drops_goes_with_the_table.
  • The tests do not compile against fix: answer requests during a table's DELETING window as the service does #550's delete_table.rs, because they call claim_table_for_delete and renew_delete_lease. The control without a claim stands in for that one.
  • At 1b0aebf, with a wrong expected not-found message, TestConcurrentDeleteTable failed in 2 of 3 runs on PostgreSQL, so its not-found branch runs there. The wire file has not changed since.

CI runs the delete modules in integration-cassandra.yml (cargo test -p extenddb-storage-cassandra --features test-hooks --test direct_integration, with EXTENDDB_TEST_CASSANDRA=required). It runs the wire class in the Cassandra pytest job, whose devtools/run-tests --backend cassandra exports EXTENDDB_TEST_BACKEND=cassandra, and in the PostgreSQL and SQLite pytest jobs.

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

On the Cassandra backend:

  • Of two concurrent DeleteTable calls on one table, one answers ResourceInUseException, where both answered 200.
  • A DeleteTable whose server process stops after its claim keeps the name refused for up to about 360 s. Before, a retry finished the removal at once. A DeleteTable that fails after its claim is finished by the sweep's next pass, and a retry before that pass answers ResourceInUseException.
  • Data-plane requests on a table during its DeleteTable answer ResourceNotFoundException when the server's key-info cache holds no entry for the table. Before, they answered 200 for about 0.3 s and then 500.
  • CreateBackup during a DeleteTable answers TableNotFoundException from the claim on. Before, it answered 200 until the data table was dropped.
  • UpdateTimeToLive during a DeleteTable answers 400 ResourceInUseException "Table is not in ACTIVE state". Before, it answered 200. fix: answer TTL and tag calls during a table's DELETING window #599 serves UpdateTimeToLive on a DELETING row on every backend.

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.

Two concurrent DeleteTable calls on one table each read the catalog row,
dropped the data tables and answered 200. Amazon DynamoDB answers one of
them 200 and the other ResourceInUseException with "Attempt to change a
resource which is still in use: Table is being deleted: <name>".

DeleteTable now claims the row with a lightweight transaction before the
first drop, conditioned on the table id and on a status other than
DELETING, and sets status_transition_at five minutes ahead. The call whose
claim applies removes the table and reports DELETING; the other answers the
being-deleted sentence and deletes nothing.

The control-plane sweep takes a DELETING row whose deadline has passed with
a compare-and-set on that deadline, and skips the row when the swap does not
apply. The call and the sweep run the same removal: the drops keyed on the
table id first, then a renewal of the lease with the same swap, then the
continuous-backup and tag deletes, which are keyed on the name and the ARN,
then the row delete conditioned on the table id. An actor whose renewal does
not apply stops before the name-keyed deletes, so a call that outlives its
lease leaves them to the sweep that took the row over. The abandoned-restore
sweep skips any row that carries a deadline, since a restore target never
carries one and a claimed row always does.

One case still depends on the lease length. An actor that has renewed its
lease and then stalls for more than 300 s before the continuous-backup
delete, the tag delete and the row delete can find that a sweep took the
row over, finished, and freed the name; its two deletes then reach a table
created under that name in the meantime. Those two keys carry no table id,
so closing the case needs a schema change.

A DeleteTable that stops after its claim leaves the row DELETING. A retry
is refused with the being-deleted sentence until the lease has passed and
the sweep's next pass has removed the table, 300 s plus up to 60 s for the
pass; before this change a retry finished the removal at once.

With the server's key-info cache warm, data-plane requests during the
delete answer as before: 200 until the base data table is dropped, then
500. With it cold they answer 404 for the whole delete, where they answered
200 and then 500 before; the 404 comes from the read that maps DELETING to
not found on this backend. The service answers 200 throughout.

The 200 of DeleteTable reports DELETING for a table that is already gone
when the answer arrives, so a DescribeTable sent after it answers 404.

The sweep now logs a row it cannot remove and goes on to the next row; it
used to return at the first failure.

Direct storage tests cover two concurrent calls (ten rounds, one of them on
a CREATING table), a table created into the name during a delete, a claim
whose call stopped, a claim carrying another table id, a renewal against a
stale deadline, two sweeps over one stopped claim, a sweep whose row is
replaced under it, the abandoned-restore sweep over a claimed restored
table, PITR and tag writes during the drops, the order of the name-keyed
deletes, and a sweep pass with a row it cannot remove. A dual-target wire
row sends two concurrent DeleteTable calls and accepts a not-found answer
for the loser only on PostgreSQL and SQLite.
@LeeroyHannigan
LeeroyHannigan force-pushed the fix/553-cassandra-concurrent-delete-table branch from 32bd451 to 13a2940 Compare October 30, 2026 10:35
@LeeroyHannigan LeeroyHannigan added the v1 Needed for the 1.0 release label Nov 6, 2026
…nt-delete-table

crates/storage-cassandra/src/backup_engine.rs keeps the restore target removal from the base branch. The deadline check this branch added to the abandoned restore sweep goes with that sweep, which main no longer has.

crates/storage-cassandra/src/delete_table.rs keeps the removal without a continuous_backups delete from the base branch and the lease claim, the renewal and the removal order from this branch. Main dropped the continuous_backups table in catalog migration 5.

crates/storage-cassandra/src/worker_store.rs keeps the lease take and the shared removal from this branch. The base branch's change there, the end of the continuous_backups delete, holds through that removal.

crates/storage-cassandra/tests/direct/deleting_window.rs keeps the module doc from this branch, which names the DeleteTable claim as the writer of the DELETING mark.

tests/python/test_deleting_window_control_plane.py keeps the index read test from the base branch inside TestDeletingWindowDataPlane and the TestConcurrentDeleteTable class from this branch after it.
…ble lease tests

Main dropped the continuous_backups table in catalog migration 5, with describe_continuous_backups and update_continuous_backups. The lease tests enabled point-in-time recovery on their tables and read the stored row. That showed two things: a fenced delete leaves the newer table's row alone, and the name-keyed deletes run after the drops. The tags share the same fence and the same place in the removal, so they now carry those checks alone.

The pitr_row helper and the continuous_backups clean-up go from delete_table_support.rs. The point-in-time recovery writes and assertions go from six tests. The test of the abandoned restore sweep over a claimed restored table goes as well: it tested a check that main's restore target removal replaced.
…nt GsiInput

Main added warm_throughput to GsiInput. The gsi_input helper of the DeleteTable lease tests now sets it to None.
…elper each

The direct test binary held two readers of system_schema.tables for a data table. One in backup_engine.rs takes the table name, one in delete_table_support.rs takes the table id. The second now formats the name and calls the first, which the file makes visible to the binary.

The DELETING window tests read a row's status with a query of their own. They now call row_status from delete_table_support.rs, which reads the same column.
…nt-delete-table

The base branch accepts a refused queued DeleteTable in the PostgreSQL snapshot test an_open_needs_one_connection_per_pool (bff95d9). No file conflicts.
…nt-delete-table

crates/storage-cassandra/src/delete_table.rs keeps this branch's side where main changed the old index metadata delete: delete_indexes_for_table deletes that metadata after the index drops. The tag delete keeps this branch's statement, keyed on table_arn, and sends it through main's self.session.run(Stmt::Write, ...). Main's tests/consistency_policy.rs refuses a query_with_values call in source that is not a test.

crates/storage-cassandra/src/worker_store.rs keeps this branch's lease take and remove_claimed_table in place of the old sweep's tag delete, the one statement main changed there. The merge also deletes the imports of PolicySession and Stmt that main added to that file. The tag delete they served is gone, and the unused_imports lint fails the -D warnings build.

crates/storage-cassandra/tests/direct/backup_engine.rs keeps this branch's pub(crate) data_table_exists, which the delete tests share, with main's cassandra_util::system_read.

crates/storage-cassandra/tests/direct_integration.rs lists concurrent_delete_table, then main's consistency_levels and consistency_shape.

tests/python/test_deleting_window_control_plane.py keeps the not-found assertion of the base branch at the end of test_index_reads_after_the_table_is_gone_are_not_found, then the TestConcurrentDeleteTable class of this branch.
…SQLite

TestConcurrentDeleteTable checked the message of the ResourceInUseException answer only. The ResourceNotFoundException it accepts on PostgreSQL and SQLite was checked by its code alone. Each accepted answer now has its message in one map, and assert_validation checks the status, the code and the message. The not-found message is ExtendDB's, Requested resource not found, the text NOT_FOUND holds. A local PostgreSQL server gave it for DeleteTable on a missing table on 2026-11-24, and SQLite shares the engine's mapping. The docstring no longer names issue and pull request numbers.

On a PostgreSQL-backed server the class passed twice. With a wrong expected message it failed in 2 of 3 runs, so the not-found branch runs there.

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

The lease fences concurrent deletes. Two DeleteTable calls at once give one 200 DELETING and one 400 ResourceInUseException with the service's "being deleted" sentence, byte-equal to the service in us-east-1, where the base answered two 200s; 48 of 48 concurrent pairs on the wire row and 20 of 20 rounds across two servers on one Cassandra 4.1 node answer this way, with and without GSIs. DeleteTable and DescribeTable report DELETING, UpdateTable and TagResource during a delete get the service's error, and CreateTable of the same name answers "Table already exists".

  • A holder stopped past its lease: the other server's sweep took the row 2.2 s after the deadline. With the name re-created with a new tag, an item and a GSI, the resumed holder answered 200, its renewal failed, it skipped the name-keyed deletes, and the new table kept its tag, item, GSI and table id.
  • Six stopped claims under two live sweeps were each removed once, with no orphan tags, index rows or data tables across 26 deletes. Every other writer of the row's status is conditional, and restore targets are not taken by the sweep.

fmt, clippy and the 1.88 MSRV check are clean, 142 unit tests and 314 of 314 direct integration tests pass, the PR's pytest files pass on a head Cassandra server (46 passed, 5 skipped by design), CI is green on 53 checks, and the five controls in the body and one more each fail their tests.

I will approve once the lease is released on error, the two answers below follow the service or are listed, and the docs match.

crates/engine/src/ttl.rs:227

UpdateTimeToLive during a delete now answers 400 ResourceInUseException Table X is not in ACTIVE state (3 of 3), where the base answered 200 (3 of 3). The service answers 200 for the first 0.3 to 1.2 s and then 400 Attempt to change a resource which is still in use: Table X is being deleted, over 13 delays in two runs. The error class matches the service's later phase and the sentence matches neither. Answering the "being deleted" sentence for a DELETING row would match the later phase; the body can list the change.

docs/differences-from-dynamodb.md:60

The row says Cassandra DeleteTable is synchronous and never marks the row DELETING, which this PR makes untrue. docs/troubleshooting.md:384 says a stopped transition completes at the next startup; on Cassandra a DeleteTable that stops after its claim keeps the name until the lease passes and the next sweep runs, up to about 360 s.

// Claim the row before the first drop. Two concurrent calls both read
// the same row; the claim applies for one of them and the other
// answers TableBeingDeleted, as the service answers the second of two
// concurrent calls (measured 2026-10-25, five rounds of five).

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.

No error path releases the lease. Once a call has claimed the row, a failure or a crash leaves it DELETING with the deadline 300 s ahead, and only the 60 s idle sweep takes it after that. With the holding server killed right after its claim, retries on the other server answered 400 "Table is being deleted" for 320.5 s, then not found; on the 550 base a retry finished the removal at once. The body discloses this as behaviour 1. On an error after the claim, swapping the deadline to now() with the compare-and-set the renewal uses, and notifying the poller, would clear in-process failures within about a second.

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.

Fixed in 66a3046. When a statement fails after the claim (the call) or the take (the sweep), remove_claimed_table now moves the actor's deadline to the current time. It uses the compare-and-set of the renewal: release_delete_lease and renew_delete_lease share swap_delete_deadline. The failed call then wakes the poller, and the poller's next pass removes the table. A failure inside the sweep does not wake the poller, because the poller runs that pass. A wake from inside it would keep the poller polling every second while the failure lasts.

a_delete_that_fails_after_its_claim_is_finished_by_the_next_sweep fails a DeleteTable at its first index table drop. It checks that the row's deadline is no longer ahead, and that one sweep pass removes the table and both index tables. With the release removed, it fails on the deadline, which is 300 s ahead.

A dropped request also left the lease. When a client closed the connection after the claim, the server stopped the call part way. On a local server, the client of a DeleteTable of a table with 8 GSIs timed out after 0.2 s. The row stayed DELETING, and the sweep removed it 351 s after the request. bba68ad runs the claim and the removal in a task that the call awaits, as the PostgreSQL backend does with its drops. With it, the row of the same request read DELETING for about 4 s and was then gone. a_delete_whose_request_is_dropped_after_its_claim_still_removes_the_table aborts a call after its claim, and it fails when the removal runs inline.

A server process that stops after the claim still leaves the 300 s lease. The body, docs/differences-from-dynamodb.md and docs/troubleshooting.md say so (08b7356).

// answers TableBeingDeleted, as the service answers the second of two
// concurrent calls (measured 2026-10-25, five rounds of five).
let lease = match caller {
DeleteTableCaller::Client => Some(

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.

CreateBackup during a delete answers TableNotFoundException for the whole delete (2 of 2 races, 3 of 3 sweep rounds); the not-found mapping comes from 550. The base answered 200 until the data table was dropped. The service accepts the backup for about 2 s (200, later AVAILABLE) and then answers TableNotFoundException while DescribeTable still says DELETING. The body lists this trade for item reads and writes and can list CreateBackup with them.

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.

Listed in the body as behaviour 3 and under Breaking changes. The body gives your service answers: 200 for about 2 s, then TableNotFoundException while DescribeTable still reads DELETING.

I checked it at the head on a local Cassandra-backed server. During a delete of a table with 8 GSIs, CreateBackup answered 400 TableNotFoundException "Table not found: " 277 of 277 times.

The answer comes from CreateBackup's check that the table is ACTIVE, which main has. The claim makes the row DELETING, so that check refuses the backup.

/// leaves those deletes and the row delete to the actor that holds the row.
const DELETE_CLAIM_LEASE_SECS: i64 = 300;

fn lease_deadline_ms() -> i64 {

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.

The deadline comes from the server's clock, and the sweep compares it with the Cassandra node's clock, so a server S seconds behind writes a lease of 300 minus S seconds. That widens the stall-after-renewal case the body names. The clock note in the docs can name this lease.

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.

Documented in 08b7356, with no code change. The clock synchronization note in docs/cassandra-setup.md and the doc comment of DELETE_CLAIM_LEASE_SECS now name the lease. The server sets the deadline from its own clock, and the sweep compares it with the node's clock. So a server S seconds behind the node writes a lease of 300 minus S seconds.

The body's case that depends on the lease length says the same. On such a server, a stall of 300 minus S seconds after the renewal is enough.

}

/// Delete index metadata and drop index data tables for a given table.
/// Drop the index data tables of a table, then delete their index metadata.

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.

Nothing tests dropping the index tables before deleting their metadata: with main's order restored, the two delete modules pass 10 of 10. A slow DeleteTable whose row a sweep takes over has no end-to-end test either: with the renewal check disabled, 1 of 10 fails, and with the renewal's deadline condition removed only the direct method test fails. A test-hooks test that pauses a call between its drops and its renewal would cover both.

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.

Added in f77e591 and 66a3046.

a_delete_whose_row_a_sweep_took_over_stops_at_its_renewal pauses a DeleteTable between its drops and its renewal, moves the deadline into the past, and lets a sweep take the row. It runs two cases. In the first, the call resumes after the sweep removed the table and the test created the name again and tagged it. In the second, the call resumes while the sweep holds the row, paused at its own renewal.

With the renewal check disabled, the first case fails: the call runs the tag delete, and the newer table loses its tag. Without the deadline condition in the compare-and-set, the second case fails: the call's renewal applies, and the call deletes the row the sweep holds. The first case passes under that control. Once the sweep finishes, the table id condition of the renewal refuses the call by itself.

The pause cannot show the order in delete_indexes_for_table, because the order only matters when a drop fails. a_delete_that_fails_after_its_claim_is_finished_by_the_next_sweep fails the first index table drop. With main's order restored it fails: the metadata is gone before the failed drop, and the sweep's pass leaves both index tables.

/// EXISTS`, the TTL entries are cleared, and the index metadata goes after
/// the index tables, so a removal that stops part way leaves the ids the
/// next attempt needs. The tags are keyed on the table ARN, which carries
/// no table id. They are deleted last, after the renewal, while the

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.

The row delete runs last, not the tag delete. The same is in tests/direct/delete_table_lease.rs:10.

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.

Fixed in 08b7356. The doc comment of remove_claimed_table and the module doc of tests/direct/delete_table_lease.rs now say that the row delete runs last. The tag delete comes before it, after the renewal.

I grepped the branch, the body and the docs for the same claim and found no other sentence that puts the tag delete last.

The DELETING window row of docs/differences-from-dynamodb.md said that DeleteTable on Cassandra never marks the row DELETING. The claim now marks it for the length of the drops. The row names the claim and the answer to a second DeleteTable. It gives the data-plane answers during the drops, with and without an entry in the key-info cache. The Control Plane table gets two rows. One is the DeleteTable 200 that reports DELETING for a table that is already gone. The other is a DeleteTable that stops after its claim. It gives the 300 s deadline, the sweep's next pass, and what a sweep does with a row it cannot remove. docs/troubleshooting.md names the stopped claim as a cause of a table stuck in DELETING on Cassandra, and adds a step to the fix.
…nt-delete-table

#550's branch is at 9cbb9fe, its merge of main at 3534c9e (#1009,
the WebAssembly build). No file conflicted, and #1009 changes no file
that this branch changes.
A DeleteTable whose removal failed after its claim left the row DELETING
with the claim's deadline 300 s ahead. A retry answered "Table is being
deleted" until that deadline passed and the next sweep removed the table.

When one of its statements fails, remove_claimed_table now moves the
deadline that the actor holds to the current time. The actor is a
DeleteTable call after its claim, or the control-plane sweep after its
take. The release uses the compare-and-set of the renewal:
release_delete_lease and renew_delete_lease share swap_delete_deadline.
The call then wakes the control-plane poller. Its next pass takes the row
and finishes the removal. A failure inside the sweep does not wake the
poller, because the poller runs that pass. A wake from inside the pass
would keep the poller polling every second while the failure lasts.

The test hook fail_next_index_table_drop fails the next drop of an index
data table in one account keyspace. The new test
a_delete_that_fails_after_its_claim_is_finished_by_the_next_sweep fails a
DeleteTable at its first index table drop. It checks that the row's
deadline is no longer ahead, and that one sweep pass then removes the
table and both index tables. The index metadata outlives the failed drop.
…ts claim

When a client closed its connection during a DeleteTable, the server
stopped running the request. A request that stopped after the claim left
the drops part way done. It also left the row DELETING with the claim's
deadline 300 s ahead, as a stopped server process does. On a local
Cassandra-backed server, the client of a DeleteTable of a table with 8
GSIs timed out after 0.2 s. The row stayed DELETING, and the sweep
removed the table 351 s after the request.

delete_table_as now runs the claim and the removal in a task that the
call awaits, as the PostgreSQL backend runs its drops. A dropped request
detaches the task, and the task finishes the removal. With this change,
DescribeTable read DELETING for about 4 s after the same request, and
then answered ResourceNotFoundException.

The new test
a_delete_whose_request_is_dropped_after_its_claim_still_removes_the_table
aborts a DeleteTable once its claim applies. It then waits for the row
and the data table to go.
…es the row

No test ran a DeleteTable call past its lease with the control-plane sweep
beside it. So no end-to-end test of the call covered the renewal check or
the deadline condition of the renewal's compare-and-set.

The test hook pause_before_delete_lease_renewal holds the next removal of
one table between its drops and its lease renewal. The new test
a_delete_whose_row_a_sweep_took_over_stops_at_its_renewal pauses a
DeleteTable there and moves the row's deadline into the past, so a sweep
takes the row. It runs two cases. In the first, the call resumes after
the sweep removed the table and the test created the name again and tagged
it. In the second, the call resumes while the sweep holds the row, paused
at its own renewal. In both cases the call answers 200 with DELETING. It
runs none of the statements after its renewal (the tag delete and the row
delete). The newer table keeps its row and its tag, and the sweep finishes
the removal.
…al order

docs/cassandra-setup.md and the doc comment of DELETE_CLAIM_LEASE_SECS now
name the lease in the clock note. The server sets the lease's deadline
from its own clock, and the sweep compares the deadline with the clock of
the Cassandra node. A server S seconds behind the node writes a lease of
300 minus S seconds.

The doc comment of remove_claimed_table and the module doc of
tests/direct/delete_table_lease.rs said that the tag delete runs last. The
row delete runs last, after the tag delete.

docs/differences-from-dynamodb.md and docs/troubleshooting.md now describe
the two ways a DeleteTable can end after its claim on Cassandra. A call
that fails answers 500 and wakes the sweep, which removes the table at its
next pass. A server process that stops leaves the row DELETING until the
lease passes and the sweep runs. That takes up to about 6 minutes, and a
restart does not shorten it. A request that its client drops does not
stop the removal. The troubleshooting cause no longer says that every
stopped transition completes at the next startup.

The commit also splits long sentences in the comments of the three
commits before it.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

UpdateTimeToLive (crates/engine/src/ttl.rs:227) has no code change in this PR. The body lists it as behaviour 4 and under Breaking changes, with your service answers. On this branch UpdateTimeToLive during a Cassandra delete answers 400 ResourceInUseException "Table is not in ACTIVE state", where #550's branch answered 200. At the head it gave that answer 241 of 241 times during a delete on a local server. #599 serves UpdateTimeToLive on a DELETING row on every backend.

For the docs rows, 1b0aebf rewrote the DELETING window row of docs/differences-from-dynamodb.md for the claim. 08b7356 makes the stopped-claim text match the release. The sweep's next pass finishes a call that fails after its claim. Only a stopped server process waits for the lease, up to about 6 minutes. The cause in docs/troubleshooting.md no longer says that every stopped transition completes at the next startup, since a Cassandra claim waits for its deadline.

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

The items from the earlier review are resolved at 08b7356, measured on two servers built from this head sharing one Cassandra 4.1 node.

  • A DeleteTable that fails after its claim hands the lease back. With DROP revoked on one index table, DeleteTable answered 500, the row's deadline was 0.6 s behind the node's clock rather than 300 s ahead, and the failing server's poller ran a pass about 0.1 s later; retries on the other server answered the being-deleted sentence while the failure lasted, and once DROP was granted the table was gone in 35.2 s and 7.0 s with no tags, index metadata, data or catalog row left, in both server orders. A request dropped after 0.2 s on an 8-GSI table is finished by its own task in about 2.7 s, and two-server races still give one 200 DELETING and one being-deleted 400, 10 of 10.
  • UpdateTimeToLive and CreateBackup during a delete are listed in the body as behaviours 3 and 4 and under Breaking changes. The concurrent pair still matches the service in us-east-1 byte for byte, and DescribeTable, UpdateTable, TagResource and CreateTable during a delete answer as at 7318dbc.
  • The clock note in cassandra-setup.md and the lease constant name the lease, the index tables drop before their metadata and that order has a test, the comments put the row delete last, and the differences and troubleshooting rows match the code.
  • Removing the release fails the failed-claim test, running the removal inline fails the dropped-request test, and restoring main's index order or disabling the renewal check or its deadline condition fails the new tests. fmt, clippy with and without test-hooks and the 1.91.1 check are clean, 181 lib, 10 consistency and 332 direct tests pass, and CI is green on 54 of 54 checks.

// poller runs that pass. A wake from inside the pass would
// keep the poller polling every second while the failure
// lasts.
engine.control_plane_notify.notify_one();

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. No test covers this wake: with notify_one() deleted, all 16 delete tests pass, because the failure test runs the sweep itself. The live runs show the wake clears the row within about a second; without it the row waits for the 60 s idle pass. tests/direct/delete_table_lease.rs is 698 lines, and moving the new tests to their own module would keep it under 600.

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.

Both stay as they are in this PR. Without the wake, the 60 s idle pass removes the row, and the failure test checks that removal by running the sweep itself. A test of the wake would have to time the removal against that pass on the Cassandra node. The new tests stay in tests/direct/delete_table_lease.rs: the move would change no test, and each push to this branch needs a new approval.

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

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants