@@ -718,8 +718,8 @@ public EncodeResult encode(final WritersProviderAndLimitsChecker writersProvider
718
718
LinkedHashMap <MongoNamespace , Integer > indexedNamespaces = new LinkedHashMap <>();
719
719
WritersProviderAndLimitsChecker .WriteResult writeResult = OK_LIMIT_NOT_REACHED ;
720
720
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 ++) {
723
723
AbstractClientNamespacedWriteModel namespacedModel = getNamespacedModel (models , modelIndexInBatch );
724
724
MongoNamespace namespace = namespacedModel .getNamespace ();
725
725
int indexedNamespacesSizeBeforeCompute = indexedNamespaces .size ();
@@ -737,14 +737,16 @@ public EncodeResult encode(final WritersProviderAndLimitsChecker writersProvider
737
737
});
738
738
if (writeResult == FAIL_LIMIT_EXCEEDED ) {
739
739
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
+ }
744
746
}
745
747
}
746
748
return new EncodeResult (
747
- options .isOrdered () && modelIndexInBatch < models .size () - 1 ,
749
+ options .isOrdered () && maxModelIndexInBatch < models .size () - 1 ,
748
750
commandIsRetryable ? doIfCommandIsRetryableAndAdvanceGetTxnNumber .get () : null );
749
751
}
750
752
0 commit comments