summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/rename_collection_test.cpp
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2018-05-17 15:12:05 -0400
committerMaria van Keulen <maria@mongodb.com>2018-06-06 16:54:44 -0400
commit7c12245583958023e35bce05d6b2212dcd7f24e3 (patch)
tree4cfa8bb4915cef1973b208d33fa6023b1c5cdb65 /src/mongo/db/catalog/rename_collection_test.cpp
parent0b001ed1ab7e8443213db38030cf17d2a6f5be2c (diff)
downloadmongo-7c12245583958023e35bce05d6b2212dcd7f24e3.tar.gz
SERVER-34615 Make UUIDCatalog updates for renameCollection atomic
Diffstat (limited to 'src/mongo/db/catalog/rename_collection_test.cpp')
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp72
1 files changed, 55 insertions, 17 deletions
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index ede724e4968..52bfaf4c8e8 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -94,13 +94,25 @@ public:
const NamespaceString& collectionName,
OptionalCollectionUUID uuid) override;
- repl::OpTime onRenameCollection(OperationContext* opCtx,
- const NamespaceString& fromCollection,
- const NamespaceString& toCollection,
- OptionalCollectionUUID uuid,
- OptionalCollectionUUID dropTargetUUID,
- bool stayTemp) override;
-
+ void onRenameCollection(OperationContext* opCtx,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ OptionalCollectionUUID uuid,
+ OptionalCollectionUUID dropTargetUUID,
+ bool stayTemp) override;
+
+ repl::OpTime preRenameCollection(OperationContext* opCtx,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ OptionalCollectionUUID uuid,
+ OptionalCollectionUUID dropTargetUUID,
+ bool stayTemp) override;
+ void postRenameCollection(OperationContext* opCtx,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ OptionalCollectionUUID uuid,
+ OptionalCollectionUUID dropTargetUUID,
+ bool stayTemp) override;
// Operations written to the oplog. These are operations for which
// ReplicationCoordinator::isOplogDisabled() returns false.
std::vector<std::string> oplogEntries;
@@ -167,21 +179,43 @@ repl::OpTime OpObserverMock::onDropCollection(OperationContext* opCtx,
return {};
}
-repl::OpTime OpObserverMock::onRenameCollection(OperationContext* opCtx,
- const NamespaceString& fromCollection,
- const NamespaceString& toCollection,
- OptionalCollectionUUID uuid,
- OptionalCollectionUUID dropTargetUUID,
- bool stayTemp) {
- _logOp(opCtx, fromCollection, "rename");
- OpObserver::Times::get(opCtx).reservedOpTimes.push_back(renameOpTime);
+void OpObserverMock::onRenameCollection(OperationContext* opCtx,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ OptionalCollectionUUID uuid,
+ OptionalCollectionUUID dropTargetUUID,
+ bool stayTemp) {
+ preRenameCollection(opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp);
OpObserverNoop::onRenameCollection(
opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp);
onRenameCollectionCalled = true;
onRenameCollectionDropTarget = dropTargetUUID;
- return {};
}
+void OpObserverMock::postRenameCollection(OperationContext* opCtx,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ OptionalCollectionUUID uuid,
+ OptionalCollectionUUID dropTargetUUID,
+ bool stayTemp) {
+ OpObserverNoop::postRenameCollection(
+ opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp);
+ onRenameCollectionCalled = true;
+ onRenameCollectionDropTarget = dropTargetUUID;
+}
+
+repl::OpTime OpObserverMock::preRenameCollection(OperationContext* opCtx,
+ const NamespaceString& fromCollection,
+ const NamespaceString& toCollection,
+ OptionalCollectionUUID uuid,
+ OptionalCollectionUUID dropTargetUUID,
+ bool stayTemp) {
+ _logOp(opCtx, fromCollection, "rename");
+ OpObserver::Times::get(opCtx).reservedOpTimes.push_back(renameOpTime);
+ OpObserverNoop::preRenameCollection(
+ opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp);
+ return {};
+}
void OpObserverMock::_logOp(OperationContext* opCtx,
const NamespaceString& nss,
const std::string& operationName) {
@@ -566,6 +600,10 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetDo
ASSERT_FALSE(_collectionExists(_opCtx.get(), collC));
// B (originally A) should exist
ASSERT_TRUE(_collectionExists(_opCtx.get(), collB));
+ // collAUUID should be associated with collB's NamespaceString in the UUIDCatalog.
+ auto newCollNS = _getCollectionNssFromUUID(_opCtx.get(), collAUUID);
+ ASSERT_TRUE(newCollNS.isValid());
+ ASSERT_EQUALS(newCollNS, collB);
}
TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetExists) {
@@ -718,7 +756,7 @@ TEST_F(RenameCollectionTest,
repl::UnreplicatedWritesBlock uwb(_opCtx.get());
ASSERT_FALSE(_opCtx->writesAreReplicated());
- // OpObserver::onRenameCollection() must return a null OpTime when writes are not replicated.
+ // OpObserver::preRenameCollection() must return a null OpTime when writes are not replicated.
_opObserver->renameOpTime = {};
_createCollection(_opCtx.get(), _sourceNss);