112
112
import static com .mongodb .assertions .Assertions .fail ;
113
113
import static com .mongodb .internal .VisibleForTesting .AccessModifier .PACKAGE ;
114
114
import static com .mongodb .internal .VisibleForTesting .AccessModifier .PRIVATE ;
115
- import static com .mongodb .internal .connection .BsonWriterHelper .decorateWithDocumentSizeChecking ;
116
115
import static com .mongodb .internal .connection .DualMessageSequences .WritersProviderAndLimitsChecker .WriteResult .FAIL_LIMIT_EXCEEDED ;
117
116
import static com .mongodb .internal .connection .DualMessageSequences .WritersProviderAndLimitsChecker .WriteResult .OK_LIMIT_NOT_REACHED ;
118
117
import static com .mongodb .internal .operation .BulkWriteBatch .logWriteModelDoesNotSupportRetries ;
@@ -234,8 +233,7 @@ private Integer executeBatch(
234
233
retryState .attach (AttachmentKeys .maxWireVersion (), connectionDescription .getMaxWireVersion (), true )
235
234
.attach (AttachmentKeys .commandDescriptionSupplier (), () -> BULK_WRITE_COMMAND_NAME , false );
236
235
ClientBulkWriteCommand bulkWriteCommand = createBulkWriteCommand (
237
- retryState , effectiveRetryWrites , effectiveWriteConcern , sessionContext , unexecutedModels ,
238
- connectionDescription .getMaxDocumentSize (), batchEncoder ,
236
+ retryState , effectiveRetryWrites , effectiveWriteConcern , sessionContext , unexecutedModels , batchEncoder ,
239
237
() -> retryState .attach (AttachmentKeys .retryableCommandFlag (), true , true ));
240
238
return executeBulkWriteCommandAndExhaustOkResponse (
241
239
retryState , connectionSource , connection , bulkWriteCommand , effectiveWriteConcern , operationContext );
@@ -342,7 +340,6 @@ private ClientBulkWriteCommand createBulkWriteCommand(
342
340
final WriteConcern effectiveWriteConcern ,
343
341
final SessionContext sessionContext ,
344
342
final List <? extends ClientNamespacedWriteModel > unexecutedModels ,
345
- final int maxStoredDocumentSize ,
346
343
final BatchEncoder batchEncoder ,
347
344
final Runnable retriesEnabler ) {
348
345
BsonDocument commandDocument = new BsonDocument (BULK_WRITE_COMMAND_NAME , new BsonInt32 (1 ))
@@ -360,8 +357,6 @@ private ClientBulkWriteCommand createBulkWriteCommand(
360
357
commandDocument ,
361
358
new ClientBulkWriteCommand .OpsAndNsInfo (
362
359
effectiveRetryWrites , unexecutedModels ,
363
- // we must validate the size only if no response is expected, otherwise we must rely on the server validation
364
- effectiveWriteConcern .isAcknowledged () ? null : maxStoredDocumentSize ,
365
360
batchEncoder ,
366
361
options ,
367
362
() -> {
@@ -679,8 +674,6 @@ OpsAndNsInfo getOpsAndNsInfo() {
679
674
public static final class OpsAndNsInfo extends DualMessageSequences {
680
675
private final boolean effectiveRetryWrites ;
681
676
private final List <? extends ClientNamespacedWriteModel > models ;
682
- @ Nullable
683
- private final Integer maxStoredDocumentSize ;
684
677
private final BatchEncoder batchEncoder ;
685
678
private final ConcreteClientBulkWriteOptions options ;
686
679
private final Supplier <Long > doIfCommandIsRetryableAndAdvanceGetTxnNumber ;
@@ -689,14 +682,12 @@ public static final class OpsAndNsInfo extends DualMessageSequences {
689
682
public OpsAndNsInfo (
690
683
final boolean effectiveRetryWrites ,
691
684
final List <? extends ClientNamespacedWriteModel > models ,
692
- @ Nullable final Integer maxStoredDocumentSize ,
693
685
final BatchEncoder batchEncoder ,
694
686
final ConcreteClientBulkWriteOptions options ,
695
687
final Supplier <Long > doIfCommandIsRetryableAndAdvanceGetTxnNumber ) {
696
688
super ("ops" , new OpsFieldNameValidator (models ), "nsInfo" , NoOpFieldNameValidator .INSTANCE );
697
689
this .effectiveRetryWrites = effectiveRetryWrites ;
698
690
this .models = models ;
699
- this .maxStoredDocumentSize = maxStoredDocumentSize ;
700
691
this .batchEncoder = batchEncoder ;
701
692
this .options = options ;
702
693
this .doIfCommandIsRetryableAndAdvanceGetTxnNumber = doIfCommandIsRetryableAndAdvanceGetTxnNumber ;
@@ -720,8 +711,7 @@ public EncodeDocumentsResult encodeDocuments(final WritersProviderAndLimitsCheck
720
711
boolean writeNewNamespace = indexedNamespaces .size () != indexedNamespacesSizeBeforeCompute ;
721
712
int finalModelIndexInBatch = modelIndexInBatch ;
722
713
writeResult = writersProviderAndLimitsChecker .tryWrite ((opsWriter , nsInfoWriter ) -> {
723
- batchEncoder .encodeWriteModel (opsWriter , maxStoredDocumentSize ,
724
- namespacedModel .getModel (), finalModelIndexInBatch , namespaceIndexInBatch );
714
+ batchEncoder .encodeWriteModel (opsWriter , namespacedModel .getModel (), finalModelIndexInBatch , namespaceIndexInBatch );
725
715
if (writeNewNamespace ) {
726
716
nsInfoWriter .writeStartDocument ();
727
717
nsInfoWriter .writeString ("ns" , namespace .getFullName ());
@@ -957,7 +947,7 @@ public BatchEncoder() {
957
947
/**
958
948
* Must be called at most once.
959
949
* Must not be called before calling
960
- * {@link #encodeWriteModel(BsonBinaryWriter, Integer, ClientWriteModel, int, int)} at least once.
950
+ * {@link #encodeWriteModel(BsonBinaryWriter, ClientWriteModel, int, int)} at least once.
961
951
* Renders {@code this} unusable.
962
952
*/
963
953
EncodedBatchInfo intoEncodedBatchInfo () {
@@ -979,15 +969,14 @@ void reset(final int modelIndexInBatch) {
979
969
980
970
void encodeWriteModel (
981
971
final BsonBinaryWriter writer ,
982
- @ Nullable final Integer maxStoredDocumentSize ,
983
972
final ClientWriteModel model ,
984
973
final int modelIndexInBatch ,
985
974
final int namespaceIndexInBatch ) {
986
975
assertNotNull (encodedBatchInfo ).modelsCount ++;
987
976
writer .writeStartDocument ();
988
977
if (model instanceof ConcreteClientInsertOneModel ) {
989
978
writer .writeInt32 ("insert" , namespaceIndexInBatch );
990
- encodeWriteModelInternals (writer , maxStoredDocumentSize , (ConcreteClientInsertOneModel ) model , modelIndexInBatch );
979
+ encodeWriteModelInternals (writer , (ConcreteClientInsertOneModel ) model , modelIndexInBatch );
991
980
} else if (model instanceof ConcreteClientUpdateOneModel ) {
992
981
writer .writeInt32 ("update" , namespaceIndexInBatch );
993
982
writer .writeBoolean ("multi" , false );
@@ -998,7 +987,7 @@ void encodeWriteModel(
998
987
encodeWriteModelInternals (writer , (ConcreteClientUpdateManyModel ) model );
999
988
} else if (model instanceof ConcreteClientReplaceOneModel ) {
1000
989
writer .writeInt32 ("update" , namespaceIndexInBatch );
1001
- encodeWriteModelInternals (writer , maxStoredDocumentSize , (ConcreteClientReplaceOneModel ) model );
990
+ encodeWriteModelInternals (writer , (ConcreteClientReplaceOneModel ) model );
1002
991
} else if (model instanceof ConcreteClientDeleteOneModel ) {
1003
992
writer .writeInt32 ("delete" , namespaceIndexInBatch );
1004
993
writer .writeBoolean ("multi" , false );
@@ -1015,14 +1004,13 @@ void encodeWriteModel(
1015
1004
1016
1005
private void encodeWriteModelInternals (
1017
1006
final BsonBinaryWriter writer ,
1018
- @ Nullable final Integer maxStoredDocumentSize ,
1019
1007
final ConcreteClientInsertOneModel model ,
1020
1008
final int modelIndexInBatch ) {
1021
1009
writer .writeName ("document" );
1022
1010
Object document = model .getDocument ();
1023
1011
assertNotNull (encodedBatchInfo ).insertModelDocumentIds .compute (modelIndexInBatch , (k , knownModelDocumentId ) -> {
1024
1012
IdHoldingBsonWriter documentIdHoldingBsonWriter = new IdHoldingBsonWriter (
1025
- decorateWithDocumentSizeChecking ( writer , maxStoredDocumentSize ) ,
1013
+ writer ,
1026
1014
// Reuse `knownModelDocumentId` if it may have been generated by `IdHoldingBsonWriter` in a previous attempt.
1027
1015
// If its type is not `BsonObjectId`, we know it could not have been generated.
1028
1016
knownModelDocumentId instanceof BsonObjectId ? knownModelDocumentId .asObjectId () : null );
@@ -1061,16 +1049,12 @@ private void encodeWriteModelInternals(final BsonWriter writer, final AbstractCl
1061
1049
options .isUpsert ().ifPresent (value -> writer .writeBoolean ("upsert" , value ));
1062
1050
}
1063
1051
1064
- private void encodeWriteModelInternals (
1065
- final BsonBinaryWriter writer ,
1066
- @ Nullable final Integer maxStoredDocumentSize ,
1067
- final ConcreteClientReplaceOneModel model ) {
1052
+ private void encodeWriteModelInternals (final BsonBinaryWriter writer , final ConcreteClientReplaceOneModel model ) {
1068
1053
writer .writeBoolean ("multi" , false );
1069
1054
writer .writeName ("filter" );
1070
1055
encodeUsingRegistry (writer , model .getFilter ());
1071
1056
writer .writeName ("updateMods" );
1072
- encodeUsingRegistry (decorateWithDocumentSizeChecking (writer , maxStoredDocumentSize ), model .getReplacement (),
1073
- COLLECTIBLE_DOCUMENT_ENCODER_CONTEXT );
1057
+ encodeUsingRegistry (writer , model .getReplacement (), COLLECTIBLE_DOCUMENT_ENCODER_CONTEXT );
1074
1058
ConcreteClientReplaceOptions options = model .getOptions ();
1075
1059
options .getCollation ().ifPresent (value -> {
1076
1060
writer .writeName ("collation" );
0 commit comments