summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcos José Grillo Ramírez <marcos.grillo@mongodb.com>2020-03-12 12:19:41 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-27 16:45:57 +0000
commit24efa5a2afeaad495a2317c09b229c35216a9dbe (patch)
tree3ea393779924015015ca0afdc954835f06e4c92e
parentc256da787a986f3adf2096306a68e782f62a3113 (diff)
downloadmongo-24efa5a2afeaad495a2317c09b229c35216a9dbe.tar.gz
SERVER-44463 insertConfigDocumentsAsRetryableWrite() incorrectly calculates BSON array overhead
(cherry picked from commit bb741a0ab1b2c80844dab55a3beecd83a8250ca4) (cherry picked from commit 4e631f51f099790bbcd9b74ad34ecaf504ee1508) (cherry picked from commit db7e98c79177c1bb417a756b29e771520f53d575)
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
index d4f51de98b8..c0b03d79227 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
@@ -973,30 +973,28 @@ void ShardingCatalogClientImpl::insertConfigDocumentsAsRetryableWrite(
std::vector<BSONObj> workingBatch;
size_t workingBatchItemSize = 0;
-
- int workingBatchDocSize = kRetryableBatchWriteBSONSizeOverhead;
+ int workingBatchDocSize = 0;
while (!docs.empty()) {
BSONObj toAdd = docs.back();
docs.pop_back();
- int docSize = toAdd.objsize();
- bool batchAtSizeLimit = (workingBatchItemSize + 1 > write_ops::kMaxWriteBatchSize) ||
- (workingBatchDocSize + docSize > BSONObjMaxUserSize);
-
- if (batchAtSizeLimit) {
+ const int docSizePlusOverhead = toAdd.objsize() + kRetryableBatchWriteBSONSizeOverhead;
+ // Check if pushing this object will exceed the batch size limit or the max object size
+ if ((workingBatchItemSize + 1 > write_ops::kMaxWriteBatchSize) ||
+ (workingBatchDocSize + docSizePlusOverhead > BSONObjMaxUserSize)) {
sendRetryableWriteBatchRequestToConfig(
asr.opCtx(), nss, workingBatch, currentTxnNumber, writeConcern);
++currentTxnNumber;
workingBatch.clear();
workingBatchItemSize = 0;
- workingBatchDocSize = kRetryableBatchWriteBSONSizeOverhead;
+ workingBatchDocSize = 0;
}
workingBatch.push_back(toAdd);
++workingBatchItemSize;
- workingBatchDocSize += docSize;
+ workingBatchDocSize += docSizePlusOverhead;
}
if (!workingBatch.empty()) {