summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-01-14 18:17:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-14 19:07:36 +0000
commit57c92c38aa9a7346c2b806596aef208a2d5fb3db (patch)
treede3af9bbf4cdb96ad693c5783dca4b173036c85c
parent4371faec4e537ed676fba1f9e4af944a01a733c7 (diff)
downloadmongo-57c92c38aa9a7346c2b806596aef208a2d5fb3db.tar.gz
SERVER-62654 Add `checkCollectionUUIDMismatch` helper
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.cpp25
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.h4
-rw-r--r--src/mongo/db/commands/find_cmd.cpp13
3 files changed, 24 insertions, 18 deletions
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.cpp b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
index 13354d6ab36..7639f7570ca 100644
--- a/src/mongo/db/catalog/collection_uuid_mismatch.cpp
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
@@ -31,13 +31,26 @@
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/catalog/collection_uuid_mismatch_info.h"
+#include "mongo/db/storage/storage_parameters_gen.h"
namespace mongo {
-void uassertCollectionUUIDMismatch(OperationContext* opCtx, const UUID& uuid) {
- uassertStatusOK({CollectionUUIDMismatchInfo{uuid,
- CollectionCatalog::get(opCtx)
- ->lookupNSSByUUID(opCtx, uuid)
- .value_or(NamespaceString{})},
- "Collection UUID does not match that specified"});
+void checkCollectionUUIDMismatch(OperationContext* opCtx,
+ const CollectionPtr& coll,
+ const boost::optional<UUID>& uuid) {
+ if (!uuid) {
+ return;
+ }
+
+ uassert(ErrorCodes::InvalidOptions,
+ "The collectionUUID parameter is not enabled",
+ feature_flags::gCommandsAcceptCollectionUUID.isEnabled(
+ serverGlobalParams.featureCompatibility));
+
+ uassert((CollectionUUIDMismatchInfo{*uuid,
+ CollectionCatalog::get(opCtx)
+ ->lookupNSSByUUID(opCtx, *uuid)
+ .value_or(NamespaceString{})}),
+ "Collection UUID does not match that specified",
+ coll && coll->uuid() == *uuid);
}
} // namespace mongo
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.h b/src/mongo/db/catalog/collection_uuid_mismatch.h
index de79c57ddb4..3c0fd3ed3a7 100644
--- a/src/mongo/db/catalog/collection_uuid_mismatch.h
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.h
@@ -32,5 +32,7 @@
#include "mongo/db/operation_context.h"
namespace mongo {
-void uassertCollectionUUIDMismatch(OperationContext* opCtx, const UUID& uuid);
+void checkCollectionUUIDMismatch(OperationContext* opCtx,
+ const CollectionPtr& coll,
+ const boost::optional<UUID>& uuid);
} // namespace mongo
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index 3ab8d7d8d6a..665a58c0850 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -478,17 +478,8 @@ public:
<< " specified in query request not found",
ctx || !findCommand->getNamespaceOrUUID().uuid());
- uassert(ErrorCodes::InvalidOptions,
- "The collectionUUID parameter is not enabled",
- !findCommand->getCollectionUUID() ||
- feature_flags::gCommandsAcceptCollectionUUID.isEnabled(
- serverGlobalParams.featureCompatibility));
-
- if (findCommand->getCollectionUUID() &&
- (!ctx->getCollection() ||
- findCommand->getCollectionUUID() != ctx->getCollection()->uuid())) {
- uassertCollectionUUIDMismatch(opCtx, *findCommand->getCollectionUUID());
- }
+ checkCollectionUUIDMismatch(
+ opCtx, ctx->getCollection(), findCommand->getCollectionUUID());
// Set the namespace if a collection was found, as opposed to nothing or a view.
if (ctx) {