Skip to content

test(storage-cassandra): hold the admitted restore's copy in the simultaneous restore test - #1499

Merged
navareamol merged 5 commits into
mainfrom
test/869-simultaneous-restore-hold
Dec 2, 2026
Merged

navareamol merged 5 commits into
mainfrom
test/869-simultaneous-restore-hold

Conversation

@navareamol

@navareamol navareamol commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

The Cassandra storage test that starts four restores of one backup at the same time now holds the admitted restore's copy until all four restores have answered.

  • A test hook, pause_before_legacy_restore_copy, holds a legacy restore's copy after its registration and before its first item is written. It does nothing without the test-hooks feature.
  • The simultaneous part of test_a_restore_is_refused_while_a_target_of_its_backup_is_creating moves into its own test, test_simultaneous_restores_of_one_backup_admit_exactly_one, behind test-hooks. CI already builds direct_integration with that feature. The rest of the original test is unchanged.
  • The new test checks that the admitted target is still CREATING when the four restores have answered, and that the copy reached the hold within 60 s after the release. A hook that does nothing fails it.
  • Each refused restore must be BackupInUse and must leave no target behind (TableNotFound on describe). The refusal text is Backup is being used to restore another table: <backup ARN>. It names the backup, not the target, so the test checks the ARN.

No product behaviour changes.

Why

Refs #869.

Two cassandra-storage jobs admitted two of the four restores. The cause is not proven for those jobs. This is what is known:

  • A restore that passes the early in-use check creates its target's tables before it registers on the backup, and each statement waits for schema agreement. If that wait is longer than the first restore's copy, the first target goes ACTIVE and its registration is removed. A later registration then finds active_restores empty and is admitted. An injected delay before one registration produced exactly this failure (see the first control below).
  • In job 126252060053 both admitted target rows carry the creation time 22:40:44.21, and the test failed at 22:40:49.56. That is a 5.35 s window in which the first restore had to finish its tables, register, copy 10,000 items at concurrency 8, activate and unregister. Whether a copy that size fits in that window on the CI runner has not been measured. Job 126985540143 has an 11.8 s window.
  • The issue names a second possible cause: a live registration cleared as stale (registration_refusal, crates/storage-cassandra/src/backup_engine.rs around lines 813-822 and 969-993). Nothing here rules it out. The new test would still catch it, because the held target stays CREATING and a second admission would fail the test.
  • Both failing jobs ran code from before feat(backup): catalog index, BackupCatalog, JobClaim, legacy reader [backup/restore 6] #671 and feat(storage-cassandra): run reads and writes at LOCAL_QUORUM #945. The old test passed 3 of 3 runs on later code (comment on the issue). So the failure has not been reproduced on current main without an injected delay.

The first commit message says the delay "outlasted the first restore's copy" as the cause. Read that as the mechanism that was shown, not as the proven cause of the two CI failures.

The hold keeps the first registration in place until all four restores have answered, so every other registration meets it, however long the table creation takes.

Open PR #527 rewrites the same simultaneous section of test_a_restore_is_refused_while_a_target_of_its_backup_is_creating, and git merge-tree reports a conflict in that test file. The two test different things. #527 writes a CREATING target row and its active_restores entry by hand and expects all four restores refused, so its restores never race on an empty map. This PR tests that exactly one of four simultaneous restores is admitted through the product's own registration. Whichever PR merges second should keep this PR's version of the section. The extra step in #527, where a new restore clears the stale entry and is admitted, can stay as a test of its own.

The older test test_a_restore_is_refused_while_a_target_of_its_backup_is_creating still depends on its 10,000-item copy outlasting its refusals. Its refusals are early reads that run before any table is created, so the window is wide. This PR leaves it as it is.

Testing done

Cassandra 127.0.0.1:9042 (1 GB heap), EXTENDDB_TEST_CASSANDRA=required, --features test-hooks, Rust 1.97.0 for clippy.

Check Result
cargo fmt --check clean
cargo +1.97.0 clippy -p extenddb-storage-cassandra --all-targets -- -D warnings, without and with test-hooks clean, clean
New test, 20 runs in a row 20 of 20 passed
Control 1: sleep before the registration of SimTarget2, hold armed passed
Control 2: same sleep, hold armed for another backup ARN (no hold on this backup) failed: exactly one is accepted
Control 3: hook made to do nothing, no sleep failed: exactly one is accepted
backup_engine:: module on this branch (100 tests, parallel) 100 passed, 0 failed
backup_engine:: module on main a417b2f8 (99 tests, parallel) 99 passed, 0 failed

Control 3 fails without any injected delay: with a 200-item copy and no hold, more than one restore is admitted on this machine.

Control 1 and 2 patch (product code, not committed):

