summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@10gen.com>2020-08-25 22:19:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-27 05:03:49 +0000
commited3073ed0ae632bdb0e40fcdbd1d41dd84ec40aa (patch)
tree5ed061fc77a30cc03879172c9e842e88331b2aa0 /src
parentcefce38b2c914aa2167943e92fb4fe23a1cb9c3b (diff)
downloadmongo-ed3073ed0ae632bdb0e40fcdbd1d41dd84ec40aa.tar.gz
SERVER-50303 Initialize tenant cloner batch size in contructor
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/SConscript1
-rw-r--r--src/mongo/db/repl/collection_cloner_test.cpp31
-rw-r--r--src/mongo/db/repl/tenant_collection_cloner.cpp1
-rw-r--r--src/mongo/db/repl/tenant_collection_cloner_test.cpp31
4 files changed, 64 insertions, 0 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index e8d98a08ecc..a9a9e3113fa 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -1535,6 +1535,7 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/db/service_context_d_test_fixture',
'$BUILD_DIR/mongo/dbtests/mocklib',
'$BUILD_DIR/mongo/util/clock_source_mock',
+ 'repl_server_parameters',
'replmocks',
'initial_sync_cloners',
'repl_sync_shared_data',
diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp
index 3f34709840a..62c9dfe2274 100644
--- a/src/mongo/db/repl/collection_cloner_test.cpp
+++ b/src/mongo/db/repl/collection_cloner_test.cpp
@@ -35,6 +35,7 @@
#include "mongo/bson/bsonmisc.h"
#include "mongo/db/repl/cloner_test_fixture.h"
#include "mongo/db/repl/collection_cloner.h"
+#include "mongo/db/repl/repl_server_parameters_gen.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/service_context_test_fixture.h"
@@ -337,6 +338,36 @@ TEST_F(CollectionClonerTestResumable, InsertDocumentsSingleBatch) {
ASSERT_EQUALS(1u, stats.receivedBatches);
}
+TEST_F(CollectionClonerTestResumable, BatchSizeStoredInConstructor) {
+ auto batchSizeDefault = collectionClonerBatchSize;
+ collectionClonerBatchSize = 3;
+ ON_BLOCK_EXIT([&]() { collectionClonerBatchSize = batchSizeDefault; });
+
+ // Set up data for preliminary stages.
+ _mockServer->setCommandReply("count", createCountResponse(2));
+ _mockServer->setCommandReply("listIndexes",
+ createCursorResponse(_nss.ns(), BSON_ARRAY(_idIndexSpec)));
+
+ // Set up documents to be returned from upstream node. It should take 3 batches to clone the
+ // documents.
+ _mockServer->insert(_nss.ns(), BSON("_id" << 1));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 2));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 3));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 4));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 5));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 6));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 7));
+
+ auto cloner = makeCollectionCloner();
+ ASSERT_OK(cloner->run());
+
+ ASSERT_EQUALS(7, _collectionStats->insertCount);
+ ASSERT_TRUE(_collectionStats->commitCalled);
+
+ auto stats = cloner->getStats();
+ ASSERT_EQUALS(3u, stats.receivedBatches);
+}
+
TEST_F(CollectionClonerTestResumable, InsertDocumentsMultipleBatches) {
// Set up data for preliminary stages
_mockServer->setCommandReply("count", createCountResponse(2));
diff --git a/src/mongo/db/repl/tenant_collection_cloner.cpp b/src/mongo/db/repl/tenant_collection_cloner.cpp
index bb531102810..d2d6b05d374 100644
--- a/src/mongo/db/repl/tenant_collection_cloner.cpp
+++ b/src/mongo/db/repl/tenant_collection_cloner.cpp
@@ -75,6 +75,7 @@ TenantCollectionCloner::TenantCollectionCloner(const NamespaceString& sourceNss,
_sourceNss(sourceNss),
_collectionOptions(collectionOptions),
_sourceDbAndUuid(NamespaceString("UNINITIALIZED")),
+ _collectionClonerBatchSize(collectionClonerBatchSize),
_countStage("count", this, &TenantCollectionCloner::countStage),
_listIndexesStage("listIndexes", this, &TenantCollectionCloner::listIndexesStage),
_createCollectionStage(
diff --git a/src/mongo/db/repl/tenant_collection_cloner_test.cpp b/src/mongo/db/repl/tenant_collection_cloner_test.cpp
index 46e214f68ad..2c2e3f56983 100644
--- a/src/mongo/db/repl/tenant_collection_cloner_test.cpp
+++ b/src/mongo/db/repl/tenant_collection_cloner_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/base/checked_cast.h"
#include "mongo/bson/bsonmisc.h"
#include "mongo/db/repl/cloner_test_fixture.h"
+#include "mongo/db/repl/repl_server_parameters_gen.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/repl/tenant_collection_cloner.h"
@@ -350,6 +351,36 @@ TEST_F(TenantCollectionClonerTest, InsertDocumentsSingleBatch) {
ASSERT_EQUALS(1u, stats.receivedBatches);
}
+TEST_F(TenantCollectionClonerTest, BatchSizeStoredInConstructor) {
+ auto batchSizeDefault = collectionClonerBatchSize;
+ collectionClonerBatchSize = 3;
+ ON_BLOCK_EXIT([&]() { collectionClonerBatchSize = batchSizeDefault; });
+
+ // Set up data for preliminary stages.
+ _mockServer->setCommandReply("count", createCountResponse(7));
+ _mockServer->setCommandReply("listIndexes",
+ createCursorResponse(_nss.ns(), BSON_ARRAY(_idIndexSpec)));
+ _mockServer->setCommandReply("find", createFindResponse());
+
+ // Set up documents to be returned from upstream node. It should take 3 batches to clone the
+ // documents.
+ _mockServer->insert(_nss.ns(), BSON("_id" << 1));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 2));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 3));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 4));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 5));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 6));
+ _mockServer->insert(_nss.ns(), BSON("_id" << 7));
+
+ auto cloner = makeCollectionCloner();
+ ASSERT_OK(cloner->run());
+
+ ASSERT_EQUALS(7, _numDocsInserted);
+
+ auto stats = cloner->getStats();
+ ASSERT_EQUALS(3u, stats.receivedBatches);
+}
+
TEST_F(TenantCollectionClonerTest, InsertDocumentsMultipleBatches) {
// Set up data for preliminary stages
_mockServer->setCommandReply("count", createCountResponse(5));