-
Notifications
You must be signed in to change notification settings - Fork 131
fix(udb): update backoff algo #3469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 11-12-chore_write_update_docs
Are you sure you want to change the base?
fix(udb): update backoff algo #3469
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 4 Skipped Deployments
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR Review: fix(udb): update backoff algoSummaryThis PR updates the transaction retry backoff algorithm to more closely align with FoundationDB's behavior. Overall, the changes look good and represent a significant improvement. Code Quality: ✅ GoodStrengths:
Suggestions:
Correctness: ✅ VerifiedAlgorithm Analysis: Old algorithm:
New algorithm:
The math checks out correctly:
Potential Issues:
|
9b19169 to
a0dfaaf
Compare
52bea63 to
ce30dce
Compare
Code Review: fix(udb): update backoff algoSummaryThis PR updates the transaction retry backoff algorithm in UniversalDB to better align with FoundationDB's behavior. Overall, this is a good improvement that makes the backoff more aggressive and consistent with FDB's design. ✅ Positive Changes
🐛 Potential IssuesCritical: Modulo bias in jitter calculationLocation: let jitter_ms = rand::random::<u64>() % base;Issue: Using modulo with Recommendation: Use a proper bounded random range: use rand::Rng;
let jitter_ms = rand::thread_rng().gen_range(0..base);This requires adding Minor: Inconsistency in test fileLocation: The test file has its own copy of // Instead of duplicating, import from the library
use universaldb::calculate_tx_retry_backoff;📊 Behavioral AnalysisOld algorithm:
New algorithm:
The new algorithm is:
🔒 Security ConsiderationsNo security concerns identified. 🧪 Test CoverageNo new tests were added. Consider adding a unit test to verify:
Example test: #[test]
fn test_backoff_algorithm() {
// Test specific attempts
assert_eq!(calculate_tx_retry_backoff(0), 10..=11);
assert_eq!(calculate_tx_retry_backoff(1), 20..=22);
// Test max cap
let backoff_7 = calculate_tx_retry_backoff(7);
let backoff_100 = calculate_tx_retry_backoff(100);
// Both should have same base (capped at 7)
assert!(backoff_7 >= 1280 && backoff_7 < 1408);
assert!(backoff_100 >= 1280 && backoff_100 < 1408);
}📝 RecommendationsRequired:
Optional: Overall Assessment✅ Approved with suggested fixes The core change is sound and improves the backoff algorithm. The modulo bias issue should be addressed before merging, and the test file inconsistency should be resolved. |
Code ReviewSummaryThis PR updates the exponential backoff algorithm for transaction retries in UniversalDB to better align with FoundationDB's implementation. The changes improve the retry behavior by capping the max backoff and adjusting the jitter calculation. Positive Changes ✅
Issues Found 🔍1. CRITICAL: Outdated duplicate function in testsLocation: There's a duplicate pub fn calculate_tx_retry_backoff(attempt: usize) -> u64 {
let base_backoff_ms = 2_u64.pow((attempt as u32).min(10)) * 10;
let jitter_ms = rand::random::<u64>() % 100;
base_backoff_ms + jitter_ms
}Action required: This duplicate should be removed and the test should import from 2. Potential arithmetic issue in jitter calculationLocation: The jitter calculation
The comment says "0-10% of backoff ms" but the actual range is 0 to (base-1)ms, which is slightly less than 10% of Suggested fix: // Jitter is 0-10% of backoff ms
let jitter_ms = rand::random::<u64>() % (base_backoff_ms / 10 + 1);This would give:
Which matches the documentation exactly. 3. Missing unit testsThere don't appear to be any unit tests specifically for
Suggested test: #[test]
fn test_tx_retry_backoff() {
// Test base values without jitter (by checking range)
for attempt in 0..10 {
let backoff = calculate_tx_retry_backoff(attempt);
let expected_base = 2_u64.pow((attempt as u32).min(7)) * 10;
let max_jitter = 2_u64.pow((attempt as u32).min(7));
assert!(backoff >= expected_base);
assert!(backoff < expected_base + max_jitter);
}
// Verify max cap
assert!(calculate_tx_retry_backoff(7) < 1500); // Should be ~1280ms + jitter
assert!(calculate_tx_retry_backoff(100) < 1500); // Should still be capped
}Minor Suggestions 💡
Security Considerations 🔒No security concerns identified. The backoff algorithm is appropriate for preventing retry storms. Performance Considerations ⚡The changes improve performance by reducing max backoff from ~10s to ~1.28s, allowing faster recovery from transient conflicts. VerdictGood improvement to align with FDB behavior, but needs the test duplicate removed and the jitter calculation fixed to match the documentation. Consider adding unit tests for this critical function. 🤖 Generated with Claude Code |

No description provided.