Skip to content

Implement Java sync improved bulk write API and unified spec tests #1486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 76 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
48b9614
Create and document Java sync improved bulk write API
stIncMale Jul 23, 2024
af854ed
Remove the type parameter from `ClientWriteModel`
stIncMale Jul 23, 2024
1eb7466
Remove `ClientBulkWriteException.create` as we can get by with the co…
stIncMale Jul 25, 2024
5567324
Merge branch 'master' into JAVA-5527
stIncMale Jul 27, 2024
644d561
Merge branch 'master' into JAVA-5527
stIncMale Aug 13, 2024
f566303
Do minor improvements
stIncMale Aug 15, 2024
3d13ffd
Make changes needed for the implementation
stIncMale Aug 15, 2024
cf46b46
Fix formatting in ClientUpdateManyModel
stIncMale Aug 15, 2024
e049234
Make a few minor changes
stIncMale Aug 15, 2024
0e16427
Merge branch 'master' into JAVA-5527
stIncMale Aug 15, 2024
0d518d8
Add more info to the API docs, add `ClientWriteModel` subtypes
stIncMale Aug 22, 2024
6b77f78
Add `ClientWriteModelWithNamespace`
stIncMale Aug 22, 2024
2ed8e87
Implement
stIncMale Aug 8, 2024
07bac95
Sync spec tests
stIncMale Aug 15, 2024
16f100b
Implement required test runner changes
stIncMale Aug 15, 2024
9f8ce2c
Improve how `indexedNamespaces` are computed
stIncMale Aug 22, 2024
fdb90d2
Remove `throws` declarations from the API
stIncMale Aug 22, 2024
39386fe
Make wording on `ClientWriteModel` methods consistent with that on `C…
stIncMale Aug 22, 2024
f67af3f
Move constructor methods to `ClientNamespacedWriteModel`
stIncMale Aug 22, 2024
53f6883
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Aug 22, 2024
9a7b668
Fix errors caused by the merge
stIncMale Aug 22, 2024
395af7a
Use `Optional` to express verbose/summary results
stIncMale Aug 22, 2024
8f504b0
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Aug 22, 2024
b02a638
Fix errors caused by the merge
stIncMale Aug 22, 2024
a11e5f6
Make an API doc improvement
stIncMale Aug 27, 2024
bfbc1cc
Refactor `shouldAttemptToRetryWriteAndAddRetryableLabel`
stIncMale Aug 27, 2024
1c3c590
Improve `CrudProseTest.insertMustGenerateIdAtMostOnce`
stIncMale Aug 27, 2024
1c9c19e
Move `MixedBulkWriteOperation.validateAndGetEffectiveWriteConcern`/`c…
stIncMale Aug 27, 2024
061e605
Add a comment in `toClientNamespacedWriteModel`
stIncMale Aug 27, 2024
8320216
Use `CommandResultDocumentCodec` in `ClientBulkWriteOperation`
stIncMale Aug 28, 2024
f41ed59
Use `Integer` for indexes in `ClientBulkWriteResult.Verbose`. Make `C…
stIncMale Aug 28, 2024
4846e0b
Use `Integer` for indexes in `ClientBulkWriteException`.
stIncMale Aug 28, 2024
dbf9a26
Take `ClientBulkWriteException` into account in `OperationExecutor.ex…
stIncMale Aug 28, 2024
a0005cd
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Aug 28, 2024
35eee96
Fixes after the merge
stIncMale Aug 28, 2024
21bb22e
Make `ClientInsertOneResult.getInsertedId` return `Optional`
stIncMale Aug 28, 2024
182b2f9
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Aug 28, 2024
fb32fde
Fixes after the merge
stIncMale Aug 28, 2024
f026ee3
Update the documentation of `ClientBulkWriteException` and remove a TODO
stIncMale Aug 28, 2024
7372f13
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Aug 28, 2024
0fb65d4
Synchronize unified tests with https://github.com/mongodb/specificati…
stIncMale Aug 29, 2024
e36898f
Refactor `CrudProseTest` to support the reactive client
stIncMale Aug 29, 2024
70bb422
Add methods for all prose tests. Where possible, implement them
stIncMale Aug 30, 2024
3584de5
Move results to `com.mongodb.client.model.bulk`
stIncMale Aug 30, 2024
5a17ea0
Merge branch 'master' into JAVA-5527
stIncMale Aug 30, 2024
8e1d770
Move internal results to `com.mongodb.internal.client.model.bulk`
stIncMale Aug 30, 2024
e973615
Document that `bulkWrite` is not supported by serverless instances
stIncMale Aug 30, 2024
33ec764
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Aug 30, 2024
ee893f2
Fixes after the merge
stIncMale Aug 30, 2024
e33f592
Add subtypes of `ClientNamespacedWriteModel` and hide `ClientWriteModel`
stIncMale Sep 3, 2024
f94ad58
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Sep 3, 2024
310426a
Fixes after the merge
stIncMale Sep 3, 2024
301a2ba
Remove a garbage comment
stIncMale Sep 3, 2024
1a57fb6
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Sep 3, 2024
6f01e61
Replace `ConcreteClientNamespacedWriteModel` with multiple more speci…
stIncMale Sep 9, 2024
c3224e9
Rearrange `ClientWriteModel` inheritance: "one" should extend "many",…
stIncMale Sep 9, 2024
c057390
Make internal `AbstractClientNamespacedWriteModel` public
stIncMale Sep 9, 2024
dbb6ec8
Rearrange `ClientWriteModel` inheritance: neither "one" nor "many" sh…
stIncMale Sep 9, 2024
cb11c44
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Sep 9, 2024
8bd7a6a
Fixes after the merge
stIncMale Sep 9, 2024
f781bca
Make internal `AbstractClientUpdateModel`, `AbstractClientDeleteModel…
stIncMale Sep 9, 2024
ec88c02
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Sep 9, 2024
14bb86e
Improve code comments in `ClientBulkWriteOperation`
stIncMale Sep 10, 2024
f186b31
Fix `server-selection/logging/operation-id.json:Failed client bulkWri…
stIncMale Sep 16, 2024
3442a73
Rename an incorrectly named variable
stIncMale Sep 17, 2024
3fc86bb
Stop linking to `Filters` from the documentation of `ClientNamespaced…
stIncMale Sep 17, 2024
86e5234
Update driver-core/src/main/com/mongodb/client/model/bulk/ClientBulkW…
stIncMale Sep 18, 2024
fb134f8
Update driver-core/src/main/com/mongodb/client/model/bulk/ClientDelet…
stIncMale Sep 18, 2024
a4bf4d0
Fix typos in API docs
stIncMale Sep 18, 2024
2837235
Change code to always refer to `ClientBulkWriteResult.Verbose` with t…
stIncMale Sep 18, 2024
b6702a6
Rename `ClientBulkWriteResult.Verbose` to `ClientBulkWriteResult.Verb…
stIncMale Sep 23, 2024
24ce6db
Improve partial result API documentation wording
stIncMale Sep 24, 2024
ca5d19a
Merge branch 'JAVA-5527' into JAVA-5528
stIncMale Sep 24, 2024
6d8a3e6
Fixes after the merge
stIncMale Sep 24, 2024
076d39a
Merge branch 'master' into JAVA-5528
stIncMale Sep 24, 2024
6b2b7a8
Merge branch 'JAVA-4586_bulk-write' into JAVA-5528
stIncMale Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion driver-core/src/main/com/mongodb/ClientBulkWriteException.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Optional;