--- a/crates/storage-cassandra/src/backup_engine.rs
+++ b/crates/storage-cassandra/src/backup_engine.rs
@@ -1516,6 +1516,9 @@ impl CassandraEngine {
         // guarantee. A refusal caused only by stale registrations is retried
         // once they are cleared, a bounded number of times.
         crate::test_hooks::before_legacy_restore_registration(&backup_arn).await;
+        if target_name == "SimTarget2" {
+            tokio::time::sleep(std::time::Duration::from_secs(20)).await;
+        }
         let mut registered = Ok(false);

Control 2 also changes the test's arming line so that the hold is armed for another backup:

--- a/crates/storage-cassandra/tests/direct/backup_engine.rs
+++ b/crates/storage-cassandra/tests/direct/backup_engine.rs
@@ -1330,3 +1330,2 @@ async fn test_simultaneous_restores_of_one_backup_admit_exactly_one() {
-    let copy_pause =
-        extenddb_storage_cassandra::test_hooks::pause_before_legacy_restore_copy(&backup_arn);
+    let copy_pause = extenddb_storage_cassandra::test_hooks::pause_before_legacy_restore_copy("unused");

Control 3 patch (not committed):

--- a/crates/storage-cassandra/src/test_hooks.rs
+++ b/crates/storage-cassandra/src/test_hooks.rs
@@ -571,7 +571,7 @@ pub(crate) async fn before_legacy_restore_copy(backup_arn: &str) {
     if let Some(pause) =
         armed::with_hooks(|hooks| hooks.before_legacy_restore_copy.remove(backup_arn))
     {
-        pause.hold().await;
+        let _ = pause;
     }
     let _ = backup_arn;
 }

Command for the controls and the 20 runs: cargo test -q -p extenddb-storage-cassandra --features test-hooks --test direct_integration -- test_simultaneous_restores. The failing text of controls 2 and 3 is assertion left == right failed: exactly one is accepted: [Ok(TableDescription { table_name: "SimTarget0" .... The tree was restored after each control.

Open question

Does live DynamoDB refuse a restore while another restore of the same backup is still creating its tables but has not registered yet? Nothing in the repo says. If it does, the gap between a target row being CREATING and its entry in active_restores is a product question, and this hold would hide it.

Amol Navare and others added 4 commits November 25, 2026 04:08
…ltaneous restore test

The test started four restores of one backup and expected one admission and
three BackupInUse. A restore creates its target's tables before it registers
on the backup, and each statement waits for schema agreement. When that wait
outlasted the first restore's copy, the first target went ACTIVE and its
registration was removed, so a later registration found no active restore and
was admitted too. Two jobs showed two admissions.

A test hook now holds a legacy restore's copy after its registration. The
simultaneous restore check moves into its own test, behind test-hooks, and
releases the copy once all four restores have answered. Product behaviour is
unchanged.
…ds the admitted copy

The test released the held copy without checking that the hold was taken, so a
hook that did nothing still passed. The test now asserts that the admitted
target is still CREATING when the four restores have answered, and that the
copy reached the hold within 60 s after the release. Each refused restore must
be BackupInUse naming the admitted target and must leave no target behind. The
doc comment says that only a restore that passes the early in-use check creates
tables.
LeeroyHannigan
LeeroyHannigan previously approved these changes Dec 2, 2026

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

Thanks. I read the change against main 92155f3. On a single-node Cassandra 4.1 with password authentication, as in CI, the new test and the changed test passed 3 of 3 runs each. The crate's 191 lib tests passed too. With the hook call at backup_engine.rs:1312 removed, the new test failed 3 of 3 runs at line 1354 (left: 4, right: 1), because all four restores were admitted.

The hook runs at the start of run_restore_copy, after the registration and before the first item is written. Pause is built on tokio::sync::Notify, so a release that comes before the copy reaches the hold cannot hang the test. The test also still catches the second cause that #869 names, a live registration cleared as stale. The held target stays CREATING while the four restores answer, so a second admission fails the test.

#527 (opened 24 October) rewrites the same simultaneous section of test_a_restore_is_refused_while_a_target_of_its_backup_is_creating. The two PRs conflict there in three hunks, and the description does not name #527. The two versions test different things:

  • #527 writes a CREATING target row and its active_restores entry by hand, then expects all four restores refused. Its four restores never race on an empty map, so it does not test that one of four simultaneous restores is admitted.
  • This PR tests that admission through the product's own registration, and the refusals too.

Whichever PR merges second should keep this PR's version of the section. #527 rewrote the section because a copy ended before a second target's schema existed. That reason does not apply once the copy is held. #527 also has one step that this PR does not: after the held row goes, a new restore clears the stale entry and is admitted. That step can stay in #527 as a test of its own. Please name #527 in the description.

The red WebAssembly / wasm check ran on 25 November on a merge commit that has main's #398 break and not its #1482 fix. This PR changes no code that the check builds, and it is not a required check.

@navareamol

Copy link
Copy Markdown
Collaborator Author

#527 is now named in the description. I read its diff: it rewrites the same simultaneous section, and git merge-tree of this branch with #527's head reports a conflict in crates/storage-cassandra/tests/direct/backup_engine.rs. Whichever PR merges second should keep this PR's version of that section. #527's step where a new restore clears the stale entry and is admitted can stay as its own test.

The red WebAssembly / wasm check is not from this change. It is not a required check and the PR changes no code it builds. Main moved since the last push, but git merge-tree shows no conflict with this branch, so I did not merge or rebase it.

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

Thanks. The doc comment of the new test now states that the registration admits exactly one restore. The description names #527 and the order for the second PR to merge. The new commit changes only that doc comment, so my runs at 4cf6561 still cover the code. CI passed at this head.

@navareamol
navareamol added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 1cd8dc3 Dec 2, 2026
69 of 70 checks passed
@navareamol
navareamol deleted the test/869-simultaneous-restore-hold branch December 2, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants