diff options
author | Eliot Horowitz <eliot@10gen.com> | 2014-03-03 17:39:34 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2014-04-03 13:31:48 -0400 |
commit | ee2e11d9a364677a5d495bf1252e87dcc5f0fb6c (patch) | |
tree | 033fbd5dc16ca3f5fcdc7dbd74cf25f1f0d52562 /src/mongo/db/commands/test_commands.cpp | |
parent | db847f131d1810622b974ba2fa20c9d8fd578a2d (diff) | |
download | mongo-ee2e11d9a364677a5d495bf1252e87dcc5f0fb6c.tar.gz |
SERVER-11643: remove many nsdetails calls
Diffstat (limited to 'src/mongo/db/commands/test_commands.cpp')
-rw-r--r-- | src/mongo/db/commands/test_commands.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 4667f6b7ecc..35612381378 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -129,7 +129,7 @@ namespace mongo { public: CapTrunc() : Command( "captrunc" ) {} virtual bool slaveOk() const { return false; } - virtual LockType locktype() const { return WRITE; } + virtual LockType locktype() const { return NONE; } // No auth needed because it only works when enabled via command line. virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, @@ -137,22 +137,23 @@ namespace mongo { virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { string coll = cmdObj[ "captrunc" ].valuestrsafe(); uassert( 13416, "captrunc must specify a collection", !coll.empty() ); - string ns = dbname + "." + coll; + NamespaceString nss( dbname, coll ); int n = cmdObj.getIntField( "n" ); + bool inc = cmdObj.getBoolField( "inc" ); // inclusive range? - // inclusive range? - bool inc = cmdObj.getBoolField( "inc" ); - NamespaceDetails *nsd = nsdetails( ns ); - massert( 13417, "captrunc collection not found or empty", nsd); + Client::WriteContext ctx( nss.ns() ); + Collection* collection = ctx.ctx().db()->getCollection( nss.ns() ); + massert( 13417, "captrunc collection not found or empty", collection); - boost::scoped_ptr<Runner> runner(InternalPlanner::collectionScan(ns, InternalPlanner::BACKWARD)); + boost::scoped_ptr<Runner> runner(InternalPlanner::collectionScan(nss.ns(), + InternalPlanner::BACKWARD)); DiskLoc end; // We remove 'n' elements so the start is one past that for( int i = 0; i < n + 1; ++i ) { Runner::RunnerState state = runner->getNext(NULL, &end); massert( 13418, "captrunc invalid n", Runner::RUNNER_ADVANCED == state); } - nsd->cappedTruncateAfter( ns.c_str(), end, inc ); + collection->details()->cappedTruncateAfter( nss.ns().c_str(), end, inc ); return true; } }; @@ -162,7 +163,7 @@ namespace mongo { public: EmptyCapped() : Command( "emptycapped" ) {} virtual bool slaveOk() const { return false; } - virtual LockType locktype() const { return WRITE; } + virtual LockType locktype() const { return NONE; } virtual bool logTheOp() { return true; } // No auth needed because it only works when enabled via command line. virtual void addRequiredPrivileges(const std::string& dbname, @@ -182,13 +183,15 @@ namespace mongo { virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { string coll = cmdObj[ "emptycapped" ].valuestrsafe(); uassert( 13428, "emptycapped must specify a collection", !coll.empty() ); - string ns = dbname + "." + coll; - NamespaceDetails *nsd = nsdetails( ns ); - massert( 13429, "emptycapped no such collection", nsd ); + NamespaceString nss( dbname, coll ); + + Client::WriteContext ctx( nss.ns() ); + Collection* collection = ctx.ctx().db()->getCollection( nss.ns() ); + massert( 13429, "emptycapped no such collection", collection ); std::vector<BSONObj> indexes = stopIndexBuilds(cc().database(), cmdObj); - nsd->emptyCappedCollection( ns.c_str() ); + collection->details()->emptyCappedCollection( nss.ns().c_str() ); IndexBuilder::restoreIndexes(indexes); |