summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-07-31 15:26:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-07 13:32:12 +0000
commit9de175fb3776415e7237e6c0af4b76f518adc451 (patch)
tree56a22e0f57be9937d53deed8f76fdbc2502639c3 /src/mongo/db/commands
parent21d5a8e5bd822e71e5fb8feb2f9e71a7e8cf25f9 (diff)
downloadmongo-9de175fb3776415e7237e6c0af4b76f518adc451.tar.gz
SERVER-47885 Added lookupCollectionByXXXForRead interface to the Collection catalog that returns collection as shared_ptr<const Collection>
AutoGetCollectionForRead and AutoGetCollectionForReadCommand now uses this and holds the shared_ptr. They return the collection as const. Const correct various places to make this possible. Moved some logic from Collection destructors to deregister from the catalog as they may now be destroyed at a later point.
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/count_cmd.cpp8
-rw-r--r--src/mongo/db/commands/dbcommands.cpp2
-rw-r--r--src/mongo/db/commands/dbcommands_d.cpp2
-rw-r--r--src/mongo/db/commands/distinct.cpp8
-rw-r--r--src/mongo/db/commands/find_cmd.cpp8
-rw-r--r--src/mongo/db/commands/haystack.cpp4
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp2
-rw-r--r--src/mongo/db/commands/list_indexes.cpp2
-rw-r--r--src/mongo/db/commands/map_reduce_agg.cpp2
-rw-r--r--src/mongo/db/commands/plan_cache_clear_command.cpp2
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp8
11 files changed, 24 insertions, 24 deletions
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp
index fe8c4af8198..45b51b5913e 100644
--- a/src/mongo/db/commands/count_cmd.cpp
+++ b/src/mongo/db/commands/count_cmd.cpp
@@ -138,7 +138,7 @@ public:
boost::optional<AutoGetCollectionForReadCommand> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsCollectionRequired(dbname, cmdObj),
- AutoGetCollection::ViewMode::kViewsPermitted);
+ AutoGetCollectionViewMode::kViewsPermitted);
const auto nss = ctx->getNss();
CountCommand request(NamespaceStringOrUUID(NamespaceString{}));
@@ -173,7 +173,7 @@ public:
result);
}
- Collection* const collection = ctx->getCollection();
+ const Collection* const collection = ctx->getCollection();
// Prevent chunks from being cleaned up during yields - this allows us to only check the
// version on initial entry into count.
@@ -208,7 +208,7 @@ public:
boost::optional<AutoGetCollectionForReadCommand> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsOrUUID(dbname, cmdObj),
- AutoGetCollection::ViewMode::kViewsPermitted);
+ AutoGetCollectionViewMode::kViewsPermitted);
const auto& nss = ctx->getNss();
CurOpFailpointHelpers::waitWhileFailPointEnabled(
@@ -236,7 +236,7 @@ public:
return true;
}
- Collection* const collection = ctx->getCollection();
+ const Collection* const collection = ctx->getCollection();
// Prevent chunks from being cleaned up during yields - this allows us to only check the
// version on initial entry into count.
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index d1addd57762..e6d860afe38 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -468,7 +468,7 @@ public:
const NamespaceString nss(ns);
AutoGetCollectionForReadCommand ctx(opCtx, nss);
- Collection* collection = ctx.getCollection();
+ const Collection* collection = ctx.getCollection();
const auto collDesc =
CollectionShardingState::get(opCtx, nss)->getCollectionDescription(opCtx);
diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp
index de2bf3ed410..37512fdb9ac 100644
--- a/src/mongo/db/commands/dbcommands_d.cpp
+++ b/src/mongo/db/commands/dbcommands_d.cpp
@@ -276,7 +276,7 @@ public:
// We drop and re-acquire these locks every document because md5'ing is expensive
unique_ptr<AutoGetCollectionForReadCommand> ctx(
new AutoGetCollectionForReadCommand(opCtx, nss));
- Collection* coll = ctx->getCollection();
+ const Collection* coll = ctx->getCollection();
auto exec = uassertStatusOK(getExecutor(opCtx,
coll,
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp
index fc8977182e8..4d3f78259e6 100644
--- a/src/mongo/db/commands/distinct.cpp
+++ b/src/mongo/db/commands/distinct.cpp
@@ -136,7 +136,7 @@ public:
boost::optional<AutoGetCollectionForReadCommand> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsCollectionRequired(dbname, cmdObj),
- AutoGetCollection::ViewMode::kViewsPermitted);
+ AutoGetCollectionViewMode::kViewsPermitted);
const auto nss = ctx->getNss();
const ExtensionsCallbackReal extensionsCallback(opCtx, &nss);
@@ -170,7 +170,7 @@ public:
result);
}
- Collection* const collection = ctx->getCollection();
+ const Collection* const collection = ctx->getCollection();
auto executor = uassertStatusOK(
getExecutorDistinct(collection, QueryPlannerParams::DEFAULT, &parsedDistinct));
@@ -190,7 +190,7 @@ public:
boost::optional<AutoGetCollectionForReadCommand> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsOrUUID(dbname, cmdObj),
- AutoGetCollection::ViewMode::kViewsPermitted);
+ AutoGetCollectionViewMode::kViewsPermitted);
const auto& nss = ctx->getNss();
if (!ctx->getView()) {
@@ -231,7 +231,7 @@ public:
return true;
}
- Collection* const collection = ctx->getCollection();
+ const Collection* const collection = ctx->getCollection();
auto executor =
getExecutorDistinct(collection, QueryPlannerParams::DEFAULT, &parsedDistinct);
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index cba4f1d224e..3f4d7d840df 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -236,7 +236,7 @@ public:
boost::optional<AutoGetCollectionForReadCommand> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsCollectionRequired(_dbName, _request.body),
- AutoGetCollection::ViewMode::kViewsPermitted);
+ AutoGetCollectionViewMode::kViewsPermitted);
const auto nss = ctx->getNss();
// Parse the command BSON to a QueryRequest.
@@ -285,7 +285,7 @@ public:
// The collection may be NULL. If so, getExecutor() should handle it by returning an
// execution tree with an EOFStage.
- Collection* const collection = ctx->getCollection();
+ const Collection* const collection = ctx->getCollection();
// Get the execution plan for the query.
bool permitYield = true;
@@ -359,7 +359,7 @@ public:
boost::optional<AutoGetCollectionForReadCommand> ctx;
ctx.emplace(opCtx,
CommandHelpers::parseNsOrUUID(_dbName, _request.body),
- AutoGetCollection::ViewMode::kViewsPermitted);
+ AutoGetCollectionViewMode::kViewsPermitted);
const auto& nss = ctx->getNss();
qr->refreshNSS(opCtx);
@@ -408,7 +408,7 @@ public:
return;
}
- Collection* const collection = ctx->getCollection();
+ const Collection* const collection = ctx->getCollection();
if (cq->getQueryRequest().isReadOnce()) {
// The readOnce option causes any storage-layer cursors created during plan
diff --git a/src/mongo/db/commands/haystack.cpp b/src/mongo/db/commands/haystack.cpp
index e4af2078f3a..bd991dffa1e 100644
--- a/src/mongo/db/commands/haystack.cpp
+++ b/src/mongo/db/commands/haystack.cpp
@@ -110,7 +110,7 @@ public:
void searchHaystack(const HaystackAccessMethod* ham,
OperationContext* opCtx,
- Collection* collection,
+ const Collection* collection,
const BSONObj& nearObj,
double maxDistance,
const BSONObj& search,
@@ -233,7 +233,7 @@ public:
uassertStatusOK(replCoord->checkCanServeReadsFor(
opCtx, nss, ReadPreferenceSetting::get(opCtx).canRunOnSecondary()));
- Collection* collection = ctx.getCollection();
+ const Collection* collection = ctx.getCollection();
if (!collection) {
errmsg = "can't find ns";
return false;
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index 5bc77e30947..a7d6239eaab 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -65,7 +65,7 @@ using namespace mongo;
* Retrieves a collection's query settings and plan cache from the database.
*/
static Status getQuerySettingsAndPlanCache(OperationContext* opCtx,
- Collection* collection,
+ const Collection* collection,
const string& ns,
QuerySettings** querySettingsOut,
PlanCache** planCacheOut) {
diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp
index 6b3a51ad12e..e793ddf2f6f 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -155,7 +155,7 @@ public:
{
AutoGetCollectionForReadCommand ctx(opCtx,
CommandHelpers::parseNsOrUUID(dbname, cmdObj));
- Collection* collection = ctx.getCollection();
+ const Collection* collection = ctx.getCollection();
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "ns does not exist: " << ctx.getNss().ns(),
collection);
diff --git a/src/mongo/db/commands/map_reduce_agg.cpp b/src/mongo/db/commands/map_reduce_agg.cpp
index 4cbbb87dc41..2f5b656262e 100644
--- a/src/mongo/db/commands/map_reduce_agg.cpp
+++ b/src/mongo/db/commands/map_reduce_agg.cpp
@@ -62,7 +62,7 @@ auto makeExpressionContext(OperationContext* opCtx,
// AutoGetCollectionForReadCommand will throw if the sharding version for this connection is
// out of date.
AutoGetCollectionForReadCommand ctx(
- opCtx, parsedMr.getNamespace(), AutoGetCollection::ViewMode::kViewsPermitted);
+ opCtx, parsedMr.getNamespace(), AutoGetCollectionViewMode::kViewsPermitted);
uassert(ErrorCodes::CommandNotSupportedOnView,
"mapReduce on a view is not supported",
!ctx.getView());
diff --git a/src/mongo/db/commands/plan_cache_clear_command.cpp b/src/mongo/db/commands/plan_cache_clear_command.cpp
index 490af16b497..61660438f04 100644
--- a/src/mongo/db/commands/plan_cache_clear_command.cpp
+++ b/src/mongo/db/commands/plan_cache_clear_command.cpp
@@ -47,7 +47,7 @@
namespace mongo {
namespace {
-PlanCache* getPlanCache(OperationContext* opCtx, Collection* collection) {
+PlanCache* getPlanCache(OperationContext* opCtx, const Collection* collection) {
invariant(collection);
PlanCache* planCache = CollectionQueryInfo::get(collection).getPlanCache();
invariant(planCache);
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index 3083dd36d4c..74c118f5b8f 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -533,7 +533,7 @@ Status runAggregate(OperationContext* opCtx,
PipelineD::resolveCollator(opCtx, request.getCollation(), nullptr));
// Obtain collection locks on the execution namespace; that is, the oplog.
- ctx.emplace(opCtx, nss, AutoGetCollection::ViewMode::kViewsForbidden);
+ ctx.emplace(opCtx, nss, AutoGetCollectionViewMode::kViewsForbidden);
} else if (nss.isCollectionlessAggregateNS() && pipelineInvolvedNamespaces.empty()) {
// If this is a collectionless agg with no foreign namespaces, don't acquire any locks.
statsTracker.emplace(opCtx,
@@ -545,7 +545,7 @@ Status runAggregate(OperationContext* opCtx,
PipelineD::resolveCollator(opCtx, request.getCollation(), nullptr));
} else {
// This is a regular aggregation. Lock the collection or view.
- ctx.emplace(opCtx, nss, AutoGetCollection::ViewMode::kViewsPermitted);
+ ctx.emplace(opCtx, nss, AutoGetCollectionViewMode::kViewsPermitted);
collatorToUse.emplace(
PipelineD::resolveCollator(opCtx, request.getCollation(), ctx->getCollection()));
if (ctx->getCollection()) {
@@ -553,7 +553,7 @@ Status runAggregate(OperationContext* opCtx,
}
}
- Collection* collection = ctx ? ctx->getCollection() : nullptr;
+ const Collection* collection = ctx ? ctx->getCollection() : nullptr;
// If this is a view, resolve it by finding the underlying collection and stitching view
// pipelines and this request's pipeline together. We then release our locks before
@@ -759,7 +759,7 @@ Status runAggregate(OperationContext* opCtx,
// For an optimized away pipeline, signal the cache that a query operation has completed.
// For normal pipelines this is done in DocumentSourceCursor.
if (ctx && ctx->getCollection()) {
- Collection* coll = ctx->getCollection();
+ const Collection* coll = ctx->getCollection();
CollectionQueryInfo::get(coll).notifyOfQuery(opCtx, coll, stats);
}
}