JAVA-5950 Update Transactions Convenient API with exponential backoff on retries#1899
Open
nhachicha wants to merge 73 commits intomongodb:backpressurefrom
Open
JAVA-5950 Update Transactions Convenient API with exponential backoff on retries#1899nhachicha wants to merge 73 commits intomongodb:backpressurefrom
nhachicha wants to merge 73 commits intomongodb:backpressurefrom
Conversation
…Impl.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s exceeded (ex operationContext.getTimeoutContext().getReadTimeoutMS())
…tionProseTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…tionProseTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…tionProseTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…tionProseTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…tionProseTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…tionProseTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…tionProseTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4 tasks
UnknownTransactionCommitResult is retriable in the commit loop if we don't exceed the timeout, so it makes sense to wrap it into a Timeout error if we exceed the timeout and want to throw and return (as described in section 10.1.1)
…re_convenient_api
Member
|
I updated the PR description with the information about DRIVERS-3436 and the JAVA-6160 which the former split into. |
stIncMale
added a commit
to stIncMale/mongo-java-driver
that referenced
this pull request
Apr 15, 2026
I manually copied it from mongodb#1899.
Add a dedicated MongoClientException subtype thrown when the convenient transactions API exceeds its overall timeout, replacing the generic MongoTimeoutException wrap in ClientSessionImpl.
stIncMale
requested changes
Apr 20, 2026
… to the @mongodb.driver.manual taglet. - Narrow wrapInMongoTimeoutException and wrapInNonTimeoutMsMongoTimeoutException return types from MongoException to MongoClientException.
vbabanin
reviewed
Apr 23, 2026
…Impl.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
…lBackoffTest.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
…lBackoffTest.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
…entSideOperationsTimeoutProseTest.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
…lBackoffTest.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
…Impl.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
vbabanin
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original PR accidentally closed #1852, it has outstanding review comments for @stIncMale to go over when re-reviewing.
Relevant specification changes:
JAVA-5950, JAVA-6046, (JAVA-6093, JAVA-6160), JAVA-6113 (only the part about
transactions-convenient-api)AI usage and effectiveness
Implementation (Sonnet/Opus 4.6): Partially AI-generated but went through many rounds of manual modifications. Tests were AI-generated based on the spec prose test descriptions, then reviewed and adjusted
It did identify a potential spec divergence: the implementation wraps non-labeled errors in MongoTimeoutException, which later resulted in a discussion during catch-up and https://jira.mongodb.org/browse/DRIVERS-3436
Copilot review 2/13 actionable (both minor nits) see details
Review generated by Claude Opus 4.6 as of commit `4a3d1ae1` on 2026-04-01.
Findings Table — Diff-Only Review vs. PR Context
testJitterSupplierstatic field — data race risk across threadsvolatileat minimum.Thread.sleep(backoffMs)may overshoot remaining timeoutshortenBy(...).onExpired(...)checks before sleeping; next iteration fails fast if expired. Overshoot bounded byclearTransactionContextOnError(e)call removedcommitTransactioncalls it internally; the outer call was redundant.CommandOperationHelper+ constantscom.mongodb.internalis internal by definition. Enables cross-package dedup.@VisibleForTestingontimeoutOrAlternative60acf51d).TRANSACTION_MAX_MSpackage-private; hardcoded expected values in testEXPECTED_BACKOFFS_MAX_VALUES.length(adopted). Hardcoded array is anbackpressure→mainmerge. Blocked on docs PR.testRetryBackoffIsEnforcedwall-clock timing sensitivitysetTestJitterSupplier. 500ms tolerance. Spec-mandated prose test.copyTimeoutContext()— verify no other callersSummary: 4 false positives, 2 resolved, 1 valid+intentional, 1 tracked, 1 accepted, 1 minor nit.
Additional Findings from PR Reviewers (not caught in diff-only review)
calculateTransactionBackoffMsJavadoc said 0-based but implementation is 1-basedMongoTimeoutExceptiond4bc4c70)applyMajorityWriteConcernToTransactionOptionscalled on outer retry60acf51d)withTransactioncode structure doesn't follow spec algorithm ordering60acf51d)mainupdated separatelyMongoTimeoutExceptionmessage inconsistency (missing period)timeoutOrAlternativeremoval +timeoutMsConfiguredrenaming60acf51d)Remaining Issues to Address
testJitterSuppliershould bevolatile— mutable static read/written across threads without memory visibility guaranteeExponentialBackoff.java|
| 2 | Spec "Note 1" about error propagation needs rework — spec language around propagation/raising is inconsistent | Medium | Spec-side | Open — spec change needed | DRIVERS-3436 |
| 3 |
TODO-BACKPRESSUREcomments in production code — must be resolved before mergingbackpressure→main| Low |MongoException.java,ExponentialBackoff.java| Open — blocked on docs PR(10gen/docs-mongodb-internal#17281) | Implicit |
| 4 | Spec submodule not pointing to latest spec tests — new
transactions-convenient-apiJSON tests not included | Medium |testing/resources/specifications(submodule) | Open —mainupdated(
55e1861) but not merged intobackpressure| TODO-BACKPRESSURE || 5 | Verify spec test
withTransaction surfaces a timeout after exhausting transient transaction retriesis run | Medium | Test runner config | Open — reminder in PR comments | — || 6 | Verify prose tests assert all error labels are copied to wrapping exception | Medium |
WithTransactionProseTest.java| Partially addressed — labels copied in code, test coverage completeness notconfirmed | — |
| 7 | OTel tracing terminology inconsistency (
finalizevsfinishvsstop) | Low (orthogonal) |ClientSessionImpl.javatracing code | Open — no ticket yet | — |Priority Summary
backpressure: Items 5, 6main: Items 3 (TODOs), 4 (submodule)What Looks Good
ClientSessionClocksingleton withSystemNanoTime+ Mockito is a significant test infrastructure improvementExponentialBackoffTesthas good coverage of boundary conditions (jitter=0, jitter=1, cap enforcement)backpressure: truehandshake flag is a clean protocol extensionabortIfInTransaction()extraction reduces duplication and improves claritywithTransaction(60acf51d) now aligns the code with the spec algorithm, making correctness easier to verifytestRetryBackoffIsEnforced,testExponentialBackoffOnTransientError) provide functional validation of backoff behavior