summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/clone.cpp4
-rw-r--r--src/mongo/db/commands/collection_to_capped.cpp1
-rw-r--r--src/mongo/db/commands/compact.cpp1
-rw-r--r--src/mongo/db/commands/copydb.cpp7
-rw-r--r--src/mongo/db/commands/count_cmd.cpp4
-rw-r--r--src/mongo/db/commands/cpuprofile.cpp6
-rw-r--r--src/mongo/db/commands/create_indexes.cpp4
-rw-r--r--src/mongo/db/commands/dbcommands.cpp17
-rw-r--r--src/mongo/db/commands/dbhash.cpp1
-rw-r--r--src/mongo/db/commands/distinct.cpp4
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp3
-rw-r--r--src/mongo/db/commands/eval.cpp3
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp2
-rw-r--r--src/mongo/db/commands/find_cmd.cpp4
-rw-r--r--src/mongo/db/commands/fsync.cpp8
-rw-r--r--src/mongo/db/commands/geo_near_cmd.cpp2
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp14
-rw-r--r--src/mongo/db/commands/group_cmd.cpp4
-rw-r--r--src/mongo/db/commands/haystack.cpp2
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp6
-rw-r--r--src/mongo/db/commands/killcursors_cmd.cpp4
-rw-r--r--src/mongo/db/commands/list_collections.cpp1
-rw-r--r--src/mongo/db/commands/list_databases.cpp6
-rw-r--r--src/mongo/db/commands/list_indexes.cpp2
-rw-r--r--src/mongo/db/commands/mr.cpp39
-rw-r--r--src/mongo/db/commands/oplog_note.cpp4
-rw-r--r--src/mongo/db/commands/parallel_collection_scan.cpp2
-rw-r--r--src/mongo/db/commands/plan_cache_commands.cpp6
-rw-r--r--src/mongo/db/commands/repair_cursor.cpp2
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp6
-rw-r--r--src/mongo/db/commands/snapshot_management.cpp7
-rw-r--r--src/mongo/db/commands/test_commands.cpp9
-rw-r--r--src/mongo/db/commands/touch.cpp2
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp2
34 files changed, 77 insertions, 112 deletions
diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp
index 8548152087d..e5979d6d41b 100644
--- a/src/mongo/db/commands/clone.cpp
+++ b/src/mongo/db/commands/clone.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/catalog/document_validation.h"
#include "mongo/db/cloner.h"
#include "mongo/db/commands.h"
+#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/jsobj.h"
#include "mongo/s/grid.h"
@@ -119,8 +120,7 @@ public:
set<string> clonedColls;
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock dbXLock(opCtx->lockState(), dbname, MODE_X);
+ Lock::DBLock dbXLock(opCtx, dbname, MODE_X);
Cloner cloner;
Status status = cloner.copyDb(opCtx, dbname, from, opts, &clonedColls);
diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp
index 222e6d8887f..121d7d0a04a 100644
--- a/src/mongo/db/commands/collection_to_capped.cpp
+++ b/src/mongo/db/commands/collection_to_capped.cpp
@@ -118,7 +118,6 @@ public:
return false;
}
- ScopedTransaction transaction(opCtx, MODE_IX);
AutoGetDb autoDb(opCtx, dbname, MODE_X);
NamespaceString nss(dbname, to);
diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp
index e93b94a5892..c1b9a3d0a6c 100644
--- a/src/mongo/db/commands/compact.cpp
+++ b/src/mongo/db/commands/compact.cpp
@@ -144,7 +144,6 @@ public:
if (cmdObj.hasElement("validate"))
compactOptions.validateDocuments = cmdObj["validate"].trueValue();
- ScopedTransaction transaction(opCtx, MODE_IX);
AutoGetDb autoDb(opCtx, db, MODE_X);
Database* const collDB = autoDb.getDb();
diff --git a/src/mongo/db/commands/copydb.cpp b/src/mongo/db/commands/copydb.cpp
index b13066949df..b665bcefb12 100644
--- a/src/mongo/db/commands/copydb.cpp
+++ b/src/mongo/db/commands/copydb.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/commands.h"
#include "mongo/db/commands/copydb.h"
#include "mongo/db/commands/copydb_start_commands.h"
+#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/namespace_string.h"
@@ -226,12 +227,10 @@ public:
if (fromSelf) {
// SERVER-4328 todo lock just the two db's not everything for the fromself case
- ScopedTransaction transaction(opCtx, MODE_X);
- Lock::GlobalWrite lk(opCtx->lockState());
+ Lock::GlobalWrite lk(opCtx);
uassertStatusOK(cloner.copyDb(opCtx, todb, fromhost, cloneOptions, NULL));
} else {
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock lk(opCtx->lockState(), todb, MODE_X);
+ Lock::DBLock lk(opCtx, todb, MODE_X);
uassertStatusOK(cloner.copyDb(opCtx, todb, fromhost, cloneOptions, NULL));
}
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp
index b8418b0bff3..e5c7827ae0e 100644
--- a/src/mongo/db/commands/count_cmd.cpp
+++ b/src/mongo/db/commands/count_cmd.cpp
@@ -122,7 +122,7 @@ public:
}
// Acquire the db read lock.
- AutoGetCollectionOrViewForRead ctx(opCtx, request.getValue().getNs());
+ AutoGetCollectionOrViewForReadCommand ctx(opCtx, request.getValue().getNs());
Collection* collection = ctx.getCollection();
if (ctx.getView()) {
@@ -187,7 +187,7 @@ public:
"http://dochub.mongodb.org/core/3.4-feature-compatibility."));
}
- AutoGetCollectionOrViewForRead ctx(opCtx, request.getValue().getNs());
+ AutoGetCollectionOrViewForReadCommand ctx(opCtx, request.getValue().getNs());
Collection* collection = ctx.getCollection();
if (ctx.getView()) {
diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp
index 608a626aa92..00cddd59397 100644
--- a/src/mongo/db/commands/cpuprofile.cpp
+++ b/src/mongo/db/commands/cpuprofile.cpp
@@ -140,8 +140,7 @@ bool CpuProfilerStartCommand::run(OperationContext* opCtx,
std::string& errmsg,
BSONObjBuilder& result) {
// The DB lock here is just so we have IX on the global lock in order to prevent shutdown
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock dbXLock(opCtx->lockState(), db, MODE_X);
+ Lock::DBLock dbXLock(opCtx, db, MODE_X);
OldClientContext ctx(opCtx, db, false /* no shard version checking */);
std::string profileFilename = cmdObj[commandName]["profileFilename"].String();
@@ -159,8 +158,7 @@ bool CpuProfilerStopCommand::run(OperationContext* opCtx,
std::string& errmsg,
BSONObjBuilder& result) {
// The DB lock here is just so we have IX on the global lock in order to prevent shutdown
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock dbXLock(opCtx->lockState(), db, MODE_X);
+ Lock::DBLock dbXLock(opCtx, db, MODE_X);
OldClientContext ctx(opCtx, db, false /* no shard version checking */);
::ProfilerStop();
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index 26901b5043e..93833f09b8e 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/catalog/index_key_validate.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
+#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
#include "mongo/db/index/index_descriptor.h"
@@ -247,8 +248,7 @@ public:
// now we know we have to create index(es)
// Note: createIndexes command does not currently respect shard versioning.
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock dbLock(opCtx->lockState(), ns.db(), MODE_X);
+ Lock::DBLock dbLock(opCtx, ns.db(), MODE_X);
if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(opCtx, ns)) {
return appendCommandStatus(
result,
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 0831a974ecc..10c75252cd2 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -293,8 +293,7 @@ public:
}
// Closing a database requires a global lock.
- ScopedTransaction transaction(opCtx, MODE_X);
- Lock::GlobalWrite lk(opCtx->lockState());
+ Lock::GlobalWrite lk(opCtx);
if (!dbHolder().get(opCtx, dbname)) {
// If the name doesn't make an exact match, check for a case insensitive match.
std::set<std::string> otherCasing = dbHolder().getNamesWithConflictingCasing(dbname);
@@ -399,11 +398,9 @@ public:
const bool readOnly = (profilingLevel < 0 || profilingLevel > 2);
const LockMode dbMode = readOnly ? MODE_S : MODE_X;
- const LockMode transactionMode = readOnly ? MODE_IS : MODE_IX;
Status status = Status::OK();
- ScopedTransaction transaction(opCtx, transactionMode);
AutoGetDb ctx(opCtx, dbname, dbMode);
Database* db = ctx.getDb();
@@ -482,9 +479,7 @@ public:
// This doesn't look like it requires exclusive DB lock, because it uses its own diag
// locking, but originally the lock was set to be WRITE, so preserving the behaviour.
- //
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock dbXLock(opCtx->lockState(), dbname, MODE_X);
+ Lock::DBLock dbXLock(opCtx, dbname, MODE_X);
// TODO (Kal): OldClientContext legacy, needs to be removed
{
@@ -773,7 +768,8 @@ public:
// Check shard version at startup.
// This will throw before we've done any work if shard version is outdated
// We drop and re-acquire these locks every document because md5'ing is expensive
- unique_ptr<AutoGetCollectionForRead> ctx(new AutoGetCollectionForRead(opCtx, nss));
+ unique_ptr<AutoGetCollectionForReadCommand> ctx(
+ new AutoGetCollectionForReadCommand(opCtx, nss));
Collection* coll = ctx->getCollection();
auto statusWithPlanExecutor = getExecutor(opCtx,
@@ -819,7 +815,7 @@ public:
try {
// RELOCKED
- ctx.reset(new AutoGetCollectionForRead(opCtx, nss));
+ ctx.reset(new AutoGetCollectionForReadCommand(opCtx, nss));
} catch (const SendStaleConfigException& ex) {
LOG(1) << "chunk metadata changed during filemd5, will retarget and continue";
break;
@@ -919,7 +915,7 @@ public:
BSONObj keyPattern = jsobj.getObjectField("keyPattern");
bool estimate = jsobj["estimate"].trueValue();
- AutoGetCollectionForRead ctx(opCtx, NamespaceString(ns));
+ AutoGetCollectionForReadCommand ctx(opCtx, NamespaceString(ns));
Collection* collection = ctx.getCollection();
long long numRecords = 0;
@@ -1168,7 +1164,6 @@ public:
// We lock the entire database in S-mode in order to ensure that the contents will not
// change for the stats snapshot. This might be unnecessary and if it becomes a
// performance issue, we can take IS lock and then lock collection-by-collection.
- ScopedTransaction scopedXact(opCtx, MODE_IS);
AutoGetDb autoDb(opCtx, ns, MODE_S);
result.append("db", ns);
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 0da2752a28d..d1761d1f103 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -109,7 +109,6 @@ public:
// We lock the entire database in S-mode in order to ensure that the contents will not
// change for the snapshot.
- ScopedTransaction scopedXact(opCtx, MODE_IS);
AutoGetDb autoDb(opCtx, ns, MODE_S);
Database* db = autoDb.getDb();
if (db) {
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp
index cec31d5f9a5..fee7ac17c58 100644
--- a/src/mongo/db/commands/distinct.cpp
+++ b/src/mongo/db/commands/distinct.cpp
@@ -134,7 +134,7 @@ public:
"http://dochub.mongodb.org/core/3.4-feature-compatibility.");
}
- AutoGetCollectionOrViewForRead ctx(opCtx, nss);
+ AutoGetCollectionOrViewForReadCommand ctx(opCtx, nss);
Collection* collection = ctx.getCollection();
if (ctx.getView()) {
@@ -189,7 +189,7 @@ public:
"http://dochub.mongodb.org/core/3.4-feature-compatibility."));
}
- AutoGetCollectionOrViewForRead ctx(opCtx, nss);
+ AutoGetCollectionOrViewForReadCommand ctx(opCtx, nss);
Collection* collection = ctx.getCollection();
if (ctx.getView()) {
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 86082761cce..0857c0b025b 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -128,8 +128,7 @@ public:
LOG(0) << "CMD: reIndex " << toReIndexNs;
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock dbXLock(opCtx->lockState(), dbname, MODE_X);
+ Lock::DBLock dbXLock(opCtx, dbname, MODE_X);
OldClientContext ctx(opCtx, toReIndexNs.ns());
Collection* collection = ctx.db()->getCollection(toReIndexNs.ns());
diff --git a/src/mongo/db/commands/eval.cpp b/src/mongo/db/commands/eval.cpp
index 20945eb4828..cec1369e4ad 100644
--- a/src/mongo/db/commands/eval.cpp
+++ b/src/mongo/db/commands/eval.cpp
@@ -181,8 +181,7 @@ public:
return dbEval(opCtx, dbname, cmdObj, result, errmsg);
}
- ScopedTransaction transaction(opCtx, MODE_X);
- Lock::GlobalWrite lk(opCtx->lockState());
+ Lock::GlobalWrite lk(opCtx);
OldClientContext ctx(opCtx, dbname, false /* no shard version checking */);
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index d97f5cf0c54..e636c8f9987 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -211,7 +211,6 @@ void FeatureCompatibilityVersion::set(OperationContext* opCtx, StringData versio
std::vector<BSONObj> indexSpecs{k32IncompatibleIndexSpec};
{
- ScopedTransaction transaction(opCtx, MODE_IX);
AutoGetOrCreateDb autoDB(opCtx, nss.db(), MODE_X);
uassert(ErrorCodes::NotMaster,
@@ -303,7 +302,6 @@ void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* opCtx,
std::vector<BSONObj> indexSpecs{k32IncompatibleIndexSpec};
{
- ScopedTransaction transaction(opCtx, MODE_IX);
AutoGetOrCreateDb autoDB(opCtx, nss.db(), MODE_X);
IndexBuilder builder(k32IncompatibleIndexSpec, false);
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index 5bb043d438a..d43e991950c 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -169,7 +169,7 @@ public:
// Acquire locks. If the namespace is a view, we release our locks and convert the query
// request into an aggregation command.
- AutoGetCollectionOrViewForRead ctx(opCtx, nss);
+ AutoGetCollectionOrViewForReadCommand ctx(opCtx, nss);
if (ctx.getView()) {
// Relinquish locks. The aggregation command will re-acquire them.
ctx.releaseLocksForView();
@@ -297,7 +297,7 @@ public:
// Acquire locks. If the query is on a view, we release our locks and convert the query
// request into an aggregation command.
- AutoGetCollectionOrViewForRead ctx(opCtx, nss);
+ AutoGetCollectionOrViewForReadCommand ctx(opCtx, nss);
Collection* collection = ctx.getCollection();
if (ctx.getView()) {
// Relinquish locks. The aggregation command will re-acquire them.
diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp
index dfe417b6c06..1cae66a6b5f 100644
--- a/src/mongo/db/commands/fsync.cpp
+++ b/src/mongo/db/commands/fsync.cpp
@@ -138,8 +138,7 @@ public:
// the simple fsync command case
if (sync) {
// can this be GlobalRead? and if it can, it should be nongreedy.
- ScopedTransaction transaction(opCtx, MODE_X);
- Lock::GlobalWrite w(opCtx->lockState());
+ Lock::GlobalWrite w(opCtx);
// TODO SERVER-26822: Replace MMAPv1 specific calls with ones that are storage
// engine agnostic.
getDur().commitNow(opCtx);
@@ -148,7 +147,7 @@ public:
}
// Take a global IS lock to ensure the storage engine is not shutdown
- Lock::GlobalLock global(opCtx->lockState(), MODE_IS, UINT_MAX);
+ Lock::GlobalLock global(opCtx, MODE_IS, UINT_MAX);
StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
result.append("numFiles", storageEngine->flushAllFiles(opCtx, sync));
return true;
@@ -345,8 +344,7 @@ void FSyncLockThread::run() {
try {
const ServiceContext::UniqueOperationContext opCtxPtr = cc().makeOperationContext();
OperationContext& opCtx = *opCtxPtr;
- ScopedTransaction transaction(&opCtx, MODE_X);
- Lock::GlobalWrite global(opCtx.lockState()); // No WriteUnitOfWork needed
+ Lock::GlobalWrite global(&opCtx); // No WriteUnitOfWork needed
try {
// TODO SERVER-26822: Replace MMAPv1 specific calls with ones that are storage engine
diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp
index 3c26005121b..8345c82c9fb 100644
--- a/src/mongo/db/commands/geo_near_cmd.cpp
+++ b/src/mongo/db/commands/geo_near_cmd.cpp
@@ -111,7 +111,7 @@ public:
}
const NamespaceString nss(parseNsCollectionRequired(dbname, cmdObj));
- AutoGetCollectionForRead ctx(opCtx, nss);
+ AutoGetCollectionForReadCommand ctx(opCtx, nss);
Collection* collection = ctx.getCollection();
if (!collection) {
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index ed4b43a81a2..78c7d822404 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -185,7 +185,7 @@ public:
// Note that we declare our locks before our ClientCursorPin, in order to ensure that
// the pin's destructor is called before the lock destructors (so that the unpin occurs
// under the lock).
- std::unique_ptr<AutoGetCollectionForRead> ctx;
+ std::unique_ptr<AutoGetCollectionForReadCommand> ctx;
std::unique_ptr<Lock::DBLock> unpinDBLock;
std::unique_ptr<Lock::CollectionLock> unpinCollLock;
@@ -193,8 +193,8 @@ public:
if (request.nss.isListIndexesCursorNS() || request.nss.isListCollectionsCursorNS()) {
cursorManager = CursorManager::getGlobalCursorManager();
} else {
- ctx = stdx::make_unique<AutoGetCollectionOrViewForRead>(opCtx, request.nss);
- auto viewCtx = static_cast<AutoGetCollectionOrViewForRead*>(ctx.get());
+ ctx = stdx::make_unique<AutoGetCollectionOrViewForReadCommand>(opCtx, request.nss);
+ auto viewCtx = static_cast<AutoGetCollectionOrViewForReadCommand*>(ctx.get());
Collection* collection = ctx->getCollection();
if (!collection) {
// Rewrite a getMore on a view to a getMore on the original underlying collection.
@@ -251,7 +251,7 @@ public:
invariant(!unpinCollLock);
sleepFor(Milliseconds(10));
ctx.reset();
- ctx = stdx::make_unique<AutoGetCollectionForRead>(opCtx, request.nss);
+ ctx = stdx::make_unique<AutoGetCollectionForReadCommand>(opCtx, request.nss);
}
if (request.nss.ns() != cursor->ns()) {
@@ -402,7 +402,7 @@ public:
// CappedInsertNotifier.
curOp->setExpectedLatencyMs(durationCount<Milliseconds>(timeout));
- ctx.reset(new AutoGetCollectionForRead(opCtx, request.nss));
+ ctx.reset(new AutoGetCollectionForReadCommand(opCtx, request.nss));
exec->restoreState();
// We woke up because either the timed_wait expired, or there was more data. Either
@@ -463,7 +463,7 @@ public:
// earlier and need to reacquire it in order to clean up our ClientCursorPin.
if (cursor->isAggCursor()) {
invariant(NULL == ctx.get());
- unpinDBLock.reset(new Lock::DBLock(opCtx->lockState(), request.nss.db(), MODE_IS));
+ unpinDBLock.reset(new Lock::DBLock(opCtx, request.nss.db(), MODE_IS));
unpinCollLock.reset(
new Lock::CollectionLock(opCtx->lockState(), request.nss.ns(), MODE_IS));
}
@@ -567,7 +567,7 @@ public:
std::unique_ptr<Lock::CollectionLock> unpinCollLock;
if (cursor->isAggCursor()) {
- unpinDBLock.reset(new Lock::DBLock(opCtx->lockState(), request.nss.db(), MODE_IS));
+ unpinDBLock.reset(new Lock::DBLock(opCtx, request.nss.db(), MODE_IS));
unpinCollLock.reset(
new Lock::CollectionLock(opCtx->lockState(), request.nss.ns(), MODE_IS));
}
diff --git a/src/mongo/db/commands/group_cmd.cpp b/src/mongo/db/commands/group_cmd.cpp
index a9e6eeca6ca..4b41fc9e42c 100644
--- a/src/mongo/db/commands/group_cmd.cpp
+++ b/src/mongo/db/commands/group_cmd.cpp
@@ -134,7 +134,7 @@ private:
groupRequest.explain = true;
- AutoGetCollectionForRead ctx(opCtx, groupRequest.ns);
+ AutoGetCollectionForReadCommand ctx(opCtx, groupRequest.ns);
Collection* coll = ctx.getCollection();
auto statusWithPlanExecutor =
@@ -166,7 +166,7 @@ private:
return appendCommandStatus(result, parseRequestStatus);
}
- AutoGetCollectionForRead ctx(opCtx, groupRequest.ns);
+ AutoGetCollectionForReadCommand ctx(opCtx, groupRequest.ns);
Collection* coll = ctx.getCollection();
auto statusWithPlanExecutor =
diff --git a/src/mongo/db/commands/haystack.cpp b/src/mongo/db/commands/haystack.cpp
index d760ee9b866..f9a41f0ccd2 100644
--- a/src/mongo/db/commands/haystack.cpp
+++ b/src/mongo/db/commands/haystack.cpp
@@ -103,7 +103,7 @@ public:
BSONObjBuilder& result) {
const NamespaceString nss = parseNsCollectionRequired(dbname, cmdObj);
- AutoGetCollectionForRead ctx(opCtx, nss);
+ AutoGetCollectionForReadCommand ctx(opCtx, nss);
Collection* collection = ctx.getCollection();
if (!collection) {
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index 68230d587af..d85565ab49c 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -165,7 +165,7 @@ Status ListFilters::runIndexFilterCommand(OperationContext* opCtx,
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query settings is owned by the collection.
- AutoGetCollectionForRead ctx(opCtx, NamespaceString(ns));
+ AutoGetCollectionForReadCommand ctx(opCtx, NamespaceString(ns));
QuerySettings* querySettings;
PlanCache* unused;
@@ -233,7 +233,7 @@ Status ClearFilters::runIndexFilterCommand(OperationContext* opCtx,
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query settings is owned by the collection.
- AutoGetCollectionForRead ctx(opCtx, NamespaceString(ns));
+ AutoGetCollectionForReadCommand ctx(opCtx, NamespaceString(ns));
QuerySettings* querySettings;
PlanCache* planCache;
@@ -335,7 +335,7 @@ Status SetFilter::runIndexFilterCommand(OperationContext* opCtx,
BSONObjBuilder* bob) {
// This is a read lock. The query settings is owned by the collection.
const NamespaceString nss(ns);
- AutoGetCollectionForRead ctx(opCtx, nss);
+ AutoGetCollectionForReadCommand ctx(opCtx, nss);
QuerySettings* querySettings;
PlanCache* planCache;
diff --git a/src/mongo/db/commands/killcursors_cmd.cpp b/src/mongo/db/commands/killcursors_cmd.cpp
index e51e4d65f8a..c1526d990b5 100644
--- a/src/mongo/db/commands/killcursors_cmd.cpp
+++ b/src/mongo/db/commands/killcursors_cmd.cpp
@@ -48,7 +48,7 @@ private:
Status _killCursor(OperationContext* opCtx,
const NamespaceString& nss,
CursorId cursorId) final {
- std::unique_ptr<AutoGetCollectionOrViewForRead> ctx;
+ std::unique_ptr<AutoGetCollectionOrViewForReadCommand> ctx;
CursorManager* cursorManager;
if (nss.isListIndexesCursorNS() || nss.isListCollectionsCursorNS()) {
@@ -57,7 +57,7 @@ private:
// data within a collection.
cursorManager = CursorManager::getGlobalCursorManager();
} else {
- ctx = stdx::make_unique<AutoGetCollectionOrViewForRead>(opCtx, nss);
+ ctx = stdx::make_unique<AutoGetCollectionOrViewForReadCommand>(opCtx, nss);
Collection* collection = ctx->getCollection();
ViewDefinition* view = ctx->getView();
if (view) {
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index a0f998fe346..da72422b4eb 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -255,7 +255,6 @@ public:
return appendCommandStatus(result, parseCursorStatus);
}
- ScopedTransaction scopedXact(opCtx, MODE_IS);
AutoGetDb autoDb(opCtx, dbname, MODE_S);
Database* db = autoDb.getDb();
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp
index ccc2f82cc49..ffe00a55362 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -114,8 +114,7 @@ public:
vector<string> dbNames;
StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
{
- ScopedTransaction transaction(opCtx, MODE_IS);
- Lock::GlobalLock lk(opCtx->lockState(), MODE_IS, UINT_MAX);
+ Lock::GlobalLock lk(opCtx, MODE_IS, UINT_MAX);
storageEngine->listDatabases(&dbNames);
}
@@ -135,8 +134,7 @@ public:
if (filterNameOnly && !filter->matchesBSON(b.asTempObj()))
continue;
- ScopedTransaction transaction(opCtx, MODE_IS);
- Lock::DBLock dbLock(opCtx->lockState(), dbname, MODE_IS);
+ Lock::DBLock dbLock(opCtx, dbname, MODE_IS);
Database* db = dbHolder().get(opCtx, dbname);
if (!db)
diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp
index 940edb13eda..73e3d19289e 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -132,7 +132,7 @@ public:
return appendCommandStatus(result, parseCursorStatus);
}
- AutoGetCollectionForRead autoColl(opCtx, ns);
+ AutoGetCollectionForReadCommand autoColl(opCtx, ns);
if (!autoColl.getDb()) {
return appendCommandStatus(result,
Status(ErrorCodes::NamespaceNotFound, "no database"));
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 9d36a06731b..ffeecffaca5 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -369,7 +369,6 @@ Config::Config(const string& _dbname, const BSONObj& cmdObj) {
void State::dropTempCollections() {
if (!_config.tempNamespace.isEmpty()) {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- ScopedTransaction scopedXact(_opCtx, MODE_IX);
AutoGetDb autoDb(_opCtx, _config.tempNamespace.db(), MODE_X);
if (auto db = autoDb.getDb()) {
WriteUnitOfWork wunit(_opCtx);
@@ -392,8 +391,7 @@ void State::dropTempCollections() {
repl::UnreplicatedWritesBlock uwb(_opCtx);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- ScopedTransaction scopedXact(_opCtx, MODE_IX);
- Lock::DBLock lk(_opCtx->lockState(), _config.incLong.db(), MODE_X);
+ Lock::DBLock lk(_opCtx, _config.incLong.db(), MODE_X);
if (Database* db = dbHolder().get(_opCtx, _config.incLong.ns())) {
WriteUnitOfWork wunit(_opCtx);
db->dropCollection(_opCtx, _config.incLong.ns());
@@ -611,9 +609,8 @@ long long State::postProcessCollection(OperationContext* opCtx,
invariant(!opCtx->lockState()->isLocked());
- ScopedTransaction transaction(opCtx, MODE_X);
// This must be global because we may write across different databases.
- Lock::GlobalWrite lock(opCtx->lockState());
+ Lock::GlobalWrite lock(opCtx);
holdingGlobalLock = true;
return postProcessCollectionNonAtomic(opCtx, curOp, pm, holdingGlobalLock);
}
@@ -626,10 +623,10 @@ unsigned long long _collectionCount(OperationContext* opCtx,
const NamespaceString& nss,
bool callerHoldsGlobalLock) {
Collection* coll = nullptr;
- boost::optional<AutoGetCollectionForRead> ctx;
+ boost::optional<AutoGetCollectionForReadCommand> ctx;
- // If the global write lock is held, we must avoid using AutoGetCollectionForRead as it may lead
- // to deadlock when waiting for a majority snapshot to be committed. See SERVER-24596.
+ // If the global write lock is held, we must avoid using AutoGetCollectionForReadCommand as it
+ // may lead to deadlock when waiting for a majority snapshot to be committed. See SERVER-24596.
if (callerHoldsGlobalLock) {
Database* db = dbHolder().get(opCtx, nss.ns());
if (db) {
@@ -654,9 +651,8 @@ long long State::postProcessCollectionNonAtomic(OperationContext* opCtx,
if (_config.outputOptions.outType == Config::REPLACE ||
_collectionCount(opCtx, _config.outputOptions.finalNamespace, callerHoldsGlobalLock) == 0) {
- ScopedTransaction transaction(opCtx, MODE_X);
// This must be global because we may write across different databases.
- Lock::GlobalWrite lock(opCtx->lockState());
+ Lock::GlobalWrite lock(opCtx);
// replace: just rename from temp to final collection name, dropping previous collection
_db.dropCollection(_config.outputOptions.finalNamespace.ns());
BSONObj info;
@@ -682,9 +678,7 @@ long long State::postProcessCollectionNonAtomic(OperationContext* opCtx,
}
unique_ptr<DBClientCursor> cursor = _db.query(_config.tempNamespace.ns(), BSONObj());
while (cursor->more()) {
- ScopedTransaction scopedXact(opCtx, MODE_X);
- Lock::DBLock lock(
- opCtx->lockState(), _config.outputOptions.finalNamespace.db(), MODE_X);
+ Lock::DBLock lock(opCtx, _config.outputOptions.finalNamespace.db(), MODE_X);
BSONObj o = cursor->nextSafe();
Helpers::upsert(opCtx, _config.outputOptions.finalNamespace.ns(), o);
pm.hit();
@@ -704,9 +698,8 @@ long long State::postProcessCollectionNonAtomic(OperationContext* opCtx,
}
unique_ptr<DBClientCursor> cursor = _db.query(_config.tempNamespace.ns(), BSONObj());
while (cursor->more()) {
- ScopedTransaction transaction(opCtx, MODE_X);
// This must be global because we may write across different databases.
- Lock::GlobalWrite lock(opCtx->lockState());
+ Lock::GlobalWrite lock(opCtx);
BSONObj temp = cursor->nextSafe();
BSONObj old;
@@ -1088,7 +1081,8 @@ void State::finalReduce(OperationContext* opCtx, CurOp* curOp, ProgressMeterHold
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(_opCtx, "finalReduce", _config.incLong.ns());
- unique_ptr<AutoGetCollectionForRead> ctx(new AutoGetCollectionForRead(_opCtx, _config.incLong));
+ unique_ptr<AutoGetCollectionForReadCommand> ctx(
+ new AutoGetCollectionForReadCommand(_opCtx, _config.incLong));
BSONObj prev;
BSONList all;
@@ -1143,7 +1137,7 @@ void State::finalReduce(OperationContext* opCtx, CurOp* curOp, ProgressMeterHold
// reduce a finalize array
finalReduce(all);
- ctx.reset(new AutoGetCollectionForRead(_opCtx, _config.incLong));
+ ctx.reset(new AutoGetCollectionForReadCommand(_opCtx, _config.incLong));
all.clear();
prev = o;
@@ -1163,7 +1157,7 @@ void State::finalReduce(OperationContext* opCtx, CurOp* curOp, ProgressMeterHold
ctx.reset();
// reduce and finalize last array
finalReduce(all);
- ctx.reset(new AutoGetCollectionForRead(_opCtx, _config.incLong));
+ ctx.reset(new AutoGetCollectionForReadCommand(_opCtx, _config.incLong));
pm.finished();
}
@@ -1405,7 +1399,7 @@ public:
unique_ptr<RangePreserver> rangePreserver;
ScopedCollectionMetadata collMetadata;
{
- AutoGetCollectionForRead ctx(opCtx, config.nss);
+ AutoGetCollectionForReadCommand ctx(opCtx, config.nss);
Collection* collection = ctx.getCollection();
if (collection) {
@@ -1424,8 +1418,8 @@ public:
// be done under the lock.
ON_BLOCK_EXIT([opCtx, &config, &rangePreserver] {
if (rangePreserver) {
- // Be sure not to use AutoGetCollectionForRead here, since that has side-effects
- // other than lock acquisition.
+ // Be sure not to use AutoGetCollectionForReadCommand here, since that has
+ // side-effects other than lock acquisition.
AutoGetCollection ctx(opCtx, config.nss, MODE_IS);
rangePreserver.reset();
}
@@ -1489,7 +1483,6 @@ public:
// useful cursor.
// Need lock and context to use it
- unique_ptr<ScopedTransaction> scopedXact(new ScopedTransaction(opCtx, MODE_IS));
unique_ptr<AutoGetDb> scopedAutoDb(new AutoGetDb(opCtx, config.nss.db(), MODE_S));
auto qr = stdx::make_unique<QueryRequest>(config.nss);
@@ -1565,11 +1558,9 @@ public:
exec->saveState();
scopedAutoDb.reset();
- scopedXact.reset();
state.reduceAndSpillInMemoryStateIfNeeded();
- scopedXact.reset(new ScopedTransaction(opCtx, MODE_IS));
scopedAutoDb.reset(new AutoGetDb(opCtx, config.nss.db(), MODE_S));
if (!exec->restoreState()) {
diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp
index 39d3d175ff0..0c59dca849a 100644
--- a/src/mongo/db/commands/oplog_note.cpp
+++ b/src/mongo/db/commands/oplog_note.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/resource_pattern.h"
#include "mongo/db/commands.h"
+#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/op_observer.h"
#include "mongo/db/operation_context.h"
@@ -87,8 +88,7 @@ public:
return appendCommandStatus(result, status);
}
- ScopedTransaction scopedXact(opCtx, MODE_X);
- Lock::GlobalWrite globalWrite(opCtx->lockState());
+ Lock::GlobalWrite globalWrite(opCtx);
WriteUnitOfWork wuow(opCtx);
getGlobalServiceContext()->getOpObserver()->onOpMessage(opCtx, dataElement.Obj());
diff --git a/src/mongo/db/commands/parallel_collection_scan.cpp b/src/mongo/db/commands/parallel_collection_scan.cpp
index df783b46062..8ff2e100a58 100644
--- a/src/mongo/db/commands/parallel_collection_scan.cpp
+++ b/src/mongo/db/commands/parallel_collection_scan.cpp
@@ -93,7 +93,7 @@ public:
BSONObjBuilder& result) {
const NamespaceString ns(parseNsCollectionRequired(dbname, cmdObj));
- AutoGetCollectionForRead ctx(opCtx, ns);
+ AutoGetCollectionForReadCommand ctx(opCtx, ns);
Collection* collection = ctx.getCollection();
if (!collection)
diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp
index ff9bd872cf3..bb4eebcb998 100644
--- a/src/mongo/db/commands/plan_cache_commands.cpp
+++ b/src/mongo/db/commands/plan_cache_commands.cpp
@@ -227,7 +227,7 @@ Status PlanCacheListQueryShapes::runPlanCacheCommand(OperationContext* opCtx,
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query cache is owned by the collection.
- AutoGetCollectionForRead ctx(opCtx, NamespaceString(ns));
+ AutoGetCollectionForReadCommand ctx(opCtx, NamespaceString(ns));
PlanCache* planCache;
Status status = getPlanCache(opCtx, ctx.getCollection(), ns, &planCache);
@@ -279,7 +279,7 @@ Status PlanCacheClear::runPlanCacheCommand(OperationContext* opCtx,
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query cache is owned by the collection.
- AutoGetCollectionForRead ctx(opCtx, NamespaceString(ns));
+ AutoGetCollectionForReadCommand ctx(opCtx, NamespaceString(ns));
PlanCache* planCache;
Status status = getPlanCache(opCtx, ctx.getCollection(), ns, &planCache);
@@ -355,7 +355,7 @@ Status PlanCacheListPlans::runPlanCacheCommand(OperationContext* opCtx,
const std::string& ns,
BSONObj& cmdObj,
BSONObjBuilder* bob) {
- AutoGetCollectionForRead ctx(opCtx, NamespaceString(ns));
+ AutoGetCollectionForReadCommand ctx(opCtx, NamespaceString(ns));
PlanCache* planCache;
Status status = getPlanCache(opCtx, ctx.getCollection(), ns, &planCache);
diff --git a/src/mongo/db/commands/repair_cursor.cpp b/src/mongo/db/commands/repair_cursor.cpp
index b5d7c2fde6f..ac6155cc394 100644
--- a/src/mongo/db/commands/repair_cursor.cpp
+++ b/src/mongo/db/commands/repair_cursor.cpp
@@ -75,7 +75,7 @@ public:
BSONObjBuilder& result) {
NamespaceString ns(parseNs(dbname, cmdObj));
- AutoGetCollectionForRead ctx(opCtx, ns);
+ AutoGetCollectionForReadCommand ctx(opCtx, ns);
Collection* collection = ctx.getCollection();
if (!collection) {
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index 684b954b0c5..35164560c16 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -309,7 +309,7 @@ Status runAggregate(OperationContext* opCtx,
// same sharding version that we synchronize on here. This is also why we always need to
// create a ClientCursor even when we aren't outputting to a cursor. See the comment on
// ShardFilterStage for more details.
- AutoGetCollectionOrViewForRead ctx(opCtx, nss);
+ AutoGetCollectionOrViewForReadCommand ctx(opCtx, nss);
Collection* collection = ctx.getCollection();
// If this is a view, resolve it by finding the underlying collection and stitching view
@@ -487,7 +487,7 @@ Status runAggregate(OperationContext* opCtx,
// AutoGetCollectionForRead. AutoGetCollectionForRead will throw if the
// sharding version is out of date, and we don't care if the sharding version
// has changed.
- Lock::DBLock dbLock(opCtx->lockState(), nss.db(), MODE_IS);
+ Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS);
if (keepCursor) {
pin->release();
@@ -498,7 +498,7 @@ Status runAggregate(OperationContext* opCtx,
} catch (...) {
// On our way out of scope, we clean up our ClientCursorPin if needed.
if (pin) {
- Lock::DBLock dbLock(opCtx->lockState(), nss.db(), MODE_IS);
+ Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS);
pin->deleteUnderlying();
}
diff --git a/src/mongo/db/commands/snapshot_management.cpp b/src/mongo/db/commands/snapshot_management.cpp
index 8ab963eb71e..1eb6e2c2126 100644
--- a/src/mongo/db/commands/snapshot_management.cpp
+++ b/src/mongo/db/commands/snapshot_management.cpp
@@ -32,6 +32,7 @@
#include "mongo/base/init.h"
#include "mongo/db/commands.h"
+#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/service_context.h"
@@ -75,8 +76,7 @@ public:
return appendCommandStatus(result, {ErrorCodes::CommandNotSupported, ""});
}
- ScopedTransaction st(opCtx, MODE_IX);
- Lock::GlobalLock lk(opCtx->lockState(), MODE_IX, UINT_MAX);
+ Lock::GlobalLock lk(opCtx, MODE_IX, UINT_MAX);
auto status = snapshotManager->prepareForCreateSnapshot(opCtx);
if (status.isOK()) {
@@ -126,8 +126,7 @@ public:
return appendCommandStatus(result, {ErrorCodes::CommandNotSupported, ""});
}
- ScopedTransaction st(opCtx, MODE_IX);
- Lock::GlobalLock lk(opCtx->lockState(), MODE_IX, UINT_MAX);
+ Lock::GlobalLock lk(opCtx, MODE_IX, UINT_MAX);
auto name = SnapshotName(cmdObj.firstElement().Long());
snapshotManager->setCommittedSnapshot(name);
return true;
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index 34bc757d554..685e8e7a013 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -85,8 +85,7 @@ public:
log() << "test only command godinsert invoked coll:" << nss.coll();
BSONObj obj = cmdObj["obj"].embeddedObjectUserCheck();
- ScopedTransaction transaction(opCtx, MODE_IX);
- Lock::DBLock lk(opCtx->lockState(), dbname, MODE_X);
+ Lock::DBLock lk(opCtx, dbname, MODE_X);
OldClientContext ctx(opCtx, nss.ns());
Database* db = ctx.db();
@@ -141,14 +140,12 @@ public:
std::vector<Privilege>* out) {}
void _sleepInReadLock(mongo::OperationContext* opCtx, long long millis) {
- ScopedTransaction transaction(opCtx, MODE_S);
- Lock::GlobalRead lk(opCtx->lockState());
+ Lock::GlobalRead lk(opCtx);
sleepmillis(millis);
}
void _sleepInWriteLock(mongo::OperationContext* opCtx, long long millis) {
- ScopedTransaction transaction(opCtx, MODE_X);
- Lock::GlobalWrite lk(opCtx->lockState());
+ Lock::GlobalWrite lk(opCtx);
sleepmillis(millis);
}
diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp
index 1f28da9e3fc..7cae0f979ee 100644
--- a/src/mongo/db/commands/touch.cpp
+++ b/src/mongo/db/commands/touch.cpp
@@ -102,7 +102,7 @@ public:
return false;
}
- AutoGetCollectionForRead context(opCtx, nss);
+ AutoGetCollectionForReadCommand context(opCtx, nss);
Collection* collection = context.getCollection();
if (!collection) {
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index 3c30ddc9e66..b6896022583 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -328,7 +328,6 @@ public:
// Explains of write commands are read-only, but we take write locks so that timing
// info is more accurate.
- ScopedTransaction scopedXact(opCtx, MODE_IX);
AutoGetCollection collection(opCtx, batch.ns, MODE_IX);
auto exec = uassertStatusOK(getExecutorUpdate(
@@ -396,7 +395,6 @@ public:
// Explains of write commands are read-only, but we take write locks so that timing
// info is more accurate.
- ScopedTransaction scopedXact(opCtx, MODE_IX);
AutoGetCollection collection(opCtx, batch.ns, MODE_IX);
// Explain the plan tree.