diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-02-13 10:45:11 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-02-13 16:13:43 -0500 |
commit | f5fc5c0ab87b4f0909387af9819fe87e5ed4758c (patch) | |
tree | b32fa6047277fb60f3859482ceb0e03bb5a6eeb3 | |
parent | dbdb362027d61abbb396dcc091ddd8dd8e8ece22 (diff) | |
download | mongo-f5fc5c0ab87b4f0909387af9819fe87e5ed4758c.tar.gz |
SERVER-13339 Cleanup in preparation for removing unused constructor
-rw-r--r-- | src/mongo/db/client.cpp | 188 | ||||
-rw-r--r-- | src/mongo/db/client.h | 64 | ||||
-rw-r--r-- | src/mongo/db/curop.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/dbhelpers.h | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/master_slave.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 6 | ||||
-rw-r--r-- | src/mongo/dbtests/executor_registry.cpp | 16 | ||||
-rw-r--r-- | src/mongo/dbtests/indexupdatetests.cpp | 14 | ||||
-rw-r--r-- | src/mongo/dbtests/query_plan_executor.cpp | 13 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_count_scan.cpp | 12 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_fetch.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_keep.cpp | 4 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_merge_sort.cpp | 14 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_sort.cpp | 12 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_update.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/querytests.cpp | 6 | ||||
-rw-r--r-- | src/mongo/dbtests/repltests.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/d_migrate.cpp | 10 | ||||
-rw-r--r-- | src/mongo/util/mmap.h | 16 | ||||
-rw-r--r-- | src/mongo/util/mmap_win.cpp | 13 |
21 files changed, 212 insertions, 218 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index 69dc31f8f1c..f39d00ec750 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -56,7 +56,6 @@ #include "mongo/db/dbwebserver.h" #include "mongo/db/instance.h" #include "mongo/db/json.h" -#include "mongo/db/jsobj.h" #include "mongo/db/lasterror.h" #include "mongo/db/repl/handshake_args.h" #include "mongo/db/repl/replication_coordinator_global.h" @@ -77,14 +76,70 @@ namespace mongo { using logger::LogComponent; +namespace { + + class HandshakeCmd : public Command { + public: + void help(stringstream& h) const { h << "internal"; } + HandshakeCmd() : Command("handshake") {} + virtual bool isWriteCommandForConfigServer() const { return false; } + virtual bool slaveOk() const { return true; } + virtual bool adminOnly() const { return false; } + virtual void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) { + ActionSet actions; + actions.addAction(ActionType::internal); + out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); + } + + virtual bool run(OperationContext* txn, + const string& ns, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result, + bool fromRepl) { + + repl::HandshakeArgs handshake; + Status status = handshake.initialize(cmdObj); + if (!status.isOK()) { + return appendCommandStatus(result, status); + } + + // TODO(dannenberg) move this into actual processing for both version + txn->getClient()->setRemoteID(handshake.getRid()); + + status = repl::getGlobalReplicationCoordinator()->processHandshake(txn, handshake); + return appendCommandStatus(result, status); + } + + } handshakeCmd; + + + /** + * Create an appropriate new locker for the storage engine in use. Caller owns the return. + */ + Locker* newLocker() { + if (isMMAPV1()) { + return new MMAPV1LockerImpl(); + } + + return new LockerImpl<false>(); + } + +} // namespace + + boost::mutex Client::clientsMutex; ClientSet Client::clients; TSP_DEFINE(Client, currentClient) - /* each thread which does db operations has a Client object in TLS. - call this when your thread starts. - */ + /** + * This must be called whenever a new thread is started, so that active threads can be tracked + * so each thread has a Client object in TLS. + */ void Client::initThread(const char *desc, AbstractMessagingPort *mp) { invariant(currentClient.get() == 0); @@ -112,17 +167,6 @@ namespace mongo { clients.insert(client); } -namespace { - // Create an appropriate new locker for the storage engine in use. Caller owns. - Locker* newLocker() { - if (isMMAPV1()) { - return new MMAPV1LockerImpl(); - } - - return new LockerImpl<false>(); - } -} - Client::Client(const string& desc, AbstractMessagingPort *p) : ClientBasic(p), _desc(desc), @@ -169,11 +213,9 @@ namespace { return false; } - BSONObj CachedBSONObjBase::_tooBig = fromjson("{\"$msg\":\"query not recording (too large)\"}"); Client::Context::Context(OperationContext* txn, const std::string& ns, Database * db) - : _client(currentClient.get()), - _justCreated(false), + : _justCreated(false), _doVersion(true), _ns(ns), _db(db), @@ -184,8 +226,7 @@ namespace { const std::string& ns, Database* db, bool justCreated) - : _client(currentClient.get()), - _justCreated(justCreated), + : _justCreated(justCreated), _doVersion(true), _ns(ns), _db(db), @@ -196,8 +237,7 @@ namespace { Client::Context::Context(OperationContext* txn, const string& ns, bool doVersion) - : _client(currentClient.get()), - _justCreated(false), // set for real in finishInit + : _justCreated(false), // set for real in finishInit _doVersion(doVersion), _ns(ns), _db(NULL), @@ -206,6 +246,42 @@ namespace { _finishInit(); } + void Client::Context::_finishInit() { + _db = dbHolder().get(_txn, _ns); + if (_db) { + _justCreated = false; + } + else { + invariant(_txn->lockState()->isDbLockedForMode(nsToDatabaseSubstring(_ns), MODE_X)); + _db = dbHolder().openDb(_txn, _ns, &_justCreated); + invariant(_db); + } + + if (_doVersion) { + _checkNotStale(); + } + + _txn->getCurOp()->enter(_ns.c_str(), _db->getProfilingLevel()); + } + + void Client::Context::_checkNotStale() const { + switch (_txn->getCurOp()->getOp()) { + case dbGetMore: // getMore is special and should be handled elsewhere. + case dbUpdate: // update & delete check shard version in instance.cpp, so don't check + case dbDelete: // here as well. + break; + default: + ensureShardVersionOKOrThrow(_ns); + } + } + + Client::Context::~Context() { + // Lock must still be held + invariant(_txn->lockState()->isLocked()); + + _txn->getCurOp()->recordGlobalTime(_txn->lockState()->isWriteLocked(), _timer.micros()); + } + AutoGetDb::AutoGetDb(OperationContext* txn, StringData ns, LockMode mode) : _dbLock(txn->lockState(), ns, mode), @@ -294,42 +370,6 @@ namespace { } } - void Client::Context::checkNotStale() const { - switch ( _client->_curOp->getOp() ) { - case dbGetMore: // getMore's are special and should be handled else where - case dbUpdate: // update & delete check shard version in instance.cpp, so don't check here as well - case dbDelete: - break; - default: { - ensureShardVersionOKOrThrow(_ns); - } - } - } - - void Client::Context::_finishInit() { - _db = dbHolder().get(_txn, _ns); - if (_db) { - _justCreated = false; - } - else { - invariant(_txn->lockState()->isDbLockedForMode(nsToDatabaseSubstring(_ns), MODE_X)); - _db = dbHolder().openDb(_txn, _ns, &_justCreated); - invariant(_db); - } - - if( _doVersion ) checkNotStale(); - - _client->_curOp->enter(_ns.c_str(), _db->getProfilingLevel()); - } - - Client::Context::~Context() { - DEV verify( _client == currentClient.get() ); - - // Lock must still be held - invariant(_txn->lockState()->isLocked()); - - _client->_curOp->recordGlobalTime(_txn->lockState()->isWriteLocked(), _timer.micros()); - } void Client::appendLastOp( BSONObjBuilder& b ) const { // _lastOp is never set if replication is off @@ -375,38 +415,6 @@ namespace { return currentClient.get(); } - class HandshakeCmd : public Command { - public: - void help(stringstream& h) const { h << "internal"; } - HandshakeCmd() : Command( "handshake" ) {} - virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool slaveOk() const { return true; } - virtual bool adminOnly() const { return false; } - virtual void addRequiredPrivileges(const std::string& dbname, - const BSONObj& cmdObj, - std::vector<Privilege>* out) { - ActionSet actions; - actions.addAction(ActionType::internal); - out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); - } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - repl::HandshakeArgs handshake; - Status status = handshake.initialize(cmdObj); - if (!status.isOK()) { - return appendCommandStatus(result, status); - } - - // TODO(dannenberg) move this into actual processing for both version - txn->getClient()->setRemoteID(handshake.getRid()); - - status = repl::getGlobalReplicationCoordinator()->processHandshake(txn, - handshake); - return appendCommandStatus(result, status); - } - - } handshakeCmd; - - void OpDebug::reset() { extra.reset(); diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index f9de90fe203..94a11fb3080 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -36,7 +36,6 @@ #pragma once -#include <boost/noncopyable.hpp> #include <boost/scoped_ptr.hpp> #include <boost/thread/thread.hpp> @@ -54,7 +53,6 @@ namespace mongo { - class AuthenticationInfo; class CurOp; class Collection; class AbstractMessagingPort; @@ -104,11 +102,11 @@ namespace mongo { public: AutoGetOrCreateDb(OperationContext* txn, StringData ns, LockMode mode); - Database* getDb() { + Database* getDb() const { return _db; } - bool justCreated() { + bool justCreated() const { return _justCreated; } @@ -178,7 +176,7 @@ namespace mongo { * Inits a thread if that thread has not already been init'd, setting the thread name to * "desc". */ - static void initThreadIfNotAlready(const char *desc) { + static void initThreadIfNotAlready(const char* desc) { if (currentClient.get()) return; initThread(desc); @@ -198,17 +196,17 @@ namespace mongo { */ bool shutdown(); - std::string clientAddress(bool includePort=false) const; + std::string clientAddress(bool includePort = false) const; CurOp* curop() const { return _curOp; } const std::string& desc() const { return _desc; } - void setLastOp( OpTime op ) { _lastOp = op; } + void setLastOp(OpTime op) { _lastOp = op; } OpTime getLastOp() const { return _lastOp; } // Return a reference to the Locker for this client. Client retains ownership. Locker* getLocker() const { return _locker.get(); } /* report what the last operation was. used by getlasterror */ - void appendLastOp( BSONObjBuilder& b ) const; + void appendLastOp(BSONObjBuilder& b) const; void reportState(BSONObjBuilder& builder); // Ensures stability of the client's OperationContext. When the client is locked, @@ -226,15 +224,19 @@ namespace mongo { bool isGod() const { return _god; } /* this is for map/reduce writes */ bool setGod(bool newVal) { const bool prev = _god; _god = newVal; return prev; } - void setRemoteID(const OID& rid) { _remoteId = rid; } // Only used for master/slave - OID getRemoteID() const { return _remoteId; } // Only used for master/slave + // Only used for master/slave + void setRemoteID(const OID& rid) { _remoteId = rid; } + OID getRemoteID() const { return _remoteId; } + ConnectionId getConnectionId() const { return _connectionId; } bool isFromUserConnection() const { return _connectionId > 0; } private: - Client(const std::string& desc, AbstractMessagingPort *p = 0); friend class CurOp; + Client(const std::string& desc, AbstractMessagingPort *p = 0); + + // Description for the client (e.g. conn8) const std::string _desc; @@ -262,16 +264,19 @@ namespace mongo { // Used by replication OpTime _lastOp; - OID _remoteId; // Only used by master-slave + + // Only used by master-slave + OID _remoteId; // Tracks if Client::shutdown() gets called (TODO: Is this necessary?) bool _shutdown; public: - /* Set database we want to use, then, restores when we finish (are out of scope) - Note this is also helpful if an exception happens as the state if fixed up. - */ + /** + * Opens the database that we want to use and sets the appropriate namespace on the + * current operation. + */ class Context { MONGO_DISALLOW_COPYING(Context); public: @@ -295,26 +300,18 @@ namespace mongo { Context(OperationContext* txn, const std::string& ns, Database * db); ~Context(); - Client* getClient() const { return _client; } + Database* db() const { return _db; } - const char * ns() const { return _ns.c_str(); } + const char* ns() const { return _ns.c_str(); } /** @return if the db was created by this Context */ bool justCreated() const { return _justCreated; } - /** call before unlocking, so clear any non-thread safe state - * _db gets restored on the relock - */ - void unlocked() { _db = 0; } - - /** call after going back into the lock, will re-establish non-thread safe stuff */ - void relocked() { _finishInit(); } - private: friend class CurOp; void _finishInit(); - void checkNotStale() const; - Client * const _client; + void _checkNotStale() const; + bool _justCreated; bool _doVersion; const std::string _ns; @@ -325,7 +322,8 @@ namespace mongo { }; // class Client::Context - class WriteContext : boost::noncopyable { + class WriteContext { + MONGO_DISALLOW_COPYING(WriteContext); public: WriteContext(OperationContext* opCtx, const std::string& ns); @@ -335,17 +333,17 @@ namespace mongo { return _c.db()->getCollection(_nss.ns()); } - Context& ctx() { return _c; } - private: - OperationContext* _txn; - NamespaceString _nss; + OperationContext* const _txn; + const NamespaceString _nss; + AutoGetOrCreateDb _autodb; Lock::CollectionLock _collk; Context _c; Collection* _collection; }; - }; // class Client + + }; /** get the Client object for this thread. */ inline Client& cc() { diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index f69d6196575..ae26aa84dd2 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -37,6 +37,7 @@ #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/catalog/database.h" #include "mongo/db/global_environment_experiment.h" +#include "mongo/db/json.h" #include "mongo/db/stats/top.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" @@ -45,9 +46,9 @@ namespace mongo { using std::string; - // Enabling the maxTimeAlwaysTimeOut fail point will cause any query or command run with a valid - // non-zero max time to fail immediately. Any getmore operation on a cursor already created - // with a valid non-zero max time will also fail immediately. + // Enabling the maxTimeAlwaysTimeOut fail point will cause any query or command run with a + // valid non-zero max time to fail immediately. Any getmore operation on a cursor already + // created with a valid non-zero max time will also fail immediately. // // This fail point cannot be used with the maxTimeNeverTimeOut fail point. MONGO_FP_DECLARE(maxTimeAlwaysTimeOut); @@ -58,7 +59,10 @@ namespace mongo { // This fail point cannot be used with the maxTimeAlwaysTimeOut fail point. MONGO_FP_DECLARE(maxTimeNeverTimeOut); - // todo : move more here + + BSONObj CachedBSONObjBase::_tooBig = + fromjson("{\"$msg\":\"query not recording (too large)\"}"); + CurOp::CurOp( Client * client , CurOp * wrapped ) : _client(client), diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 32fa31f3725..4a271717406 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -271,24 +271,7 @@ namespace mongo { update(txn, context.db(), request, &debug); - context.getClient()->curop()->done(); - } - - void Helpers::putSingletonGod(OperationContext* txn, const char *ns, BSONObj obj, bool logTheOp) { - OpDebug debug; - Client::Context context(txn, ns); - - const NamespaceString requestNs(ns); - UpdateRequest request(requestNs); - - request.setGod(); - request.setUpdates(obj); - request.setUpsert(); - request.setUpdateOpLog(logTheOp); - - update(txn, context.db(), request, &debug); - - context.getClient()->curop()->done(); + txn->getClient()->curop()->done(); } BSONObj Helpers::toKeyFormat( const BSONObj& o ) { diff --git a/src/mongo/db/dbhelpers.h b/src/mongo/db/dbhelpers.h index f9ead76bc20..e75a99aa9b6 100644 --- a/src/mongo/db/dbhelpers.h +++ b/src/mongo/db/dbhelpers.h @@ -116,7 +116,6 @@ namespace mongo { */ static bool getSingleton(OperationContext* txn, const char *ns, BSONObj& result); static void putSingleton(OperationContext* txn, const char *ns, BSONObj obj); - static void putSingletonGod(OperationContext* txn, const char *ns, BSONObj obj, bool logTheOp); /** * get last object int he collection; e.g. {$natural : -1} diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index 8f9fe332453..ae90609016e 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -688,7 +688,7 @@ namespace repl { // mongos will not send requests there. That's why the last argument is false (do not do // version checking). Client::Context ctx(txn, ns, false); - ctx.getClient()->curop()->reset(); + txn->getCurOp()->reset(); bool empty = !ctx.db()->getDatabaseCatalogEntry()->hasUserData(); bool incompleteClone = incompleteCloneDbs.count( clientName ) != 0; diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index beca5f37083..5086c6b3943 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -269,7 +269,7 @@ namespace { OplogDocWriter writer( partial, obj ); checkOplogInsert( localOplogRSCollection->insertDocument( txn, &writer, false ) ); - ctx.getClient()->setLastOp( slot.first ); + txn->getClient()->setLastOp( slot.first ); wunit.commit(); @@ -335,7 +335,7 @@ namespace { OplogDocWriter writer( partial, obj ); checkOplogInsert( localOplogMainCollection->insertDocument( txn, &writer, false ) ); - ctx.getClient()->setLastOp( slot.first ); + txn->getClient()->setLastOp(slot.first); wunit.commit(); } @@ -462,7 +462,7 @@ namespace { long long hash = ops.back()["h"].numberLong(); bgsync->setLastAppliedHash(hash); - ctx.getClient()->setLastOp(lastOptime); + txn->getClient()->setLastOp(lastOptime); replCoord->setMyLastOptime(lastOptime); setNewOptime(lastOptime); diff --git a/src/mongo/dbtests/executor_registry.cpp b/src/mongo/dbtests/executor_registry.cpp index d526f5389ae..16f0da39149 100644 --- a/src/mongo/dbtests/executor_registry.cpp +++ b/src/mongo/dbtests/executor_registry.cpp @@ -82,7 +82,7 @@ namespace ExecutorRegistry { ws.release(), scan.release(), cq, - _ctx->ctx().db()->getCollection(ns()), + _ctx->db()->getCollection(ns()), PlanExecutor::YIELD_MANUAL, &exec); ASSERT_OK(status); @@ -91,24 +91,24 @@ namespace ExecutorRegistry { void registerExecutor( PlanExecutor* exec ) { WriteUnitOfWork wuow(&_opCtx); - _ctx->ctx().db()->getOrCreateCollection(&_opCtx, ns()) - ->getCursorManager() - ->registerExecutor(exec); + _ctx->db()->getOrCreateCollection(&_opCtx, ns()) + ->getCursorManager() + ->registerExecutor(exec); wuow.commit(); } void deregisterExecutor( PlanExecutor* exec ) { WriteUnitOfWork wuow(&_opCtx); - _ctx->ctx().db()->getOrCreateCollection(&_opCtx, ns()) - ->getCursorManager() - ->deregisterExecutor(exec); + _ctx->db()->getOrCreateCollection(&_opCtx, ns()) + ->getCursorManager() + ->deregisterExecutor(exec); wuow.commit(); } int N() { return 50; } Collection* collection() { - return _ctx->ctx().db()->getCollection( ns() ); + return _ctx->db()->getCollection(ns()); } static const char* ns() { return "unittests.ExecutorRegistryDiskLocInvalidation"; } diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index 30ac55d7389..6617b12d1a0 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -346,7 +346,7 @@ namespace IndexUpdateTests { public: void run() { // Create a new collection. - Database* db = _ctx.ctx().db(); + Database* db = _ctx.db(); Collection* coll; { WriteUnitOfWork wunit(&_txn); @@ -384,7 +384,7 @@ namespace IndexUpdateTests { public: void run() { // Create a new collection. - Database* db = _ctx.ctx().db(); + Database* db = _ctx.db(); Collection* coll; { WriteUnitOfWork wunit(&_txn); @@ -419,7 +419,7 @@ namespace IndexUpdateTests { public: void run() { // Create a new collection. - Database* db = _ctx.ctx().db(); + Database* db = _ctx.db(); Collection* coll; RecordId loc1; RecordId loc2; @@ -468,7 +468,7 @@ namespace IndexUpdateTests { public: void run() { // Create a new collection. - Database* db = _ctx.ctx().db(); + Database* db = _ctx.db(); Collection* coll; { WriteUnitOfWork wunit(&_txn); @@ -502,7 +502,7 @@ namespace IndexUpdateTests { public: void run() { // Create a new collection. - Database* db = _ctx.ctx().db(); + Database* db = _ctx.db(); Collection* coll; { WriteUnitOfWork wunit(&_txn); @@ -535,7 +535,7 @@ namespace IndexUpdateTests { public: void run() { // Recreate the collection as capped, without an _id index. - Database* db = _ctx.ctx().db(); + Database* db = _ctx.db(); Collection* coll; { WriteUnitOfWork wunit(&_txn); @@ -573,7 +573,7 @@ namespace IndexUpdateTests { public: void run() { // Recreate the collection as capped, without an _id index. - Database* db = _ctx.ctx().db(); + Database* db = _ctx.db(); Collection* coll; { WriteUnitOfWork wunit(&_txn); diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp index f524c421df2..0092674c58b 100644 --- a/src/mongo/dbtests/query_plan_executor.cpp +++ b/src/mongo/dbtests/query_plan_executor.cpp @@ -126,18 +126,17 @@ namespace QueryPlanExecutor { * * The caller takes ownership of the returned PlanExecutor*. */ - PlanExecutor* makeIndexScanExec(Client::Context& context, - BSONObj& indexSpec, int start, int end) { + PlanExecutor* makeIndexScanExec(Database* db, BSONObj& indexSpec, int start, int end) { // Build the index scan stage. IndexScanParams ixparams; - ixparams.descriptor = getIndex(context.db(), indexSpec); + ixparams.descriptor = getIndex(db, indexSpec); ixparams.bounds.isSimpleRange = true; ixparams.bounds.startKey = BSON("" << start); ixparams.bounds.endKey = BSON("" << end); ixparams.bounds.endKeyInclusive = true; ixparams.direction = 1; - const Collection* coll = context.db()->getCollection(ns()); + const Collection* coll = db->getCollection(ns()); auto_ptr<WorkingSet> ws(new WorkingSet()); IndexScan* ix = new IndexScan(&_txn, ixparams, ws.get(), NULL); @@ -238,7 +237,7 @@ namespace QueryPlanExecutor { BSONObj indexSpec = BSON("a" << 1); addIndex(indexSpec); - scoped_ptr<PlanExecutor> exec(makeIndexScanExec(ctx.ctx(), indexSpec, 7, 10)); + scoped_ptr<PlanExecutor> exec(makeIndexScanExec(ctx.db(), indexSpec, 7, 10)); registerExec(exec.get()); BSONObj objOut; @@ -270,7 +269,7 @@ namespace QueryPlanExecutor { // Create the PlanExecutor which feeds the aggregation pipeline. boost::shared_ptr<PlanExecutor> innerExec( - makeIndexScanExec(ctx.ctx(), indexSpec, 7, 10)); + makeIndexScanExec(ctx.db(), indexSpec, 7, 10)); // Create the aggregation pipeline. boost::intrusive_ptr<ExpressionContext> expCtx = @@ -389,7 +388,7 @@ namespace QueryPlanExecutor { addIndex(indexSpec); BSONObj filterObj = fromjson("{a: {$gte: 2}}"); - scoped_ptr<PlanExecutor> exec(makeIndexScanExec(ctx.ctx(), indexSpec, 2, 5)); + scoped_ptr<PlanExecutor> exec(makeIndexScanExec(ctx.db(), indexSpec, 2, 5)); BSONObj objOut; ASSERT_EQUALS(PlanExecutor::ADVANCED, exec->getNext(&objOut, NULL)); diff --git a/src/mongo/dbtests/query_stage_count_scan.cpp b/src/mongo/dbtests/query_stage_count_scan.cpp index 5e15fcaa3c8..f972df3ba22 100644 --- a/src/mongo/dbtests/query_stage_count_scan.cpp +++ b/src/mongo/dbtests/query_stage_count_scan.cpp @@ -304,7 +304,7 @@ namespace QueryStageCountScan { // Set up count stage CountScanParams params; - params.descriptor = getIndex(ctx.ctx().db(), BSON("a" << 1)); + params.descriptor = getIndex(ctx.db(), BSON("a" << 1)); params.startKey = BSON("" << 2); params.startKeyInclusive = false; params.endKey = BSON("" << 6); @@ -355,7 +355,7 @@ namespace QueryStageCountScan { // Set up count stage CountScanParams params; - params.descriptor = getIndex(ctx.ctx().db(), BSON("a" << 1)); + params.descriptor = getIndex(ctx.db(), BSON("a" << 1)); params.startKey = BSON("" << 2); params.startKeyInclusive = false; params.endKey = BSON("" << 6); @@ -409,7 +409,7 @@ namespace QueryStageCountScan { // Set up count stage CountScanParams params; - params.descriptor = getIndex(ctx.ctx().db(), BSON("a" << 1)); + params.descriptor = getIndex(ctx.db(), BSON("a" << 1)); params.startKey = BSON("" << 2); params.startKeyInclusive = false; params.endKey = BSON("" << 6); @@ -466,7 +466,7 @@ namespace QueryStageCountScan { // Set up count stage CountScanParams params; - params.descriptor = getIndex(ctx.ctx().db(), BSON("a" << 1)); + params.descriptor = getIndex(ctx.db(), BSON("a" << 1)); params.startKey = BSON("" << 2); params.startKeyInclusive = false; params.endKey = BSON("" << 50); @@ -524,7 +524,7 @@ namespace QueryStageCountScan { // Ensure that count does not include unused keys CountScanParams params; - params.descriptor = getIndex(ctx.ctx().db(), BSON("a" << 1)); + params.descriptor = getIndex(ctx.db(), BSON("a" << 1)); params.startKey = BSON("" << 1); params.startKeyInclusive = true; params.endKey = BSON("" << 1); @@ -557,7 +557,7 @@ namespace QueryStageCountScan { // Run count and check CountScanParams params; - params.descriptor = getIndex(ctx.ctx().db(), BSON("a" << 1)); + params.descriptor = getIndex(ctx.db(), BSON("a" << 1)); params.startKey = BSON("" << 0); params.startKeyInclusive = true; params.endKey = BSON("" << 2); diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index b58c9572125..303082dfa84 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -92,7 +92,7 @@ namespace QueryStageFetch { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp index 5a6fb4e5f34..2b9695127c3 100644 --- a/src/mongo/dbtests/query_stage_keep.cpp +++ b/src/mongo/dbtests/query_stage_keep.cpp @@ -109,7 +109,7 @@ namespace QueryStageKeep { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -174,7 +174,7 @@ namespace QueryStageKeep { void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp index e2b0d9e44fb..d1b3688fdd9 100644 --- a/src/mongo/dbtests/query_stage_merge_sort.cpp +++ b/src/mongo/dbtests/query_stage_merge_sort.cpp @@ -114,7 +114,7 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -183,7 +183,7 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -251,7 +251,7 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -320,7 +320,7 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -390,7 +390,7 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -458,7 +458,7 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -516,7 +516,7 @@ namespace QueryStageMergeSortTests { public: void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp index dfc2e94d947..841044639ff 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -221,7 +221,7 @@ namespace QueryStageSortTests { void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -241,7 +241,7 @@ namespace QueryStageSortTests { void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -270,7 +270,7 @@ namespace QueryStageSortTests { void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -291,7 +291,7 @@ namespace QueryStageSortTests { void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -397,7 +397,7 @@ namespace QueryStageSortTests { void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); @@ -494,7 +494,7 @@ namespace QueryStageSortTests { void run() { Client::WriteContext ctx(&_txn, ns()); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { WriteUnitOfWork wuow(&_txn); diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp index 305cd1a1e71..1fbf1647d5c 100644 --- a/src/mongo/dbtests/query_stage_update.cpp +++ b/src/mongo/dbtests/query_stage_update.cpp @@ -260,7 +260,7 @@ namespace QueryStageUpdate { CurOp& curOp = *c.curop(); OpDebug* opDebug = &curOp.debug(); UpdateDriver driver( (UpdateDriver::Options()) ); - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); // Get the RecordIds that would be returned by an in-order scan. diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index 3b531ab60fe..441903bd4ab 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -1288,10 +1288,10 @@ namespace QueryTests { BSON("_id" << 20) , res , true)); ASSERT_EQUALS( 40 , res["x"].numberInt() ); - ASSERT( Helpers::findById( &_txn, ctx.ctx().db(), ns() , BSON( "_id" << 20 ) , res ) ); + ASSERT( Helpers::findById( &_txn, ctx.db(), ns() , BSON( "_id" << 20 ) , res ) ); ASSERT_EQUALS( 40 , res["x"].numberInt() ); - ASSERT( ! Helpers::findById( &_txn, ctx.ctx().db(), ns() , BSON( "_id" << 200 ) , res ) ); + ASSERT( ! Helpers::findById( &_txn, ctx.db(), ns() , BSON( "_id" << 200 ) , res ) ); long long slow; long long fast; @@ -1566,7 +1566,7 @@ namespace QueryTests { { Client::WriteContext ctx(&_txn, ns() ); - ClientCursorPin pinCursor( ctx.ctx().db()->getCollection( ns() ) + ClientCursorPin pinCursor( ctx.db()->getCollection( ns() ) ->getCursorManager(), cursorId ); string expectedAssertion = diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp index 420b3975bd6..9b4d67608db 100644 --- a/src/mongo/dbtests/repltests.cpp +++ b/src/mongo/dbtests/repltests.cpp @@ -85,9 +85,9 @@ namespace ReplTests { Client::WriteContext ctx(&_txn, ns()); WriteUnitOfWork wuow(&_txn); - Collection* c = ctx.ctx().db()->getCollection(ns()); + Collection* c = ctx.db()->getCollection(ns()); if ( ! c ) { - c = ctx.ctx().db()->createCollection(&_txn, ns()); + c = ctx.db()->createCollection(&_txn, ns()); } ASSERT(c->getIndexCatalog()->haveIdIndex(&_txn)); diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index f25da428743..fc001b2c3ef 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -1963,7 +1963,7 @@ namespace mongo { } // Only copy if ns doesn't already exist - Database* db = ctx.ctx().db(); + Database* db = ctx.db(); Collection* collection = db->getCollection( ns ); if ( !collection ) { @@ -2165,7 +2165,7 @@ namespace mongo { min, max, shardKeyPattern, - cx.ctx().db(), + cx.db(), docToClone, &localDoc)) { string errMsg = @@ -2430,7 +2430,7 @@ namespace mongo { false /* god */, true /* fromMigrate */); - *lastOpApplied = ctx.getClient()->getLastOp().asDate(); + *lastOpApplied = txn->getClient()->getLastOp().asDate(); didAnything = true; } } @@ -2448,7 +2448,7 @@ namespace mongo { min, max, shardKeyPattern, - cx.ctx().db(), + cx.db(), updatedDoc, &localDoc)) { string errMsg = @@ -2466,7 +2466,7 @@ namespace mongo { // We are in write lock here, so sure we aren't killing Helpers::upsert( txn, ns , updatedDoc , true ); - *lastOpApplied = cx.ctx().getClient()->getLastOp().asDate(); + *lastOpApplied = txn->getClient()->getLastOp().asDate(); didAnything = true; } } diff --git a/src/mongo/util/mmap.h b/src/mongo/util/mmap.h index efadd91b124..ded6279b1ba 100644 --- a/src/mongo/util/mmap.h +++ b/src/mongo/util/mmap.h @@ -33,9 +33,6 @@ #include <sstream> #include <vector> -#include <boost/noncopyable.hpp> -#include <boost/thread/xtime.hpp> - #include "mongo/client/export_macros.h" #include "mongo/util/concurrency/rwlock.h" @@ -63,7 +60,7 @@ namespace mongo { }; // lock order: lock dbMutex before this if you lock both - class MONGO_CLIENT_API LockMongoFilesShared { + class LockMongoFilesShared { friend class LockMongoFilesExclusive; static RWLockRecursiveNongreedy mmmutex; static unsigned era; @@ -83,7 +80,7 @@ namespace mongo { static void assertAtLeastReadLocked() { mmmutex.assertAtLeastReadLocked(); } }; - class MONGO_CLIENT_API LockMongoFilesExclusive { + class LockMongoFilesExclusive { RWLockRecursive::Exclusive lk; public: LockMongoFilesExclusive() : lk(LockMongoFilesShared::mmmutex) { @@ -92,7 +89,8 @@ namespace mongo { }; /* the administrative-ish stuff here */ - class MongoFile : boost::noncopyable { + class MongoFile { + MONGO_DISALLOW_COPYING(MongoFile); public: /** Flushable has to fail nicely if the underlying object gets killed */ class Flushable { @@ -101,6 +99,7 @@ namespace mongo { virtual void flush() = 0; }; + MongoFile() {} virtual ~MongoFile() {} enum Options { @@ -163,8 +162,11 @@ namespace mongo { DurableMappedFile *a = finder.find("file_name_a"); DurableMappedFile *b = finder.find("file_name_b"); */ - class MONGO_CLIENT_API MongoFileFinder : boost::noncopyable { + class MongoFileFinder { + MONGO_DISALLOW_COPYING(MongoFileFinder); public: + MongoFileFinder() { } + /** @return The MongoFile object associated with the specified file name. If no file is open with the specified name, returns null. */ diff --git a/src/mongo/util/mmap_win.cpp b/src/mongo/util/mmap_win.cpp index 8ce10b5241e..354ca4df62c 100644 --- a/src/mongo/util/mmap_win.cpp +++ b/src/mongo/util/mmap_win.cpp @@ -31,11 +31,11 @@ #include "mongo/platform/basic.h" -#include "mongo/db/concurrency/d_concurrency.h" +#include "mongo/util/mmap.h" + #include "mongo/db/storage/mmap_v1/durable_mapped_file.h" #include "mongo/util/file_allocator.h" #include "mongo/util/log.h" -#include "mongo/util/mmap.h" #include "mongo/util/processinfo.h" #include "mongo/util/text.h" #include "mongo/util/timer.h" @@ -150,10 +150,11 @@ namespace mongo { } MemoryMappedFile::MemoryMappedFile() - : _uniqueId(mmfNextId.fetchAndAdd(1)) { - fd = 0; - maphandle = 0; - len = 0; + : _uniqueId(mmfNextId.fetchAndAdd(1)), + fd(0), + maphandle(0), + len(0) { + created(); } |