Simplify RetryState creation#1967
Conversation
There was a problem hiding this comment.
Pull request overview
This PR simplifies internal retry-state wiring by removing TimeoutContext-dependent RetryState construction and updating callers/tests to use the new constructors and constants.
Changes:
- Refactored
RetryStateto useRetryState()/RetryState(int)and renamed retry constants (e.g.,MAX_RETRIES). - Updated retry initialization in command/bulk write operations and adjusted retry-loop helpers to no longer require a
TimeoutContextparameter. - Updated unit tests to construct
RetryStatedirectly instead of buildingTimeoutContext/TimeoutSettingsfixtures.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| driver-core/src/main/com/mongodb/internal/async/function/RetryState.java | Simplifies construction and retry constant naming; adjusts last-attempt detection logic. |
| driver-core/src/main/com/mongodb/internal/async/AsyncRunnable.java | Changes thenRunRetryingWhile signature to drop TimeoutContext and uses default RetryState. |
| driver-core/src/main/com/mongodb/internal/operation/CommandOperationHelper.java | Updates initial retry-state creation to use new RetryState constructors and MAX_RETRIES. |
| driver-core/src/main/com/mongodb/internal/operation/MixedBulkWriteOperation.java | Switches bulk write retry-state creation to new RetryState() and updates retry constant usage. |
| driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java | Updates retry loop invocation to match the new thenRunRetryingWhile signature. |
| driver-core/src/test/unit/com/mongodb/internal/async/AsyncFunctionsAbstractTest.java | Updates retry loop test usage to match the new thenRunRetryingWhile signature. |
| driver-core/src/test/unit/com/mongodb/internal/async/function/RetryStateTest.java | Removes TimeoutContext fixtures and constructs RetryState directly for parameterized coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
JAVA-5956, JAVA-6117, JAVA-6113, JAVA-6119, JAVA-6141
75434a1 to
cc5dba2
Compare
|
Assigned |
| public final class RetryState { | ||
| public static final int RETRIES = 1; | ||
| public static final int INFINITE_ATTEMPTS = Integer.MAX_VALUE; | ||
| public static final int MAX_RETRIES = 1; |
There was a problem hiding this comment.
This is how the limit is called in client-backpressure.md, so I renamed the constant.
| public RetryingAsyncCallbackSupplier( | ||
| final RetryState state, | ||
| final BiPredicate<RetryState, Throwable> retryPredicate, | ||
| final AsyncCallbackSupplier<R> asyncFunction) { | ||
| this(state, (previouslyChosenFailure, lastAttemptFailure) -> lastAttemptFailure, retryPredicate, asyncFunction); | ||
| } |
There was a problem hiding this comment.
This constructor was used only once, was not documented, and as far as I can tell, wasn't really making anything clearer or simpler.
RetryState.retryUntilTimeoutThrowsExceptionwas useless, so I removed it.RetryState, so I need to simplify how it is created, to make that future change simpler.AI usage
All changes were done by hand, AI (Claude + Sonnet 4.6, Copilot) was used only to review: found 6 issues, 4 were useful.
JAVA-5956, JAVA-6117, JAVA-6113, JAVA-6119, JAVA-6141