import static com.mongodb.assertions.Assertions.isTrueArgument;
import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.internal.operation.ClientBulkWriteOperation.Exceptions.serverAddressFromException;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableList;
Expand Down Expand Up @@ -58,14 +60,20 @@ public final class ClientBulkWriteException extends MongoServerException {
* @param writeErrors The {@linkplain #getWriteErrors() write errors}.
* @param partialResult The {@linkplain #getPartialResult() partial result}.
* @param serverAddress The {@linkplain MongoServerException#getServerAddress() server address}.
* If {@code error} is a {@link MongoServerException} or a {@link MongoSocketException}, then {@code serverAddress}
* must be equal to the {@link ServerAddress} they bear.
*/
public ClientBulkWriteException(
@Nullable final MongoException error,
@Nullable final List<WriteConcernError> writeConcernErrors,
@Nullable final Map<Integer, WriteError> writeErrors,
@Nullable final ClientBulkWriteResult partialResult,
final ServerAddress serverAddress) {
super(message(error, writeConcernErrors, writeErrors, partialResult, serverAddress), serverAddress);
super(
message(
error, writeConcernErrors, writeErrors, partialResult,
notNull("serverAddress", serverAddress)),
validateServerAddress(error, serverAddress));
isTrueArgument("At least one of `writeConcernErrors`, `writeErrors`, `partialResult` must be non-null or non-empty",
!(writeConcernErrors == null || writeConcernErrors.isEmpty())
|| !(writeErrors == null || writeErrors.isEmpty())
Expand All @@ -89,6 +97,14 @@ private static String message(
+ (partialResult == null ? "" : " Partial result: " + partialResult + ".");
}

private static ServerAddress validateServerAddress(@Nullable final MongoException error, final ServerAddress serverAddress) {
serverAddressFromException(error).ifPresent(serverAddressFromError ->
isTrueArgument("`serverAddress` must be equal to that of the `error`", serverAddressFromError.equals(serverAddress)));
return error instanceof MongoServerException
? ((MongoServerException) error).getServerAddress()
: serverAddress;
}

/**
* The top-level error. That is an error that is neither a {@linkplain #getWriteConcernErrors() write concern error},
* nor is an {@linkplain #getWriteErrors() error of an individual write operation}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static <R> AsyncCallbackSupplier<R> decorateReadWithRetriesAsync(final RetryStat
static <R> AsyncCallbackSupplier<R> decorateWriteWithRetriesAsync(final RetryState retryState, final OperationContext operationContext,
final AsyncCallbackSupplier<R> asyncWriteFunction) {
return new RetryingAsyncCallbackSupplier<>(retryState, onRetryableWriteAttemptFailure(operationContext),
CommandOperationHelper::shouldAttemptToRetryWrite, callback -> {
CommandOperationHelper::loggingShouldAttemptToRetryWriteAndAddRetryableLabel, callback -> {
logRetryExecute(retryState, operationContext);
asyncWriteFunction.get(callback);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import static com.mongodb.internal.bulk.WriteRequest.Type.REPLACE;
import static com.mongodb.internal.bulk.WriteRequest.Type.UPDATE;
import static com.mongodb.internal.operation.DocumentHelper.putIfNotNull;
import static com.mongodb.internal.operation.MixedBulkWriteOperation.commandWriteConcern;
import static com.mongodb.internal.operation.CommandOperationHelper.commandWriteConcern;
import static com.mongodb.internal.operation.OperationHelper.LOGGER;
import static com.mongodb.internal.operation.OperationHelper.isRetryableWrite;
import static com.mongodb.internal.operation.WriteConcernHelper.createWriteConcernError;
Expand Down Expand Up @@ -111,7 +111,7 @@ static BulkWriteBatch createBulkWriteBatch(final MongoNamespace namespace,
}
if (canRetryWrites && !writeRequestsAreRetryable) {
canRetryWrites = false;
LOGGER.debug("retryWrites set but one or more writeRequests do not support retryable writes");
logWriteModelDoesNotSupportRetries();
}
return new BulkWriteBatch(namespace, connectionDescription, ordered, writeConcern, bypassDocumentValidation,
canRetryWrites, new BulkWriteBatchCombiner(connectionDescription.getServerAddress(), ordered, writeConcern),
Expand Down Expand Up @@ -385,4 +385,8 @@ private static boolean isRetryable(final WriteRequest writeRequest) {
}
return true;
}

static void logWriteModelDoesNotSupportRetries() {
LOGGER.debug("retryWrites set but one or more writeRequests do not support retryable writes");
}
}
Loading