Skip to content

Refactor MixedBulkWriteOperation to simplify retry logic there#1989

Open
stIncMale wants to merge 7 commits into
mongodb:backpressurefrom
stIncMale:refactorRetriesInMixedBulkWrite
Open

Refactor MixedBulkWriteOperation to simplify retry logic there#1989
stIncMale wants to merge 7 commits into
mongodb:backpressurefrom
stIncMale:refactorRetriesInMixedBulkWrite

Conversation

@stIncMale
Copy link
Copy Markdown
Member

@stIncMale stIncMale commented May 28, 2026

For reviewers

I recommend reviewing the changes commit by commit. Review the sync code changes to assess the correctness compared to the pre-PR code. Then review the async code changes to assess whether the sync code was correctly translated into the async code.

AI usage

All the changes were handmade. AI was used only to review the changes.

JAVA-6218

stIncMale added 7 commits May 27, 2026 17:39
…addRetryableLabelOrGetWriteAttemptFailureNotToBeRetried`

JAVA-6218
- Make the parameter order of `SyncOperationHelper.withSourceAndConnection` consistent with `AsyncOperationHelper.withAsyncSourceAndConnection`.
- Remove `throws` from `AsyncOperationHelper.withAsyncSourceAndConnection`/`withAsyncSuppliedResource`.

JAVA-6218
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 refactors MixedBulkWriteOperation retry handling to use per-batch RetryState instances and shared retry helpers, while updating related helper APIs, tests, and async control-flow conventions.

Changes:

  • Reworks mixed bulk write sync/async retry flow and removes the custom bulk-write retry tracker.
  • Updates shared retry/helper APIs and callers for source/connection handling and retry failure bookkeeping.
  • Adjusts functional/unit tests and shared test utilities to reflect the new retry/resource lifecycle.

Reviewed changes

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

Show a summary per file
File Description
driver-core/src/main/com/mongodb/internal/operation/MixedBulkWriteOperation.java Refactors bulk write batching, retry, async execution, and resource holder logic.
driver-core/src/main/com/mongodb/internal/operation/SyncOperationHelper.java Reorders withSourceAndConnection parameters and updates retry failure handling.
driver-core/src/main/com/mongodb/internal/operation/AsyncOperationHelper.java Updates async retry failure handling and helper signatures.
driver-core/src/main/com/mongodb/internal/operation/CommandOperationHelper.java Renames retry-label helper and passes server deprioritization directly.
driver-core/src/main/com/mongodb/internal/operation/ClientBulkWriteOperation.java Aligns helper usage and async control flow with the refactored retry helpers.
driver-core/src/main/com/mongodb/internal/operation/retry/AttachmentKeys.java Removes obsolete bulk write tracker attachment key.
driver-core/src/main/com/mongodb/internal/async/function/RetryState.java Removes external last-attempt marking API.
driver-core/src/main/com/mongodb/internal/async/AsyncRunnable.java Documents MutableValue usage in async lambdas.
driver-core/src/main/com/mongodb/internal/operation/FindOperation.java Updates withSourceAndConnection call signature.
driver-core/src/main/com/mongodb/internal/operation/ListCollectionsOperation.java Updates withSourceAndConnection call signature.
driver-core/src/main/com/mongodb/internal/operation/ListIndexesOperation.java Updates withSourceAndConnection call signature.
driver-core/src/test/functional/com/mongodb/OperationFunctionalSpecification.groovy Adds configurable expected connection release counts.
driver-core/src/test/functional/com/mongodb/internal/operation/MixedBulkWriteOperationSpecification.groovy Updates mixed bulk write retry expectations.
driver-core/src/test/unit/com/mongodb/internal/async/function/RetryStateTest.java Removes tests for deleted markAsLastAttempt.
driver-sync/src/test/functional/com/mongodb/client/MongoWriteConcernWithResponseExceptionTest.java Refactors test for sync/reactive reuse and failpoint listener utility.
driver-sync/src/test/functional/com/mongodb/client/FailPoint.java Makes failpoint guard close idempotent.
driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/MongoWriteConcernWithResponseExceptionTest.java Reuses sync test through reactive sync adapter override.

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

@stIncMale
Copy link
Copy Markdown
Member Author

The code is so good that Copilot failed to find anything! 💪 😃

@stIncMale stIncMale requested a review from vbabanin May 28, 2026 21:55
@stIncMale stIncMale marked this pull request as ready for review May 28, 2026 21:55
@stIncMale stIncMale requested a review from a team as a code owner May 28, 2026 21:55
getWriteAttemptFailureNotToBeRetriedOrAddRetryableLabel(retryState, mongoException);
resultAccumulator.onBulkWriteCommandErrorWithoutResponse(mongoException);
if (retryWritesSetting) {
// Adding the `RetryableError` label here is unnecessary at this point:
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.

@stIncMale TODO Change to RetryableWriteError. Search for other occurrences in this PR.

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