Skip to content

test(backup): hold the restore registration with a gate in the retry test - #1182

Merged
hitesh96db merged 2 commits into
mainfrom
fix/951-restore-registration-gate
Nov 21, 2026
Merged

hitesh96db merged 2 commits into
mainfrom
fix/951-restore-registration-gate

Conversation

@hitesh96db

@hitesh96db hitesh96db commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

a_retry_waits_on_its_registration_and_another_backup_is_refused in crates/engine/src/backup/tests.rs now holds the first restore registration with a gate that the test opens, in place of a fixed 400 ms delay. No product code changes.

  • The fake's claim_restore waits for a permit of claim_restore_gate when one is set, as bulk_load_gate and count_gate do for their calls.
  • The restore of the other backup runs while the gate is closed. It must answer TableInUseException and register nothing.
  • The retry is then spawned. The gate opens once the retry logs that it waits on the registration in flight, and the retry and the first request both answer CREATING.
  • The fake's five gate waits (claim_restore, bulk_load and its per-item gate, count_restore_target, and the item stream of open_table_snapshot) go through one helper, pass.

Why

Closes #951

The in-flight entry for a registration ends when the retries waiting on it get their answer. The test sent the other backup's restore after the retry had been answered, so that request never met the entry. It met the committed target at the name check (check_restore_target_name), before it registered anything. That answers TableInUseException only while the target is still CREATING. When the first restore job, two items, had already made the target ACTIVE, the answer was TableAlreadyExistsException("Table already exists: MusicRestored"). The same failure appeared in runs 44197562178 and 43946703111 (mongodb-rust) after the issue was filed.

With the gate, the other request meets the in-flight entry on every run, which is the case the test describes.

Testing done

  • cargo test -p extenddb-engine: 870 passed.
  • The changed test 300 times in a row with 8 busy processes loading the CPU: 300 passed. It now takes about 0.02 s.
  • With the in-flight lookup in BackupRuntime::begin_restore_registration disabled, the test fails at the TableInUseException assertion, after 60 s: the other request then waits at the closed gate until the registration bound. With the lookup restored, it passes.
  • After the helper: cargo test -p extenddb-engine --lib backup:: 467 passed, and the changed test 50 of 50.
  • cargo +1.97.0 fmt --all -- --check and cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -D warnings are clean.

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


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.

@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 gate fixes the race and the code is right. I ran main's version of the test 300 times with 8 busy processes on the host, and 7 runs failed with the CI message, TableAlreadyExistsException("Table already exists: MusicRestored"). This head passed 300 of 300 under the same load, and 200 of 200 with main at 2ef5613 merged in. With the in-flight lookup in begin_restore_registration disabled, the test fails at the TableInUseException assertion, as the description says. It takes 60 s to fail that way, because the other request then waits at the closed gate until the registration bound.

Before I approve, please fix one thing in the Why section and the commit message. They describe a path the other request didn't take. On main it never reaches claim_restore. restore_from_row runs check_restore_target_name (crates/engine/src/backup.rs:1940) before it registers anything. That check answers TableInUseException for a CREATING target and TableAlreadyExistsException for an ACTIVE one. I timed main's version. The retry took about 397 ms, because it waits on the first registration. The other request got its answer in about 0.1 ms, with one entry in restore_claims. Main's last assertion, restore_claims.len() == 1, also passed on every green run, and the fake records each claim_restore call before its delay. So the 400 ms belongs to the retry. Please change "It slept its own 400 ms in claim_restore and then met the committed target." to "It met the committed target at the name check (check_restore_target_name), before it registered anything." In the commit message, please drop "after its own 400 ms delay" and name the name check there too. The commit message goes into main's history when the PR merges.

You could also fold the gate waits in the fake into one helper. The new wait in claim_restore (crates/engine/src/backup/tests.rs:2132) is the fifth copy of the same five lines, beside lines 3091, 3107, 3270 and 3533. This helper works at all five places:

/// Wait for one permit of `gate`, when there is one, and keep it.
async fn pass(gate: Option<&tokio::sync::Semaphore>) {
    if let Some(gate) = gate {
        gate.acquire()
            .await
            .expect("the gate is never closed")
            .forget();
    }
}

Each site then becomes pass(gate.as_deref()).await (item_gate at line 3107). I tried it on your head. Clippy with -D warnings is clean, the file is 15 lines shorter, and backup::tests passed 431 of 431 in two runs. In a third run a_truncated_spooled_manifest_has_the_resume_read_the_store failed with "no bulk_load began". That test builds spooled_runtime, which #997 gave a 1 s heartbeat on main, and it passed 20 of 20 alone.

Hitesh Sharma added 2 commits November 20, 2026 14:21
…test

a_retry_waits_on_its_registration_and_another_backup_is_refused sent
the other backup's restore after the retry had been answered. The
in-flight entry ends with that answer, so the request never met it: it
met the committed target at the name check (check_restore_target_name),
before it registered anything. That check answers TableInUseException
only while the first target is CREATING. When the two-item restore job
had already made the target ACTIVE, it answered
TableAlreadyExistsException.

A gate the test opens now holds the first registration. The other
backup's restore runs while the gate is closed and must be refused
without registering. The retry is spawned, and the gate opens once the
retry logs that it waits on the registration in flight. The test no
longer sleeps 400 ms.

Closes #951
The five places where the fake waits for a gate permit now call
pass(), which takes the permit when a gate is set. The retry test's
doc comment names the name check (check_restore_target_name) as where
a later request meets the committed target.
@hitesh96db
hitesh96db force-pushed the fix/951-restore-registration-gate branch from 16bce98 to 2f48759 Compare November 20, 2026 22:26
@hitesh96db

Copy link
Copy Markdown
Contributor Author

@LeeroyHannigan Thanks. Both are in, and the branch was rewritten so the corrected message is the one that merges.

  • The Why section now says the other request met the committed target at the name check (check_restore_target_name), before it registered anything. 0ed5ef4 carries the same correction in its commit message, without "after its own 400 ms delay". The test's doc comment names the name check too.
  • 2f48759 folds the five gate waits into pass, as you proposed: claim_restore, bulk_load and its per-item gate, count_restore_target, and the item stream of open_table_snapshot.

On 2f48759: cargo +1.97.0 fmt --all -- --check and cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -D warnings are clean, cargo test -p extenddb-engine --lib backup:: passed 467 of 467, and the changed test passed 50 of 50. The description now also says that with the in-flight lookup disabled the test fails after 60 s, at the registration bound.

@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, both are in. The Why section and the message of 0ed5ef4 now name the name check, which is where the other request stops on main. pass replaces the five waits that keep their permit, and "the gate is never closed" now appears only in pass.

On this head, backup:: passed 467 of 467, and 467 of 467 with main at ca768ed merged in. The changed test passed 200 of 200 runs with 8 busy processes on the host. With the in-flight lookup disabled, it fails at the TableInUseException assertion after 60 s, as the description says. fmt is clean, and so is clippy with -D warnings and the backup-test-hooks feature. In CI, run-integration (1) failed once at the server log check of #1157 and passed when rerun.

@hitesh96db
hitesh96db added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit f0170bd Nov 21, 2026
71 of 73 checks passed
@hitesh96db
hitesh96db deleted the fix/951-restore-registration-gate branch November 21, 2026 00:53
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.

Flaky: a_retry_waits_on_its_registration_and_another_backup_is_refused gets TableAlreadyExistsException

2 participants