summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-10-21 14:14:13 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-10-21 14:46:55 +0000
commit478c1607b57bc725eee1bec6ca04f177d4de1520 (patch)
tree1c8cd8047eb33e37e818e365416535a6ae250fe5 /src/mongo/db/commands
parent06e43e02a452ae1c4fffcffb0242b4a528bdacb4 (diff)
downloadmongo-478c1607b57bc725eee1bec6ca04f177d4de1520.tar.gz
SERVER-68337 Perform `collectionUUID` check inside `AutoGetCollection`
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/count_cmd.cpp14
-rw-r--r--src/mongo/db/commands/create_indexes_cmd.cpp9
-rw-r--r--src/mongo/db/commands/distinct.cpp14
-rw-r--r--src/mongo/db/commands/find_cmd.cpp10
-rw-r--r--src/mongo/db/commands/map_reduce_agg.cpp4
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp11
6 files changed, 34 insertions, 28 deletions
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp
index 0b875b9fa67..194ebe36ff1 100644
--- a/src/mongo/db/commands/count_cmd.cpp
+++ b/src/mongo/db/commands/count_cmd.cpp
@@ -153,9 +153,10 @@ public:
// Acquire locks. The RAII object is optional, because in the case
// of a view, the locks need to be released.
boost::optional<AutoGetCollectionForReadCommandMaybeLockFree> ctx;
- ctx.emplace(opCtx,
- CommandHelpers::parseNsCollectionRequired(dbName, cmdObj),
- auto_get_collection::ViewMode::kViewsPermitted);
+ ctx.emplace(
+ opCtx,
+ CommandHelpers::parseNsCollectionRequired(dbName, cmdObj),
+ AutoGetCollection::Options{}.viewMode(auto_get_collection::ViewMode::kViewsPermitted));
const auto nss = ctx->getNss();
CountCommandRequest request(NamespaceStringOrUUID(NamespaceString{}));
@@ -234,9 +235,10 @@ public:
// Acquire locks and resolve possible UUID. The RAII object is optional, because in the case
// of a view, the locks need to be released.
boost::optional<AutoGetCollectionForReadCommandMaybeLockFree> ctx;
- ctx.emplace(opCtx,
- CommandHelpers::parseNsOrUUID(dbName, cmdObj),
- auto_get_collection::ViewMode::kViewsPermitted);
+ ctx.emplace(
+ opCtx,
+ CommandHelpers::parseNsOrUUID(dbName, cmdObj),
+ AutoGetCollection::Options{}.viewMode(auto_get_collection::ViewMode::kViewsPermitted));
const auto& nss = ctx->getNss();
CurOpFailpointHelpers::waitWhileFailPointEnabled(
diff --git a/src/mongo/db/commands/create_indexes_cmd.cpp b/src/mongo/db/commands/create_indexes_cmd.cpp
index 6010cfcd64c..bad9b865ac1 100644
--- a/src/mongo/db/commands/create_indexes_cmd.cpp
+++ b/src/mongo/db/commands/create_indexes_cmd.cpp
@@ -500,12 +500,13 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx,
}
bool indexExists = writeConflictRetry(opCtx, "createCollectionWithIndexes", ns.ns(), [&] {
- AutoGetCollection collection(opCtx, ns, MODE_IX);
+ AutoGetCollection collection(
+ opCtx,
+ ns,
+ MODE_IX,
+ AutoGetCollection::Options{}.expectedUUID(cmd.getCollectionUUID()));
CollectionShardingState::get(opCtx, ns)->checkShardVersionOrThrow(opCtx);
- checkCollectionUUIDMismatch(
- opCtx, ns, collection.getCollection(), cmd.getCollectionUUID());
-
// Before potentially taking an exclusive collection lock, check if all indexes already
// exist while holding an intent lock.
if (collection &&
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp
index e37ff47d2de..c4c89cbf66c 100644
--- a/src/mongo/db/commands/distinct.cpp
+++ b/src/mongo/db/commands/distinct.cpp
@@ -151,9 +151,10 @@ public:
// Acquire locks. The RAII object is optional, because in the case of a view, the locks
// need to be released.
boost::optional<AutoGetCollectionForReadCommandMaybeLockFree> ctx;
- ctx.emplace(opCtx,
- CommandHelpers::parseNsCollectionRequired(dbName, cmdObj),
- auto_get_collection::ViewMode::kViewsPermitted);
+ ctx.emplace(
+ opCtx,
+ CommandHelpers::parseNsCollectionRequired(dbName, cmdObj),
+ AutoGetCollection::Options{}.viewMode(auto_get_collection::ViewMode::kViewsPermitted));
const auto nss = ctx->getNss();
const ExtensionsCallbackReal extensionsCallback(opCtx, &nss);
@@ -205,9 +206,10 @@ public:
// Acquire locks and resolve possible UUID. The RAII object is optional, because in the case
// of a view, the locks need to be released.
boost::optional<AutoGetCollectionForReadCommandMaybeLockFree> ctx;
- ctx.emplace(opCtx,
- CommandHelpers::parseNsOrUUID(dbName, cmdObj),
- auto_get_collection::ViewMode::kViewsPermitted);
+ ctx.emplace(
+ opCtx,
+ CommandHelpers::parseNsOrUUID(dbName, cmdObj),
+ AutoGetCollection::Options{}.viewMode(auto_get_collection::ViewMode::kViewsPermitted));
const auto& nss = ctx->getNss();
if (!ctx->getView()) {
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index c3d62936a84..5036cce11e5 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -288,7 +288,8 @@ public:
boost::optional<AutoGetCollectionForReadCommandMaybeLockFree> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsCollectionRequired(_dbName, _request.body),
- auto_get_collection::ViewMode::kViewsPermitted);
+ AutoGetCollection::Options{}.viewMode(
+ auto_get_collection::ViewMode::kViewsPermitted));
const auto nss = ctx->getNss();
// Going forward this operation must never ignore interrupt signals while waiting for
@@ -473,7 +474,9 @@ public:
boost::optional<AutoGetCollectionForReadCommandMaybeLockFree> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsOrUUID(_dbName, _request.body),
- auto_get_collection::ViewMode::kViewsPermitted);
+ AutoGetCollection::Options{}
+ .viewMode(auto_get_collection::ViewMode::kViewsPermitted)
+ .expectedUUID(findCommand->getCollectionUUID()));
const auto& nss = ctx->getNss();
// Going forward this operation must never ignore interrupt signals while waiting for
@@ -490,9 +493,6 @@ public:
<< " specified in query request not found",
ctx || !findCommand->getNamespaceOrUUID().uuid());
- checkCollectionUUIDMismatch(
- opCtx, nss, ctx->getCollection(), findCommand->getCollectionUUID());
-
// Set the namespace if a collection was found, as opposed to nothing or a view.
if (ctx) {
query_request_helper::refreshNSS(ctx->getNss(), findCommand.get());
diff --git a/src/mongo/db/commands/map_reduce_agg.cpp b/src/mongo/db/commands/map_reduce_agg.cpp
index 73560f2b1c3..f78993457e2 100644
--- a/src/mongo/db/commands/map_reduce_agg.cpp
+++ b/src/mongo/db/commands/map_reduce_agg.cpp
@@ -69,7 +69,9 @@ auto makeExpressionContext(OperationContext* opCtx,
// AutoGetCollectionForReadCommand will throw if the sharding version for this connection is
// out of date.
AutoGetCollectionForReadCommandMaybeLockFree ctx(
- opCtx, parsedMr.getNamespace(), auto_get_collection::ViewMode::kViewsPermitted);
+ opCtx,
+ parsedMr.getNamespace(),
+ AutoGetCollection::Options{}.viewMode(auto_get_collection::ViewMode::kViewsPermitted));
uassert(ErrorCodes::CommandNotSupportedOnView,
"mapReduce on a view is not supported",
!ctx.getView());
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index e558e3b3ef4..6294be64f83 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -705,12 +705,11 @@ Status runAggregate(OperationContext* opCtx,
InterruptibleLockGuard interruptibleLockAcquisition(opCtx->lockState());
auto initContext = [&](auto_get_collection::ViewMode m) -> void {
- ctx.emplace(opCtx,
- nss,
- m,
- Date_t::max(),
- AutoStatsTracker::LogMode::kUpdateTopAndCurOp,
- secondaryExecNssList);
+ ctx.emplace(
+ opCtx,
+ nss,
+ AutoGetCollection::Options{}.viewMode(m).secondaryNssOrUUIDs(secondaryExecNssList),
+ AutoStatsTracker::LogMode::kUpdateTopAndCurOp);
collections = MultipleCollectionAccessor(opCtx,
&ctx->getCollection(),
ctx->getNss(),