Skip to content

Make RetryState.isLastAttempt private, and simplify the code#1961

Open
stIncMale wants to merge 4 commits intomongodb:mainfrom
stIncMale:makeRetryStateIsLastAttemptPrivate
Open

Make RetryState.isLastAttempt private, and simplify the code#1961
stIncMale wants to merge 4 commits intomongodb:mainfrom
stIncMale:makeRetryStateIsLastAttemptPrivate

Conversation

@stIncMale
Copy link
Copy Markdown
Member

With the backpressure spec changes, it has become painfully obvious that the logic of restricting the number of retries based on either a fixed number of retries, or a CSOT exception, is business logic, and not the internal logic of RetryingSupplier/RetryState. Given that most of the business logic lives outside of RetryingSupplier/RetryState, the part about the limit will also be moved out. This PR, just like #1952, does the preliminary work.

JAVA-5956, JAVA-6117, JAVA-6113, JAVA-6119, JAVA-6141

JAVA-5956, JAVA-6117, JAVA-6113, JAVA-6119, JAVA-6141
@stIncMale stIncMale requested a review from vbabanin May 5, 2026 16:57
@stIncMale stIncMale self-assigned this May 5, 2026
@stIncMale stIncMale requested a review from Copilot May 5, 2026 18:51
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

private boolean isLastAttempt(final Throwable attemptException) {
boolean lastIteration = loopState.isLastIteration();
boolean operationTimeout = retryUntilTimeoutThrowsException && attemptException instanceof MongoOperationTimeoutException;
assertFalse(lastIteration && operationTimeout);
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.

breakAndThrowIfRetryAnd/breakAndCompleteIfRetryAnd can't cause both lastIteration and operationTimeout to be true. Therefore, technically, only markAsLastAttempt is capable of that. The latter is called only from MixedBulkWriteOperation, as the AI correctly identified, and only if MongoException happens. So it looks like lastIteration && operationTimeout may indeed happen. However, if it happens, then the iteration is marked as the last one because of the exception. Therefore, we should remove assertFalse(lastIteration && operationTimeout), but nothing else needs to be changed.

Done in 446312c. @vbabanin, you may want to look at this.

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 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread driver-core/src/main/com/mongodb/internal/async/function/RetryState.java Outdated
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 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@stIncMale stIncMale marked this pull request as ready for review May 5, 2026 23:40
@stIncMale stIncMale requested a review from a team as a code owner May 5, 2026 23:40
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