summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/find_and_modify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands/find_and_modify.cpp')
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp122
1 files changed, 61 insertions, 61 deletions
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index d0a260164d4..3aa7eb2018c 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -105,7 +105,7 @@ const DeleteStats* getDeleteStats(const PlanExecutor* exec) {
*
* If the operation failed, then an error Status is returned.
*/
-StatusWith<boost::optional<BSONObj>> advanceExecutor(OperationContext* txn,
+StatusWith<boost::optional<BSONObj>> advanceExecutor(OperationContext* opCtx,
PlanExecutor* exec,
bool isRemove) {
BSONObj value;
@@ -191,8 +191,8 @@ void appendCommandResponse(PlanExecutor* exec,
}
}
-Status checkCanAcceptWritesForDatabase(OperationContext* txn, const NamespaceString& nsString) {
- if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(txn, nsString)) {
+Status checkCanAcceptWritesForDatabase(OperationContext* opCtx, const NamespaceString& nsString) {
+ if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(opCtx, nsString)) {
return Status(ErrorCodes::NotMaster,
str::stream()
<< "Not primary while running findAndModify command on collection "
@@ -201,12 +201,12 @@ Status checkCanAcceptWritesForDatabase(OperationContext* txn, const NamespaceStr
return Status::OK();
}
-void recordStatsForTopCommand(OperationContext* txn) {
- auto curOp = CurOp::get(txn);
+void recordStatsForTopCommand(OperationContext* opCtx) {
+ auto curOp = CurOp::get(opCtx);
const int writeLocked = 1;
- Top::get(txn->getClient()->getServiceContext())
- .record(txn,
+ Top::get(opCtx->getClient()->getServiceContext())
+ .record(opCtx,
curOp->getNS(),
curOp->getLogicalOp(),
writeLocked,
@@ -249,7 +249,7 @@ public:
return ReadWriteType::kWrite;
}
- Status explain(OperationContext* txn,
+ Status explain(OperationContext* opCtx,
const std::string& dbName,
const BSONObj& cmdObj,
ExplainCommon::Verbosity verbosity,
@@ -269,14 +269,14 @@ public:
const FindAndModifyRequest& args = parseStatus.getValue();
const NamespaceString& nsString = args.getNamespaceString();
- OpDebug* opDebug = &CurOp::get(txn)->debug();
+ OpDebug* opDebug = &CurOp::get(opCtx)->debug();
if (args.isRemove()) {
DeleteRequest request(nsString);
const bool isExplain = true;
makeDeleteRequest(args, isExplain, &request);
- ParsedDelete parsedDelete(txn, &request);
+ ParsedDelete parsedDelete(opCtx, &request);
Status parsedDeleteStatus = parsedDelete.parseRequest();
if (!parsedDeleteStatus.isOK()) {
return parsedDeleteStatus;
@@ -284,18 +284,18 @@ public:
// Explain calls of the findAndModify command are read-only, but we take write
// locks so that the timing information is more accurate.
- AutoGetCollection autoColl(txn, nsString, MODE_IX);
+ AutoGetCollection autoColl(opCtx, nsString, MODE_IX);
if (!autoColl.getDb()) {
return {ErrorCodes::NamespaceNotFound,
str::stream() << "database " << dbName << " does not exist."};
}
- auto css = CollectionShardingState::get(txn, nsString);
- css->checkShardVersionOrThrow(txn);
+ auto css = CollectionShardingState::get(opCtx, nsString);
+ css->checkShardVersionOrThrow(opCtx);
Collection* const collection = autoColl.getCollection();
auto statusWithPlanExecutor =
- getExecutorDelete(txn, opDebug, collection, &parsedDelete);
+ getExecutorDelete(opCtx, opDebug, collection, &parsedDelete);
if (!statusWithPlanExecutor.isOK()) {
return statusWithPlanExecutor.getStatus();
}
@@ -307,7 +307,7 @@ public:
const bool isExplain = true;
makeUpdateRequest(args, isExplain, &updateLifecycle, &request);
- ParsedUpdate parsedUpdate(txn, &request);
+ ParsedUpdate parsedUpdate(opCtx, &request);
Status parsedUpdateStatus = parsedUpdate.parseRequest();
if (!parsedUpdateStatus.isOK()) {
return parsedUpdateStatus;
@@ -315,18 +315,18 @@ public:
// Explain calls of the findAndModify command are read-only, but we take write
// locks so that the timing information is more accurate.
- AutoGetCollection autoColl(txn, nsString, MODE_IX);
+ AutoGetCollection autoColl(opCtx, nsString, MODE_IX);
if (!autoColl.getDb()) {
return {ErrorCodes::NamespaceNotFound,
str::stream() << "database " << dbName << " does not exist."};
}
- auto css = CollectionShardingState::get(txn, nsString);
- css->checkShardVersionOrThrow(txn);
+ auto css = CollectionShardingState::get(opCtx, nsString);
+ css->checkShardVersionOrThrow(opCtx);
Collection* collection = autoColl.getCollection();
auto statusWithPlanExecutor =
- getExecutorUpdate(txn, opDebug, collection, &parsedUpdate);
+ getExecutorUpdate(opCtx, opDebug, collection, &parsedUpdate);
if (!statusWithPlanExecutor.isOK()) {
return statusWithPlanExecutor.getStatus();
}
@@ -337,14 +337,14 @@ public:
return Status::OK();
}
- bool run(OperationContext* txn,
+ bool run(OperationContext* opCtx,
const std::string& dbName,
BSONObj& cmdObj,
int options,
std::string& errmsg,
BSONObjBuilder& result) override {
// findAndModify command is not replicated directly.
- invariant(txn->writesAreReplicated());
+ invariant(opCtx->writesAreReplicated());
const NamespaceString fullNs = parseNsCollectionRequired(dbName, cmdObj);
Status allowedWriteStatus = userAllowedWriteNS(fullNs.ns());
if (!allowedWriteStatus.isOK()) {
@@ -362,21 +362,21 @@ public:
boost::optional<DisableDocumentValidation> maybeDisableValidation;
if (shouldBypassDocumentValidationForCommand(cmdObj))
- maybeDisableValidation.emplace(txn);
+ maybeDisableValidation.emplace(opCtx);
- auto client = txn->getClient();
+ auto client = opCtx->getClient();
auto lastOpAtOperationStart = repl::ReplClientInfo::forClient(client).getLastOp();
ScopeGuard lastOpSetterGuard =
MakeObjGuard(repl::ReplClientInfo::forClient(client),
&repl::ReplClientInfo::setLastOpToSystemLastOpTime,
- txn);
+ opCtx);
// If this is the local database, don't set last op.
if (dbName == "local") {
lastOpSetterGuard.Dismiss();
}
- auto curOp = CurOp::get(txn);
+ auto curOp = CurOp::get(opCtx);
OpDebug* opDebug = &curOp->debug();
// Although usually the PlanExecutor handles WCE internally, it will throw WCEs when it is
@@ -388,38 +388,38 @@ public:
const bool isExplain = false;
makeDeleteRequest(args, isExplain, &request);
- ParsedDelete parsedDelete(txn, &request);
+ ParsedDelete parsedDelete(opCtx, &request);
Status parsedDeleteStatus = parsedDelete.parseRequest();
if (!parsedDeleteStatus.isOK()) {
return appendCommandStatus(result, parsedDeleteStatus);
}
- AutoGetOrCreateDb autoDb(txn, dbName, MODE_IX);
- Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), MODE_IX);
+ AutoGetOrCreateDb autoDb(opCtx, dbName, MODE_IX);
+ Lock::CollectionLock collLock(opCtx->lockState(), nsString.ns(), MODE_IX);
// Attach the namespace and database profiling level to the current op.
{
- stdx::lock_guard<Client> lk(*txn->getClient());
- CurOp::get(txn)->enter_inlock(nsString.ns().c_str(),
- autoDb.getDb()->getProfilingLevel());
+ stdx::lock_guard<Client> lk(*opCtx->getClient());
+ CurOp::get(opCtx)->enter_inlock(nsString.ns().c_str(),
+ autoDb.getDb()->getProfilingLevel());
}
- auto css = CollectionShardingState::get(txn, nsString);
- css->checkShardVersionOrThrow(txn);
+ auto css = CollectionShardingState::get(opCtx, nsString);
+ css->checkShardVersionOrThrow(opCtx);
- Status isPrimary = checkCanAcceptWritesForDatabase(txn, nsString);
+ Status isPrimary = checkCanAcceptWritesForDatabase(opCtx, nsString);
if (!isPrimary.isOK()) {
return appendCommandStatus(result, isPrimary);
}
Collection* const collection = autoDb.getDb()->getCollection(nsString.ns());
- if (!collection && autoDb.getDb()->getViewCatalog()->lookup(txn, nsString.ns())) {
+ if (!collection && autoDb.getDb()->getViewCatalog()->lookup(opCtx, nsString.ns())) {
return appendCommandStatus(result,
{ErrorCodes::CommandNotSupportedOnView,
"findAndModify not supported on a view"});
}
auto statusWithPlanExecutor =
- getExecutorDelete(txn, opDebug, collection, &parsedDelete);
+ getExecutorDelete(opCtx, opDebug, collection, &parsedDelete);
if (!statusWithPlanExecutor.isOK()) {
return appendCommandStatus(result, statusWithPlanExecutor.getStatus());
}
@@ -427,12 +427,12 @@ public:
std::move(statusWithPlanExecutor.getValue());
{
- stdx::lock_guard<Client> lk(*txn->getClient());
- CurOp::get(txn)->setPlanSummary_inlock(Explain::getPlanSummary(exec.get()));
+ stdx::lock_guard<Client> lk(*opCtx->getClient());
+ CurOp::get(opCtx)->setPlanSummary_inlock(Explain::getPlanSummary(exec.get()));
}
StatusWith<boost::optional<BSONObj>> advanceStatus =
- advanceExecutor(txn, exec.get(), args.isRemove());
+ advanceExecutor(opCtx, exec.get(), args.isRemove());
if (!advanceStatus.isOK()) {
return appendCommandStatus(result, advanceStatus.getStatus());
}
@@ -443,7 +443,7 @@ public:
PlanSummaryStats summaryStats;
Explain::getSummaryStats(*exec, &summaryStats);
if (collection) {
- collection->infoCache()->notifyOfQuery(txn, summaryStats.indexesUsed);
+ collection->infoCache()->notifyOfQuery(opCtx, summaryStats.indexesUsed);
}
opDebug->setPlanSummaryMetrics(summaryStats);
@@ -455,7 +455,7 @@ public:
Explain::getWinningPlanStats(exec.get(), &execStatsBob);
curOp->debug().execStats = execStatsBob.obj();
}
- recordStatsForTopCommand(txn);
+ recordStatsForTopCommand(opCtx);
boost::optional<BSONObj> value = advanceStatus.getValue();
appendCommandResponse(exec.get(), args.isRemove(), value, result);
@@ -465,32 +465,32 @@ public:
const bool isExplain = false;
makeUpdateRequest(args, isExplain, &updateLifecycle, &request);
- ParsedUpdate parsedUpdate(txn, &request);
+ ParsedUpdate parsedUpdate(opCtx, &request);
Status parsedUpdateStatus = parsedUpdate.parseRequest();
if (!parsedUpdateStatus.isOK()) {
return appendCommandStatus(result, parsedUpdateStatus);
}
- AutoGetOrCreateDb autoDb(txn, dbName, MODE_IX);
- Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), MODE_IX);
+ AutoGetOrCreateDb autoDb(opCtx, dbName, MODE_IX);
+ Lock::CollectionLock collLock(opCtx->lockState(), nsString.ns(), MODE_IX);
// Attach the namespace and database profiling level to the current op.
{
- stdx::lock_guard<Client> lk(*txn->getClient());
- CurOp::get(txn)->enter_inlock(nsString.ns().c_str(),
- autoDb.getDb()->getProfilingLevel());
+ stdx::lock_guard<Client> lk(*opCtx->getClient());
+ CurOp::get(opCtx)->enter_inlock(nsString.ns().c_str(),
+ autoDb.getDb()->getProfilingLevel());
}
- auto css = CollectionShardingState::get(txn, nsString);
- css->checkShardVersionOrThrow(txn);
+ auto css = CollectionShardingState::get(opCtx, nsString);
+ css->checkShardVersionOrThrow(opCtx);
- Status isPrimary = checkCanAcceptWritesForDatabase(txn, nsString);
+ Status isPrimary = checkCanAcceptWritesForDatabase(opCtx, nsString);
if (!isPrimary.isOK()) {
return appendCommandStatus(result, isPrimary);
}
Collection* collection = autoDb.getDb()->getCollection(nsString.ns());
- if (!collection && autoDb.getDb()->getViewCatalog()->lookup(txn, nsString.ns())) {
+ if (!collection && autoDb.getDb()->getViewCatalog()->lookup(opCtx, nsString.ns())) {
return appendCommandStatus(result,
{ErrorCodes::CommandNotSupportedOnView,
"findAndModify not supported on a view"});
@@ -503,7 +503,7 @@ public:
// in exclusive mode in order to create the collection.
collLock.relockAsDatabaseExclusive(autoDb.lock());
collection = autoDb.getDb()->getCollection(nsString.ns());
- Status isPrimaryAfterRelock = checkCanAcceptWritesForDatabase(txn, nsString);
+ Status isPrimaryAfterRelock = checkCanAcceptWritesForDatabase(opCtx, nsString);
if (!isPrimaryAfterRelock.isOK()) {
return appendCommandStatus(result, isPrimaryAfterRelock);
}
@@ -511,9 +511,9 @@ public:
if (collection) {
// Someone else beat us to creating the collection, do nothing.
} else {
- WriteUnitOfWork wuow(txn);
+ WriteUnitOfWork wuow(opCtx);
Status createCollStatus =
- userCreateNS(txn, autoDb.getDb(), nsString.ns(), BSONObj());
+ userCreateNS(opCtx, autoDb.getDb(), nsString.ns(), BSONObj());
if (!createCollStatus.isOK()) {
return appendCommandStatus(result, createCollStatus);
}
@@ -525,7 +525,7 @@ public:
}
auto statusWithPlanExecutor =
- getExecutorUpdate(txn, opDebug, collection, &parsedUpdate);
+ getExecutorUpdate(opCtx, opDebug, collection, &parsedUpdate);
if (!statusWithPlanExecutor.isOK()) {
return appendCommandStatus(result, statusWithPlanExecutor.getStatus());
}
@@ -533,12 +533,12 @@ public:
std::move(statusWithPlanExecutor.getValue());
{
- stdx::lock_guard<Client> lk(*txn->getClient());
- CurOp::get(txn)->setPlanSummary_inlock(Explain::getPlanSummary(exec.get()));
+ stdx::lock_guard<Client> lk(*opCtx->getClient());
+ CurOp::get(opCtx)->setPlanSummary_inlock(Explain::getPlanSummary(exec.get()));
}
StatusWith<boost::optional<BSONObj>> advanceStatus =
- advanceExecutor(txn, exec.get(), args.isRemove());
+ advanceExecutor(opCtx, exec.get(), args.isRemove());
if (!advanceStatus.isOK()) {
return appendCommandStatus(result, advanceStatus.getStatus());
}
@@ -549,7 +549,7 @@ public:
PlanSummaryStats summaryStats;
Explain::getSummaryStats(*exec, &summaryStats);
if (collection) {
- collection->infoCache()->notifyOfQuery(txn, summaryStats.indexesUsed);
+ collection->infoCache()->notifyOfQuery(opCtx, summaryStats.indexesUsed);
}
UpdateStage::recordUpdateStatsInOpDebug(getUpdateStats(exec.get()), opDebug);
opDebug->setPlanSummaryMetrics(summaryStats);
@@ -559,13 +559,13 @@ public:
Explain::getWinningPlanStats(exec.get(), &execStatsBob);
curOp->debug().execStats = execStatsBob.obj();
}
- recordStatsForTopCommand(txn);
+ recordStatsForTopCommand(opCtx);
boost::optional<BSONObj> value = advanceStatus.getValue();
appendCommandResponse(exec.get(), args.isRemove(), value, result);
}
}
- MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "findAndModify", nsString.ns());
+ MONGO_WRITE_CONFLICT_RETRY_LOOP_END(opCtx, "findAndModify", nsString.ns());
if (repl::ReplClientInfo::forClient(client).getLastOp() != lastOpAtOperationStart) {
// If this operation has already generated a new lastOp, don't bother setting it here.