summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/initial_syncer_test.cpp
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2017-09-23 17:59:29 -0400
committerMaria van Keulen <maria@mongodb.com>2017-10-09 13:28:52 -0400
commit84690cb878db1b231c00d3c9fcb0005ca7cb6361 (patch)
tree738d18a8d529febb9ce18e3659f8abd020e35590 /src/mongo/db/repl/initial_syncer_test.cpp
parent11704779713e962e7756291960104d517adac16c (diff)
downloadmongo-84690cb878db1b231c00d3c9fcb0005ca7cb6361.tar.gz
SERVER-30131 Ensure collections on local have UUIDs
Diffstat (limited to 'src/mongo/db/repl/initial_syncer_test.cpp')
-rw-r--r--src/mongo/db/repl/initial_syncer_test.cpp108
1 files changed, 106 insertions, 2 deletions
diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp
index 952c3d5e2f4..04e7b67c32a 100644
--- a/src/mongo/db/repl/initial_syncer_test.cpp
+++ b/src/mongo/db/repl/initial_syncer_test.cpp
@@ -222,6 +222,10 @@ protected:
bool droppedUserDBs = false;
std::vector<std::string> droppedCollections;
int documentsInsertedCount = 0;
+ bool schemaUpgraded = false;
+ OptionalCollectionUUID uuid;
+ bool getCollectionUUIDShouldFail = false;
+ bool upgradeUUIDSchemaVersionNonReplicatedShouldFail = false;
};
stdx::mutex _storageInterfaceWorkDoneMutex; // protects _storageInterfaceWorkDone.
@@ -234,6 +238,10 @@ protected:
const NamespaceString& nss) {
LockGuard lock(_storageInterfaceWorkDoneMutex);
_storageInterfaceWorkDone.createOplogCalled = true;
+ _storageInterfaceWorkDone.schemaUpgraded = false;
+ _storageInterfaceWorkDone.uuid = boost::none;
+ _storageInterfaceWorkDone.getCollectionUUIDShouldFail = false;
+ _storageInterfaceWorkDone.upgradeUUIDSchemaVersionNonReplicatedShouldFail = false;
return Status::OK();
};
_storageInterface->truncateCollFn = [this](OperationContext* opCtx,
@@ -286,6 +294,35 @@ protected:
return StatusWith<std::unique_ptr<CollectionBulkLoader>>(
std::unique_ptr<CollectionBulkLoader>(collInfo->loader));
};
+ _storageInterface->getCollectionUUIDFn = [this](OperationContext* opCtx,
+ const NamespaceString& nss) {
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ if (_storageInterfaceWorkDone.getCollectionUUIDShouldFail) {
+ // getCollectionUUID returns NamespaceNotFound if either the db or the collection is
+ // missing.
+ return StatusWith<OptionalCollectionUUID>(Status(
+ ErrorCodes::NamespaceNotFound,
+ str::stream() << "getCollectionUUID failed because namespace " << nss.ns()
+ << " not found."));
+ } else {
+ return StatusWith<OptionalCollectionUUID>(_storageInterfaceWorkDone.uuid);
+ }
+ };
+
+ _storageInterface->upgradeUUIDSchemaVersionNonReplicatedFn =
+ [this](OperationContext* opCtx) {
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ if (_storageInterfaceWorkDone.upgradeUUIDSchemaVersionNonReplicatedShouldFail) {
+ // One of the status codes a failed upgradeUUIDSchemaVersionNonReplicated call
+ // can return is NamespaceNotFound.
+ return Status(ErrorCodes::NamespaceNotFound,
+ "upgradeUUIDSchemaVersionNonReplicated failed because the "
+ "desired ns was not found.");
+ } else {
+ _storageInterfaceWorkDone.schemaUpgraded = true;
+ return Status::OK();
+ }
+ };
_dbWorkThreadPool = stdx::make_unique<OldThreadPool>(1);
@@ -405,6 +442,9 @@ protected:
}
}
+ void doSuccessfulInitialSyncWithOneBatch();
+ OplogEntry doInitialSyncWithOneBatch();
+
std::unique_ptr<TaskExecutorMock> _executorProxy;
InitialSyncerOptions _options;
@@ -2998,8 +3038,7 @@ TEST_F(InitialSyncerTest, InitialSyncerCancelsGetNextApplierBatchCallbackOnOplog
ASSERT_EQUALS(ErrorCodes::OperationFailed, _lastApplied);
}
-TEST_F(InitialSyncerTest,
- InitialSyncerReturnsLastAppliedOnReachingStopTimestampAfterApplyingOneBatch) {
+OplogEntry InitialSyncerTest::doInitialSyncWithOneBatch() {
auto initialSyncer = &getInitialSyncer();
auto opCtx = makeOpCtx();
@@ -3056,6 +3095,11 @@ TEST_F(InitialSyncerTest,
}
initialSyncer->join();
+ return lastOp;
+}
+
+void InitialSyncerTest::doSuccessfulInitialSyncWithOneBatch() {
+ auto lastOp = doInitialSyncWithOneBatch();
ASSERT_EQUALS(lastOp.getOpTime(), unittest::assertGet(_lastApplied).opTime);
ASSERT_EQUALS(lastOp.getHash(), unittest::assertGet(_lastApplied).value);
@@ -3064,6 +3108,17 @@ TEST_F(InitialSyncerTest,
}
TEST_F(InitialSyncerTest,
+ InitialSyncerReturnsLastAppliedOnReachingStopTimestampAfterApplyingOneBatch) {
+ // In this test, getCollectionUUID should not return a UUID. Hence,
+ // upgradeUUIDSchemaVersionNonReplicated should not be called.
+ doSuccessfulInitialSyncWithOneBatch();
+
+ // Ensure upgradeUUIDSchemaVersionNonReplicated was not called.
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ ASSERT_FALSE(_storageInterfaceWorkDone.schemaUpgraded);
+}
+
+TEST_F(InitialSyncerTest,
InitialSyncerReturnsLastAppliedOnReachingStopTimestampAfterApplyingMultipleBatches) {
auto initialSyncer = &getInitialSyncer();
auto opCtx = makeOpCtx();
@@ -3586,4 +3641,53 @@ TEST_F(InitialSyncerTest, GetInitialSyncProgressReturnsCorrectProgress) {
<< attempt1;
}
+TEST_F(InitialSyncerTest, InitialSyncerUpdatesCollectionUUIDsIfgetCollectionUUIDReturnsUUID) {
+ // Ensure getCollectionUUID returns a UUID. This should trigger a call to
+ // upgradeUUIDSchemaVersionNonReplicated.
+ {
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ _storageInterfaceWorkDone.uuid = UUID::gen();
+ }
+ doSuccessfulInitialSyncWithOneBatch();
+
+ // Ensure upgradeUUIDSchemaVersionNonReplicated was called.
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ ASSERT_TRUE(_storageInterfaceWorkDone.schemaUpgraded);
+}
+
+TEST_F(InitialSyncerTest, InitialSyncerCapturesGetCollectionUUIDError) {
+ // Ensure getCollectionUUID returns a bad status. This should be passed to the initial syncer.
+ {
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ _storageInterfaceWorkDone.getCollectionUUIDShouldFail = true;
+ }
+ doInitialSyncWithOneBatch();
+
+ // Ensure the getCollectionUUID status was captured.
+ ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, _lastApplied);
+
+ // Ensure upgradeUUIDSchemaVersionNonReplicated was not called.
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ ASSERT_FALSE(_storageInterfaceWorkDone.schemaUpgraded);
+}
+
+TEST_F(InitialSyncerTest, InitialSyncerCapturesUpgradeUUIDSchemaVersionError) {
+ // Ensure getCollectionUUID returns a UUID. This should trigger a call to
+ // upgradeUUIDSchemaVersionNonReplicated.
+ {
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ _storageInterfaceWorkDone.uuid = UUID::gen();
+ }
+
+ // Ensure upgradeUUIDSchemaVersionNonReplicated returns a bad status. This should be passed to
+ // the initial syncer.
+ {
+ LockGuard lock(_storageInterfaceWorkDoneMutex);
+ _storageInterfaceWorkDone.upgradeUUIDSchemaVersionNonReplicatedShouldFail = true;
+ }
+ doInitialSyncWithOneBatch();
+
+ // Ensure the upgradeUUIDSchemaVersionNonReplicated status was captured.
+ ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, _lastApplied);
+}
} // namespace