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/count.cpp18
-rw-r--r--src/mongo/db/commands/dbhash.cpp14
-rw-r--r--src/mongo/db/commands/distinct.cpp7
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp1
-rw-r--r--src/mongo/db/commands/find_cmd.cpp12
-rw-r--r--src/mongo/db/commands/geo_near_cmd.cpp20
-rw-r--r--src/mongo/db/commands/group.cpp10
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp20
-rw-r--r--src/mongo/db/commands/list_collections.cpp4
-rw-r--r--src/mongo/db/commands/list_databases.cpp22
-rw-r--r--src/mongo/db/commands/list_indexes.cpp8
-rw-r--r--src/mongo/db/commands/mr.cpp47
-rw-r--r--src/mongo/db/commands/parallel_collection_scan.cpp6
-rw-r--r--src/mongo/db/commands/pipeline_command.cpp6
-rw-r--r--src/mongo/db/commands/plan_cache_commands.cpp18
-rw-r--r--src/mongo/db/commands/rename_collection.cpp3
-rw-r--r--src/mongo/db/commands/touch.cpp11
-rw-r--r--src/mongo/db/commands/validate.cpp12
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp4
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp1
20 files changed, 123 insertions, 121 deletions
diff --git a/src/mongo/db/commands/count.cpp b/src/mongo/db/commands/count.cpp
index e91b6e12fb5..d102bedf5df 100644
--- a/src/mongo/db/commands/count.cpp
+++ b/src/mongo/db/commands/count.cpp
@@ -77,8 +77,8 @@ namespace mongo {
request.explain = true;
// Acquire the db read lock.
- Client::ReadContext ctx(txn, request.ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, request.ns);
+ AutoGetCollectionForRead ctx(txn, request.ns);
+ Collection* collection = ctx.getCollection();
PlanExecutor* rawExec;
Status getExecStatus = getExecutorCount(txn, collection, request, &rawExec);
@@ -105,8 +105,8 @@ namespace mongo {
return appendCommandStatus(result, parseStatus);
}
- Client::ReadContext ctx(txn, request.ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, request.ns);
+ AutoGetCollectionForRead ctx(txn, request.ns);
+ Collection* collection = ctx.getCollection();
PlanExecutor* rawExec;
Status getExecStatus = getExecutorCount(txn, collection, request, &rawExec);
@@ -234,19 +234,19 @@ namespace mongo {
string &err,
int &errCode) {
- // Lock 'ns'.
- Client::ReadContext ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
- const string& dbname = ctx.ctx().db()->name();
+ AutoGetCollectionForRead ctx(txn, ns);
+ Collection* collection = ctx.getCollection();
if (NULL == collection) {
err = "ns missing";
return -1;
}
+ const NamespaceString nss(ns);
+
CountRequest request;
CmdCount* countComm = static_cast<CmdCount*>(Command::findCommand("count"));
- Status parseStatus = countComm->parseRequest(dbname, cmd, &request);
+ Status parseStatus = countComm->parseRequest(nss.db().toString(), cmd, &request);
if (!parseStatus.isOK()) {
err = parseStatus.reason();
errCode = parseStatus.code();
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 7518365a53a..596675d1ef6 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -64,7 +64,6 @@ namespace mongo {
}
string DBHashCmd::hashCollection( OperationContext* opCtx, Database* db, const string& fullCollectionName, bool* fromCache ) {
-
scoped_ptr<scoped_lock> cachedHashedLock;
if ( isCachable( fullCollectionName ) ) {
@@ -148,11 +147,14 @@ namespace mongo {
list<string> colls;
const string ns = parseNs(dbname, cmdObj);
- Client::ReadContext ctx(txn, ns);
- Database* db = ctx.ctx().db();
- if ( db )
- db->getDatabaseCatalogEntry()->getCollectionNamespaces( &colls );
- colls.sort();
+ // We lock the entire database in S-mode in order to ensure that the contents will not
+ // change for the snapshot.
+ AutoGetDb autoDb(txn, ns, newlm::MODE_S);
+ Database* db = autoDb.getDb();
+ if (db) {
+ db->getDatabaseCatalogEntry()->getCollectionNamespaces(&colls);
+ colls.sort();
+ }
result.appendNumber( "numCollections" , (long long)colls.size() );
result.append( "host" , prettyHostName() );
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp
index de6ce85b6c3..4f34ea89aba 100644
--- a/src/mongo/db/commands/distinct.cpp
+++ b/src/mongo/db/commands/distinct.cpp
@@ -70,7 +70,6 @@ namespace mongo {
bool fromRepl ) {
Timer t;
- string ns = dbname + '.' + cmdObj.firstElement().valuestr();
// ensure that the key is a string
uassert(18510,
@@ -98,10 +97,10 @@ namespace mongo {
BSONArrayBuilder arr( bb );
BSONElementSet values;
- Client::ReadContext ctx(txn, ns);
-
- Collection* collection = ctx.ctx().db()->getCollection( txn, ns );
+ const string ns = parseNs(dbname, cmdObj);
+ AutoGetCollectionForRead ctx(txn, ns);
+ Collection* collection = ctx.getCollection();
if (!collection) {
result.appendArray( "values" , BSONObj() );
result.append("stats", BSON("n" << 0 <<
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index ba93d95bc54..26ea4d8df9c 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -36,6 +36,7 @@
#include <vector>
#include "mongo/db/background.h"
+#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/index_builder.h"
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index f1aef7ba2e5..9bd8d9935e9 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -73,22 +73,24 @@ namespace mongo {
}
auto_ptr<LiteParsedQuery> lpq(rawLpq);
- Client::ReadContext ctx(txn, fullns);
- // The collection may be NULL. If so, getExecutor() should handle it by returning
- // an execution tree with an EOFStage.
- Collection* collection = ctx.ctx().db()->getCollection(txn, fullns);
+ const NamespaceString nss(fullns);
// Finish the parsing step by using the LiteParsedQuery to create a CanonicalQuery.
// This requires a lock on the collection in case we're parsing $where: where-specific
// parsing code assumes we have a lock and creates execution machinery that requires it.
CanonicalQuery* rawCq;
- WhereCallbackReal whereCallback(txn, ctx.ctx().db()->name());
+ WhereCallbackReal whereCallback(txn, nss.db());
Status canonStatus = CanonicalQuery::canonicalize(lpq.release(), &rawCq, whereCallback);
if (!canonStatus.isOK()) {
return canonStatus;
}
auto_ptr<CanonicalQuery> cq(rawCq);
+ AutoGetCollectionForRead ctx(txn, nss);
+ // The collection may be NULL. If so, getExecutor() should handle it by returning
+ // an execution tree with an EOFStage.
+ Collection* collection = ctx.getCollection();
+
// We have a parsed query. Time to get the execution plan for it.
PlanExecutor* rawExec;
Status execStatus = Status::OK();
diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp
index 2268eb18f6f..388e4c7bb27 100644
--- a/src/mongo/db/commands/geo_near_cmd.cpp
+++ b/src/mongo/db/commands/geo_near_cmd.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/catalog/database.h"
+#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/curop.h"
#include "mongo/db/geo/geoconstants.h"
@@ -69,22 +70,15 @@ namespace mongo {
}
bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
- const string ns = dbname + "." + cmdObj.firstElement().valuestr();
-
if (!cmdObj["start"].eoo()) {
errmsg = "using deprecated 'start' argument to geoNear";
return false;
}
- Client::ReadContext ctx(txn, ns);
-
- Database* db = ctx.ctx().db();
- if ( !db ) {
- errmsg = "can't find ns";
- return false;
- }
+ const NamespaceString nss(parseNs(dbname, cmdObj));
+ AutoGetCollectionForRead ctx(txn, nss);
- Collection* collection = db->getCollection( txn, ns );
+ Collection* collection = ctx.getCollection();
if ( !collection ) {
errmsg = "can't find ns";
return false;
@@ -131,7 +125,7 @@ namespace mongo {
}
if (!cmdObj["uniqueDocs"].eoo()) {
- warning() << ns << ": ignoring deprecated uniqueDocs option in geoNear command";
+ warning() << nss << ": ignoring deprecated uniqueDocs option in geoNear command";
}
// And, build the full query expression.
@@ -170,11 +164,9 @@ namespace mongo {
"$dis" << BSON("$meta" << LiteParsedQuery::metaGeoNearDistance));
CanonicalQuery* cq;
-
- const NamespaceString nss(dbname);
const WhereCallbackReal whereCallback(txn, nss.db());
- if (!CanonicalQuery::canonicalize(ns,
+ if (!CanonicalQuery::canonicalize(nss,
rewritten,
BSONObj(),
projObj,
diff --git a/src/mongo/db/commands/group.cpp b/src/mongo/db/commands/group.cpp
index 1310ad381f3..376ed35823a 100644
--- a/src/mongo/db/commands/group.cpp
+++ b/src/mongo/db/commands/group.cpp
@@ -35,7 +35,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/catalog/database.h"
-#include "mongo/db/client_basic.h"
+#include "mongo/db/client.h"
#include "mongo/db/exec/group.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/query/get_executor.h"
@@ -134,8 +134,8 @@ namespace mongo {
return appendCommandStatus(out, parseRequestStatus);
}
- Client::ReadContext ctx(txn, groupRequest.ns);
- Collection* coll = ctx.ctx().db()->getCollection(txn, groupRequest.ns);
+ AutoGetCollectionForRead ctx(txn, groupRequest.ns);
+ Collection* coll = ctx.getCollection();
PlanExecutor *rawPlanExecutor;
Status getExecStatus = getExecutorGroup(txn, coll, groupRequest, &rawPlanExecutor);
@@ -186,8 +186,8 @@ namespace mongo {
groupRequest.explain = true;
- Client::ReadContext ctx(txn, groupRequest.ns);
- Collection* coll = ctx.ctx().db()->getCollection(txn, groupRequest.ns);
+ AutoGetCollectionForRead ctx(txn, groupRequest.ns);
+ Collection* coll = ctx.getCollection();
PlanExecutor *rawPlanExecutor;
Status getExecStatus = getExecutorGroup(txn, coll, groupRequest, &rawPlanExecutor);
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index ab47fe40fe7..a876a0a509a 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -169,11 +169,12 @@ namespace mongo {
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query settings is owned by the collection.
- Client::ReadContext ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
+ AutoGetCollectionForRead ctx(txn, ns);
+
QuerySettings* querySettings;
PlanCache* unused;
- Status status = getQuerySettingsAndPlanCache(txn, collection, ns, &querySettings, &unused);
+ Status status =
+ getQuerySettingsAndPlanCache(txn, ctx.getCollection(), ns, &querySettings, &unused);
if (!status.isOK()) {
// No collection - return empty array of filters.
BSONArrayBuilder hintsBuilder(bob->subarrayStart("filters"));
@@ -231,12 +232,12 @@ namespace mongo {
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query settings is owned by the collection.
- Client::ReadContext ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
+ AutoGetCollectionForRead ctx(txn, ns);
+
QuerySettings* querySettings;
PlanCache* planCache;
Status status =
- getQuerySettingsAndPlanCache(txn, collection, ns, &querySettings, &planCache);
+ getQuerySettingsAndPlanCache(txn, ctx.getCollection(), ns, &querySettings, &planCache);
if (!status.isOK()) {
// No collection - do nothing.
return Status::OK();
@@ -326,12 +327,13 @@ namespace mongo {
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query settings is owned by the collection.
- Client::ReadContext ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
+ const NamespaceString nss(ns);
+ AutoGetCollectionForRead ctx(txn, nss);
+
QuerySettings* querySettings;
PlanCache* planCache;
Status status =
- getQuerySettingsAndPlanCache(txn, collection, ns, &querySettings, &planCache);
+ getQuerySettingsAndPlanCache(txn, ctx.getCollection(), ns, &querySettings, &planCache);
if (!status.isOK()) {
return status;
}
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 720542cd580..e00872f983e 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -67,9 +67,9 @@ namespace mongo {
BSONObjBuilder& result,
bool /*fromRepl*/) {
- Lock::DBRead lk( txn->lockState(), dbname );
+ AutoGetDb autoDb(txn, dbname, newlm::MODE_S);
- const Database* d = dbHolder().get( txn, dbname );
+ const Database* d = autoDb.getDb();
const DatabaseCatalogEntry* dbEntry = NULL;
list<string> names;
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp
index 4c87043f9c9..8a11e595231 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -88,10 +88,7 @@ namespace mongo {
b.append( "sizeOnDisk", (double) size );
totalSize += size;
- {
- Client::ReadContext rc(txn, *i );
- b.appendBool( "empty", rc.ctx().db()->getDatabaseCatalogEntry()->isEmpty() );
- }
+ b.appendBool("empty", size == 0);
dbInfos.push_back( b.obj() );
@@ -99,24 +96,27 @@ namespace mongo {
}
set<string> allShortNames;
- {
- Lock::GlobalRead lk(txn->lockState());
- dbHolder().getAllShortNames(allShortNames);
- }
+ dbHolder().getAllShortNames(allShortNames);
for ( set<string>::iterator i = allShortNames.begin(); i != allShortNames.end(); i++ ) {
string name = *i;
- if ( seen.count( name ) )
+ if (seen.count(name)) {
continue;
+ }
+
+ // This should never happen once the write collection locking changes are in
+ // invariant(false);
BSONObjBuilder b;
b.append( "name" , name );
b.append( "sizeOnDisk" , (double)1.0 );
{
- Client::ReadContext ctx(txn, name);
- b.appendBool( "empty", ctx.ctx().db()->getDatabaseCatalogEntry()->isEmpty() );
+ // This will open the database, if it was closed
+ AutoGetDb autoDb(txn, *i, newlm::MODE_S);
+ Database* db = autoDb.getDb();
+ b.appendBool("empty", db->getDatabaseCatalogEntry()->isEmpty());
}
dbInfos.push_back( b.obj() );
diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp
index 7849417e370..bc526a834b8 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -67,15 +67,15 @@ namespace mongo {
BSONObjBuilder& result,
bool /*fromRepl*/) {
- string ns = parseNs( dbname, cmdObj );
-
- Lock::DBRead lock( txn->lockState(), dbname );
- const Database* d = dbHolder().get( txn, dbname );
+ AutoGetDb autoDb(txn, dbname, newlm::MODE_S);
+ const Database* d = autoDb.getDb();
if ( !d ) {
return appendCommandStatus( result, Status( ErrorCodes::NamespaceNotFound,
"no database" ) );
}
+ const string ns = parseNs(dbname, cmdObj);
+
const DatabaseCatalogEntry* dbEntry = d->getDatabaseCatalogEntry();
const CollectionCatalogEntry* cce = dbEntry->getCollectionCatalogEntry( txn, ns );
if ( !cce ) {
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index e58e001a221..d5613aea554 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -983,7 +983,7 @@ namespace mongo {
verify( foundIndex );
}
- scoped_ptr<Client::ReadContext> ctx(new Client::ReadContext(_txn, _config.incLong));
+ scoped_ptr<AutoGetCollectionForRead> ctx(new AutoGetCollectionForRead(_txn, _config.incLong));
BSONObj prev;
BSONList all;
@@ -1004,7 +1004,7 @@ namespace mongo {
whereCallback).isOK());
PlanExecutor* rawExec;
- verify(getExecutor(_txn, getCollectionOrUassert(ctx->ctx().db(), _config.incLong),
+ verify(getExecutor(_txn, getCollectionOrUassert(ctx->getDb(), _config.incLong),
cq, &rawExec, QueryPlannerParams::NO_TABLE_SCAN).isOK());
auto_ptr<PlanExecutor> exec(rawExec);
@@ -1039,7 +1039,7 @@ namespace mongo {
// reduce a finalize array
finalReduce( all );
- ctx.reset(new Client::ReadContext(_txn, _config.incLong));
+ ctx.reset(new AutoGetCollectionForRead(_txn, _config.incLong));
all.clear();
prev = o;
@@ -1055,7 +1055,7 @@ namespace mongo {
ctx.reset();
// reduce and finalize last array
finalReduce( all );
- ctx.reset(new Client::ReadContext(_txn, _config.incLong));
+ ctx.reset(new AutoGetCollectionForRead(_txn, _config.incLong));
pm.finished();
}
@@ -1270,10 +1270,12 @@ namespace mongo {
// Prevent sharding state from changing during the MR.
auto_ptr<RangePreserver> rangePreserver;
{
- Client::ReadContext ctx(txn, config.ns);
- Collection* collection = ctx.ctx().db()->getCollection( txn, config.ns );
- if ( collection )
+ AutoGetCollectionForRead ctx(txn, config.ns);
+
+ Collection* collection = ctx.getCollection();
+ if (collection) {
rangePreserver.reset(new RangePreserver(collection));
+ }
// Get metadata before we check our version, to make sure it doesn't increment
// in the meantime. Need to do this in the same lock scope as the block.
@@ -1332,14 +1334,11 @@ namespace mongo {
{
// We've got a cursor preventing migrations off, now re-establish our useful cursor
- // Need lock and context to use it
- scoped_ptr<Lock::DBRead> lock(new Lock::DBRead(txn->lockState(), config.ns));
+ const NamespaceString nss(config.ns);
- // This context does no version check, safe b/c we checked earlier and have an
- // open cursor
- scoped_ptr<Client::Context> ctx(new Client::Context(txn, config.ns, false));
+ // Need lock and context to use it
+ scoped_ptr<Lock::DBRead> lock(new Lock::DBRead(txn->lockState(), nss.db()));
- const NamespaceString nss(config.ns);
const WhereCallbackReal whereCallback(txn, nss.db());
CanonicalQuery* cq;
@@ -1353,8 +1352,11 @@ namespace mongo {
return 0;
}
+ Database* db = dbHolder().get(txn, nss.db());
+ invariant(db);
+
PlanExecutor* rawExec;
- if (!getExecutor(txn, state.getCollectionOrUassert(ctx->db(), config.ns),
+ if (!getExecutor(txn, state.getCollectionOrUassert(db, config.ns),
cq, &rawExec).isOK()) {
uasserted(17239, "Can't get executor for query "
+ config.filter.toString());
@@ -1396,12 +1398,21 @@ namespace mongo {
// TODO: As an optimization, we might want to do the save/restore
// state and yield inside the reduceAndSpillInMemoryState method, so
// it only happens if necessary.
- ctx.reset();
lock.reset();
state.reduceAndSpillInMemoryStateIfNeeded();
- lock.reset(new Lock::DBRead(txn->lockState(), config.ns));
-
- ctx.reset(new Client::Context(txn, config.ns, false));
+ lock.reset(new Lock::DBRead(txn->lockState(), nss.db()));
+
+ // Need to reload the database, in case it was dropped after we
+ // released the lock
+ db = dbHolder().get(txn, nss.db());
+ if (db == NULL) {
+ // Database was deleted after we freed the lock
+ StringBuilder sb;
+ sb << "Database "
+ << nss.db()
+ << " was deleted in the middle of the reduce job.";
+ uasserted(28523, sb.str());
+ }
reduceTime += t.micros();
diff --git a/src/mongo/db/commands/parallel_collection_scan.cpp b/src/mongo/db/commands/parallel_collection_scan.cpp
index 2e653880b80..449254bc138 100644
--- a/src/mongo/db/commands/parallel_collection_scan.cpp
+++ b/src/mongo/db/commands/parallel_collection_scan.cpp
@@ -74,11 +74,9 @@ namespace mongo {
NamespaceString ns( dbname, cmdObj[name].String() );
- Client::ReadContext ctx(txn, ns.ns());
-
- Database* db = ctx.ctx().db();
- Collection* collection = db->getCollection( txn, ns );
+ AutoGetCollectionForRead ctx(txn, ns.ns());
+ Collection* collection = ctx.getCollection();
if ( !collection )
return appendCommandStatus( result,
Status( ErrorCodes::NamespaceNotFound,
diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp
index f360d550f7f..dc2581b3a12 100644
--- a/src/mongo/db/commands/pipeline_command.cpp
+++ b/src/mongo/db/commands/pipeline_command.cpp
@@ -26,7 +26,7 @@
* it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
#include <boost/smart_ptr.hpp>
#include <vector>
@@ -223,9 +223,9 @@ namespace mongo {
// 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.
- Client::ReadContext ctx(txn, ns);
+ AutoGetCollectionForRead ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
+ Collection* collection = ctx.getCollection();
// This does mongod-specific stuff like creating the input PlanExecutor and adding
// it to the front of the pipeline if needed.
diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp
index 601e9b47318..3f9223aa15c 100644
--- a/src/mongo/db/commands/plan_cache_commands.cpp
+++ b/src/mongo/db/commands/plan_cache_commands.cpp
@@ -225,10 +225,10 @@ namespace mongo {
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query cache is owned by the collection.
- Client::ReadContext ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
+ AutoGetCollectionForRead ctx(txn, ns);
+
PlanCache* planCache;
- Status status = getPlanCache(txn, collection, ns, &planCache);
+ Status status = getPlanCache(txn, ctx.getCollection(), ns, &planCache);
if (!status.isOK()) {
// No collection - return results with empty shapes array.
BSONArrayBuilder arrayBuilder(bob->subarrayStart("shapes"));
@@ -273,10 +273,10 @@ namespace mongo {
BSONObj& cmdObj,
BSONObjBuilder* bob) {
// This is a read lock. The query cache is owned by the collection.
- Client::ReadContext ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
+ AutoGetCollectionForRead ctx(txn, ns);
+
PlanCache* planCache;
- Status status = getPlanCache(txn, collection, ns, &planCache);
+ Status status = getPlanCache(txn, ctx.getCollection(), ns, &planCache);
if (!status.isOK()) {
// No collection - nothing to do. Return OK status.
return Status::OK();
@@ -347,10 +347,10 @@ namespace mongo {
const std::string& ns,
BSONObj& cmdObj,
BSONObjBuilder* bob) {
- Client::ReadContext ctx(txn, ns);
- Collection* collection = ctx.ctx().db()->getCollection(txn, ns);
+ AutoGetCollectionForRead ctx(txn, ns);
+
PlanCache* planCache;
- Status status = getPlanCache(txn, collection, ns, &planCache);
+ Status status = getPlanCache(txn, ctx.getCollection(), ns, &planCache);
if (!status.isOK()) {
// No collection - return empty plans array.
BSONArrayBuilder plansBuilder(bob->subarrayStart("plans"));
diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp
index dd613705eac..12b44ad77ad 100644
--- a/src/mongo/db/commands/rename_collection.cpp
+++ b/src/mongo/db/commands/rename_collection.cpp
@@ -178,8 +178,7 @@ namespace mongo {
// Dismissed on success
ScopeGuard indexBuildRestorer = MakeGuard(IndexBuilder::restoreIndexes, indexesInProg);
- bool unused;
- Database* const targetDB = dbHolder().getOrCreate(txn, nsToDatabase(target), unused);
+ Database* const targetDB = dbHolder().openDb(txn, nsToDatabase(target));
{
WriteUnitOfWork wunit(txn);
diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp
index 187ba27ab04..34cdc891c78 100644
--- a/src/mongo/db/commands/touch.cpp
+++ b/src/mongo/db/commands/touch.cpp
@@ -30,7 +30,7 @@
* it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
#include <string>
#include <vector>
@@ -41,8 +41,8 @@
#include "mongo/db/auth/privilege.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
+#include "mongo/db/client.h"
#include "mongo/db/commands.h"
-#include "mongo/db/curop.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context_impl.h"
@@ -85,7 +85,7 @@ namespace mongo {
return false;
}
- NamespaceString nss( dbname, coll );
+ const NamespaceString nss( dbname, coll );
if ( ! nss.isNormal() ) {
errmsg = "bad namespace name";
return false;
@@ -99,10 +99,9 @@ namespace mongo {
return false;
}
- Client::ReadContext context(txn, nss.ns());
+ AutoGetCollectionForRead context(txn, nss);
- Database* db = context.ctx().db();
- Collection* collection = db->getCollection( txn, nss.ns() );
+ Collection* collection = context.getCollection();
if ( !collection ) {
errmsg = "collection not found";
return false;
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index bbddae56505..650087760fc 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -77,17 +77,11 @@ namespace mongo {
LOG(0) << "CMD: validate " << ns << endl;
}
- Client::ReadContext ctx(txn, ns_string.ns());
+ AutoGetCollectionForRead ctx(txn, ns_string.ns());
- Database* db = ctx.ctx().db();
- if ( !db ) {
- errmsg = "database not found";
- return false;
- }
-
- Collection* collection = db->getCollection( txn, ns );
+ Collection* collection = ctx.getCollection();
if ( !collection ) {
- errmsg = "collection not found";
+ errmsg = "ns not found";
return false;
}
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 8b21578ce89..1e433e82e66 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -914,7 +914,9 @@ namespace mongo {
bool WriteBatchExecutor::ExecInsertsState::_lockAndCheckImpl(WriteOpResult* result) {
if (hasLock()) {
- txn->getCurOp()->enter(_context.get());
+ // TODO: Client::Context legacy, needs to be removed
+ txn->getCurOp()->enter(_context->ns(),
+ _context->db() ? _context->db()->getProfilingLevel() : 0);
return true;
}
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index a51fac45f9d..fb014322e4a 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -31,6 +31,7 @@
#include "mongo/base/init.h"
#include "mongo/bson/mutable/document.h"
#include "mongo/bson/mutable/element.h"
+#include "mongo/db/client.h"
#include "mongo/db/commands/write_commands/batch_executor.h"
#include "mongo/db/commands/write_commands/write_commands_common.h"
#include "mongo/db/curop.h"