summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@10gen.com>2020-08-29 00:15:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-04 02:40:53 +0000
commit1bb2d6e2943d24ed3eef9cc9123fdfdd60e63562 (patch)
tree536f2290dba3a1e96e8dd943c88b472cd6c1ec1e /src
parente703a72a49151fa782cfd83a654a6af55663ca38 (diff)
downloadmongo-1bb2d6e2943d24ed3eef9cc9123fdfdd60e63562.tar.gz
SERVER-50492 Move initial sync functionality out of ReplSyncSharedData
SERVER-50492 Split ClonerTestFixture into InitialSyncClonerTestFixture and TenantMigrationClonerTestFixture SERVER-50492 Fix log component for tenant cloners SERVER-50492 Fix tenant cloner naming
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/SConscript6
-rw-r--r--src/mongo/db/repl/all_database_cloner_test.cpp12
-rw-r--r--src/mongo/db/repl/base_cloner.cpp119
-rw-r--r--src/mongo/db/repl/base_cloner.h10
-rw-r--r--src/mongo/db/repl/cloner_test_fixture.cpp11
-rw-r--r--src/mongo/db/repl/cloner_test_fixture.h4
-rw-r--r--src/mongo/db/repl/collection_cloner_test.cpp12
-rw-r--r--src/mongo/db/repl/database_cloner_test.cpp12
-rw-r--r--src/mongo/db/repl/initial_sync_base_cloner.cpp4
-rw-r--r--src/mongo/db/repl/initial_sync_base_cloner.h15
-rw-r--r--src/mongo/db/repl/initial_sync_cloner_test_fixture.cpp61
-rw-r--r--src/mongo/db/repl/initial_sync_cloner_test_fixture.h52
-rw-r--r--src/mongo/db/repl/initial_sync_shared_data.h73
-rw-r--r--src/mongo/db/repl/repl_sync_shared_data.h108
-rw-r--r--src/mongo/db/repl/tenant_all_database_cloner.cpp2
-rw-r--r--src/mongo/db/repl/tenant_all_database_cloner.h4
-rw-r--r--src/mongo/db/repl/tenant_all_database_cloner_test.cpp33
-rw-r--r--src/mongo/db/repl/tenant_base_cloner.cpp (renamed from src/mongo/db/repl/tenant_migration_base_cloner.cpp)20
-rw-r--r--src/mongo/db/repl/tenant_base_cloner.h (renamed from src/mongo/db/repl/tenant_migration_base_cloner.h)22
-rw-r--r--src/mongo/db/repl/tenant_cloner_test_fixture.cpp50
-rw-r--r--src/mongo/db/repl/tenant_cloner_test_fixture.h49
-rw-r--r--src/mongo/db/repl/tenant_collection_cloner.cpp2
-rw-r--r--src/mongo/db/repl/tenant_collection_cloner.h6
-rw-r--r--src/mongo/db/repl/tenant_collection_cloner_test.cpp24
-rw-r--r--src/mongo/db/repl/tenant_database_cloner.cpp2
-rw-r--r--src/mongo/db/repl/tenant_database_cloner.h4
-rw-r--r--src/mongo/db/repl/tenant_database_cloner_test.cpp22
-rw-r--r--src/mongo/db/repl/tenant_migration_shared_data.h19
28 files changed, 433 insertions, 325 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index 6bb2fc91044..63a2626d1b3 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -1012,7 +1012,7 @@ env.Library(
'tenant_all_database_cloner.cpp',
'tenant_collection_cloner.cpp',
'tenant_database_cloner.cpp',
- 'tenant_migration_base_cloner.cpp',
+ 'tenant_base_cloner.cpp',
],
LIBDEPS = [
'$BUILD_DIR/mongo/base',
@@ -1533,10 +1533,12 @@ env.CppUnitTest(
'cloner_test_fixture.cpp',
'collection_cloner_test.cpp',
'database_cloner_test.cpp',
+ 'initial_sync_cloner_test_fixture.cpp',
'initial_sync_shared_data_test.cpp',
'tenant_all_database_cloner_test.cpp',
'tenant_collection_cloner_test.cpp',
- 'tenant_database_cloner_test.cpp'
+ 'tenant_database_cloner_test.cpp',
+ 'tenant_cloner_test_fixture.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/auth/authmocks', # Required for service context test fixture
diff --git a/src/mongo/db/repl/all_database_cloner_test.cpp b/src/mongo/db/repl/all_database_cloner_test.cpp
index 450ec40e477..eca18bb1753 100644
--- a/src/mongo/db/repl/all_database_cloner_test.cpp
+++ b/src/mongo/db/repl/all_database_cloner_test.cpp
@@ -32,7 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/repl/all_database_cloner.h"
-#include "mongo/db/repl/cloner_test_fixture.h"
+#include "mongo/db/repl/initial_sync_cloner_test_fixture.h"
#include "mongo/db/repl/replication_consistency_markers_impl.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/repl/storage_interface_mock.h"
@@ -46,15 +46,11 @@
namespace mongo {
namespace repl {
-class AllDatabaseClonerTest : public ClonerTestFixture {
+class AllDatabaseClonerTest : public InitialSyncClonerTestFixture {
public:
AllDatabaseClonerTest() {}
protected:
- void setUp() override {
- ClonerTestFixture::setUp();
- _sharedData = std::make_unique<InitialSyncSharedData>(kInitialRollbackId, Days(1), &_clock);
- }
std::unique_ptr<AllDatabaseCloner> makeAllDatabaseCloner() {
return std::make_unique<AllDatabaseCloner>(getSharedData(),
_source,
@@ -66,10 +62,6 @@ protected:
std::vector<std::string> getDatabasesFromCloner(AllDatabaseCloner* cloner) {
return cloner->_databases;
}
-
- InitialSyncSharedData* getSharedData() {
- return checked_cast<InitialSyncSharedData*>(_sharedData.get());
- }
};
TEST_F(AllDatabaseClonerTest, RetriesConnect) {
diff --git a/src/mongo/db/repl/base_cloner.cpp b/src/mongo/db/repl/base_cloner.cpp
index 271b950c865..c5bfbd95077 100644
--- a/src/mongo/db/repl/base_cloner.cpp
+++ b/src/mongo/db/repl/base_cloner.cpp
@@ -27,7 +27,7 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kReplicationInitialSync
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kReplication
#include "mongo/platform/basic.h"
@@ -87,11 +87,12 @@ Status BaseCloner::run() {
}
stdx::lock_guard<ReplSyncSharedData> lk(*_sharedData);
if (!_sharedData->getStatus(lk).isOK()) {
- LOGV2(21065,
- "Failing data clone because of failure outside data clone: "
- "{error}",
- "Failing data clone because of failure outside data clone",
- "error"_attr = _sharedData->getStatus(lk));
+ LOGV2_OPTIONS(21065,
+ {getLogComponent()},
+ "Failing data clone because of failure outside data clone: "
+ "{error}",
+ "Failing data clone because of failure outside data clone",
+ "error"_attr = _sharedData->getStatus(lk));
}
return _sharedData->getStatus(lk);
}
@@ -101,23 +102,25 @@ bool BaseCloner::isMyFailPoint(const BSONObj& data) const {
}
BaseCloner::AfterStageBehavior BaseCloner::runStage(BaseClonerStage* stage) {
- LOGV2_DEBUG(21069,
- 1,
- "Cloner {cloner} running stage {stage}",
- "Cloner running stage",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName());
+ LOGV2_DEBUG_OPTIONS(21069,
+ 1,
+ {getLogComponent()},
+ "Cloner {cloner} running stage {stage}",
+ "Cloner running stage",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName());
pauseForFuzzer(stage);
auto isThisStageFailPoint = [this, stage](const BSONObj& data) {
return data["stage"].str() == stage->getName() && isMyFailPoint(data);
};
hangBeforeClonerStage.executeIf(
[&](const BSONObj& data) {
- LOGV2(21070,
- "Cloner {cloner} hanging before running stage {stage}",
- "Cloner hanging before running stage",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName());
+ LOGV2_OPTIONS(21070,
+ {getLogComponent()},
+ "Cloner {cloner} hanging before running stage {stage}",
+ "Cloner hanging before running stage",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName());
while (!mustExit() && hangBeforeClonerStage.shouldFail(isThisStageFailPoint)) {
sleepmillis(100);
}
@@ -126,22 +129,24 @@ BaseCloner::AfterStageBehavior BaseCloner::runStage(BaseClonerStage* stage) {
auto afterStageBehavior = runStageWithRetries(stage);
hangAfterClonerStage.executeIf(
[&](const BSONObj& data) {
- LOGV2(21071,
- "Cloner {cloner} hanging after running stage {stage}",
- "Cloner hanging after running stage",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName());
+ LOGV2_OPTIONS(21071,
+ {getLogComponent()},
+ "Cloner {cloner} hanging after running stage {stage}",
+ "Cloner hanging after running stage",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName());
while (!mustExit() && hangAfterClonerStage.shouldFail(isThisStageFailPoint)) {
sleepmillis(100);
}
},
isThisStageFailPoint);
- LOGV2_DEBUG(21072,
- 1,
- "Cloner {cloner} finished running stage {stage}",
- "Cloner finished running stage",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName());
+ LOGV2_DEBUG_OPTIONS(21072,
+ 1,
+ {getLogComponent()},
+ "Cloner {cloner} finished running stage {stage}",
+ "Cloner finished running stage",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName());
return afterStageBehavior;
}
@@ -160,24 +165,26 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage*
// If lastError is set, this is a retry.
hangBeforeRetryingClonerStage.executeIf(
[&](const BSONObj& data) {
- LOGV2(21074,
- "Cloner {cloner} hanging before retrying stage {stage}",
- "Cloner hanging before retrying stage",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName());
+ LOGV2_OPTIONS(21074,
+ {getLogComponent()},
+ "Cloner {cloner} hanging before retrying stage {stage}",
+ "Cloner hanging before retrying stage",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName());
while (!mustExit() &&
hangBeforeRetryingClonerStage.shouldFail(isThisStageFailPoint)) {
sleepmillis(100);
}
},
isThisStageFailPoint);
- LOGV2(21075,
- "Sync process retrying {cloner} stage {stage} due to "
- "{error}",
- "Sync process retrying cloner stage due to error",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName(),
- "error"_attr = lastError);
+ LOGV2_OPTIONS(21075,
+ {getLogComponent()},
+ "Sync process retrying {cloner} stage {stage} due to "
+ "{error}",
+ "Sync process retrying cloner stage due to error",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName(),
+ "error"_attr = lastError);
// Execute any per-retry logic needed by the cloner.
handleStageAttemptFailed(stage, lastError);
}
@@ -185,23 +192,25 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage*
} catch (DBException& e) {
lastError = e.toStatus();
if (!stage->isTransientError(lastError)) {
- LOGV2(21077,
- "Non-retryable error occurred during cloner "
- "{cloner} stage {stage}: {error}",
- "Non-retryable error occurred during cloner stage",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName(),
- "error"_attr = lastError);
+ LOGV2_OPTIONS(21077,
+ {getLogComponent()},
+ "Non-retryable error occurred during cloner "
+ "{cloner} stage {stage}: {error}",
+ "Non-retryable error occurred during cloner stage",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName(),
+ "error"_attr = lastError);
throw;
}
- LOGV2_DEBUG(21078,
- 1,
- "Transient error occurred during cloner "
- "{cloner} stage {stage}: {error}",
- "Transient error occurred during cloner stage",
- "cloner"_attr = getClonerName(),
- "stage"_attr = stage->getName(),
- "error"_attr = lastError);
+ LOGV2_DEBUG_OPTIONS(21078,
+ 1,
+ {getLogComponent()},
+ "Transient error occurred during cloner "
+ "{cloner} stage {stage}: {error}",
+ "Transient error occurred during cloner stage",
+ "cloner"_attr = getClonerName(),
+ "stage"_attr = stage->getName(),
+ "error"_attr = lastError);
}
}
}
diff --git a/src/mongo/db/repl/base_cloner.h b/src/mongo/db/repl/base_cloner.h
index 4ff4a5f7346..f6367d33126 100644
--- a/src/mongo/db/repl/base_cloner.h
+++ b/src/mongo/db/repl/base_cloner.h
@@ -43,6 +43,11 @@
#include "mongo/util/future.h"
namespace mongo {
+
+namespace logv2 {
+class LogComponent;
+}
+
namespace repl {
class BaseCloner {
@@ -243,6 +248,11 @@ protected:
return "";
}
+ /**
+ * Must override this to specify the log component for messages in this class.
+ */
+ virtual logv2::LogComponent getLogComponent() = 0;
+
private:
virtual ClonerStages getStages() = 0;
diff --git a/src/mongo/db/repl/cloner_test_fixture.cpp b/src/mongo/db/repl/cloner_test_fixture.cpp
index 305861a3eb6..f2dcf803d7b 100644
--- a/src/mongo/db/repl/cloner_test_fixture.cpp
+++ b/src/mongo/db/repl/cloner_test_fixture.cpp
@@ -71,11 +71,6 @@ void ClonerTestFixture::setUp() {
// Required by CollectionCloner::listIndexesStage() and IndexBuildsCoordinator.
getServiceContext()->setStorageEngine(std::make_unique<StorageEngineMock>());
-
- // Set the initial sync ID on the mock server.
- _mockServer->insert(
- ReplicationConsistencyMarkersImpl::kDefaultInitialSyncIdNamespace.toString(),
- BSON("_id" << _initialSyncId));
}
void ClonerTestFixture::tearDown() {
@@ -84,11 +79,5 @@ void ClonerTestFixture::tearDown() {
unittest::Test::tearDown();
}
-void ClonerTestFixture::setInitialSyncId() {
- stdx::lock_guard<ReplSyncSharedData> lk(*_sharedData);
- _sharedData->setSyncSourceWireVersion(lk, WireVersion::RESUMABLE_INITIAL_SYNC);
- _sharedData->setInitialSyncSourceId(lk, _initialSyncId);
-}
-
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/cloner_test_fixture.h b/src/mongo/db/repl/cloner_test_fixture.h
index ca458b8e100..0da9dc95d0c 100644
--- a/src/mongo/db/repl/cloner_test_fixture.h
+++ b/src/mongo/db/repl/cloner_test_fixture.h
@@ -59,8 +59,6 @@ protected:
void tearDown() override;
- void setInitialSyncId();
-
StorageInterfaceMock _storageInterface;
HostAndPort _source;
std::unique_ptr<ThreadPool> _dbWorkThreadPool;
@@ -68,8 +66,6 @@ protected:
std::unique_ptr<DBClientConnection> _mockClient;
std::unique_ptr<ReplSyncSharedData> _sharedData;
ClockSourceMock _clock;
- UUID _initialSyncId = UUID::gen();
- static constexpr int kInitialRollbackId = 1;
private:
unittest::MinimumLoggedSeverityGuard _verboseGuard{logv2::LogComponent::kReplicationInitialSync,
diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp
index 62c9dfe2274..8792b0e80f0 100644
--- a/src/mongo/db/repl/collection_cloner_test.cpp
+++ b/src/mongo/db/repl/collection_cloner_test.cpp
@@ -31,10 +31,9 @@
#include <vector>
-#include "mongo/base/checked_cast.h"
#include "mongo/bson/bsonmisc.h"
-#include "mongo/db/repl/cloner_test_fixture.h"
#include "mongo/db/repl/collection_cloner.h"
+#include "mongo/db/repl/initial_sync_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"
@@ -56,14 +55,13 @@ public:
}
};
-class CollectionClonerTest : public ClonerTestFixture {
+class CollectionClonerTest : public InitialSyncClonerTestFixture {
public:
CollectionClonerTest() {}
protected:
void setUp() override {
- ClonerTestFixture::setUp();
- _sharedData = std::make_unique<InitialSyncSharedData>(kInitialRollbackId, Days(1), &_clock);
+ InitialSyncClonerTestFixture::setUp();
_collectionStats = std::make_shared<CollectionMockStats>();
_standardCreateCollectionFn = [this](const NamespaceString& nss,
const CollectionOptions& options,
@@ -117,10 +115,6 @@ protected:
return cloner->_idIndexSpec;
}
- InitialSyncSharedData* getSharedData() {
- return checked_cast<InitialSyncSharedData*>(_sharedData.get());
- }
-
std::shared_ptr<CollectionMockStats> _collectionStats; // Used by the _loader.
StorageInterfaceMock::CreateCollectionForBulkFn _standardCreateCollectionFn;
CollectionBulkLoaderMock* _loader = nullptr; // Owned by CollectionCloner.
diff --git a/src/mongo/db/repl/database_cloner_test.cpp b/src/mongo/db/repl/database_cloner_test.cpp
index 1d767d4396e..7dc72b24592 100644
--- a/src/mongo/db/repl/database_cloner_test.cpp
+++ b/src/mongo/db/repl/database_cloner_test.cpp
@@ -29,10 +29,9 @@
#include "mongo/platform/basic.h"
-#include "mongo/base/checked_cast.h"
#include "mongo/db/clientcursor.h"
-#include "mongo/db/repl/cloner_test_fixture.h"
#include "mongo/db/repl/database_cloner.h"
+#include "mongo/db/repl/initial_sync_cloner_test_fixture.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/service_context_test_fixture.h"
@@ -49,14 +48,13 @@ struct CollectionCloneInfo {
CollectionBulkLoaderMock* loader = nullptr;
};
-class DatabaseClonerTest : public ClonerTestFixture {
+class DatabaseClonerTest : public InitialSyncClonerTestFixture {
public:
DatabaseClonerTest() {}
protected:
void setUp() override {
- ClonerTestFixture::setUp();
- _sharedData = std::make_unique<InitialSyncSharedData>(kInitialRollbackId, Days(1), &_clock);
+ InitialSyncClonerTestFixture::setUp();
_storageInterface.createCollectionForBulkFn =
[this](const NamespaceString& nss,
const CollectionOptions& options,
@@ -107,10 +105,6 @@ protected:
return cloner->_collections;
}
- InitialSyncSharedData* getSharedData() {
- return checked_cast<InitialSyncSharedData*>(_sharedData.get());
- }
-
std::map<NamespaceString, CollectionCloneInfo> _collections;
static std::string _dbName;
diff --git a/src/mongo/db/repl/initial_sync_base_cloner.cpp b/src/mongo/db/repl/initial_sync_base_cloner.cpp
index 2840191d985..acc6d41d89d 100644
--- a/src/mongo/db/repl/initial_sync_base_cloner.cpp
+++ b/src/mongo/db/repl/initial_sync_base_cloner.cpp
@@ -205,5 +205,9 @@ void InitialSyncBaseCloner::pauseForFuzzer(BaseClonerStage* stage) {
}
}
+logv2::LogComponent InitialSyncBaseCloner::getLogComponent() {
+ return logv2::LogComponent::kReplicationInitialSync;
+}
+
} // namespace repl
} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/initial_sync_base_cloner.h b/src/mongo/db/repl/initial_sync_base_cloner.h
index ff1f28142a9..f5eb9882725 100644
--- a/src/mongo/db/repl/initial_sync_base_cloner.h
+++ b/src/mongo/db/repl/initial_sync_base_cloner.h
@@ -87,8 +87,21 @@ private:
*/
void pauseForFuzzer(BaseClonerStage* stage) final;
+ /**
+ * Provides part of a log message for the initial sync describing the namespace the
+ * cloner is operating on. It must start with the database name, followed by the
+ * string ' db: { ', followed by the stage name, followed by ': ' and the collection UUID
+ * if known.
+ */
+ virtual std::string describeForFuzzer(BaseClonerStage*) const = 0;
+
+ /**
+ * Overriden to allow the BaseCloner to use the initial sync log component.
+ */
+ virtual logv2::LogComponent getLogComponent() final;
+
// Operation that may currently be retrying.
- ReplSyncSharedData::RetryableOperation _retryableOp;
+ InitialSyncSharedData::RetryableOperation _retryableOp;
};
} // namespace repl
diff --git a/src/mongo/db/repl/initial_sync_cloner_test_fixture.cpp b/src/mongo/db/repl/initial_sync_cloner_test_fixture.cpp
new file mode 100644
index 00000000000..fb2c60e7378
--- /dev/null
+++ b/src/mongo/db/repl/initial_sync_cloner_test_fixture.cpp
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/base/checked_cast.h"
+#include "mongo/db/repl/initial_sync_cloner_test_fixture.h"
+#include "mongo/db/repl/replication_consistency_markers_impl.h"
+
+namespace mongo {
+namespace repl {
+
+void InitialSyncClonerTestFixture::setUp() {
+ ClonerTestFixture::setUp();
+
+ _sharedData = std::make_unique<InitialSyncSharedData>(kInitialRollbackId, Days(1), &_clock);
+
+ // Set the initial sync ID on the mock server.
+ _mockServer->insert(
+ ReplicationConsistencyMarkersImpl::kDefaultInitialSyncIdNamespace.toString(),
+ BSON("_id" << _initialSyncId));
+}
+
+InitialSyncSharedData* InitialSyncClonerTestFixture::getSharedData() {
+ return checked_cast<InitialSyncSharedData*>(_sharedData.get());
+}
+
+void InitialSyncClonerTestFixture::setInitialSyncId() {
+ stdx::lock_guard<InitialSyncSharedData> lk(*getSharedData());
+ getSharedData()->setSyncSourceWireVersion(lk, WireVersion::RESUMABLE_INITIAL_SYNC);
+ getSharedData()->setInitialSyncSourceId(lk, _initialSyncId);
+}
+
+} // namespace repl
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/initial_sync_cloner_test_fixture.h b/src/mongo/db/repl/initial_sync_cloner_test_fixture.h
new file mode 100644
index 00000000000..f51f9204435
--- /dev/null
+++ b/src/mongo/db/repl/initial_sync_cloner_test_fixture.h
@@ -0,0 +1,52 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/db/repl/cloner_test_fixture.h"
+#include "mongo/db/repl/initial_sync_shared_data.h"
+
+namespace mongo {
+namespace repl {
+
+class InitialSyncClonerTestFixture : public ClonerTestFixture {
+protected:
+ void setUp() override;
+
+ InitialSyncSharedData* getSharedData();
+
+ // Updates the initial sync id stored in InitialSyncSharedData.
+ void setInitialSyncId();
+
+ UUID _initialSyncId = UUID::gen();
+ static constexpr int kInitialRollbackId = 1;
+};
+
+} // namespace repl
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/initial_sync_shared_data.h b/src/mongo/db/repl/initial_sync_shared_data.h
index 45f76338350..0644f151997 100644
--- a/src/mongo/db/repl/initial_sync_shared_data.h
+++ b/src/mongo/db/repl/initial_sync_shared_data.h
@@ -41,8 +41,16 @@ private:
class RetryingOperation;
public:
+ typedef boost::optional<RetryingOperation> RetryableOperation;
+
InitialSyncSharedData(int rollBackId, Milliseconds allowedOutageDuration, ClockSource* clock)
- : ReplSyncSharedData(rollBackId, allowedOutageDuration, clock) {}
+ : ReplSyncSharedData(clock),
+ _rollBackId(rollBackId),
+ _allowedOutageDuration(allowedOutageDuration) {}
+
+ int getRollBackId() const {
+ return _rollBackId;
+ }
int getRetryingOperationsCount(WithLock lk) {
return _retryingOperationsCount;
@@ -55,28 +63,28 @@ public:
/**
* Sets the wire version of the sync source.
*/
- void setSyncSourceWireVersion(WithLock, WireVersion wireVersion) final {
+ void setSyncSourceWireVersion(WithLock, WireVersion wireVersion) {
_syncSourceWireVersion = wireVersion;
}
/**
* Returns the wire version of the sync source, if previously set.
*/
- boost::optional<WireVersion> getSyncSourceWireVersion(WithLock) final {
+ boost::optional<WireVersion> getSyncSourceWireVersion(WithLock) {
return _syncSourceWireVersion;
}
/**
* Sets the initial sync ID of the sync source.
*/
- void setInitialSyncSourceId(WithLock, boost::optional<UUID> syncSourceId) final {
+ void setInitialSyncSourceId(WithLock, boost::optional<UUID> syncSourceId) {
_initialSyncSourceId = syncSourceId;
}
/**
* Gets the previously-set initial sync ID of the sync source.
*/
- boost::optional<UUID> getInitialSyncSourceId(WithLock) final {
+ boost::optional<UUID> getInitialSyncSourceId(WithLock) {
return _initialSyncSourceId;
}
@@ -106,9 +114,54 @@ public:
*
* Returns true if the operation should be retried, false if it has timed out.
*/
- bool shouldRetryOperation(WithLock lk, RetryableOperation* retryableOp) override;
+ bool shouldRetryOperation(WithLock lk, RetryableOperation* retryableOp);
+
+ /**
+ * Returns the total time the sync source may be unreachable in a single outage before
+ * shouldRetryOperation() returns false.
+ */
+ Milliseconds getAllowedOutageDuration(WithLock lk) {
+ return _allowedOutageDuration;
+ }
+
+ void setAllowedOutageDuration_forTest(WithLock, Milliseconds allowedOutageDuration) {
+ _allowedOutageDuration = allowedOutageDuration;
+ }
private:
+ class RetryingOperation {
+ public:
+ RetryingOperation(InitialSyncSharedData* sharedData) : _sharedData(sharedData) {}
+ // This class is a non-copyable RAII class.
+ RetryingOperation(const RetryingOperation&) = delete;
+ RetryingOperation(RetryingOperation&&) = delete;
+ ~RetryingOperation() {
+ if (_sharedData) {
+ stdx::lock_guard<InitialSyncSharedData> lk(*_sharedData);
+ release(lk);
+ }
+ }
+
+ RetryingOperation& operator=(const RetryingOperation&) = delete;
+ RetryingOperation& operator=(RetryingOperation&&) = default;
+
+ /**
+ * release() is used by shouldRetryOperation to allow destroying a RetryingOperation
+ * while holding the lock.
+ */
+ void release(WithLock lk) {
+ _sharedData->decrementRetryingOperations(lk);
+ _sharedData = nullptr;
+ }
+
+ InitialSyncSharedData* getSharedData() {
+ return _sharedData;
+ }
+
+ private:
+ InitialSyncSharedData* _sharedData;
+ };
+
/**
* Increment the number of retrying operations, set syncSourceUnreachableSince if this is the
* only retrying operation. This is used when an operation starts retrying.
@@ -122,12 +175,15 @@ private:
* and update _totalTimeUnreachable.
* Returns the new number of retrying operations.
*/
- int decrementRetryingOperations(WithLock lk) override;
+ int decrementRetryingOperations(WithLock lk);
void incrementTotalRetries(WithLock lk) {
_totalRetries++;
}
+ // Rollback ID at start of initial sync.
+ const int _rollBackId;
+
/**
* This object must be locked when accessing the members below.
*/
@@ -147,6 +203,9 @@ private:
// outage, that we were retrying because we were unable to reach the sync source.
Milliseconds _totalTimeUnreachable;
+ // Time allowed for an outage before "shouldRetryOperation" returns false.
+ Milliseconds _allowedOutageDuration;
+
// Operation that may currently be retrying.
RetryableOperation _retryableOp;
diff --git a/src/mongo/db/repl/repl_sync_shared_data.h b/src/mongo/db/repl/repl_sync_shared_data.h
index a3c8f262aba..1c9ab2e9d2e 100644
--- a/src/mongo/db/repl/repl_sync_shared_data.h
+++ b/src/mongo/db/repl/repl_sync_shared_data.h
@@ -42,21 +42,10 @@
namespace mongo {
namespace repl {
class ReplSyncSharedData {
-protected:
- class RetryingOperation;
-
public:
- typedef boost::optional<RetryingOperation> RetryableOperation;
-
- ReplSyncSharedData(int rollBackId, Milliseconds allowedOutageDuration, ClockSource* clock)
- : _rollBackId(rollBackId), _clock(clock), _allowedOutageDuration(allowedOutageDuration) {}
+ ReplSyncSharedData(ClockSource* clock) : _clock(clock) {}
virtual ~ReplSyncSharedData() {}
- // TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- int getRollBackId() const {
- return _rollBackId;
- }
-
ClockSource* getClock() const {
return _clock;
}
@@ -83,107 +72,12 @@ public:
*/
void setStatusIfOK(WithLock lk, Status newStatus);
- /**
- * Sets the wire version of the sync source.
- * TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- */
- virtual void setSyncSourceWireVersion(WithLock, WireVersion wireVersion) = 0;
-
- /**
- * Returns the wire version of the sync source, if previously set.
- * TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- */
- virtual boost::optional<WireVersion> getSyncSourceWireVersion(WithLock) = 0;
-
- /**
- * Sets the initial sync ID of the sync source.
- * TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- */
- virtual void setInitialSyncSourceId(WithLock, boost::optional<UUID> syncSourceId) = 0;
-
- /**
- * Gets the previously-set initial sync ID of the sync source.
- * TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- */
- virtual boost::optional<UUID> getInitialSyncSourceId(WithLock) = 0;
-
- /**
- * Returns true if the operation should be retried, false if it has timed out.
- * TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- */
- virtual bool shouldRetryOperation(WithLock lk, RetryableOperation* retryableOp) = 0;
-
- /**
- * Decrements the number of retrying operations. If now zero, clear syncSourceUnreachableSince
- * and update _totalTimeUnreachable.
- * Returns the new number of retrying operations.
- * TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- */
- virtual int decrementRetryingOperations(WithLock lk) = 0;
-
- /**
- * Returns the total time the sync source may be unreachable in a single outage before
- * shouldRetryOperation() returns false.
- * TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- */
- Milliseconds getAllowedOutageDuration(WithLock lk) {
- return _allowedOutageDuration;
- }
-
- // TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- void setAllowedOutageDuration_forTest(WithLock, Milliseconds allowedOutageDuration) {
- _allowedOutageDuration = allowedOutageDuration;
- }
-
-protected:
- // TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- class RetryingOperation {
- public:
- RetryingOperation(ReplSyncSharedData* sharedData) : _sharedData(sharedData) {}
- // This class is a non-copyable RAII class.
- RetryingOperation(const RetryingOperation&) = delete;
- RetryingOperation(RetryingOperation&&) = delete;
- ~RetryingOperation() {
- if (_sharedData) {
- stdx::lock_guard<ReplSyncSharedData> lk(*_sharedData);
- release(lk);
- }
- }
-
- RetryingOperation& operator=(const RetryingOperation&) = delete;
- RetryingOperation& operator=(RetryingOperation&&) = default;
-
- /**
- * release() is used by shouldRetryOperation to allow destroying a RetryingOperation
- * while holding the lock.
- */
- void release(WithLock lk) {
- _sharedData->decrementRetryingOperations(lk);
- _sharedData = nullptr;
- }
-
- ReplSyncSharedData* getSharedData() {
- return _sharedData;
- }
-
- private:
- ReplSyncSharedData* _sharedData;
- };
-
private:
- // Rollback ID at start of initial sync.
- // TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- const int _rollBackId;
-
// Clock source used for timing outages and recording stats.
ClockSource* const _clock;
mutable Mutex _mutex = MONGO_MAKE_LATCH("ReplSyncSharedData::_mutex"_sd);
- // Time allowed for an outage before "shouldRetryOperation" returns false.
- // TODO(SERVER-50492): Move this into InitialSyncSharedData once the base cloner has been split.
- Milliseconds _allowedOutageDuration;
-
// Status of the entire sync process. All syncing tasks should exit if this becomes non-OK.
Status _status = Status::OK();
};
diff --git a/src/mongo/db/repl/tenant_all_database_cloner.cpp b/src/mongo/db/repl/tenant_all_database_cloner.cpp
index 5aaf3a116c7..a1f1728ba2f 100644
--- a/src/mongo/db/repl/tenant_all_database_cloner.cpp
+++ b/src/mongo/db/repl/tenant_all_database_cloner.cpp
@@ -53,7 +53,7 @@ TenantAllDatabaseCloner::TenantAllDatabaseCloner(TenantMigrationSharedData* shar
StorageInterface* storageInterface,
ThreadPool* dbPool,
StringData tenantId)
- : TenantMigrationBaseCloner(
+ : TenantBaseCloner(
"TenantAllDatabaseCloner"_sd, sharedData, source, client, storageInterface, dbPool),
_tenantId(tenantId),
_listDatabasesStage("listDatabases", this, &TenantAllDatabaseCloner::listDatabasesStage) {}
diff --git a/src/mongo/db/repl/tenant_all_database_cloner.h b/src/mongo/db/repl/tenant_all_database_cloner.h
index 681e7a2bf4e..300c3f54d16 100644
--- a/src/mongo/db/repl/tenant_all_database_cloner.h
+++ b/src/mongo/db/repl/tenant_all_database_cloner.h
@@ -32,14 +32,14 @@
#include <vector>
#include "mongo/db/repl/base_cloner.h"
+#include "mongo/db/repl/tenant_base_cloner.h"
#include "mongo/db/repl/tenant_database_cloner.h"
-#include "mongo/db/repl/tenant_migration_base_cloner.h"
#include "mongo/db/repl/tenant_migration_shared_data.h"
namespace mongo {
namespace repl {
-class TenantAllDatabaseCloner final : public TenantMigrationBaseCloner {
+class TenantAllDatabaseCloner final : public TenantBaseCloner {
public:
struct Stats {
size_t databasesCloned{0};
diff --git a/src/mongo/db/repl/tenant_all_database_cloner_test.cpp b/src/mongo/db/repl/tenant_all_database_cloner_test.cpp
index 823e7ec27ca..71e4ecbf964 100644
--- a/src/mongo/db/repl/tenant_all_database_cloner_test.cpp
+++ b/src/mongo/db/repl/tenant_all_database_cloner_test.cpp
@@ -31,11 +31,10 @@
#include "mongo/platform/basic.h"
-#include "mongo/base/checked_cast.h"
-#include "mongo/db/repl/cloner_test_fixture.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/repl/tenant_all_database_cloner.h"
+#include "mongo/db/repl/tenant_cloner_test_fixture.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/dbtests/mock/mock_dbclient_connection.h"
#include "mongo/logv2/log.h"
@@ -46,17 +45,11 @@
namespace mongo {
namespace repl {
-class TenantAllDatabaseClonerTest : public ClonerTestFixture {
+class TenantAllDatabaseClonerTest : public TenantClonerTestFixture {
public:
TenantAllDatabaseClonerTest() {}
protected:
- void setUp() override {
- ClonerTestFixture::setUp();
- _sharedData = std::make_unique<TenantMigrationSharedData>(kInitialRollbackId, &_clock);
- _mockClient->setOperationTime(_operationTime);
- }
-
std::unique_ptr<TenantAllDatabaseCloner> makeAllDatabaseCloner() {
return std::make_unique<TenantAllDatabaseCloner>(getSharedData(),
_source,
@@ -81,26 +74,12 @@ protected:
return bob.obj();
}
- TenantMigrationSharedData* getSharedData() {
- return checked_cast<TenantMigrationSharedData*>(_sharedData.get());
- }
-
- static Timestamp _operationTime;
- static std::string _tenantId;
- static std::string _tenantDbA;
- static std::string _tenantDbAAB;
- static std::string _tenantDbABC;
- static std::string _tenantDbB;
+ const std::string _tenantDbA = _tenantId + "_a";
+ const std::string _tenantDbAAB = _tenantId + "_aab";
+ const std::string _tenantDbABC = _tenantId + "_abc";
+ const std::string _tenantDbB = _tenantId + "_b";
};
-/* static */
-Timestamp TenantAllDatabaseClonerTest::_operationTime = Timestamp(12345, 67);
-std::string TenantAllDatabaseClonerTest::_tenantId = "tenant42";
-std::string TenantAllDatabaseClonerTest::_tenantDbA = _tenantId + "_a";
-std::string TenantAllDatabaseClonerTest::_tenantDbAAB = _tenantId + "_aab";
-std::string TenantAllDatabaseClonerTest::_tenantDbABC = _tenantId + "_abc";
-std::string TenantAllDatabaseClonerTest::_tenantDbB = _tenantId + "_b";
-
TEST_F(TenantAllDatabaseClonerTest, FailsOnListDatabases) {
Status expectedResult{ErrorCodes::BadValue, "foo"};
_mockServer->setCommandReply("listDatabases", expectedResult);
diff --git a/src/mongo/db/repl/tenant_migration_base_cloner.cpp b/src/mongo/db/repl/tenant_base_cloner.cpp
index 977ddb5247f..9ac68eddbe0 100644
--- a/src/mongo/db/repl/tenant_migration_base_cloner.cpp
+++ b/src/mongo/db/repl/tenant_base_cloner.cpp
@@ -27,23 +27,27 @@
* it in the license file.
*/
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kReplicationInitialSync
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTenantMigration
#include "mongo/platform/basic.h"
-#include "mongo/db/repl/tenant_migration_base_cloner.h"
+#include "mongo/db/repl/tenant_base_cloner.h"
#include "mongo/logv2/log.h"
namespace mongo {
namespace repl {
-TenantMigrationBaseCloner::TenantMigrationBaseCloner(StringData clonerName,
- TenantMigrationSharedData* sharedData,
- const HostAndPort& source,
- DBClientConnection* client,
- StorageInterface* storageInterface,
- ThreadPool* dbPool)
+TenantBaseCloner::TenantBaseCloner(StringData clonerName,
+ TenantMigrationSharedData* sharedData,
+ const HostAndPort& source,
+ DBClientConnection* client,
+ StorageInterface* storageInterface,
+ ThreadPool* dbPool)
: BaseCloner(clonerName, sharedData, source, client, storageInterface, dbPool) {}
+logv2::LogComponent TenantBaseCloner::getLogComponent() {
+ return logv2::LogComponent::kTenantMigration;
+}
+
} // namespace repl
} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/tenant_migration_base_cloner.h b/src/mongo/db/repl/tenant_base_cloner.h
index 9f9d6509a75..c5ccdba93f9 100644
--- a/src/mongo/db/repl/tenant_migration_base_cloner.h
+++ b/src/mongo/db/repl/tenant_base_cloner.h
@@ -36,20 +36,26 @@
namespace mongo {
namespace repl {
-class TenantMigrationBaseCloner : public BaseCloner {
+class TenantBaseCloner : public BaseCloner {
public:
- TenantMigrationBaseCloner(StringData clonerName,
- TenantMigrationSharedData* sharedData,
- const HostAndPort& source,
- DBClientConnection* client,
- StorageInterface* storageInterface,
- ThreadPool* dbPool);
- virtual ~TenantMigrationBaseCloner() = default;
+ TenantBaseCloner(StringData clonerName,
+ TenantMigrationSharedData* sharedData,
+ const HostAndPort& source,
+ DBClientConnection* client,
+ StorageInterface* storageInterface,
+ ThreadPool* dbPool);
+ virtual ~TenantBaseCloner() = default;
protected:
TenantMigrationSharedData* getSharedData() const override {
return checked_cast<TenantMigrationSharedData*>(BaseCloner::getSharedData());
}
+
+private:
+ /**
+ * Overriden to allow the BaseCloner to use the tenant migration log component.
+ */
+ virtual logv2::LogComponent getLogComponent() final;
};
} // namespace repl
diff --git a/src/mongo/db/repl/tenant_cloner_test_fixture.cpp b/src/mongo/db/repl/tenant_cloner_test_fixture.cpp
new file mode 100644
index 00000000000..b1323a23229
--- /dev/null
+++ b/src/mongo/db/repl/tenant_cloner_test_fixture.cpp
@@ -0,0 +1,50 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/base/checked_cast.h"
+#include "mongo/db/repl/tenant_cloner_test_fixture.h"
+
+namespace mongo {
+namespace repl {
+
+void TenantClonerTestFixture::setUp() {
+ ClonerTestFixture::setUp();
+
+ _sharedData = std::make_unique<TenantMigrationSharedData>(&_clock);
+
+ _mockClient->setOperationTime(_operationTime);
+}
+
+TenantMigrationSharedData* TenantClonerTestFixture::getSharedData() {
+ return checked_cast<TenantMigrationSharedData*>(_sharedData.get());
+}
+} // namespace repl
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/tenant_cloner_test_fixture.h b/src/mongo/db/repl/tenant_cloner_test_fixture.h
new file mode 100644
index 00000000000..3233485057d
--- /dev/null
+++ b/src/mongo/db/repl/tenant_cloner_test_fixture.h
@@ -0,0 +1,49 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/db/repl/cloner_test_fixture.h"
+#include "mongo/db/repl/tenant_migration_shared_data.h"
+
+namespace mongo {
+namespace repl {
+
+class TenantClonerTestFixture : public ClonerTestFixture {
+protected:
+ void setUp() override;
+
+ TenantMigrationSharedData* getSharedData();
+
+ const Timestamp _operationTime = Timestamp(12345, 67);
+ const std::string _tenantId = "tenant42";
+};
+
+} // namespace repl
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/repl/tenant_collection_cloner.cpp b/src/mongo/db/repl/tenant_collection_cloner.cpp
index 8d90c77a2d3..43251eb6294 100644
--- a/src/mongo/db/repl/tenant_collection_cloner.cpp
+++ b/src/mongo/db/repl/tenant_collection_cloner.cpp
@@ -71,7 +71,7 @@ TenantCollectionCloner::TenantCollectionCloner(const NamespaceString& sourceNss,
StorageInterface* storageInterface,
ThreadPool* dbPool,
StringData tenantId)
- : TenantMigrationBaseCloner(
+ : TenantBaseCloner(
"TenantCollectionCloner"_sd, sharedData, source, client, storageInterface, dbPool),
_sourceNss(sourceNss),
_collectionOptions(collectionOptions),
diff --git a/src/mongo/db/repl/tenant_collection_cloner.h b/src/mongo/db/repl/tenant_collection_cloner.h
index 76b44cbfca3..45d0ba022f7 100644
--- a/src/mongo/db/repl/tenant_collection_cloner.h
+++ b/src/mongo/db/repl/tenant_collection_cloner.h
@@ -34,14 +34,14 @@
#include "mongo/db/repl/base_cloner.h"
#include "mongo/db/repl/task_runner.h"
-#include "mongo/db/repl/tenant_migration_base_cloner.h"
+#include "mongo/db/repl/tenant_base_cloner.h"
#include "mongo/db/repl/tenant_migration_shared_data.h"
#include "mongo/util/progress_meter.h"
namespace mongo {
namespace repl {
-class TenantCollectionCloner : public TenantMigrationBaseCloner {
+class TenantCollectionCloner : public TenantBaseCloner {
public:
struct Stats {
static constexpr StringData kDocumentsToCopyFieldName = "documentsToCopy"_sd;
@@ -229,11 +229,9 @@ private:
TaskRunner _dbWorkTaskRunner; // (R)
// The database name prefix of the tenant associated with this migration.
- // TODO(SERVER-50492): Consider moving this into TenantMigrationSharedData.
std::string _tenantId; // (R)
// The operationTime returned with the listIndexes result.
- // TODO(SERVER-50492): Consider moving this into TenantMigrationSharedData.
Timestamp _operationTime; // (X)
};
diff --git a/src/mongo/db/repl/tenant_collection_cloner_test.cpp b/src/mongo/db/repl/tenant_collection_cloner_test.cpp
index 2c2e3f56983..9c0cfdf73fb 100644
--- a/src/mongo/db/repl/tenant_collection_cloner_test.cpp
+++ b/src/mongo/db/repl/tenant_collection_cloner_test.cpp
@@ -31,12 +31,11 @@
#include <vector>
-#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_cloner_test_fixture.h"
#include "mongo/db/repl/tenant_collection_cloner.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/dbtests/mock/mock_dbclient_connection.h"
@@ -56,14 +55,13 @@ public:
}
};
-class TenantCollectionClonerTest : public ClonerTestFixture {
+class TenantCollectionClonerTest : public TenantClonerTestFixture {
public:
TenantCollectionClonerTest() {}
protected:
void setUp() override {
- ClonerTestFixture::setUp();
- _sharedData = std::make_unique<TenantMigrationSharedData>(kInitialRollbackId, &_clock);
+ TenantClonerTestFixture::setUp();
_standardCreateCollectionFn = [this](OperationContext* opCtx,
const NamespaceString& nss,
const CollectionOptions& options) -> Status {
@@ -87,8 +85,6 @@ protected:
};
_mockServer->assignCollectionUuid(_nss.ns(), _collUuid);
- _mockServer->setCommandReply("replSetGetRBID",
- BSON("ok" << 1 << "rbid" << getSharedData()->getRollBackId()));
_mockClient->setOperationTime(_operationTime);
}
std::unique_ptr<TenantCollectionCloner> makeCollectionCloner(
@@ -128,10 +124,6 @@ protected:
return cloner->_idIndexSpec;
}
- TenantMigrationSharedData* getSharedData() {
- return checked_cast<TenantMigrationSharedData*>(_sharedData.get());
- }
-
StorageInterfaceMock::CreateCollectionFn _standardCreateCollectionFn;
StorageInterfaceMock::CreateIndexesOnEmptyCollectionFn
_standardCreateIndexesOnEmptyCollectionFn;
@@ -148,17 +140,9 @@ protected:
<< "a_1"),
BSON("v" << 1 << "key" << BSON("b" << 1) << "name"
<< "b_1")};
- static std::string _tenantId;
- static NamespaceString _nss;
- static Timestamp _operationTime;
+ const NamespaceString _nss = {_tenantId + "_testDb", "testcoll"};
};
-/* static */
-std::string TenantCollectionClonerTest::_tenantId = "tenant42";
-NamespaceString TenantCollectionClonerTest::_nss = {_tenantId + "_testDb", "testcoll"};
-Timestamp TenantCollectionClonerTest::_operationTime = Timestamp(12345, 42);
-
-
TEST_F(TenantCollectionClonerTest, CountStage) {
auto cloner = makeCollectionCloner();
cloner->setStopAfterStage_forTest("count");
diff --git a/src/mongo/db/repl/tenant_database_cloner.cpp b/src/mongo/db/repl/tenant_database_cloner.cpp
index 2d83fa28018..4294020a281 100644
--- a/src/mongo/db/repl/tenant_database_cloner.cpp
+++ b/src/mongo/db/repl/tenant_database_cloner.cpp
@@ -55,7 +55,7 @@ TenantDatabaseCloner::TenantDatabaseCloner(const std::string& dbName,
StorageInterface* storageInterface,
ThreadPool* dbPool,
StringData tenantId)
- : TenantMigrationBaseCloner(
+ : TenantBaseCloner(
"TenantDatabaseCloner"_sd, sharedData, source, client, storageInterface, dbPool),
_dbName(dbName),
_listCollectionsStage("listCollections", this, &TenantDatabaseCloner::listCollectionsStage),
diff --git a/src/mongo/db/repl/tenant_database_cloner.h b/src/mongo/db/repl/tenant_database_cloner.h
index 87ba04ea3a5..899593d9930 100644
--- a/src/mongo/db/repl/tenant_database_cloner.h
+++ b/src/mongo/db/repl/tenant_database_cloner.h
@@ -32,14 +32,14 @@
#include <vector>
#include "mongo/db/repl/base_cloner.h"
+#include "mongo/db/repl/tenant_base_cloner.h"
#include "mongo/db/repl/tenant_collection_cloner.h"
-#include "mongo/db/repl/tenant_migration_base_cloner.h"
#include "mongo/db/repl/tenant_migration_shared_data.h"
namespace mongo {
namespace repl {
-class TenantDatabaseCloner final : public TenantMigrationBaseCloner {
+class TenantDatabaseCloner final : public TenantBaseCloner {
public:
struct Stats {
std::string dbname;
diff --git a/src/mongo/db/repl/tenant_database_cloner_test.cpp b/src/mongo/db/repl/tenant_database_cloner_test.cpp
index 9c3290a36a6..50385e8fd2f 100644
--- a/src/mongo/db/repl/tenant_database_cloner_test.cpp
+++ b/src/mongo/db/repl/tenant_database_cloner_test.cpp
@@ -29,11 +29,10 @@
#include "mongo/platform/basic.h"
-#include "mongo/base/checked_cast.h"
#include "mongo/db/clientcursor.h"
-#include "mongo/db/repl/cloner_test_fixture.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/repl/storage_interface_mock.h"
+#include "mongo/db/repl/tenant_cloner_test_fixture.h"
#include "mongo/db/repl/tenant_database_cloner.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/dbtests/mock/mock_dbclient_connection.h"
@@ -49,14 +48,13 @@ struct TenantCollectionCloneInfo {
bool collCreated = false;
};
-class TenantDatabaseClonerTest : public ClonerTestFixture {
+class TenantDatabaseClonerTest : public TenantClonerTestFixture {
public:
TenantDatabaseClonerTest() {}
protected:
void setUp() override {
- ClonerTestFixture::setUp();
- _sharedData = std::make_unique<TenantMigrationSharedData>(kInitialRollbackId, &_clock);
+ TenantClonerTestFixture::setUp();
_storageInterface.createCollFn = [this](OperationContext* opCtx,
const NamespaceString& nss,
const CollectionOptions& options) -> Status {
@@ -78,7 +76,6 @@ protected:
collInfo->numDocsInserted += ops.size();
return Status::OK();
};
- setInitialSyncId();
_mockClient->setOperationTime(_operationTime);
}
@@ -127,22 +124,11 @@ protected:
return cloner->_collections;
}
- TenantMigrationSharedData* getSharedData() {
- return checked_cast<TenantMigrationSharedData*>(_sharedData.get());
- }
-
std::map<NamespaceString, TenantCollectionCloneInfo> _collections;
- static std::string _tenantId;
- static std::string _dbName;
- static Timestamp _operationTime;
+ const std::string _dbName = _tenantId + "_testDb";
};
-/* static */
-std::string TenantDatabaseClonerTest::_tenantId = "tenant42";
-std::string TenantDatabaseClonerTest::_dbName = _tenantId + "_testDb";
-Timestamp TenantDatabaseClonerTest::_operationTime = Timestamp(12345, 42);
-
// A database may have no collections. Nothing to do for the tenant database cloner.
TEST_F(TenantDatabaseClonerTest, ListCollectionsReturnedNoCollections) {
_mockServer->setCommandReply("listCollections", createListCollectionsResponse({}));
diff --git a/src/mongo/db/repl/tenant_migration_shared_data.h b/src/mongo/db/repl/tenant_migration_shared_data.h
index aa343545378..63c8283b637 100644
--- a/src/mongo/db/repl/tenant_migration_shared_data.h
+++ b/src/mongo/db/repl/tenant_migration_shared_data.h
@@ -36,29 +36,12 @@ namespace mongo {
namespace repl {
class TenantMigrationSharedData final : public ReplSyncSharedData {
public:
- TenantMigrationSharedData(int rollBackId, ClockSource* clock)
- : ReplSyncSharedData(rollBackId, Days(1) /* allowedOutageDuration */, clock) {}
+ TenantMigrationSharedData(ClockSource* clock) : ReplSyncSharedData(clock) {}
void setLastVisibleOpTime(WithLock, OpTime opTime);
OpTime getLastVisibleOpTime(WithLock);
- // These are all dummy implementations.
- void setSyncSourceWireVersion(WithLock, WireVersion wireVersion) override {}
- boost::optional<WireVersion> getSyncSourceWireVersion(WithLock) override {
- return boost::none;
- }
- void setInitialSyncSourceId(WithLock, boost::optional<UUID> syncSourceId) override {}
- boost::optional<UUID> getInitialSyncSourceId(WithLock) override {
- return boost::none;
- }
- bool shouldRetryOperation(WithLock lk, RetryableOperation* retryableOp) override {
- return false;
- };
- int decrementRetryingOperations(WithLock lk) override {
- return 0;
- }
-
private:
// Must hold mutex (in base class) to access this.
OpTime _lastVisibleOpTime;