本文整理汇总了C++中OperationContext::getCurOp方法的典型用法代码示例。如果您正苦于以下问题:C++ OperationContext::getCurOp方法的具体用法?C++ OperationContext::getCurOp怎么用?C++ OperationContext::getCurOp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationContext
的用法示例。
在下文中一共展示了OperationContext::getCurOp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: yield
bool PlanYieldPolicy::yield(RecordFetcher* fetcher) {
invariant(_planYielding);
invariant(allowedToYield());
_forceYield = false;
OperationContext* opCtx = _planYielding->getOpCtx();
invariant(opCtx);
invariant(!opCtx->lockState()->inAWriteUnitOfWork());
// Can't use MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN/END since we need to call saveState
// before reseting the transaction.
for (int attempt = 1; true; attempt++) {
try {
// All YIELD_AUTO plans will get here eventually when the elapsed tracker triggers
// that it's time to yield. Whether or not we will actually yield, we need to check
// if this operation has been interrupted. Throws if the interrupt flag is set.
if (_policy == PlanExecutor::YIELD_AUTO) {
opCtx->checkForInterrupt();
}
// No need to yield if the collection is NULL.
if (NULL == _planYielding->collection()) {
return true;
}
try {
_planYielding->saveState();
}
catch (const WriteConflictException& wce) {
invariant(!"WriteConflictException not allowed in saveState");
}
if (_policy == PlanExecutor::WRITE_CONFLICT_RETRY_ONLY) {
// Just reset the snapshot. Leave all LockManager locks alone.
opCtx->recoveryUnit()->commitAndRestart();
}
else {
// Release and reacquire locks.
QueryYield::yieldAllLocks(opCtx, fetcher);
}
return _planYielding->restoreStateWithoutRetrying(opCtx);
}
catch (const WriteConflictException& wce) {
opCtx->getCurOp()->debug().writeConflicts++;
WriteConflictException::logAndBackoff(attempt,
"plan execution restoreState",
_planYielding->collection()->ns().ns());
// retry
}
}
}
示例2: explainStages
// static
void Explain::explainStages(PlanExecutor* exec,
ExplainCommon::Verbosity verbosity,
BSONObjBuilder* out) {
//
// Step 1: run the stages as required by the verbosity level.
//
// Inspect the tree to see if there is a MultiPlanStage.
MultiPlanStage* mps = getMultiPlanStage(exec->getRootStage());
// Get stats of the winning plan from the trial period, if the verbosity level
// is high enough and there was a runoff between multiple plans.
auto_ptr<PlanStageStats> winningStatsTrial;
if (verbosity >= ExplainCommon::EXEC_ALL_PLANS && NULL != mps) {
winningStatsTrial.reset(exec->getStats());
invariant(winningStatsTrial.get());
}
// If we need execution stats, then run the plan in order to gather the stats.
Status executePlanStatus = Status::OK();
if (verbosity >= ExplainCommon::EXEC_STATS) {
executePlanStatus = exec->executePlan();
}
//
// Step 2: collect plan stats (which also give the structure of the plan tree).
//
// Get stats for the winning plan.
scoped_ptr<PlanStageStats> winningStats(exec->getStats());
// Get stats for the rejected plans, if more than one plan was considered.
OwnedPointerVector<PlanStageStats> allPlansStats;
if (NULL != mps) {
allPlansStats = mps->generateCandidateStats();
}
//
// Step 3: use the stats trees to produce explain BSON.
//
CanonicalQuery* query = exec->getCanonicalQuery();
if (verbosity >= ExplainCommon::QUERY_PLANNER) {
generatePlannerInfo(query, winningStats.get(), allPlansStats.vector(), out);
}
if (verbosity >= ExplainCommon::EXEC_STATS) {
BSONObjBuilder execBob(out->subobjStart("executionStats"));
// If there is an execution error while running the query, the error is reported under
// the "executionStats" section and the explain as a whole succeeds.
execBob.append("executionSuccess", executePlanStatus.isOK());
if (!executePlanStatus.isOK()) {
execBob.append("errorMessage", executePlanStatus.reason());
execBob.append("errorCode", executePlanStatus.code());
}
// Generate exec stats BSON for the winning plan.
OperationContext* opCtx = exec->getOpCtx();
long long totalTimeMillis = opCtx->getCurOp()->elapsedMillis();
generateExecStats(winningStats.get(), verbosity, &execBob, totalTimeMillis);
// Also generate exec stats for all plans, if the verbosity level is high enough.
// These stats reflect what happened during the trial period that ranked the plans.
if (verbosity >= ExplainCommon::EXEC_ALL_PLANS) {
// If we ranked multiple plans against each other, then add stats collected
// from the trial period of the winning plan. The "allPlansExecution" section
// will contain an apples-to-apples comparison of the winning plan's stats against
// all rejected plans' stats collected during the trial period.
if (NULL != mps) {
invariant(winningStatsTrial.get());
allPlansStats.push_back(winningStatsTrial.release());
}
BSONArrayBuilder allPlansBob(execBob.subarrayStart("allPlansExecution"));
for (size_t i = 0; i < allPlansStats.size(); ++i) {
BSONObjBuilder planBob(allPlansBob.subobjStart());
generateExecStats(allPlansStats[i], verbosity, &planBob);
planBob.doneFast();
}
allPlansBob.doneFast();
}
execBob.doneFast();
}
generateServerInfo(out);
}