Skip to content

Commit 52bb622

Browse files
committed
Fix how ClientBulkWriteOperation.ClientBulkWriteCommand.OpsAndNsInfo.encode determines if a server response is required
JAVA-5529
1 parent e2aaa2a commit 52bb622

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

driver-core/src/main/com/mongodb/internal/operation/ClientBulkWriteOperation.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ public EncodeResult encode(final WritersProviderAndLimitsChecker writersProvider
718718
LinkedHashMap<MongoNamespace, Integer> indexedNamespaces = new LinkedHashMap<>();
719719
WritersProviderAndLimitsChecker.WriteResult writeResult = OK_LIMIT_NOT_REACHED;
720720
boolean commandIsRetryable = effectiveRetryWrites;
721-
int modelIndexInBatch = 0;
722-
for (; modelIndexInBatch < models.size() && writeResult == OK_LIMIT_NOT_REACHED; modelIndexInBatch++) {
721+
int maxModelIndexInBatch = -1;
722+
for (int modelIndexInBatch = 0; modelIndexInBatch < models.size() && writeResult == OK_LIMIT_NOT_REACHED; modelIndexInBatch++) {
723723
AbstractClientNamespacedWriteModel namespacedModel = getNamespacedModel(models, modelIndexInBatch);
724724
MongoNamespace namespace = namespacedModel.getNamespace();
725725
int indexedNamespacesSizeBeforeCompute = indexedNamespaces.size();
@@ -737,14 +737,16 @@ public EncodeResult encode(final WritersProviderAndLimitsChecker writersProvider
737737
});
738738
if (writeResult == FAIL_LIMIT_EXCEEDED) {
739739
batchEncoder.reset(finalModelIndexInBatch);
740-
modelIndexInBatch--;
741-
} else if (commandIsRetryable && doesNotSupportRetries(namespacedModel)) {
742-
commandIsRetryable = false;
743-
logWriteModelDoesNotSupportRetries();
740+
} else {
741+
maxModelIndexInBatch = finalModelIndexInBatch;
742+
if (commandIsRetryable && doesNotSupportRetries(namespacedModel)) {
743+
commandIsRetryable = false;
744+
logWriteModelDoesNotSupportRetries();
745+
}
744746
}
745747
}
746748
return new EncodeResult(
747-
options.isOrdered() && modelIndexInBatch < models.size() - 1,
749+
options.isOrdered() && maxModelIndexInBatch < models.size() - 1,
748750
commandIsRetryable ? doIfCommandIsRetryableAndAdvanceGetTxnNumber.get() : null);
749751
}
750752

0 commit comments

Comments
 (0)