summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-01-24 20:10:27 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-24 21:24:12 +0000
commit2d23c2650eee84f5bcbb9bef5acdad4a583d488b (patch)
tree1d5d632b12e088b2b06e97f043eda0ea9527c2fb /src/mongo/db/s
parentba25336add6ed39d8a5dc3d0371e3e34730aa83d (diff)
downloadmongo-2d23c2650eee84f5bcbb9bef5acdad4a583d488b.tar.gz
SERVER-62454 Add `collectionUUID` parameter to `shardCollection` command
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/create_collection_coordinator.cpp8
-rw-r--r--src/mongo/db/s/create_collection_coordinator.h5
2 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp
index ad201f5caf4..f705250c347 100644
--- a/src/mongo/db/s/create_collection_coordinator.cpp
+++ b/src/mongo/db/s/create_collection_coordinator.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/audit.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/cancelable_operation_context.h"
+#include "mongo/db/catalog/collection_uuid_mismatch.h"
#include "mongo/db/catalog/create_collection.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/commands/create_gen.h"
@@ -473,6 +474,7 @@ ExecutorFuture<void> CreateCollectionCoordinator::_runImpl(
getCollation(opCtx, nss(), _doc.getCollation()).second,
_doc.getUnique().value_or(false))) {
_result = createCollectionResponseOpt;
+ _checkCollectionUUIDMismatch(opCtx);
// The collection was already created and commited but there was a
// stepdown after the commit.
RecoverableCriticalSectionService::get(opCtx)
@@ -511,6 +513,7 @@ ExecutorFuture<void> CreateCollectionCoordinator::_runImpl(
}
}
+ _checkCollectionUUIDMismatch(opCtx);
_createPolicy(opCtx);
_createCollectionAndIndexes(opCtx);
@@ -675,6 +678,11 @@ void CreateCollectionCoordinator::_checkCommandArguments(OperationContext* opCtx
}
}
+void CreateCollectionCoordinator::_checkCollectionUUIDMismatch(OperationContext* opCtx) const {
+ AutoGetCollection coll{opCtx, nss(), MODE_IS};
+ checkCollectionUUIDMismatch(opCtx, coll.getCollection(), _doc.getCollectionUUID());
+}
+
void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext* opCtx) {
LOGV2_DEBUG(
5277903, 2, "Create collection _createCollectionAndIndexes", "namespace"_attr = nss());
diff --git a/src/mongo/db/s/create_collection_coordinator.h b/src/mongo/db/s/create_collection_coordinator.h
index 446f430b33f..bee8b8d2c79 100644
--- a/src/mongo/db/s/create_collection_coordinator.h
+++ b/src/mongo/db/s/create_collection_coordinator.h
@@ -98,6 +98,11 @@ private:
void _checkCommandArguments(OperationContext* opCtx);
/**
+ * Checks that the collection has UUID matching the collectionUUID parameter, if provided.
+ */
+ void _checkCollectionUUIDMismatch(OperationContext* opCtx) const;
+
+ /**
* Ensures the collection is created locally and has the appropiate shard index.
*/
void _createCollectionAndIndexes(OperationContext* opCtx);