summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_executor_impl.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/query/plan_executor_impl.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/query/plan_executor_impl.cpp')
-rw-r--r--src/mongo/db/query/plan_executor_impl.cpp47
1 files changed, 14 insertions, 33 deletions
diff --git a/src/mongo/db/query/plan_executor_impl.cpp b/src/mongo/db/query/plan_executor_impl.cpp
index ae40ecd070e..6691a52fb8a 100644
--- a/src/mongo/db/query/plan_executor_impl.cpp
+++ b/src/mongo/db/query/plan_executor_impl.cpp
@@ -33,12 +33,10 @@
#include "mongo/db/query/plan_executor_impl.h"
-#include "mongo/util/duration.h"
#include <memory>
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/catalog/collection.h"
-#include "mongo/db/concurrency/exception_util.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
#include "mongo/db/exec/cached_plan.h"
@@ -63,7 +61,6 @@
#include "mongo/db/query/plan_yield_policy_impl.h"
#include "mongo/db/query/yield_policy_callbacks_impl.h"
#include "mongo/db/repl/replication_coordinator.h"
-#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/service_context.h"
#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
@@ -77,8 +74,8 @@ using std::string;
using std::unique_ptr;
using std::vector;
-const OperationContext::Decoration<boost::optional<repl::OpTime>> clientsLastKnownCommittedOpTime =
- OperationContext::declareDecoration<boost::optional<repl::OpTime>>();
+const OperationContext::Decoration<repl::OpTime> clientsLastKnownCommittedOpTime =
+ OperationContext::declareDecoration<repl::OpTime>();
// This failpoint is also accessed by the SBE executor so we define it outside of an anonymous
// namespace.
@@ -103,11 +100,11 @@ std::unique_ptr<PlanYieldPolicy> makeYieldPolicy(PlanExecutorImpl* exec,
}
case PlanYieldPolicy::YieldPolicy::ALWAYS_TIME_OUT: {
return std::make_unique<AlwaysTimeOutYieldPolicy>(
- exec->getOpCtx(), exec->getOpCtx()->getServiceContext()->getFastClockSource());
+ exec->getOpCtx()->getServiceContext()->getFastClockSource());
}
case PlanYieldPolicy::YieldPolicy::ALWAYS_MARK_KILLED: {
return std::make_unique<AlwaysPlanKilledYieldPolicy>(
- exec->getOpCtx(), exec->getOpCtx()->getServiceContext()->getFastClockSource());
+ exec->getOpCtx()->getServiceContext()->getFastClockSource());
}
default:
MONGO_UNREACHABLE;
@@ -137,6 +134,13 @@ PlanExecutorImpl::PlanExecutorImpl(OperationContext* opCtx,
invariant(!_expCtx || _expCtx->opCtx == _opCtx);
invariant(!_cq || !_expCtx || _cq->getExpCtx() == _expCtx);
+ // If this PlanExecutor is executing a COLLSCAN, keep a pointer directly to the COLLSCAN
+ // stage. This is used for change streams in order to keep the the latest oplog timestamp
+ // and post batch resume token up to date as the oplog scan progresses.
+ if (auto collectionScan = getStageByType(_root.get(), STAGE_COLLSCAN)) {
+ _collScanStage = static_cast<CollectionScan*>(collectionScan);
+ }
+
// If we don't yet have a namespace string, then initialize it from either 'collection' or
// '_cq'.
if (_nss.isEmpty()) {
@@ -168,13 +172,6 @@ PlanExecutorImpl::PlanExecutorImpl(OperationContext* opCtx,
_planExplainer->updateEnumeratorExplainInfo(
subplanStage->compositeSolution()->_enumeratorExplainInfo);
}
-
- // If this PlanExecutor is executing a COLLSCAN, keep a pointer directly to the COLLSCAN
- // stage. This is used for change streams in order to keep the the latest oplog timestamp
- // and post batch resume token up to date as the oplog scan progresses.
- if (auto collectionScan = getStageByType(_root.get(), STAGE_COLLSCAN)) {
- _collScanStage = static_cast<CollectionScan*>(collectionScan);
- }
}
Status PlanExecutorImpl::_pickBestPlan() {
@@ -362,25 +359,8 @@ PlanExecutor::ExecState PlanExecutorImpl::_getNextImpl(Snapshotted<Document>* ob
// 2) some stage requested a yield, or
// 3) we need to yield and retry due to a WriteConflictException.
// In all cases, the actual yielding happens here.
-
- const auto whileYieldingFn = [&]() {
- // If we yielded because we encountered a sharding critical section, wait for the
- // critical section to end before continuing. By waiting for the critical section to be
- // exited we avoid busy spinning immediately and encountering the same critical section
- // again. It is important that this wait happens after having released the lock
- // hierarchy -- otherwise deadlocks could happen, or the very least, locks would be
- // unnecessarily held while waiting.
- const auto& shardingCriticalSection = planExecutorShardingCriticalSectionFuture(_opCtx);
- if (shardingCriticalSection) {
- OperationShardingState::waitForCriticalSectionToComplete(_opCtx,
- *shardingCriticalSection)
- .ignore();
- planExecutorShardingCriticalSectionFuture(_opCtx).reset();
- }
- };
-
if (_yieldPolicy->shouldYieldOrInterrupt(_opCtx)) {
- uassertStatusOK(_yieldPolicy->yieldOrInterrupt(_opCtx, whileYieldingFn));
+ uassertStatusOK(_yieldPolicy->yieldOrInterrupt(_opCtx));
}
WorkingSetID id = WorkingSet::INVALID_ID;
@@ -447,7 +427,8 @@ PlanExecutor::ExecState PlanExecutorImpl::_getNextImpl(Snapshotted<Document>* ob
CurOp::get(_opCtx)->debug().additiveMetrics.incrementWriteConflicts(1);
writeConflictsInARow++;
- logWriteConflictAndBackoff(writeConflictsInARow, "plan execution", _nss.ns());
+ WriteConflictException::logAndBackoff(
+ writeConflictsInARow, "plan execution", _nss.ns());
// If we're allowed to, we will yield next time through the loop.
if (_yieldPolicy->canAutoYield()) {