Skip to content

Simplify RetryState creation#1967

Open
stIncMale wants to merge 1 commit intomongodb:mainfrom
stIncMale:refactorRetryStateConstruction
Open

Simplify RetryState creation#1967
stIncMale wants to merge 1 commit intomongodb:mainfrom
stIncMale:refactorRetryStateConstruction

Conversation

@stIncMale
Copy link
Copy Markdown
Member

@stIncMale stIncMale commented May 7, 2026

  • RetryState.retryUntilTimeoutThrowsException was useless, so I removed it.
  • The logic that limits the number of retries is going to be removed from 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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RetryState to use RetryState() / 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 TimeoutContext parameter.
  • Updated unit tests to construct RetryState directly instead of building TimeoutContext/TimeoutSettings fixtures.

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.

Comment thread driver-core/src/test/unit/com/mongodb/internal/async/function/RetryStateTest.java Outdated
JAVA-5956, JAVA-6117, JAVA-6113, JAVA-6119, JAVA-6141
@stIncMale stIncMale force-pushed the refactorRetryStateConstruction branch from 75434a1 to cc5dba2 Compare May 7, 2026 23:24
@stIncMale stIncMale requested a review from Copilot May 7, 2026 23:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@stIncMale stIncMale marked this pull request as ready for review May 7, 2026 23:47
@stIncMale stIncMale requested a review from a team as a code owner May 7, 2026 23:47
@stIncMale stIncMale requested a review from rozza May 7, 2026 23:47
@codeowners-service-app
Copy link
Copy Markdown

Assigned atandon2024 for team dbx-java because rozza is out of office.

@stIncMale stIncMale requested review from vbabanin and removed request for atandon2024 and rozza May 7, 2026 23:48
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;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the limit is called in client-backpressure.md, so I renamed the constant.

Comment on lines -90 to -95
public RetryingAsyncCallbackSupplier(
final RetryState state,
final BiPredicate<RetryState, Throwable> retryPredicate,
final AsyncCallbackSupplier<R> asyncFunction) {
this(state, (previouslyChosenFailure, lastAttemptFailure) -> lastAttemptFailure, retryPredicate, asyncFunction);
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor was used only once, was not documented, and as far as I can tell, wasn't really making anything clearer or simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants