Repository navigation
test(backup): hold the restore registration with a gate in the retry test - #1182
Conversation
LeeroyHannigan
left a comment
There was a problem hiding this comment.
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.
…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.
16bce98 to
2f48759
Compare
|
@LeeroyHannigan Thanks. Both are in, and the branch was rewritten so the corrected message is the one that merges.
On 2f48759: |
LeeroyHannigan
left a comment
There was a problem hiding this comment.
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.
What
a_retry_waits_on_its_registration_and_another_backup_is_refusedincrates/engine/src/backup/tests.rsnow holds the first restore registration with a gate that the test opens, in place of a fixed 400 ms delay. No product code changes.claim_restorewaits for a permit ofclaim_restore_gatewhen one is set, asbulk_load_gateandcount_gatedo for their calls.TableInUseExceptionand register nothing.claim_restore,bulk_loadand its per-item gate,count_restore_target, and the item stream ofopen_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 answersTableInUseExceptiononly while the target is still CREATING. When the first restore job, two items, had already made the target ACTIVE, the answer wasTableAlreadyExistsException("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.BackupRuntime::begin_restore_registrationdisabled, the test fails at theTableInUseExceptionassertion, after 60 s: the other request then waits at the closed gate until the registration bound. With the lookup restored, it passes.cargo test -p extenddb-engine --lib backup::467 passed, and the changed test 50 of 50.cargo +1.97.0 fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-engine --all-targets -- -D warningsare clean.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.