summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-09-30 11:19:31 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-13 00:32:43 +0000
commitbcab0c7e1c1b2e1516d06d23233fea9a425b99f7 (patch)
tree8d805048d69ece52bb64e740532f5968b671865c /src/mongo/db/commands
parent0dadef8dd93175bf3a75412d8a32b377d9eba42c (diff)
downloadmongo-bcab0c7e1c1b2e1516d06d23233fea9a425b99f7.tar.gz
SERVER-51200 CollectionPtr in RequiresCollectionStage point to instance owned by AutoGetCollection
RequiresCollectionStage now holds a pointer to CollectionPtr owned by an AutoGetCollection. When we save and restore the executor a new CollectionPtr pointer needs to be assigned. Plan executors can no longer be created with temporary CollectionPtr instances and their interface have been changed to take pointers to avoid binding to rvalues. RequiresCollectionStage no longer loads collections from the catalog and will be in sync with the owning AutoGetCollection.
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/count_cmd.cpp4
-rw-r--r--src/mongo/db/commands/dbcommands.cpp4
-rw-r--r--src/mongo/db/commands/dbcommands_d.cpp4
-rw-r--r--src/mongo/db/commands/dbhash.cpp4
-rw-r--r--src/mongo/db/commands/distinct.cpp4
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp8
-rw-r--r--src/mongo/db/commands/find_cmd.cpp4
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp6
-rw-r--r--src/mongo/db/commands/haystack.cpp2
-rw-r--r--src/mongo/db/commands/list_collections.cpp2
-rw-r--r--src/mongo/db/commands/list_indexes.cpp2
-rw-r--r--src/mongo/db/commands/test_commands.cpp2
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp12
13 files changed, 31 insertions, 27 deletions
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp
index 427a9f2da96..ed880886f40 100644
--- a/src/mongo/db/commands/count_cmd.cpp
+++ b/src/mongo/db/commands/count_cmd.cpp
@@ -190,7 +190,7 @@ public:
opCtx, request.getCollation().value_or(BSONObj()), nss);
auto statusWithPlanExecutor =
- getExecutorCount(expCtx, collection, request, true /*explain*/, nss);
+ getExecutorCount(expCtx, &collection, request, true /*explain*/, nss);
if (!statusWithPlanExecutor.isOK()) {
return statusWithPlanExecutor.getStatus();
}
@@ -252,7 +252,7 @@ public:
auto statusWithPlanExecutor =
getExecutorCount(makeExpressionContextForGetExecutor(
opCtx, request.getCollation().value_or(BSONObj()), nss),
- collection,
+ &collection,
request,
false /*explain*/,
nss);
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 57c21d78ebc..b608cb8622a 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -526,7 +526,7 @@ public:
return 1;
}
exec = InternalPlanner::collectionScan(
- opCtx, ns, collection.getCollection(), PlanYieldPolicy::YieldPolicy::NO_YIELD);
+ opCtx, ns, &collection.getCollection(), PlanYieldPolicy::YieldPolicy::NO_YIELD);
} else if (min.isEmpty() || max.isEmpty()) {
errmsg = "only one of min or max specified";
return false;
@@ -551,7 +551,7 @@ public:
max = Helpers::toKeyFormat(kp.extendRangeBound(max, false));
exec = InternalPlanner::indexScan(opCtx,
- collection.getCollection(),
+ &collection.getCollection(),
idx,
min,
max,
diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp
index 5a8aafa3f3a..bfe0fc17cb1 100644
--- a/src/mongo/db/commands/dbcommands_d.cpp
+++ b/src/mongo/db/commands/dbcommands_d.cpp
@@ -304,7 +304,7 @@ public:
const CollectionPtr& coll = ctx->getCollection();
auto exec = uassertStatusOK(getExecutor(opCtx,
- coll,
+ &coll,
std::move(cq),
PlanYieldPolicy::YieldPolicy::YIELD_MANUAL,
QueryPlannerParams::NO_TABLE_SCAN));
@@ -389,7 +389,7 @@ public:
}
// Now that we have the lock again, we can restore the PlanExecutor.
- exec->restoreState(&coll);
+ exec->restoreState(&ctx->getCollection());
}
} catch (DBException& exception) {
exception.addContext("Executor error during filemd5 command");
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 6ef685dd420..bae3b34eb19 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -350,7 +350,7 @@ private:
std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec;
if (desc) {
exec = InternalPlanner::indexScan(opCtx,
- collection,
+ &collection,
desc,
BSONObj(),
BSONObj(),
@@ -360,7 +360,7 @@ private:
InternalPlanner::IXSCAN_FETCH);
} else if (collection->isCapped()) {
exec = InternalPlanner::collectionScan(
- opCtx, nss.ns(), collection, PlanYieldPolicy::YieldPolicy::NO_YIELD);
+ opCtx, nss.ns(), &collection, PlanYieldPolicy::YieldPolicy::NO_YIELD);
} else {
LOGV2(20455,
"Can't find _id index for namespace: {namespace}",
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp
index 226d3b52183..0d00569097c 100644
--- a/src/mongo/db/commands/distinct.cpp
+++ b/src/mongo/db/commands/distinct.cpp
@@ -177,7 +177,7 @@ public:
const auto& collection = ctx->getCollection();
auto executor = uassertStatusOK(
- getExecutorDistinct(collection, QueryPlannerParams::DEFAULT, &parsedDistinct));
+ getExecutorDistinct(&collection, QueryPlannerParams::DEFAULT, &parsedDistinct));
auto bodyBuilder = result->getBodyBuilder();
Explain::explainStages(executor.get(), collection, verbosity, BSONObj(), &bodyBuilder);
@@ -238,7 +238,7 @@ public:
const auto& collection = ctx->getCollection();
auto executor =
- getExecutorDistinct(collection, QueryPlannerParams::DEFAULT, &parsedDistinct);
+ getExecutorDistinct(&collection, QueryPlannerParams::DEFAULT, &parsedDistinct);
uassertStatusOK(executor.getStatus());
{
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 4fe85f09807..877e54d6c1d 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -292,7 +292,7 @@ public:
CollectionShardingState::get(opCtx, nsString)->checkShardVersionOrThrow(opCtx);
const auto exec = uassertStatusOK(
- getExecutorDelete(opDebug, collection.getCollection(), &parsedDelete, verbosity));
+ getExecutorDelete(opDebug, &collection.getCollection(), &parsedDelete, verbosity));
auto bodyBuilder = result->getBodyBuilder();
Explain::explainStages(
@@ -316,7 +316,7 @@ public:
CollectionShardingState::get(opCtx, nsString)->checkShardVersionOrThrow(opCtx);
const auto exec = uassertStatusOK(
- getExecutorUpdate(opDebug, collection.getCollection(), &parsedUpdate, verbosity));
+ getExecutorUpdate(opDebug, &collection.getCollection(), &parsedUpdate, verbosity));
auto bodyBuilder = result->getBodyBuilder();
Explain::explainStages(
@@ -476,7 +476,7 @@ public:
checkIfTransactionOnCappedColl(collection.getCollection(), inTransaction);
const auto exec = uassertStatusOK(getExecutorDelete(
- opDebug, collection.getCollection(), &parsedDelete, boost::none /* verbosity */));
+ opDebug, &collection.getCollection(), &parsedDelete, boost::none /* verbosity */));
{
stdx::lock_guard<Client> lk(*opCtx->getClient());
@@ -563,7 +563,7 @@ public:
checkIfTransactionOnCappedColl(collection, inTransaction);
const auto exec = uassertStatusOK(
- getExecutorUpdate(opDebug, collection, parsedUpdate, boost::none /* verbosity */));
+ getExecutorUpdate(opDebug, &collection, parsedUpdate, boost::none /* verbosity */));
{
stdx::lock_guard<Client> lk(*opCtx->getClient());
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index bf992594df1..96d612b60e5 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -294,7 +294,7 @@ public:
// Get the execution plan for the query.
bool permitYield = true;
auto exec =
- uassertStatusOK(getExecutorFind(opCtx, collection, std::move(cq), permitYield));
+ uassertStatusOK(getExecutorFind(opCtx, &collection, std::move(cq), permitYield));
auto bodyBuilder = result->getBodyBuilder();
// Got the execution tree. Explain it.
@@ -423,7 +423,7 @@ public:
// Get the execution plan for the query.
bool permitYield = true;
auto exec =
- uassertStatusOK(getExecutorFind(opCtx, collection, std::move(cq), permitYield));
+ uassertStatusOK(getExecutorFind(opCtx, &collection, std::move(cq), permitYield));
{
stdx::lock_guard<Client> lk(*opCtx->getClient());
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index 54be8b56b81..64edcbfff86 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -516,7 +516,7 @@ public:
opCtx->recoveryUnit()->setReadOnce(true);
}
exec->reattachToOperationContext(opCtx);
- exec->restoreState(nullptr);
+ exec->restoreState(readLock ? &readLock->getCollection() : nullptr);
auto planSummary = exec->getPlanExplainer().getPlanSummary();
{
@@ -584,10 +584,10 @@ public:
// of this operation's CurOp to signal that we've hit this point and then spin until the
// failpoint is released.
std::function<void()> saveAndRestoreStateWithReadLockReacquisition =
- [exec, dropAndReacquireReadLock]() {
+ [exec, dropAndReacquireReadLock, &readLock]() {
exec->saveState();
dropAndReacquireReadLock();
- exec->restoreState(nullptr);
+ exec->restoreState(&readLock->getCollection());
};
waitWithPinnedCursorDuringGetMoreBatch.execute([&](const BSONObj& data) {
diff --git a/src/mongo/db/commands/haystack.cpp b/src/mongo/db/commands/haystack.cpp
index b17c97d22f9..92fc8f7a2a2 100644
--- a/src/mongo/db/commands/haystack.cpp
+++ b/src/mongo/db/commands/haystack.cpp
@@ -157,7 +157,7 @@ public:
auto exec = InternalPlanner::indexScan(opCtx,
- collection,
+ &collection,
ham->_descriptor,
key,
key,
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index d8485d09937..bd93f374fac 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -373,7 +373,7 @@ public:
uassertStatusOK(plan_executor_factory::make(expCtx,
std::move(ws),
std::move(root),
- nullptr,
+ &CollectionPtr::null,
PlanYieldPolicy::YieldPolicy::NO_YIELD,
cursorNss));
diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp
index 94d4eb1e51d..1b1386e1902 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -186,7 +186,7 @@ public:
uassertStatusOK(plan_executor_factory::make(expCtx,
std::move(ws),
std::move(root),
- nullptr,
+ &CollectionPtr::null,
PlanYieldPolicy::YieldPolicy::NO_YIELD,
nss));
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index a5844835ccb..c3813857782 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -162,7 +162,7 @@ public:
// end.
auto exec = InternalPlanner::collectionScan(opCtx,
fullNs.ns(),
- collection.getCollection(),
+ &collection.getCollection(),
PlanYieldPolicy::YieldPolicy::NO_YIELD,
InternalPlanner::BACKWARD);
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index a016aef5de2..fca0e4f3de4 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -461,8 +461,10 @@ private:
// info is more accurate.
AutoGetCollection collection(opCtx, _batch.getNamespace(), MODE_IX);
- auto exec = uassertStatusOK(getExecutorUpdate(
- &CurOp::get(opCtx)->debug(), collection.getCollection(), &parsedUpdate, verbosity));
+ auto exec = uassertStatusOK(getExecutorUpdate(&CurOp::get(opCtx)->debug(),
+ &collection.getCollection(),
+ &parsedUpdate,
+ verbosity));
auto bodyBuilder = result->getBodyBuilder();
Explain::explainStages(
exec.get(), collection.getCollection(), verbosity, BSONObj(), &bodyBuilder);
@@ -556,8 +558,10 @@ private:
AutoGetCollection collection(opCtx, _batch.getNamespace(), MODE_IX);
// Explain the plan tree.
- auto exec = uassertStatusOK(getExecutorDelete(
- &CurOp::get(opCtx)->debug(), collection.getCollection(), &parsedDelete, verbosity));
+ auto exec = uassertStatusOK(getExecutorDelete(&CurOp::get(opCtx)->debug(),
+ &collection.getCollection(),
+ &parsedDelete,
+ verbosity));
auto bodyBuilder = result->getBodyBuilder();
Explain::explainStages(
exec.get(), collection.getCollection(), verbosity, BSONObj(), &bodyBuilder);