diff options
100 files changed, 843 insertions, 674 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 6cac8800221..f7bb1d71384 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -712,6 +712,7 @@ serverOnlyFiles = [ "db/background.cpp", "db/catalog/index_catalog_entry.cpp", "db/catalog/index_create.cpp", "db/client.cpp", + "db/db_raii.cpp", "db/clientcursor.cpp", "db/cloner.cpp", "db/commands/apply_ops.cpp", diff --git a/src/mongo/db/auth/auth_index_d.cpp b/src/mongo/db/auth/auth_index_d.cpp index bf2042019dd..8cbd093c2c7 100644 --- a/src/mongo/db/auth/auth_index_d.cpp +++ b/src/mongo/db/auth/auth_index_d.cpp @@ -40,6 +40,7 @@ #include "mongo/db/index/index_descriptor.h" #include "mongo/db/jsobj.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/db_raii.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/auth/authz_manager_external_state_d.cpp b/src/mongo/db/auth/authz_manager_external_state_d.cpp index 4f5d9378c41..dfb37502332 100644 --- a/src/mongo/db/auth/authz_manager_external_state_d.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_d.cpp @@ -40,8 +40,9 @@ #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/user_name.h" #include "mongo/db/client.h" -#include "mongo/db/dbhelpers.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/jsobj.h" #include "mongo/db/operation_context.h" diff --git a/src/mongo/db/catalog/cursor_manager.cpp b/src/mongo/db/catalog/cursor_manager.cpp index 9638a28bdc2..e1a7c1193b3 100644 --- a/src/mongo/db/catalog/cursor_manager.cpp +++ b/src/mongo/db/catalog/cursor_manager.cpp @@ -38,6 +38,7 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/client.h" +#include "mongo/db/db_raii.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/operation_context.h" #include "mongo/db/query/plan_executor.h" diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index 7f89e797e0b..610a46cbeb4 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -167,163 +167,6 @@ namespace { return false; } - - Client::Context::Context(OperationContext* txn, const std::string& ns, Database * db) - : _justCreated(false), - _doVersion(true), - _ns(ns), - _db(db), - _txn(txn) { - } - - Client::Context::Context(OperationContext* txn, - const std::string& ns, - Database* db, - bool justCreated) - : _justCreated(justCreated), - _doVersion(true), - _ns(ns), - _db(db), - _txn(txn) { - _finishInit(); - } - - Client::Context::Context(OperationContext* txn, - const string& ns, - bool doVersion) - : _justCreated(false), // set for real in finishInit - _doVersion(doVersion), - _ns(ns), - _db(NULL), - _txn(txn) { - - _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), - _db(dbHolder().get(txn, ns)) { - - } - - AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* txn, - StringData ns, - LockMode mode) - : _transaction(txn, MODE_IX), - _dbLock(txn->lockState(), ns, mode), - _db(dbHolder().get(txn, ns)) { - invariant(mode == MODE_IX || mode == MODE_X); - _justCreated = false; - // If the database didn't exist, relock in MODE_X - if (_db == NULL) { - if (mode != MODE_X) { - _dbLock.relockWithMode(MODE_X); - } - _db = dbHolder().openDb(txn, ns); - _justCreated = true; - } - } - - AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn, - const std::string& ns) - : _txn(txn), - _transaction(txn, MODE_IS), - _db(_txn, nsToDatabaseSubstring(ns), MODE_IS), - _collLock(_txn->lockState(), ns, MODE_IS), - _coll(NULL) { - - _init(ns, nsToCollectionSubstring(ns)); - } - - AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn, - const NamespaceString& nss) - : _txn(txn), - _transaction(txn, MODE_IS), - _db(_txn, nss.db(), MODE_IS), - _collLock(_txn->lockState(), nss.toString(), MODE_IS), - _coll(NULL) { - - _init(nss.toString(), nss.coll()); - } - - void AutoGetCollectionForRead::_init(const std::string& ns, StringData coll) { - massert(28535, "need a non-empty collection name", !coll.empty()); - - // TODO: Client::Context legacy, needs to be removed - _txn->getCurOp()->ensureStarted(); - _txn->getCurOp()->setNS(ns); - - // We have both the DB and collection locked, which the prerequisite to do a stable shard - // version check. - ensureShardVersionOKOrThrow(ns); - - // At this point, we are locked in shared mode for the database by the DB lock in the - // constructor, so it is safe to load the DB pointer. - if (_db.getDb()) { - // TODO: Client::Context legacy, needs to be removed - _txn->getCurOp()->enter(ns.c_str(), _db.getDb()->getProfilingLevel()); - - _coll = _db.getDb()->getCollection(ns); - } - } - - AutoGetCollectionForRead::~AutoGetCollectionForRead() { - // Report time spent in read lock - _txn->getCurOp()->recordGlobalTime(false, _timer.micros()); - } - - Client::WriteContext::WriteContext(OperationContext* opCtx, const std::string& ns) - : _txn(opCtx), - _nss(ns), - _autodb(opCtx, _nss.db(), MODE_IX), - _collk(opCtx->lockState(), ns, MODE_IX), - _c(opCtx, ns, _autodb.getDb(), _autodb.justCreated()) { - _collection = _c.db()->getCollection( ns ); - if ( !_collection && !_autodb.justCreated() ) { - // relock in MODE_X - _collk.relockWithMode( MODE_X, _autodb.lock() ); - Database* db = dbHolder().get(_txn, ns ); - invariant( db == _c.db() ); - } - } - Locker* Client::getLocker() { if (!_locker) { _locker.reset(newLocker()); diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index b83ce05c9c0..bd3f83667a5 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -40,7 +40,6 @@ #include <boost/thread/thread.hpp> #include "mongo/bson/optime.h" -#include "mongo/db/catalog/database.h" #include "mongo/db/client_basic.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/lasterror.h" @@ -61,100 +60,6 @@ namespace mongo { typedef long long ConnectionId; - /** - * RAII-style class, which acquires a lock on the specified database in the requested mode and - * obtains a reference to the database. Used as a shortcut for calls to dbHolder().get(). - * - * It is guaranteed that locks will be released when this object goes out of scope, therefore - * the database reference returned by this class should not be retained. - * - * TODO: This should be moved outside of client.h (maybe dbhelpers.h) - */ - class AutoGetDb { - MONGO_DISALLOW_COPYING(AutoGetDb); - public: - AutoGetDb(OperationContext* txn, StringData ns, LockMode mode); - - Database* getDb() const { - return _db; - } - - private: - const Lock::DBLock _dbLock; - Database* const _db; - }; - - /** - * RAII-style class, which acquires a lock on the specified database in the requested mode and - * obtains a reference to the database, creating it was non-existing. Used as a shortcut for - * calls to dbHolder().openDb(), taking care of locking details. The requested mode must be - * MODE_IX or MODE_X. If the database needs to be created, the lock will automatically be - * reacquired as MODE_X. - * - * It is guaranteed that locks will be released when this object goes out of scope, therefore - * the database reference returned by this class should not be retained. - * - * TODO: This should be moved outside of client.h (maybe dbhelpers.h) - */ - class AutoGetOrCreateDb { - MONGO_DISALLOW_COPYING(AutoGetOrCreateDb); - public: - AutoGetOrCreateDb(OperationContext* txn, StringData ns, LockMode mode); - - Database* getDb() const { - return _db; - } - - bool justCreated() const { - return _justCreated; - } - - Lock::DBLock& lock() { return _dbLock; } - - private: - ScopedTransaction _transaction; - Lock::DBLock _dbLock; // not const, as we may need to relock for implicit create - Database* _db; - bool _justCreated; - }; - - /** - * RAII-style class, which would acquire the appropritate hierarchy of locks for obtaining - * a particular collection and would retrieve a reference to the collection. - * - * It is guaranteed that locks will be released when this object goes out of scope, therefore - * database and collection references returned by this class should not be retained. - * - * TODO: This should be moved outside of client.h (maybe dbhelpers.h) - */ - class AutoGetCollectionForRead { - MONGO_DISALLOW_COPYING(AutoGetCollectionForRead); - public: - AutoGetCollectionForRead(OperationContext* txn, const std::string& ns); - AutoGetCollectionForRead(OperationContext* txn, const NamespaceString& nss); - ~AutoGetCollectionForRead(); - - Database* getDb() const { - return _db.getDb(); - } - - Collection* getCollection() const { - return _coll; - } - - private: - void _init(const std::string& ns, - StringData coll); - - const Timer _timer; - OperationContext* const _txn; - const ScopedTransaction _transaction; - const AutoGetDb _db; - const Lock::CollectionLock _collLock; - - Collection* _coll; - }; - typedef unordered_set<Client*> ClientSet; /** the database's concept of an outside "client" */ @@ -269,79 +174,6 @@ namespace mongo { // Tracks if Client::shutdown() gets called (TODO: Is this necessary?) bool _shutdown; - - public: - - /** - * Opens the database that we want to use and sets the appropriate namespace on the - * current operation. - */ - class Context { - MONGO_DISALLOW_COPYING(Context); - public: - /** this is probably what you want */ - Context(OperationContext* txn, const std::string& ns, bool doVersion = true); - - /** - * Below still calls _finishInit, but assumes database has already been acquired - * or just created. - */ - Context(OperationContext* txn, - const std::string& ns, - Database* db, - bool justCreated); - - /** - * note: this does not call _finishInit -- i.e., does not call - * ensureShardVersionOKOrThrow for example. - * see also: reset(). - */ - Context(OperationContext* txn, const std::string& ns, Database * db); - - ~Context(); - - Database* db() const { return _db; } - const char* ns() const { return _ns.c_str(); } - - /** @return if the db was created by this Context */ - bool justCreated() const { return _justCreated; } - - private: - friend class CurOp; - void _finishInit(); - void _checkNotStale() const; - - bool _justCreated; - bool _doVersion; - const std::string _ns; - Database * _db; - OperationContext* _txn; - - Timer _timer; - }; // class Client::Context - - - class WriteContext { - MONGO_DISALLOW_COPYING(WriteContext); - public: - WriteContext(OperationContext* opCtx, const std::string& ns); - - Database* db() const { return _c.db(); } - - Collection* getCollection() const { - return _c.db()->getCollection(_nss.ns()); - } - - private: - OperationContext* const _txn; - const NamespaceString _nss; - - AutoGetOrCreateDb _autodb; - Lock::CollectionLock _collk; - Context _c; - Collection* _collection; - }; - }; /** get the Client object for this thread. */ diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index d22663f1f98..395e24baae6 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -43,6 +43,7 @@ #include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/auth/internal_user_auth.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/index_create.h" #include "mongo/db/commands.h" diff --git a/src/mongo/db/commands/apply_ops.cpp b/src/mongo/db/commands/apply_ops.cpp index 69641f16c43..2ab7f437c44 100644 --- a/src/mongo/db/commands/apply_ops.cpp +++ b/src/mongo/db/commands/apply_ops.cpp @@ -42,6 +42,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/commands/dbhash.h" +#include "mongo/db/db_raii.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/global_environment_experiment.h" @@ -163,7 +164,7 @@ namespace mongo { invariant(!txn->lockState()->saveLockStateAndUnlock(&lockSnapshot)); }; - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); Status status(ErrorCodes::InternalError, ""); while (true) { diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 9d15d3df794..9e2c33a9a87 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -35,13 +35,14 @@ #include "mongo/db/background.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/index_builder.h" #include "mongo/db/op_observer.h" -#include "mongo/db/query/internal_plans.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/find.h" +#include "mongo/db/query/internal_plans.h" #include "mongo/db/repl/replication_coordinator_global.h" -#include "mongo/db/operation_context_impl.h" namespace mongo { @@ -72,7 +73,7 @@ namespace { // create new collection { - Client::Context ctx(txn, toNs ); + OldClientContext ctx(txn, toNs ); BSONObjBuilder spec; spec.appendBool( "capped", true ); spec.append( "size", size ); diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index ef60369eaeb..12bb7f16a6d 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -40,8 +40,9 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/commands.h" -#include "mongo/db/curop.h" #include "mongo/db/concurrency/d_concurrency.h" +#include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/index_builder.h" #include "mongo/db/jsobj.h" #include "mongo/db/operation_context_impl.h" @@ -153,7 +154,7 @@ namespace mongo { return false; } - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); BackgroundOperation::assertNoBgOpInProgForNs(ns.ns()); if ( collection->isCapped() ) { diff --git a/src/mongo/db/commands/count.cpp b/src/mongo/db/commands/count.cpp index 9b23d0cc216..64605e5878a 100644 --- a/src/mongo/db/commands/count.cpp +++ b/src/mongo/db/commands/count.cpp @@ -32,14 +32,15 @@ #include <boost/scoped_ptr.hpp> +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/client.h" -#include "mongo/db/catalog/collection.h" #include "mongo/db/commands.h" #include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/count.h" -#include "mongo/db/query/get_executor.h" #include "mongo/db/query/explain.h" +#include "mongo/db/query/get_executor.h" #include "mongo/db/range_preserver.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp index 44cae32b50c..8e24af0eaff 100644 --- a/src/mongo/db/commands/cpuprofile.cpp +++ b/src/mongo/db/commands/cpuprofile.cpp @@ -58,6 +58,7 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/jsobj.h" namespace mongo { @@ -136,7 +137,7 @@ namespace mongo { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), db, MODE_X); // The lock here is just to prevent concurrency, nothing will write. - Client::Context ctx(txn, db); + OldClientContext ctx(txn, db); std::string profileFilename = cmdObj[commandName]["profileFilename"].String(); if ( ! ::ProfilerStart( profileFilename.c_str() ) ) { @@ -155,7 +156,7 @@ namespace mongo { bool fromRepl ) { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), db, MODE_X); - Client::Context ctx(txn, db); + OldClientContext ctx(txn, db); ::ProfilerStop(); return true; diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp index bf0f43dcc9b..2d531a5a4c2 100644 --- a/src/mongo/db/commands/dbhash.cpp +++ b/src/mongo/db/commands/dbhash.cpp @@ -34,10 +34,11 @@ #include <boost/scoped_ptr.hpp> -#include "mongo/db/client.h" -#include "mongo/db/commands.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_catalog_entry.h" +#include "mongo/db/client.h" +#include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/query/internal_plans.h" #include "mongo/util/log.h" #include "mongo/util/md5.hpp" diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp index cd80f48a13a..3bf0220c8c9 100644 --- a/src/mongo/db/commands/distinct.cpp +++ b/src/mongo/db/commands/distinct.cpp @@ -37,11 +37,12 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/instance.h" #include "mongo/db/jsobj.h" +#include "mongo/db/query/explain.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/query_planner_common.h" -#include "mongo/db/query/explain.h" #include "mongo/util/timer.h" namespace mongo { diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index e861204c1c4..fa555166966 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -36,23 +36,24 @@ #include <vector> #include "mongo/db/background.h" -#include "mongo/db/client.h" -#include "mongo/db/commands.h" -#include "mongo/db/curop.h" -#include "mongo/db/dbdirectclient.h" -#include "mongo/db/global_environment_experiment.h" -#include "mongo/db/index_builder.h" -#include "mongo/db/index/index_descriptor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_create.h" #include "mongo/db/catalog/index_key_validate.h" +#include "mongo/db/client.h" +#include "mongo/db/commands.h" #include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/dbdirectclient.h" +#include "mongo/db/global_environment_experiment.h" +#include "mongo/db/index/index_descriptor.h" +#include "mongo/db/index_builder.h" #include "mongo/db/op_observer.h" -#include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/log.h" namespace mongo { @@ -158,7 +159,7 @@ namespace mongo { return false; } - Client::Context ctx(txn, toDeleteNs); + OldClientContext ctx(txn, toDeleteNs); stopIndexBuilds(txn, db, jsobj); IndexCatalog* indexCatalog = collection->getIndexCatalog(); @@ -264,7 +265,7 @@ namespace mongo { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, toDeleteNs); + OldClientContext ctx(txn, toDeleteNs); Collection* collection = ctx.db()->getCollection( toDeleteNs ); diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 4e2ebd6bf3d..224e58be74b 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -36,15 +36,16 @@ #include "mongo/db/commands.h" #include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/exec/update.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/global_environment_experiment.h" -#include "mongo/db/projection.h" #include "mongo/db/op_observer.h" #include "mongo/db/ops/delete.h" #include "mongo/db/ops/update.h" #include "mongo/db/ops/update_lifecycle_impl.h" +#include "mongo/db/projection.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/write_concern.h" @@ -144,7 +145,7 @@ namespace mongo { // Take X lock so we can create collection, then re-run operation. ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock lk(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, ns, false /* don't check version */); + OldClientContext ctx(txn, ns, false /* don't check version */); if (!fromRepl && !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() @@ -227,7 +228,7 @@ namespace mongo { AutoGetOrCreateDb autoDb(txn, dbname, MODE_IX); Lock::CollectionLock collLock(txn->lockState(), ns, MODE_IX); - Client::Context ctx(txn, ns, autoDb.getDb(), autoDb.justCreated()); + OldClientContext ctx(txn, ns, autoDb.getDb(), autoDb.justCreated()); if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index 2983d993e2c..362cfda5524 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -38,6 +38,7 @@ #include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/query/explain.h" diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp index 450366da759..066386779de 100644 --- a/src/mongo/db/commands/geo_near_cmd.cpp +++ b/src/mongo/db/commands/geo_near_cmd.cpp @@ -39,14 +39,15 @@ #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/geo/geoconstants.h" -#include "mongo/db/matcher/expression_geo.h" #include "mongo/db/geo/geoparser.h" -#include "mongo/db/index_names.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/index_names.h" #include "mongo/db/jsobj.h" -#include "mongo/db/query/get_executor.h" +#include "mongo/db/matcher/expression_geo.h" #include "mongo/db/query/explain.h" +#include "mongo/db/query/get_executor.h" #include "mongo/db/range_preserver.h" #include "mongo/platform/unordered_map.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/group.cpp b/src/mongo/db/commands/group.cpp index 2543b9b7a4b..b4e18446791 100644 --- a/src/mongo/db/commands/group.cpp +++ b/src/mongo/db/commands/group.cpp @@ -38,6 +38,7 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/catalog/database.h" #include "mongo/db/client.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/group.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/query/get_executor.h" diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp index 575415a3a59..9366f8358a1 100644 --- a/src/mongo/db/commands/index_filter_commands.cpp +++ b/src/mongo/db/commands/index_filter_commands.cpp @@ -32,17 +32,18 @@ #include <string> #include <sstream> -#include "mongo/db/matcher/expression_parser.h" #include "mongo/base/init.h" #include "mongo/base/owned_pointer_vector.h" #include "mongo/base/status.h" -#include "mongo/db/client.h" -#include "mongo/db/catalog/database.h" -#include "mongo/db/jsobj.h" #include "mongo/db/auth/authorization_session.h" +#include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database.h" +#include "mongo/db/client.h" #include "mongo/db/commands/index_filter_commands.h" #include "mongo/db/commands/plan_cache_commands.h" -#include "mongo/db/catalog/collection.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/jsobj.h" +#include "mongo/db/matcher/expression_parser.h" namespace { diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index 3c25e39d088..7ec59ca4d62 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -40,6 +40,7 @@ #include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/global_environment_experiment.h" diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp index 8e3243fbcac..41457ce9d20 100644 --- a/src/mongo/db/commands/list_indexes.cpp +++ b/src/mongo/db/commands/list_indexes.cpp @@ -34,11 +34,12 @@ #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/cursor_manager.h" #include "mongo/db/catalog/database.h" -#include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" +#include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/global_environment_experiment.h" diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index c3349c814eb..15918b1d28f 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -43,26 +43,27 @@ #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_experiment.h" -#include "mongo/db/instance.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/instance.h" #include "mongo/db/matcher/matcher.h" +#include "mongo/db/namespace_string.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/query_planner.h" -#include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/range_preserver.h" -#include "mongo/db/namespace_string.h" -#include "mongo/db/operation_context_impl.h" +#include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/storage_options.h" -#include "mongo/scripting/engine.h" #include "mongo/s/chunk_manager.h" #include "mongo/s/collection_metadata.h" #include "mongo/s/d_state.h" #include "mongo/s/grid.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/s/stale_exception.h" +#include "mongo/scripting/engine.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -370,7 +371,7 @@ namespace mongo { if (_useIncremental) { // Create the inc collection and make sure we have index on "0" key. // Intentionally not replicating the inc collection to secondaries. - Client::WriteContext incCtx(_txn, _config.incLong); + OldClientWriteContext incCtx(_txn, _config.incLong); WriteUnitOfWork wuow(_txn); Collection* incColl = incCtx.getCollection(); invariant(!incColl); @@ -396,7 +397,7 @@ namespace mongo { { // copy indexes into temporary storage - Client::WriteContext finalCtx(_txn, _config.outputOptions.finalNamespace); + OldClientWriteContext finalCtx(_txn, _config.outputOptions.finalNamespace); Collection* const finalColl = finalCtx.getCollection(); if ( finalColl ) { IndexCatalog::IndexIterator ii = @@ -423,7 +424,7 @@ namespace mongo { { // create temp collection and insert the indexes from temporary storage - Client::WriteContext tempCtx(_txn, _config.tempNamespace); + OldClientWriteContext tempCtx(_txn, _config.tempNamespace); WriteUnitOfWork wuow(_txn); uassert(ErrorCodes::NotMaster, "no longer master", repl::getGlobalReplicationCoordinator()-> @@ -641,7 +642,7 @@ namespace mongo { bool found; { - Client::Context tx(txn, _config.outputOptions.finalNamespace); + OldClientContext tx(txn, _config.outputOptions.finalNamespace); Collection* coll = tx.db()->getCollection(_config.outputOptions.finalNamespace); found = Helpers::findOne(_txn, @@ -679,7 +680,7 @@ namespace mongo { verify( _onDisk ); - Client::WriteContext ctx(_txn, ns ); + OldClientWriteContext ctx(_txn, ns ); WriteUnitOfWork wuow(_txn); uassert(ErrorCodes::NotMaster, "no longer master", repl::getGlobalReplicationCoordinator()-> @@ -704,7 +705,7 @@ namespace mongo { void State::_insertToInc( BSONObj& o ) { verify( _onDisk ); - Client::WriteContext ctx(_txn, _config.incLong ); + OldClientWriteContext ctx(_txn, _config.incLong ); WriteUnitOfWork wuow(_txn); Collection* coll = getCollectionOrUassert(ctx.db(), _config.incLong); uassertStatusOK( coll->insertDocument( _txn, o, true ).getStatus() ); @@ -984,7 +985,7 @@ namespace mongo { BSONObj sortKey = BSON( "0" << 1 ); { - Client::WriteContext incCtx(_txn, _config.incLong ); + OldClientWriteContext incCtx(_txn, _config.incLong ); WriteUnitOfWork wuow(_txn); Collection* incColl = getCollectionOrUassert(incCtx.db(), _config.incLong ); diff --git a/src/mongo/db/commands/parallel_collection_scan.cpp b/src/mongo/db/commands/parallel_collection_scan.cpp index 89c0d888361..40bbeb7b085 100644 --- a/src/mongo/db/commands/parallel_collection_scan.cpp +++ b/src/mongo/db/commands/parallel_collection_scan.cpp @@ -33,6 +33,7 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/multi_iterator.h" #include "mongo/util/touch_pages.h" diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp index db28236268e..192924bceb7 100644 --- a/src/mongo/db/commands/pipeline_command.cpp +++ b/src/mongo/db/commands/pipeline_command.cpp @@ -37,17 +37,18 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/catalog/database.h" #include "mongo/db/client.h" -#include "mongo/db/curop.h" #include "mongo/db/commands.h" +#include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/pipeline_proxy.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/pipeline/accumulator.h" #include "mongo/db/pipeline/document.h" #include "mongo/db/pipeline/document_source.h" -#include "mongo/db/pipeline/expression_context.h" #include "mongo/db/pipeline/expression.h" -#include "mongo/db/pipeline/pipeline_d.h" +#include "mongo/db/pipeline/expression_context.h" #include "mongo/db/pipeline/pipeline.h" +#include "mongo/db/pipeline/pipeline_d.h" #include "mongo/db/query/find_constants.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/storage_options.h" diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp index 8477afb1b69..576e1e23b9e 100644 --- a/src/mongo/db/commands/plan_cache_commands.cpp +++ b/src/mongo/db/commands/plan_cache_commands.cpp @@ -36,12 +36,13 @@ #include "mongo/base/init.h" #include "mongo/base/status.h" -#include "mongo/db/client.h" -#include "mongo/db/catalog/database.h" -#include "mongo/db/jsobj.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/commands/plan_cache_commands.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database.h" +#include "mongo/db/client.h" +#include "mongo/db/commands/plan_cache_commands.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/jsobj.h" #include "mongo/db/query/explain.h" #include "mongo/db/query/plan_ranker.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp index a9da366eb74..81e5f992f83 100644 --- a/src/mongo/db/commands/rename_collection.cpp +++ b/src/mongo/db/commands/rename_collection.cpp @@ -37,13 +37,14 @@ #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/commands/rename_collection.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/index_builder.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/insert.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/scopeguard.h" @@ -125,7 +126,7 @@ namespace mongo { } // We stay in source context the whole time. This is mostly to set the CurOp namespace. - Client::Context ctx(txn, source); + OldClientContext ctx(txn, source); if ( !NamespaceString::validCollectionComponent(target.c_str()) ) { errmsg = "invalid collection name: " + target; diff --git a/src/mongo/db/commands/repair_cursor.cpp b/src/mongo/db/commands/repair_cursor.cpp index b521d526932..dad8b305201 100644 --- a/src/mongo/db/commands/repair_cursor.cpp +++ b/src/mongo/db/commands/repair_cursor.cpp @@ -34,6 +34,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/multi_iterator.h" namespace mongo { diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 34151c96303..0db4eb08f90 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -34,15 +34,16 @@ #include "mongo/base/init.h" #include "mongo/base/initializer_context.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/index_builder.h" -#include "mongo/db/query/internal_plans.h" -#include "mongo/db/catalog/collection.h" #include "mongo/db/op_observer.h" -#include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/query/internal_plans.h" +#include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/log.h" namespace mongo { @@ -74,7 +75,7 @@ namespace mongo { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock lk(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, ns ); + OldClientContext ctx(txn, ns ); Database* db = ctx.db(); WriteUnitOfWork wunit(txn); @@ -159,7 +160,7 @@ namespace mongo { int n = cmdObj.getIntField( "n" ); bool inc = cmdObj.getBoolField( "inc" ); // inclusive range? - Client::WriteContext ctx(txn, nss.ns() ); + OldClientWriteContext ctx(txn, nss.ns() ); Collection* collection = ctx.getCollection(); massert( 13417, "captrunc collection not found or empty", collection); diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp index 063d6225976..2288d54551d 100644 --- a/src/mongo/db/commands/touch.cpp +++ b/src/mongo/db/commands/touch.cpp @@ -44,6 +44,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/concurrency/d_concurrency.h" +#include "mongo/db/db_raii.h" #include "mongo/db/jsobj.h" #include "mongo/db/operation_context_impl.h" #include "mongo/util/timer.h" diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index e1ca14c8222..f8509b394f3 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -32,10 +32,11 @@ #include "mongo/platform/basic.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/commands.h" -#include "mongo/db/query/internal_plans.h" +#include "mongo/db/db_raii.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" +#include "mongo/db/query/internal_plans.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index 48f1f0a1be4..c0b1b0a3a27 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -37,23 +37,25 @@ #include "mongo/base/error_codes.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/catalog/database_holder.h" +#include "mongo/db/catalog/index_create.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" +#include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/exec/delete.h" +#include "mongo/db/exec/update.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/instance.h" #include "mongo/db/introspect.h" #include "mongo/db/lasterror.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/catalog/database_holder.h" -#include "mongo/db/catalog/index_create.h" -#include "mongo/db/concurrency/write_conflict_exception.h" -#include "mongo/db/exec/delete.h" -#include "mongo/db/exec/update.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/delete_request.h" +#include "mongo/db/ops/insert.h" #include "mongo/db/ops/parsed_delete.h" #include "mongo/db/ops/parsed_update.h" -#include "mongo/db/ops/insert.h" #include "mongo/db/ops/update_lifecycle_impl.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/plan_executor.h" @@ -63,7 +65,6 @@ #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/server_parameters.h" #include "mongo/db/stats/counters.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/db/write_concern.h" #include "mongo/s/collection_metadata.h" #include "mongo/s/d_state.h" @@ -750,7 +751,7 @@ namespace mongo { // Context object on the target database. Must appear after writeLock, so that it is // destroyed in proper order. - scoped_ptr<Client::Context> _context; + scoped_ptr<OldClientContext> _context; // Target collection. Collection* _collection; @@ -972,7 +973,7 @@ namespace mongo { bool WriteBatchExecutor::ExecInsertsState::_lockAndCheckImpl(WriteOpResult* result, bool intentLock) { if (hasLock()) { - // TODO: Client::Context legacy, needs to be removed + // TODO: OldClientContext legacy, needs to be removed txn->getCurOp()->enter(_context->ns(), _context->db() ? _context->db()->getProfilingLevel() : 0); return true; @@ -1010,7 +1011,7 @@ namespace mongo { } _context.reset(); - _context.reset(new Client::Context(txn, nss, false)); + _context.reset(new OldClientContext(txn, nss, false)); Database* database = _context->db(); dassert(database); @@ -1232,7 +1233,7 @@ namespace mongo { MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock lk(txn->lockState(), nsString.db(), MODE_X); - Client::Context ctx(txn, nsString.ns(), false /* don't check version */); + OldClientContext ctx(txn, nsString.ns(), false /* don't check version */); if (!checkIsMasterForDatabase(nsString, result)) { return; @@ -1291,7 +1292,7 @@ namespace mongo { continue; } - Client::Context ctx(txn, nsString.ns(), false /* don't check version */); + OldClientContext ctx(txn, nsString.ns(), false /* don't check version */); Collection* collection = db->getCollection(nsString.ns()); if ( collection == NULL ) { @@ -1415,7 +1416,7 @@ namespace mongo { // Context once we're locked, to set more details in currentOp() // TODO: better constructor? - Client::Context ctx(txn, nss.ns(), false /* don't check version */); + OldClientContext ctx(txn, nss.ns(), false /* don't check version */); PlanExecutor* rawExec; uassertStatusOK(getExecutorDelete(txn, diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index 90540b7892c..1c05f300236 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -36,6 +36,7 @@ #include "mongo/db/commands/write_commands/batch_executor.h" #include "mongo/db/commands/write_commands/write_commands_common.h" #include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/json.h" #include "mongo/db/lasterror.h" #include "mongo/db/ops/delete_request.h" @@ -223,7 +224,7 @@ namespace mongo { AutoGetDb autoDb( txn, nsString.db(), MODE_IX ); Lock::CollectionLock colLock( txn->lockState(), nsString.ns(), MODE_IX ); - // We check the shard version explicitly here rather than using Client::Context, + // We check the shard version explicitly here rather than using OldClientContext, // as Context can do implicit database creation if the db does not exist. We want // explain to be a no-op that reports a trivial EOF plan against non-existent dbs // or collections. @@ -268,7 +269,7 @@ namespace mongo { AutoGetDb autoDb(txn, nsString.db(), MODE_IX); Lock::CollectionLock colLock(txn->lockState(), nsString.ns(), MODE_IX); - // We check the shard version explicitly here rather than using Client::Context, + // We check the shard version explicitly here rather than using OldClientContext, // as Context can do implicit database creation if the db does not exist. We want // explain to be a no-op that reports a trivial EOF plan against non-existent dbs // or collections. diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 56d502b99b5..f7742c00ab1 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -59,6 +59,7 @@ #include "mongo/db/clientcursor.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbmessage.h" #include "mongo/db/dbwebserver.h" @@ -73,8 +74,8 @@ #include "mongo/db/lasterror.h" #include "mongo/db/log_process_details.h" #include "mongo/db/mongod_options.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/range_deleter_service.h" #include "mongo/db/repair_database.h" diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp new file mode 100644 index 00000000000..597c1ca6a28 --- /dev/null +++ b/src/mongo/db/db_raii.cpp @@ -0,0 +1,197 @@ +/** + * Copyright (C) 2014 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/db_raii.h" + +#include "mongo/db/catalog/database_holder.h" +#include "mongo/db/curop.h" +#include "mongo/s/d_state.h" + +namespace mongo { + + AutoGetDb::AutoGetDb(OperationContext* txn, StringData ns, LockMode mode) + : _dbLock(txn->lockState(), ns, mode), + _db(dbHolder().get(txn, ns)) { + + } + + AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* txn, + StringData ns, + LockMode mode) + : _transaction(txn, MODE_IX), + _dbLock(txn->lockState(), ns, mode), + _db(dbHolder().get(txn, ns)) { + invariant(mode == MODE_IX || mode == MODE_X); + _justCreated = false; + // If the database didn't exist, relock in MODE_X + if (_db == NULL) { + if (mode != MODE_X) { + _dbLock.relockWithMode(MODE_X); + } + _db = dbHolder().openDb(txn, ns); + _justCreated = true; + } + } + + AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn, + const std::string& ns) + : _txn(txn), + _transaction(txn, MODE_IS), + _db(_txn, nsToDatabaseSubstring(ns), MODE_IS), + _collLock(_txn->lockState(), ns, MODE_IS), + _coll(NULL) { + + _init(ns, nsToCollectionSubstring(ns)); + } + + AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* txn, + const NamespaceString& nss) + : _txn(txn), + _transaction(txn, MODE_IS), + _db(_txn, nss.db(), MODE_IS), + _collLock(_txn->lockState(), nss.toString(), MODE_IS), + _coll(NULL) { + + _init(nss.toString(), nss.coll()); + } + + void AutoGetCollectionForRead::_init(const std::string& ns, StringData coll) { + massert(28535, "need a non-empty collection name", !coll.empty()); + + // TODO: OldClientContext legacy, needs to be removed + _txn->getCurOp()->ensureStarted(); + _txn->getCurOp()->setNS(ns); + + // We have both the DB and collection locked, which the prerequisite to do a stable shard + // version check. + ensureShardVersionOKOrThrow(ns); + + // At this point, we are locked in shared mode for the database by the DB lock in the + // constructor, so it is safe to load the DB pointer. + if (_db.getDb()) { + // TODO: OldClientContext legacy, needs to be removed + _txn->getCurOp()->enter(ns.c_str(), _db.getDb()->getProfilingLevel()); + + _coll = _db.getDb()->getCollection(ns); + } + } + + AutoGetCollectionForRead::~AutoGetCollectionForRead() { + // Report time spent in read lock + _txn->getCurOp()->recordGlobalTime(false, _timer.micros()); + } + + + OldClientContext::OldClientContext(OperationContext* txn, const std::string& ns, Database * db) + : _justCreated(false), + _doVersion(true), + _ns(ns), + _db(db), + _txn(txn) { + } + + OldClientContext::OldClientContext(OperationContext* txn, + const std::string& ns, + Database* db, + bool justCreated) + : _justCreated(justCreated), + _doVersion(true), + _ns(ns), + _db(db), + _txn(txn) { + _finishInit(); + } + + OldClientContext::OldClientContext(OperationContext* txn, + const std::string& ns, + bool doVersion) + : _justCreated(false), // set for real in finishInit + _doVersion(doVersion), + _ns(ns), + _db(NULL), + _txn(txn) { + + _finishInit(); + } + + void OldClientContext::_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 OldClientContext::_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); + } + } + + OldClientContext::~OldClientContext() { + // Lock must still be held + invariant(_txn->lockState()->isLocked()); + + _txn->getCurOp()->recordGlobalTime(_txn->lockState()->isWriteLocked(), _timer.micros()); + } + + + + OldClientWriteContext::OldClientWriteContext(OperationContext* opCtx, const std::string& ns) + : _txn(opCtx), + _nss(ns), + _autodb(opCtx, _nss.db(), MODE_IX), + _collk(opCtx->lockState(), ns, MODE_IX), + _c(opCtx, ns, _autodb.getDb(), _autodb.justCreated()) { + _collection = _c.db()->getCollection( ns ); + if ( !_collection && !_autodb.justCreated() ) { + // relock in MODE_X + _collk.relockWithMode( MODE_X, _autodb.lock() ); + Database* db = dbHolder().get(_txn, ns ); + invariant( db == _c.db() ); + } + } + +} // namespace mongo diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h new file mode 100644 index 00000000000..580389e9b1b --- /dev/null +++ b/src/mongo/db/db_raii.h @@ -0,0 +1,202 @@ +/** + * Copyright (C) 2014 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include <string> + +#include "mongo/base/string_data.h" +#include "mongo/db/catalog/database.h" +#include "mongo/db/concurrency/d_concurrency.h" +#include "mongo/db/namespace_string.h" +#include "mongo/db/operation_context.h" +#include "mongo/util/timer.h" + +namespace mongo { + + class Collection; + + /** + * RAII-style class, which acquires a lock on the specified database in the requested mode and + * obtains a reference to the database. Used as a shortcut for calls to dbHolder().get(). + * + * It is guaranteed that locks will be released when this object goes out of scope, therefore + * the database reference returned by this class should not be retained. + */ + class AutoGetDb { + MONGO_DISALLOW_COPYING(AutoGetDb); + public: + AutoGetDb(OperationContext* txn, StringData ns, LockMode mode); + + Database* getDb() const { + return _db; + } + + private: + const Lock::DBLock _dbLock; + Database* const _db; + }; + + /** + * RAII-style class, which acquires a lock on the specified database in the requested mode and + * obtains a reference to the database, creating it was non-existing. Used as a shortcut for + * calls to dbHolder().openDb(), taking care of locking details. The requested mode must be + * MODE_IX or MODE_X. If the database needs to be created, the lock will automatically be + * reacquired as MODE_X. + * + * It is guaranteed that locks will be released when this object goes out of scope, therefore + * the database reference returned by this class should not be retained. + */ + class AutoGetOrCreateDb { + MONGO_DISALLOW_COPYING(AutoGetOrCreateDb); + public: + AutoGetOrCreateDb(OperationContext* txn, StringData ns, LockMode mode); + + Database* getDb() const { + return _db; + } + + bool justCreated() const { + return _justCreated; + } + + Lock::DBLock& lock() { return _dbLock; } + + private: + ScopedTransaction _transaction; + Lock::DBLock _dbLock; // not const, as we may need to relock for implicit create + Database* _db; + bool _justCreated; + }; + + /** + * RAII-style class, which would acquire the appropritate hierarchy of locks for obtaining + * a particular collection and would retrieve a reference to the collection. + * + * It is guaranteed that locks will be released when this object goes out of scope, therefore + * database and collection references returned by this class should not be retained. + */ + class AutoGetCollectionForRead { + MONGO_DISALLOW_COPYING(AutoGetCollectionForRead); + public: + AutoGetCollectionForRead(OperationContext* txn, const std::string& ns); + AutoGetCollectionForRead(OperationContext* txn, const NamespaceString& nss); + ~AutoGetCollectionForRead(); + + Database* getDb() const { + return _db.getDb(); + } + + Collection* getCollection() const { + return _coll; + } + + private: + void _init(const std::string& ns, + StringData coll); + + const Timer _timer; + OperationContext* const _txn; + const ScopedTransaction _transaction; + const AutoGetDb _db; + const Lock::CollectionLock _collLock; + + Collection* _coll; + }; + + /** + * Opens the database that we want to use and sets the appropriate namespace on the + * current operation. + */ + class OldClientContext { + MONGO_DISALLOW_COPYING(OldClientContext); + public: + /** this is probably what you want */ + OldClientContext(OperationContext* txn, const std::string& ns, bool doVersion = true); + + /** + * Below still calls _finishInit, but assumes database has already been acquired + * or just created. + */ + OldClientContext(OperationContext* txn, + const std::string& ns, + Database* db, + bool justCreated); + + /** + * note: this does not call _finishInit -- i.e., does not call + * ensureShardVersionOKOrThrow for example. + * see also: reset(). + */ + OldClientContext(OperationContext* txn, const std::string& ns, Database * db); + + ~OldClientContext(); + + Database* db() const { return _db; } + const char* ns() const { return _ns.c_str(); } + + /** @return if the db was created by this OldClientContext */ + bool justCreated() const { return _justCreated; } + + private: + friend class CurOp; + void _finishInit(); + void _checkNotStale() const; + + bool _justCreated; + bool _doVersion; + const std::string _ns; + Database * _db; + OperationContext* _txn; + + Timer _timer; + }; + + + class OldClientWriteContext { + MONGO_DISALLOW_COPYING(OldClientWriteContext); + public: + OldClientWriteContext(OperationContext* opCtx, const std::string& ns); + + Database* db() const { return _c.db(); } + + Collection* getCollection() const { + return _c.db()->getCollection(_nss.ns()); + } + + private: + OperationContext* const _txn; + const NamespaceString _nss; + + AutoGetOrCreateDb _autodb; + Lock::CollectionLock _collk; + OldClientContext _c; + Collection* _collection; + }; + +} // namespace mongo diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index d68e1a73f23..d70b60f266d 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -48,18 +48,19 @@ #include "mongo/db/auth/user_management_commands_parser.h" #include "mongo/db/auth/user_name.h" #include "mongo/db/background.h" -#include "mongo/db/clientcursor.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/database_catalog_entry.h" +#include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" #include "mongo/db/commands/server_status.h" #include "mongo/db/commands/shutdown.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" -#include "mongo/db/global_environment_experiment.h" #include "mongo/db/global_environment_d.h" +#include "mongo/db/global_environment_experiment.h" #include "mongo/db/index_builder.h" #include "mongo/db/instance.h" #include "mongo/db/introspect.h" @@ -75,8 +76,8 @@ #include "mongo/db/repair_database.h" #include "mongo/db/repl/repl_settings.h" #include "mongo/db/repl/replication_coordinator_global.h" -#include "mongo/db/storage/storage_engine.h" #include "mongo/db/storage/mmap_v1/dur_stats.h" +#include "mongo/db/storage/storage_engine.h" #include "mongo/db/write_concern.h" #include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" // for SendStaleConfigException @@ -201,7 +202,7 @@ namespace mongo { // DB doesn't exist, so deem it a success. return true; } - Client::Context context(txn, dbname); + OldClientContext context(txn, dbname); if (!fromRepl && !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() @@ -288,7 +289,7 @@ namespace mongo { // TODO: SERVER-4328 Don't lock globally ScopedTransaction transaction(txn, MODE_X); Lock::GlobalWrite lk(txn->lockState()); - Client::Context context(txn, dbname ); + OldClientContext context(txn, dbname ); log() << "repairDatabase " << dbname; std::vector<BSONObj> indexesInProg = stopIndexBuilds(txn, context.db(), cmdObj); @@ -370,7 +371,7 @@ namespace mongo { // in the local database. ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, dbname); + OldClientContext ctx(txn, dbname); BSONElement e = cmdObj.firstElement(); result.append("was", ctx.db()->getProfilingLevel()); @@ -431,7 +432,7 @@ namespace mongo { // ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, dbname); + OldClientContext ctx(txn, dbname); int was = _diaglog.setLevel( cmdObj.firstElement().numberInt() ); _diaglog.flush(); @@ -506,7 +507,7 @@ namespace mongo { errmsg = "ns not found"; return false; } - Client::Context context(txn, nsToDrop); + OldClientContext context(txn, nsToDrop); if (!fromRepl && !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() @@ -607,7 +608,7 @@ namespace mongo { MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); if (!fromRepl && !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() @@ -1056,7 +1057,7 @@ namespace mongo { return false; } - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); if (!fromRepl && !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() @@ -1220,7 +1221,7 @@ namespace mongo { const string ns = parseNs(dbname, jsobj); - // TODO: Client::Context legacy, needs to be removed + // TODO: OldClientContext legacy, needs to be removed txn->getCurOp()->ensureStarted(); txn->getCurOp()->setNS(dbname); @@ -1250,7 +1251,7 @@ namespace mongo { result.appendNumber("fileSize", 0); } else { - // TODO: Client::Context legacy, needs to be removed + // TODO: OldClientContext legacy, needs to be removed txn->getCurOp()->enter(dbname.c_str(), db->getProfilingLevel()); db->getStats(txn, &result, scale); diff --git a/src/mongo/db/dbeval.cpp b/src/mongo/db/dbeval.cpp index ee4f3480aeb..f4c49a8c74d 100644 --- a/src/mongo/db/dbeval.cpp +++ b/src/mongo/db/dbeval.cpp @@ -38,6 +38,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/introspect.h" #include "mongo/db/jsobj.h" #include "mongo/db/json.h" @@ -179,7 +180,7 @@ namespace { ScopedTransaction transaction(txn, MODE_X); Lock::GlobalWrite lk(txn->lockState()); - Client::Context ctx(txn, dbname); + OldClientContext ctx(txn, dbname); return dbEval(txn, dbname, cmdObj, result, errmsg); } diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 10d0848182b..74737b38d28 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -38,14 +38,17 @@ #include <fstream> #include "mongo/client/dbclientinterface.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/index_create.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/global_environment_experiment.h" +#include "mongo/db/index/btree_access_method.h" #include "mongo/db/json.h" #include "mongo/db/keypattern.h" -#include "mongo/db/index/btree_access_method.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/delete.h" #include "mongo/db/ops/update.h" #include "mongo/db/ops/update_lifecycle_impl.h" @@ -56,11 +59,9 @@ #include "mongo/db/query/query_planner.h" #include "mongo/db/range_arithmetic.h" #include "mongo/db/repl/replication_coordinator_global.h" +#include "mongo/db/storage_options.h" #include "mongo/db/write_concern.h" #include "mongo/db/write_concern_options.h" -#include "mongo/db/operation_context_impl.h" -#include "mongo/db/storage_options.h" -#include "mongo/db/catalog/collection.h" #include "mongo/s/d_state.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/util/log.h" @@ -237,7 +238,7 @@ namespace mongo { BSONObj id = e.wrap(); OpDebug debug; - Client::Context context(txn, ns); + OldClientContext context(txn, ns); const NamespaceString requestNs(ns); UpdateRequest request(requestNs); @@ -255,7 +256,7 @@ namespace mongo { void Helpers::putSingleton(OperationContext* txn, const char *ns, BSONObj obj) { OpDebug debug; - Client::Context context(txn, ns); + OldClientContext context(txn, ns); const NamespaceString requestNs(ns); UpdateRequest request(requestNs); @@ -360,7 +361,7 @@ namespace mongo { while ( 1 ) { // Scoping for write lock. { - Client::WriteContext ctx(txn, ns); + OldClientWriteContext ctx(txn, ns); Collection* collection = ctx.getCollection(); if ( !collection ) break; @@ -578,7 +579,7 @@ namespace mongo { void Helpers::emptyCollection(OperationContext* txn, const char *ns) { - Client::Context context(txn, ns); + OldClientContext context(txn, ns); deleteObjects(txn, context.db(), ns, BSONObj(), PlanExecutor::YIELD_MANUAL, false); } diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp index e1fc8e2b068..0e2bf932edb 100644 --- a/src/mongo/db/exec/stagedebug_cmd.cpp +++ b/src/mongo/db/exec/stagedebug_cmd.cpp @@ -26,13 +26,16 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/base/init.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/catalog/database.h" -#include "mongo/db/commands.h" #include "mongo/db/client.h" +#include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/and_hash.h" #include "mongo/db/exec/and_sorted.h" #include "mongo/db/exec/collection_scan.h" @@ -126,7 +129,7 @@ namespace mongo { // execution trees. ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock lk(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, dbname); + OldClientContext ctx(txn, dbname); // Make sure the collection is valid. Database* db = ctx.db(); diff --git a/src/mongo/db/geo/haystack.cpp b/src/mongo/db/geo/haystack.cpp index cf2c218fa35..0998e610803 100644 --- a/src/mongo/db/geo/haystack.cpp +++ b/src/mongo/db/geo/haystack.cpp @@ -26,20 +26,23 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include <vector> #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/privilege.h" -#include "mongo/db/curop.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/commands.h" +#include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/index/haystack_access_method.h" -#include "mongo/db/index/index_descriptor.h" #include "mongo/db/index/index_access_method.h" +#include "mongo/db/index/index_descriptor.h" #include "mongo/db/index_names.h" #include "mongo/db/jsobj.h" -#include "mongo/db/catalog/collection.h" -#include "mongo/db/commands.h" /** * Examines all documents in a given radius of a given point. diff --git a/src/mongo/db/global_environment_d.cpp b/src/mongo/db/global_environment_d.cpp index 420f9c0779f..3cb18d9a3fe 100644 --- a/src/mongo/db/global_environment_d.cpp +++ b/src/mongo/db/global_environment_d.cpp @@ -34,14 +34,15 @@ #include "mongo/base/initializer.h" #include "mongo/db/client.h" #include "mongo/db/curop.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/db/storage/storage_engine_lock_file.h" #include "mongo/db/storage/storage_engine_metadata.h" +#include "mongo/db/storage_options.h" #include "mongo/scripting/engine.h" -#include "mongo/util/mongoutils/str.h" #include "mongo/util/log.h" +#include "mongo/util/mongoutils/str.h" #include "mongo/util/scopeguard.h" namespace mongo { diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index f6bb21e682f..ad8f7c8f06f 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -28,6 +28,8 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kIndex +#include "mongo/platform/basic.h" + #include "mongo/db/index/btree_access_method.h" #include <vector> @@ -38,12 +40,12 @@ #include "mongo/db/curop.h" #include "mongo/db/jsobj.h" #include "mongo/db/keypattern.h" -#include "mongo/db/server_parameters.h" #include "mongo/db/operation_context.h" +#include "mongo/db/server_parameters.h" +#include "mongo/db/storage_options.h" #include "mongo/util/log.h" #include "mongo/util/progress_meter.h" - namespace mongo { using std::endl; diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp index b50bdf552a2..62eef061ff6 100644 --- a/src/mongo/db/index_builder.cpp +++ b/src/mongo/db/index_builder.cpp @@ -33,12 +33,13 @@ #include "mongo/db/index_builder.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/client.h" -#include "mongo/db/curop.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/index_create.h" +#include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/operation_context_impl.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" @@ -91,7 +92,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dlk(txn.lockState(), ns.db(), MODE_X); - Client::Context ctx(&txn, ns.getSystemIndexesCollection()); + OldClientContext ctx(&txn, ns.getSystemIndexesCollection()); Database* db = dbHolder().get(&txn, ns.db().toString()); diff --git a/src/mongo/db/index_rebuilder.cpp b/src/mongo/db/index_rebuilder.cpp index cb8030750de..d8d7ab5dfa5 100644 --- a/src/mongo/db/index_rebuilder.cpp +++ b/src/mongo/db/index_rebuilder.cpp @@ -42,6 +42,7 @@ #include "mongo/db/catalog/database_catalog_entry.h" #include "mongo/db/catalog/index_create.h" #include "mongo/db/client.h" +#include "mongo/db/db_raii.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/instance.h" #include "mongo/db/operation_context_impl.h" @@ -70,7 +71,7 @@ namespace { // for this namespace. ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock lk(txn->lockState(), nsToDatabaseSubstring(ns), MODE_X); - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); Collection* collection = ctx.db()->getCollection(ns); if ( collection == NULL ) diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 26af00cad16..a60b2714dd1 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -43,6 +43,7 @@ #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/background.h" +#include "mongo/db/catalog/index_create.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" #include "mongo/db/commands/fsync.h" @@ -51,13 +52,14 @@ #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/currentop_command.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/dbmessage.h" -#include "mongo/db/storage/storage_engine.h" -#include "mongo/db/operation_context_impl.h" -#include "mongo/db/global_optime.h" +#include "mongo/db/exec/delete.h" +#include "mongo/db/exec/update.h" #include "mongo/db/global_environment_experiment.h" +#include "mongo/db/global_optime.h" #include "mongo/db/instance.h" #include "mongo/db/introspect.h" #include "mongo/db/json.h" @@ -65,22 +67,21 @@ #include "mongo/db/matcher/matcher.h" #include "mongo/db/mongod_options.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/catalog/index_create.h" -#include "mongo/db/exec/delete.h" -#include "mongo/db/exec/update.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/delete_request.h" #include "mongo/db/ops/insert.h" #include "mongo/db/ops/parsed_delete.h" #include "mongo/db/ops/parsed_update.h" -#include "mongo/db/ops/update_lifecycle_impl.h" #include "mongo/db/ops/update_driver.h" +#include "mongo/db/ops/update_lifecycle_impl.h" #include "mongo/db/ops/update_request.h" #include "mongo/db/query/find.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/stats/counters.h" +#include "mongo/db/storage/storage_engine.h" #include "mongo/db/storage_options.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/process_id.h" @@ -683,13 +684,13 @@ namespace { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbLock(txn->lockState(), nsString.db(), MODE_IX); if (dbHolder().get(txn, nsString.db()) == NULL) { - // If DB doesn't exist, don't implicitly create it in Client::Context + // If DB doesn't exist, don't implicitly create it in OldClientContext break; } Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), parsedUpdate.isIsolated() ? MODE_X : MODE_IX); - Client::Context ctx(txn, nsString); + OldClientContext ctx(txn, nsString); // The common case: no implicit collection creation if (!upsert || ctx.db()->getCollection(nsString) != NULL) { @@ -729,7 +730,7 @@ namespace { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbLock(txn->lockState(), nsString.db(), MODE_X); - Client::Context ctx(txn, nsString); + OldClientContext ctx(txn, nsString); uassert(ErrorCodes::NotMaster, str::stream() << "Not primary while performing update on " << nsString.ns(), repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( @@ -806,7 +807,7 @@ namespace { Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), parsedDelete.isIsolated() ? MODE_X : MODE_IX); - Client::Context ctx(txn, nsString); + OldClientContext ctx(txn, nsString); PlanExecutor* rawExec; uassertStatusOK(getExecutorDelete(txn, @@ -960,7 +961,7 @@ namespace { } void checkAndInsert(OperationContext* txn, - Client::Context& ctx, + OldClientContext& ctx, const char *ns, /*modifies*/BSONObj& js) { @@ -998,7 +999,7 @@ namespace { } NOINLINE_DECL void insertMulti(OperationContext* txn, - Client::Context& ctx, + OldClientContext& ctx, bool keepGoing, const char *ns, vector<BSONObj>& objs, @@ -1140,9 +1141,9 @@ namespace { uassert(notMasterCodeForInsert, "not master", repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(nsString.db())); - // Client::Context may implicitly create a database, so check existence + // OldClientContext may implicitly create a database, so check existence if (dbHolder().get(txn, nsString.db()) != NULL) { - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); if (ctx.db()->getCollection(nsString)) { if (multi.size() > 1) { const bool keepGoing = d.reservedField() & InsertOption_ContinueOnError; @@ -1167,7 +1168,7 @@ namespace { uassert(notMasterCodeForInsert, "not master", repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(nsString.db())); - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); if (multi.size() > 1) { const bool keepGoing = d.reservedField() & InsertOption_ContinueOnError; diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp index 797ff974c7b..b7ed58abce3 100644 --- a/src/mongo/db/introspect.cpp +++ b/src/mongo/db/introspect.cpp @@ -36,9 +36,10 @@ #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/user_set.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/jsobj.h" -#include "mongo/db/catalog/collection.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/ops/delete.cpp b/src/mongo/db/ops/delete.cpp index 92dca155c61..ed53c86e1e8 100644 --- a/src/mongo/db/ops/delete.cpp +++ b/src/mongo/db/ops/delete.cpp @@ -26,8 +26,11 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/db/ops/delete.h" +#include "mongo/db/catalog/database.h" #include "mongo/db/exec/delete.h" #include "mongo/db/ops/delete_request.h" #include "mongo/db/ops/parsed_delete.h" diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp index b92aa821bb3..c2c42aaa0d4 100644 --- a/src/mongo/db/ops/update.cpp +++ b/src/mongo/db/ops/update.cpp @@ -36,6 +36,7 @@ #include "mongo/client/dbclientinterface.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/clientcursor.h" #include "mongo/db/concurrency/d_concurrency.h" diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp index c2cd4ddb539..3891008ff1c 100644 --- a/src/mongo/db/pipeline/document_source_cursor.cpp +++ b/src/mongo/db/pipeline/document_source_cursor.cpp @@ -33,6 +33,7 @@ #include <boost/shared_ptr.hpp> #include "mongo/db/catalog/database_holder.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/instance.h" #include "mongo/db/pipeline/document.h" @@ -41,7 +42,6 @@ #include "mongo/db/storage_options.h" #include "mongo/s/d_state.h" - namespace mongo { using boost::intrusive_ptr; diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp index b11e0ede71e..51a4a6ef4cd 100644 --- a/src/mongo/db/pipeline/pipeline_d.cpp +++ b/src/mongo/db/pipeline/pipeline_d.cpp @@ -36,6 +36,7 @@ #include "mongo/client/dbclientinterface.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/pipeline/document_source.h" #include "mongo/db/pipeline/pipeline.h" diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index fc1656d8154..1b26f411937 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -35,9 +35,11 @@ #include <boost/scoped_ptr.hpp> #include "mongo/client/dbclientinterface.h" +#include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database_holder.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" -#include "mongo/db/catalog/database_holder.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/filter.h" #include "mongo/db/exec/oplogstart.h" #include "mongo/db/exec/working_set_common.h" @@ -53,7 +55,6 @@ #include "mongo/db/server_parameters.h" #include "mongo/db/storage/oplog_hack.h" #include "mongo/db/storage_options.h" -#include "mongo/db/catalog/collection.h" #include "mongo/s/chunk_version.h" #include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" diff --git a/src/mongo/db/range_deleter_db_env.cpp b/src/mongo/db/range_deleter_db_env.cpp index 1eb18efaa87..a717a2ba6fc 100644 --- a/src/mongo/db/range_deleter_db_env.cpp +++ b/src/mongo/db/range_deleter_db_env.cpp @@ -37,6 +37,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/client.h" #include "mongo/db/clientcursor.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/write_concern_options.h" diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index 2782061bce3..a8397987999 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -53,10 +53,12 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/cloner.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/update.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/repl/handshake_args.h" @@ -64,7 +66,6 @@ #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/repl/sync.h" #include "mongo/db/server_parameters.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage_options.h" #include "mongo/util/concurrency/thread_pool.h" #include "mongo/util/exit.h" @@ -216,7 +217,7 @@ namespace repl { { OpDebug debug; - Client::Context ctx(txn, "local.sources"); + OldClientContext ctx(txn, "local.sources"); const NamespaceString requestNs("local.sources"); UpdateRequest request(requestNs); @@ -255,7 +256,7 @@ namespace repl { */ void ReplSource::loadAll(OperationContext* txn, SourceVector &v) { const char* localSources = "local.sources"; - Client::Context ctx(txn, localSources); + OldClientContext ctx(txn, localSources); SourceVector old = v; v.clear(); @@ -458,7 +459,7 @@ namespace repl { void ReplSource::resyncDrop( OperationContext* txn, const string& db ) { log() << "resync: dropping database " << db; - Client::Context ctx(txn, db); + OldClientContext ctx(txn, db); dropDatabase(txn, ctx.db()); } @@ -608,7 +609,7 @@ namespace repl { incompleteCloneDbs.erase(*i); addDbNextPass.erase(*i); - Client::Context ctx(txn, *i); + OldClientContext ctx(txn, *i); dropDatabase(txn, ctx.db()); } @@ -726,7 +727,7 @@ namespace repl { // This code executes on the slaves only, so it doesn't need to be sharding-aware since // 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); + OldClientContext ctx(txn, ns, false); txn->getCurOp()->reset(); bool empty = !ctx.db()->getDatabaseCatalogEntry()->hasUserData(); @@ -757,7 +758,7 @@ namespace repl { log() << "An earlier initial clone of '" << clientName << "' did not complete, now resyncing." << endl; } save(txn); - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); nClonedThisPass++; resync(txn, ctx.db()->name()); addDbNextPass.erase(clientName); @@ -1388,7 +1389,7 @@ namespace repl { BSONObjBuilder b; b.append(_id); BSONObj result; - Client::Context ctx(&txn, ns); + OldClientContext ctx(&txn, ns); if( Helpers::findById(&txn, ctx.db(), ns, b.done(), result) ) _dummy_z += result.objsize(); // touch } diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index b97f447eb2a..d526a50231d 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -41,12 +41,14 @@ #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_global.h" -#include "mongo/db/background.h" #include "mongo/db/auth/privilege.h" +#include "mongo/db/background.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/commands.h" #include "mongo/db/commands/dbhash.h" #include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_experiment.h" @@ -54,16 +56,15 @@ #include "mongo/db/index_builder.h" #include "mongo/db/namespace_string.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" +#include "mongo/db/ops/delete.h" #include "mongo/db/ops/update.h" #include "mongo/db/ops/update_lifecycle_impl.h" -#include "mongo/db/ops/delete.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/stats/counters.h" -#include "mongo/db/operation_context_impl.h" -#include "mongo/db/storage_options.h" #include "mongo/db/storage/storage_engine.h" -#include "mongo/db/catalog/collection.h" +#include "mongo/db/storage_options.h" #include "mongo/s/d_state.h" #include "mongo/scripting/engine.h" #include "mongo/util/elapsed_tracker.h" @@ -247,7 +248,7 @@ namespace { if (_localOplogCollection == nullptr) { - Client::Context ctx(txn, _oplogCollectionName); + OldClientContext ctx(txn, _oplogCollectionName); _localDB = ctx.db(); invariant(_localDB); _localOplogCollection = _localDB->getCollection(_oplogCollectionName); @@ -296,7 +297,7 @@ namespace { Lock::DBLock lk(txn->lockState(), "local", MODE_X); if ( _localOplogCollection == 0 ) { - Client::Context ctx(txn, rsOplogName); + OldClientContext ctx(txn, rsOplogName); _localDB = ctx.db(); verify( _localDB ); @@ -306,7 +307,7 @@ namespace { _localOplogCollection); } - Client::Context ctx(txn, rsOplogName, _localDB); + OldClientContext ctx(txn, rsOplogName, _localDB); WriteUnitOfWork wunit(txn); for (std::deque<BSONObj>::const_iterator it = ops.begin(); @@ -352,7 +353,7 @@ namespace { const ReplSettings& replSettings = getGlobalReplicationCoordinator()->getSettings(); bool rs = !replSettings.replSet.empty(); - Client::Context ctx(txn, _oplogCollectionName); + OldClientContext ctx(txn, _oplogCollectionName); Collection* collection = ctx.db()->getCollection( _oplogCollectionName ); if ( collection ) { diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 9d5ba123213..0433feb138d 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -38,6 +38,7 @@ #include "mongo/base/status_with.h" #include "mongo/bson/oid.h" +#include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index a836ef84cc6..8d064089244 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -34,6 +34,7 @@ #include "mongo/client/connpool.h" #include "mongo/db/commands/server_status.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/jsobj.h" #include "mongo/db/operation_context_impl.h" diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp index c58bee8af0b..dda8f77b153 100644 --- a/src/mongo/db/repl/rs_initialsync.cpp +++ b/src/mongo/db/repl/rs_initialsync.cpp @@ -39,11 +39,12 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/client.h" #include "mongo/db/cloner.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_experiment.h" +#include "mongo/db/op_observer.h" #include "mongo/db/operation_context_impl.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/op_observer.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/initial_sync.h" #include "mongo/db/repl/minvalid.h" diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index aba19c1e1f8..22870e6de7e 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -40,6 +40,7 @@ #include "mongo/db/client.h" #include "mongo/db/cloner.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/delete.h" @@ -259,7 +260,7 @@ namespace { void syncRollbackFindCommonPoint(OperationContext* txn, DBClientConnection* them, FixUpInfo& fixUpInfo) { - Client::Context ctx(txn, rsOplogName); + OldClientContext ctx(txn, rsOplogName); boost::scoped_ptr<PlanExecutor> exec( InternalPlanner::collectionScan(txn, @@ -539,7 +540,7 @@ namespace { } log() << "rollback 4.7"; - Client::Context ctx(txn, rsOplogName); + OldClientContext ctx(txn, rsOplogName); Collection* oplogCollection = ctx.db()->getCollection(rsOplogName); uassert(13423, str::stream() << "replSet error in rollback can't find " << rsOplogName, @@ -575,7 +576,7 @@ namespace { removeSaver.reset(new Helpers::RemoveSaver("rollback", "", doc.ns)); // todo: lots of overhead in context, this can be faster - Client::Context ctx(txn, doc.ns); + OldClientContext ctx(txn, doc.ns); // Add the doc to our rollback file BSONObj obj; diff --git a/src/mongo/db/repl/sync.cpp b/src/mongo/db/repl/sync.cpp index daa6d305a57..1f5cef2f773 100644 --- a/src/mongo/db/repl/sync.cpp +++ b/src/mongo/db/repl/sync.cpp @@ -37,6 +37,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/client.h" +#include "mongo/db/db_raii.h" #include "mongo/db/jsobj.h" #include "mongo/db/record_id.h" #include "mongo/db/repl/oplogreader.h" diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index 786537f3965..390385bb0bd 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -45,14 +45,15 @@ #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" #include "mongo/db/global_environment_experiment.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/prefetch.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/minvalid.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/stats/timer_stats.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/util/exit.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" @@ -184,7 +185,7 @@ namespace repl { nsToDatabaseSubstring(ns), MODE_X)); } - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); if ( createCollection == 0 && !isIndexBuild && diff --git a/src/mongo/db/storage/mmap_v1/repair_database.cpp b/src/mongo/db/storage/mmap_v1/repair_database.cpp index aff3379e6a6..36f2b36b671 100644 --- a/src/mongo/db/storage/mmap_v1/repair_database.cpp +++ b/src/mongo/db/storage/mmap_v1/repair_database.cpp @@ -43,9 +43,10 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/index_create.h" #include "mongo/db/client.h" +#include "mongo/db/db_raii.h" #include "mongo/db/index/index_descriptor.h" -#include "mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h" #include "mongo/db/storage/mmap_v1/dur.h" +#include "mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h" #include "mongo/db/storage/mmap_v1/mmap_v1_options.h" #include "mongo/util/file.h" #include "mongo/util/file_allocator.h" @@ -335,7 +336,7 @@ namespace mongo { map<string,CollectionOptions> namespacesToCopy; { string ns = dbName + ".system.namespaces"; - Client::Context ctx(txn, ns ); + OldClientContext ctx(txn, ns ); Collection* coll = originalDatabase->getCollection( ns ); if ( coll ) { scoped_ptr<RecordIterator> it( coll->getIterator(txn) ); @@ -380,7 +381,7 @@ namespace mongo { wunit.commit(); } - Client::Context readContext(txn, ns, originalDatabase); + OldClientContext readContext(txn, ns, originalDatabase); Collection* originalCollection = originalDatabase->getCollection( ns ); invariant( originalCollection ); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp index e5b8fdb95d7..dc9b5fc1e52 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp @@ -35,10 +35,11 @@ #include <set> #include "mongo/base/checked_cast.h" -#include "mongo/db/client.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" +#include "mongo/db/db_raii.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context_impl.h" @@ -96,7 +97,7 @@ namespace mongo { return 0; } - Client::Context ctx(&txn, _ns, false); + OldClientContext ctx(&txn, _ns, false); WiredTigerRecordStore* rs = checked_cast<WiredTigerRecordStore*>(collection->getRecordStore()); WriteUnitOfWork wuow(&txn); diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index a7b0367fd99..c2ba257e213 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -38,13 +38,14 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/user_name.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/collection_catalog_entry.h" +#include "mongo/db/catalog/database_catalog_entry.h" +#include "mongo/db/catalog/database_holder.h" #include "mongo/db/client.h" #include "mongo/db/commands/fsync.h" #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/concurrency/write_conflict_exception.h" -#include "mongo/db/catalog/collection_catalog_entry.h" -#include "mongo/db/catalog/database_catalog_entry.h" -#include "mongo/db/catalog/database_holder.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/delete.h" diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp index efd31f5e580..c7cb467983b 100644 --- a/src/mongo/dbtests/clienttests.cpp +++ b/src/mongo/dbtests/clienttests.cpp @@ -31,11 +31,11 @@ #include "mongo/client/dbclientcursor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" - namespace ClientTests { using std::auto_ptr; @@ -100,7 +100,7 @@ namespace ClientTests { void run() { OperationContextImpl txn; - Client::WriteContext ctx(&txn, ns()); + OldClientWriteContext ctx(&txn, ns()); DBDirectClient db(&txn); db.insert(ns(), BSON("x" << 1 << "y" << 2)); diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp index 918b87ed3d7..5233c18d2bf 100644 --- a/src/mongo/dbtests/counttests.cpp +++ b/src/mongo/dbtests/counttests.cpp @@ -30,11 +30,12 @@ #include <boost/thread/thread.hpp> +#include "mongo/db/catalog/collection.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/json.h" -#include "mongo/db/catalog/collection.h" #include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" @@ -112,7 +113,7 @@ namespace CountTests { ScopedTransaction _scopedXact; Lock::DBLock _lk; - Client::Context _context; + OldClientContext _context; Database* _database; Collection* _collection; diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp index 913618d7b29..24aeb64be2a 100644 --- a/src/mongo/dbtests/dbhelper_tests.cpp +++ b/src/mongo/dbtests/dbhelper_tests.cpp @@ -29,6 +29,7 @@ #include "mongo/client/dbclientcursor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database_holder.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/operation_context_impl.h" @@ -68,7 +69,7 @@ namespace mongo { // Remove _id range [_min, _max). ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_X); - Client::Context ctx(&txn, ns ); + OldClientContext ctx(&txn, ns ); KeyRange range( ns, BSON( "_id" << _min ), diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp index f82bb2402eb..21d502f340b 100644 --- a/src/mongo/dbtests/dbtests.cpp +++ b/src/mongo/dbtests/dbtests.cpp @@ -39,6 +39,7 @@ #include "mongo/db/auth/authz_manager_external_state_mock.h" #include "mongo/db/catalog/index_create.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/global_environment_d.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/repl/replication_coordinator_global.h" diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp index ad812a971d0..b0790d2e6fc 100644 --- a/src/mongo/dbtests/documentsourcetests.cpp +++ b/src/mongo/dbtests/documentsourcetests.cpp @@ -35,6 +35,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/operation_context_impl.h" #include "mongo/db/pipeline/dependencies.h" @@ -181,7 +182,7 @@ namespace DocumentSourceTests { _source.reset(); _exec.reset(); - Client::WriteContext ctx(&_opCtx, ns); + OldClientWriteContext ctx(&_opCtx, ns); CanonicalQuery* cq; uassertStatusOK(CanonicalQuery::canonicalize(ns, /*query=*/BSONObj(), &cq)); PlanExecutor* execBare; diff --git a/src/mongo/dbtests/executor_registry.cpp b/src/mongo/dbtests/executor_registry.cpp index 16f0da39149..d05abef5323 100644 --- a/src/mongo/dbtests/executor_registry.cpp +++ b/src/mongo/dbtests/executor_registry.cpp @@ -34,6 +34,7 @@ #include "mongo/client/dbclientcursor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/plan_stage.h" @@ -44,7 +45,6 @@ #include "mongo/db/query/plan_executor.h" #include "mongo/dbtests/dbtests.h" - namespace ExecutorRegistry { using std::auto_ptr; @@ -54,7 +54,7 @@ namespace ExecutorRegistry { ExecutorRegistryBase() : _client(&_opCtx) { - _ctx.reset(new Client::WriteContext(&_opCtx, ns())); + _ctx.reset(new OldClientWriteContext(&_opCtx, ns())); _client.dropCollection(ns()); for (int i = 0; i < N(); ++i) { @@ -115,7 +115,7 @@ namespace ExecutorRegistry { // Order of these is important for initialization OperationContextImpl _opCtx; - auto_ptr<Client::WriteContext> _ctx; + auto_ptr<OldClientWriteContext> _ctx; DBDirectClient _client; }; @@ -292,7 +292,7 @@ namespace ExecutorRegistry { // requires a "global write lock." _ctx.reset(); _client.dropDatabase("somesillydb"); - _ctx.reset(new Client::WriteContext(&_opCtx, ns())); + _ctx.reset(new OldClientWriteContext(&_opCtx, ns())); // Unregister and restore state. deregisterExecutor(run.get()); @@ -308,7 +308,7 @@ namespace ExecutorRegistry { // Drop our DB. Once again, must give up the lock. _ctx.reset(); _client.dropDatabase("unittests"); - _ctx.reset(new Client::WriteContext(&_opCtx, ns())); + _ctx.reset(new OldClientWriteContext(&_opCtx, ns())); // Unregister and restore state. deregisterExecutor(run.get()); diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp index 346ba85a799..e5907f13e16 100644 --- a/src/mongo/dbtests/indexcatalogtests.cpp +++ b/src/mongo/dbtests/indexcatalogtests.cpp @@ -20,10 +20,10 @@ #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/operation_context_impl.h" - #include "mongo/dbtests/dbtests.h" namespace IndexCatalogTests { @@ -36,7 +36,7 @@ namespace IndexCatalogTests { OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); - Client::Context ctx(&txn, _ns); + OldClientContext ctx(&txn, _ns); WriteUnitOfWork wuow(&txn); _db = ctx.db(); @@ -49,7 +49,7 @@ namespace IndexCatalogTests { OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); - Client::Context ctx(&txn, _ns); + OldClientContext ctx(&txn, _ns); WriteUnitOfWork wuow(&txn); _db->dropCollection(&txn, _ns); @@ -58,7 +58,7 @@ namespace IndexCatalogTests { void run() { OperationContextImpl txn; - Client::WriteContext ctx(&txn, _ns); + OldClientWriteContext ctx(&txn, _ns); int numFinishedIndexesStart = _catalog->numIndexesReady(&txn); @@ -103,7 +103,7 @@ namespace IndexCatalogTests { OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); - Client::Context ctx(&txn, _ns); + OldClientContext ctx(&txn, _ns); WriteUnitOfWork wuow(&txn); _db = ctx.db(); @@ -116,7 +116,7 @@ namespace IndexCatalogTests { OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); - Client::Context ctx(&txn, _ns); + OldClientContext ctx(&txn, _ns); WriteUnitOfWork wuow(&txn); _db->dropCollection(&txn, _ns); @@ -125,7 +125,7 @@ namespace IndexCatalogTests { void run() { OperationContextImpl txn; - Client::WriteContext ctx(&txn, _ns); + OldClientWriteContext ctx(&txn, _ns); const std::string indexName = "x_1"; ASSERT_OK(dbtests::createIndexFromSpec(&txn, _ns, BSON("name" << indexName << diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index a1604f6a46a..cf92968a55a 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -33,15 +33,15 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_create.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_d.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/platform/cstdint.h" - #include "mongo/dbtests/dbtests.h" +#include "mongo/platform/cstdint.h" namespace IndexUpdateTests { @@ -120,7 +120,7 @@ namespace IndexUpdateTests { } OperationContextImpl _txn; - Client::WriteContext _ctx; + OldClientWriteContext _ctx; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp index 8d66896eb85..194769d7cb7 100644 --- a/src/mongo/dbtests/matchertests.cpp +++ b/src/mongo/dbtests/matchertests.cpp @@ -31,6 +31,7 @@ #include <iostream> +#include "mongo/db/db_raii.h" #include "mongo/db/json.h" #include "mongo/db/matcher/matcher.h" #include "mongo/db/operation_context_impl.h" diff --git a/src/mongo/dbtests/namespacetests.cpp b/src/mongo/dbtests/namespacetests.cpp index 1017be597e5..f8b6c0d95f1 100644 --- a/src/mongo/dbtests/namespacetests.cpp +++ b/src/mongo/dbtests/namespacetests.cpp @@ -37,20 +37,21 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database_holder.h" +#include "mongo/db/db_raii.h" #include "mongo/db/index/expression_keys_private.h" #include "mongo/db/index_legacy.h" #include "mongo/db/index_names.h" #include "mongo/db/json.h" -#include "mongo/db/query/internal_plans.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/query/internal_plans.h" +#include "mongo/db/storage/mmap_v1/catalog/namespace.h" +#include "mongo/db/storage/mmap_v1/catalog/namespace_details.h" +#include "mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.h" #include "mongo/db/storage/mmap_v1/extent.h" #include "mongo/db/storage/mmap_v1/extent_manager.h" #include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h" #include "mongo/db/storage/mmap_v1/record_store_v1_capped.h" #include "mongo/db/storage/mmap_v1/record_store_v1_simple.h" -#include "mongo/db/storage/mmap_v1/catalog/namespace.h" -#include "mongo/db/storage/mmap_v1/catalog/namespace_details.h" -#include "mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/log.h" @@ -139,7 +140,7 @@ namespace NamespaceTests { class Base { const char *ns_; Lock::GlobalWrite lk; - Client::Context _context; + OldClientContext _context; public: Base( const char *ns = "unittests.NamespaceDetailsTests" ) : ns_( ns ) , _context( ns ) {} virtual ~Base() { diff --git a/src/mongo/dbtests/oplogstarttests.cpp b/src/mongo/dbtests/oplogstarttests.cpp index a3b67efac51..745bcfd3a01 100644 --- a/src/mongo/dbtests/oplogstarttests.cpp +++ b/src/mongo/dbtests/oplogstarttests.cpp @@ -24,15 +24,16 @@ #include <boost/scoped_ptr.hpp> +#include "mongo/db/catalog/collection.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/oplogstart.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/global_environment_experiment.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/canonical_query.h" #include "mongo/db/repl/repl_settings.h" -#include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" namespace OplogStartTests { @@ -107,7 +108,7 @@ namespace OplogStartTests { ScopedTransaction _scopedXact; Lock::GlobalWrite _lk; WriteUnitOfWork _wunit; - Client::Context _context; + OldClientContext _context; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp index fbf557e9f40..28f777063ed 100644 --- a/src/mongo/dbtests/pdfiletests.cpp +++ b/src/mongo/dbtests/pdfiletests.cpp @@ -31,11 +31,12 @@ #include "mongo/platform/basic.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/json.h" -#include "mongo/db/ops/insert.h" -#include "mongo/db/catalog/collection.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/ops/insert.h" #include "mongo/dbtests/dbtests.h" namespace PdfileTests { @@ -68,7 +69,7 @@ namespace PdfileTests { OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::GlobalWrite _lk; - Client::Context _context; + OldClientContext _context; }; class InsertNoId : public Base { diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp index a9be990268d..f5a0320d3d6 100644 --- a/src/mongo/dbtests/plan_ranking.cpp +++ b/src/mongo/dbtests/plan_ranking.cpp @@ -36,6 +36,7 @@ #include "mongo/client/dbclientcursor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/multi_plan.h" #include "mongo/db/index/index_descriptor.h" @@ -75,7 +76,7 @@ namespace PlanRankingTests { // Run all tests with hash-based intersection enabled. internalQueryPlannerEnableHashIntersection = true; - Client::WriteContext ctx(&_txn, ns); + OldClientWriteContext ctx(&_txn, ns); _client.dropCollection(ns); } @@ -86,7 +87,7 @@ namespace PlanRankingTests { } void insert(const BSONObj& obj) { - Client::WriteContext ctx(&_txn, ns); + OldClientWriteContext ctx(&_txn, ns); _client.insert(ns, obj); } diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp index 2cdb3118f9c..8525f2bdade 100644 --- a/src/mongo/dbtests/query_multi_plan_runner.cpp +++ b/src/mongo/dbtests/query_multi_plan_runner.cpp @@ -30,6 +30,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/fetch.h" @@ -74,12 +75,12 @@ namespace QueryMultiPlanRunner { class MultiPlanRunnerBase { public: MultiPlanRunnerBase() : _client(&_txn) { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } virtual ~MultiPlanRunnerBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -88,12 +89,12 @@ namespace QueryMultiPlanRunner { } void insert(const BSONObj& obj) { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.insert(ns(), obj); } void remove(const BSONObj& obj) { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.remove(ns(), obj); } diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp index 0092674c58b..552a46e8237 100644 --- a/src/mongo/dbtests/query_plan_executor.cpp +++ b/src/mongo/dbtests/query_plan_executor.cpp @@ -29,9 +29,10 @@ #include <boost/scoped_ptr.hpp> #include <boost/shared_ptr.hpp> -#include "mongo/db/clientcursor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/clientcursor.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/fetch.h" @@ -201,7 +202,7 @@ namespace QueryPlanExecutor { class DropCollScan : public PlanExecutorBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); insert(BSON("_id" << 1)); insert(BSON("_id" << 2)); @@ -230,7 +231,7 @@ namespace QueryPlanExecutor { class DropIndexScan : public PlanExecutorBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); insert(BSON("_id" << 1 << "a" << 6)); insert(BSON("_id" << 2 << "a" << 7)); insert(BSON("_id" << 3 << "a" << 8)); @@ -259,7 +260,7 @@ namespace QueryPlanExecutor { class DropIndexScanAgg : public PlanExecutorBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); insert(BSON("_id" << 1 << "a" << 6)); insert(BSON("_id" << 2 << "a" << 7)); @@ -355,7 +356,7 @@ namespace QueryPlanExecutor { class SnapshotControl : public SnapshotBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); setupCollection(); BSONObj filterObj = fromjson("{a: {$gte: 2}}"); @@ -382,7 +383,7 @@ namespace QueryPlanExecutor { class SnapshotTest : public SnapshotBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); setupCollection(); BSONObj indexSpec = BSON("_id" << 1); addIndex(indexSpec); @@ -413,7 +414,7 @@ namespace QueryPlanExecutor { class Invalidate : public PlanExecutorBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); insert(BSON("a" << 1 << "b" << 1)); BSONObj filterObj = fromjson("{_id: {$gt: 0}, b: {$gt: 0}}"); @@ -439,7 +440,7 @@ namespace QueryPlanExecutor { class InvalidatePinned : public PlanExecutorBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); insert(BSON("a" << 1 << "b" << 1)); Collection* collection = ctx.getCollection(); @@ -480,7 +481,7 @@ namespace QueryPlanExecutor { public: void run() { { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); insert(BSON("a" << 1 << "b" << 1)); } diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp index 44eca7ed214..5ce224bf463 100644 --- a/src/mongo/dbtests/query_stage_and.cpp +++ b/src/mongo/dbtests/query_stage_and.cpp @@ -35,7 +35,9 @@ #include <boost/shared_ptr.hpp> #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/and_hash.h" #include "mongo/db/exec/and_sorted.h" @@ -45,7 +47,6 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/mongoutils/str.h" @@ -162,7 +163,7 @@ namespace QueryStageAnd { class QueryStageAndHashInvalidation : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -265,7 +266,7 @@ namespace QueryStageAnd { class QueryStageAndHashInvalidateLookahead : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -353,7 +354,7 @@ namespace QueryStageAnd { class QueryStageAndHashTwoLeaf : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -403,7 +404,7 @@ namespace QueryStageAnd { class QueryStageAndHashTwoLeafFirstChildLargeKeys : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -456,7 +457,7 @@ namespace QueryStageAnd { class QueryStageAndHashTwoLeafLastChildLargeKeys : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -508,7 +509,7 @@ namespace QueryStageAnd { class QueryStageAndHashThreeLeaf : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -570,7 +571,7 @@ namespace QueryStageAnd { class QueryStageAndHashThreeLeafMiddleChildLargeKeys : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -630,7 +631,7 @@ namespace QueryStageAnd { class QueryStageAndHashWithNothing : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -690,7 +691,7 @@ namespace QueryStageAnd { class QueryStageAndHashProducesNothing : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -739,7 +740,7 @@ namespace QueryStageAnd { class QueryStageAndHashWithMatcher : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -792,7 +793,7 @@ namespace QueryStageAnd { class QueryStageAndHashFirstChildFetched : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -851,7 +852,7 @@ namespace QueryStageAnd { class QueryStageAndHashSecondChildFetched : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -915,7 +916,7 @@ namespace QueryStageAnd { class QueryStageAndSortedInvalidation : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -1033,7 +1034,7 @@ namespace QueryStageAnd { class QueryStageAndSortedThreeLeaf : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -1087,7 +1088,7 @@ namespace QueryStageAnd { class QueryStageAndSortedWithNothing : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -1132,7 +1133,7 @@ namespace QueryStageAnd { class QueryStageAndSortedProducesNothing : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -1181,7 +1182,7 @@ namespace QueryStageAnd { class QueryStageAndSortedWithMatcher : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -1227,7 +1228,7 @@ namespace QueryStageAnd { class QueryStageAndSortedByLastChild : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -1290,7 +1291,7 @@ namespace QueryStageAnd { class QueryStageAndSortedFirstChildFetched : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { @@ -1344,7 +1345,7 @@ namespace QueryStageAnd { class QueryStageAndSortedSecondChildFetched : public QueryStageAndBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = ctx.getCollection(); if (!coll) { diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index 80ac05acd0c..ab6ea366ea9 100644 --- a/src/mongo/dbtests/query_stage_collscan.cpp +++ b/src/mongo/dbtests/query_stage_collscan.cpp @@ -35,13 +35,14 @@ #include "mongo/client/dbclientcursor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/plan_stage.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" -#include "mongo/db/query/plan_executor.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/query/plan_executor.h" #include "mongo/db/storage/record_store.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/fail_point_service.h" @@ -59,7 +60,7 @@ namespace QueryStageCollectionScan { class QueryStageCollectionScanBase { public: QueryStageCollectionScanBase() : _client(&_txn) { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); for (int i = 0; i < numObj(); ++i) { BSONObjBuilder bob; @@ -69,7 +70,7 @@ namespace QueryStageCollectionScan { } virtual ~QueryStageCollectionScanBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -263,7 +264,7 @@ namespace QueryStageCollectionScan { class QueryStageCollscanInvalidateUpcomingObject : public QueryStageCollectionScanBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Collection* coll = ctx.getCollection(); @@ -325,7 +326,7 @@ namespace QueryStageCollectionScan { class QueryStageCollscanInvalidateUpcomingObjectBackward : public QueryStageCollectionScanBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Collection* coll = ctx.getCollection(); // Get the RecordIds that would be returned by an in-order scan. diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp index f100a8901f1..1973ba6b6d7 100644 --- a/src/mongo/dbtests/query_stage_count.cpp +++ b/src/mongo/dbtests/query_stage_count.cpp @@ -29,6 +29,7 @@ #include <boost/scoped_ptr.hpp> #include <memory> +#include "mongo/db/db_raii.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/collection_scan_common.h" #include "mongo/db/exec/count.h" @@ -231,7 +232,7 @@ namespace QueryStageCount { OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::DBLock _dbLock; - Client::Context _ctx; + OldClientContext _ctx; Collection* _coll; }; diff --git a/src/mongo/dbtests/query_stage_count_scan.cpp b/src/mongo/dbtests/query_stage_count_scan.cpp index f972df3ba22..523bde78664 100644 --- a/src/mongo/dbtests/query_stage_count_scan.cpp +++ b/src/mongo/dbtests/query_stage_count_scan.cpp @@ -29,16 +29,17 @@ #include <boost/shared_ptr.hpp> #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" -#include "mongo/db/exec/keep_mutations.h" #include "mongo/db/exec/count_scan.h" +#include "mongo/db/exec/keep_mutations.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/fail_point.h" #include "mongo/util/fail_point_registry.h" @@ -55,7 +56,7 @@ namespace QueryStageCountScan { } virtual ~CountBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -110,7 +111,7 @@ namespace QueryStageCountScan { class QueryStageCountScanDups : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert some docs insert(BSON("a" << BSON_ARRAY(5 << 7))); @@ -142,7 +143,7 @@ namespace QueryStageCountScan { class QueryStageCountScanInclusiveBounds : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert some docs for (int i = 0; i < 10; ++i) { @@ -174,7 +175,7 @@ namespace QueryStageCountScan { class QueryStageCountScanExclusiveBounds : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert some docs for (int i = 0; i < 10; ++i) { @@ -206,7 +207,7 @@ namespace QueryStageCountScan { class QueryStageCountScanLowerBound : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert doc, add index insert(BSON("a" << 2)); @@ -234,7 +235,7 @@ namespace QueryStageCountScan { class QueryStageCountScanNothingInInterval : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert documents, add index insert(BSON("a" << 2)); @@ -264,7 +265,7 @@ namespace QueryStageCountScan { class QueryStageCountScanNothingInIntervalFirstMatchTooHigh : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert some documents, add index insert(BSON("a" << 2)); @@ -294,7 +295,7 @@ namespace QueryStageCountScan { class QueryStageCountScanNoChangeDuringYield : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert documents, add index for (int i = 0; i < 10; ++i) { @@ -345,7 +346,7 @@ namespace QueryStageCountScan { class QueryStageCountScanDeleteDuringYield : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert documents, add index for (int i = 0; i < 10; ++i) { @@ -399,7 +400,7 @@ namespace QueryStageCountScan { class QueryStageCountScanInsertNewDocsDuringYield : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert documents, add index for (int i = 0; i < 10; ++i) { @@ -456,7 +457,7 @@ namespace QueryStageCountScan { class QueryStageCountScanBecomesMultiKeyDuringYield : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert documents, add index for (int i = 0; i < 10; ++i) { @@ -509,7 +510,7 @@ namespace QueryStageCountScan { class QueryStageCountScanUnusedKeys : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert docs, add index for (int i = 0; i < 10; ++i) { @@ -544,7 +545,7 @@ namespace QueryStageCountScan { class QueryStageCountScanUnusedEndKey : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert docs, add index for (int i = 0; i < 10; ++i) { @@ -577,7 +578,7 @@ namespace QueryStageCountScan { class QueryStageCountScanKeyBecomesUnusedDuringYield : public CountBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Insert documents, add index for (int i = 0; i < 10; ++i) { diff --git a/src/mongo/dbtests/query_stage_delete.cpp b/src/mongo/dbtests/query_stage_delete.cpp index 5a2385887ce..970fe9fd527 100644 --- a/src/mongo/dbtests/query_stage_delete.cpp +++ b/src/mongo/dbtests/query_stage_delete.cpp @@ -34,6 +34,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/delete.h" @@ -52,7 +53,7 @@ namespace QueryStageDelete { class QueryStageDeleteBase { public: QueryStageDeleteBase() : _client(&_txn) { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); for (size_t i = 0; i < numObj(); ++i) { BSONObjBuilder bob; @@ -62,7 +63,7 @@ namespace QueryStageDelete { } virtual ~QueryStageDeleteBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -111,7 +112,7 @@ namespace QueryStageDelete { class QueryStageDeleteInvalidateUpcomingObject : public QueryStageDeleteBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Collection* coll = ctx.getCollection(); diff --git a/src/mongo/dbtests/query_stage_distinct.cpp b/src/mongo/dbtests/query_stage_distinct.cpp index 3029464cfd1..f7c85764bb0 100644 --- a/src/mongo/dbtests/query_stage_distinct.cpp +++ b/src/mongo/dbtests/query_stage_distinct.cpp @@ -27,7 +27,9 @@ */ #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/distinct_scan.h" #include "mongo/db/exec/plan_stage.h" @@ -35,7 +37,6 @@ #include "mongo/db/operation_context_impl.h" #include "mongo/db/query/index_bounds_builder.h" #include "mongo/db/query/plan_executor.h" -#include "mongo/db/catalog/collection.h" #include "mongo/dbtests/dbtests.h" /** diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index 303082dfa84..c8617a59acf 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -33,7 +33,9 @@ #include <boost/shared_ptr.hpp> #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/fetch.h" #include "mongo/db/exec/plan_stage.h" @@ -41,7 +43,6 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" #include "mongo/dbtests/dbtests.h" namespace QueryStageFetch { @@ -91,7 +92,7 @@ namespace QueryStageFetch { class FetchStageAlreadyFetched : public QueryStageFetchBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -153,7 +154,7 @@ namespace QueryStageFetch { void run() { ScopedTransaction transaction(&_txn, MODE_IX); Lock::DBLock lk(_txn.lockState(), nsToDatabaseSubstring(ns()), MODE_X); - Client::Context ctx(&_txn, ns()); + OldClientContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { diff --git a/src/mongo/dbtests/query_stage_ixscan.cpp b/src/mongo/dbtests/query_stage_ixscan.cpp index 1bd44f78ff5..c0db9cbc1ed 100644 --- a/src/mongo/dbtests/query_stage_ixscan.cpp +++ b/src/mongo/dbtests/query_stage_ixscan.cpp @@ -27,6 +27,7 @@ */ #include "mongo/db/client.h" +#include "mongo/db/db_raii.h" #include "mongo/db/exec/index_scan.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/jsobj.h" @@ -141,7 +142,7 @@ namespace QueryStageIxscan { ScopedTransaction _scopedXact; Lock::DBLock _dbLock; - Client::Context _ctx; + OldClientContext _ctx; Collection* _coll; WorkingSet _ws; diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp index 2b9695127c3..f78a2977300 100644 --- a/src/mongo/dbtests/query_stage_keep.cpp +++ b/src/mongo/dbtests/query_stage_keep.cpp @@ -33,7 +33,9 @@ #include <boost/shared_ptr.hpp> #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/eof.h" @@ -43,7 +45,6 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/fail_point.h" #include "mongo/util/fail_point_registry.h" @@ -108,7 +109,7 @@ namespace QueryStageKeep { class KeepStageBasic : public QueryStageKeepBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -172,7 +173,7 @@ namespace QueryStageKeep { class KeepStageFlagAdditionalAfterStreamingStarts : public QueryStageKeepBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp index d1b3688fdd9..4685c53b084 100644 --- a/src/mongo/dbtests/query_stage_merge_sort.cpp +++ b/src/mongo/dbtests/query_stage_merge_sort.cpp @@ -27,16 +27,17 @@ */ #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/fetch.h" #include "mongo/db/exec/index_scan.h" -#include "mongo/db/exec/plan_stage.h" #include "mongo/db/exec/merge_sort.h" +#include "mongo/db/exec/plan_stage.h" #include "mongo/db/json.h" -#include "mongo/db/query/plan_executor.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" +#include "mongo/db/query/plan_executor.h" #include "mongo/dbtests/dbtests.h" /** @@ -56,7 +57,7 @@ namespace QueryStageMergeSortTests { } virtual ~QueryStageMergeSortTestBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -113,7 +114,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortPrefixIndex : public QueryStageMergeSortTestBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -182,7 +183,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortDups : public QueryStageMergeSortTestBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -250,7 +251,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortDupsNoDedup : public QueryStageMergeSortTestBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -319,7 +320,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortPrefixIndexReverse : public QueryStageMergeSortTestBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -389,7 +390,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortOneStageEOF : public QueryStageMergeSortTestBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -457,7 +458,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortManyShort : public QueryStageMergeSortTestBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -515,7 +516,7 @@ namespace QueryStageMergeSortTests { class QueryStageMergeSortInvalidation : public QueryStageMergeSortTestBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp index 841044639ff..b2a484f7add 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -27,16 +27,17 @@ */ #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/fetch.h" #include "mongo/db/exec/plan_stage.h" #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/sort.h" #include "mongo/db/json.h" -#include "mongo/db/query/plan_executor.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/db/catalog/collection.h" +#include "mongo/db/query/plan_executor.h" #include "mongo/dbtests/dbtests.h" /** @@ -220,7 +221,7 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -240,7 +241,7 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -269,7 +270,7 @@ namespace QueryStageSortTests { virtual int numObj() { return 10000; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -290,7 +291,7 @@ namespace QueryStageSortTests { virtual int limit() const { return 10; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -396,7 +397,7 @@ namespace QueryStageSortTests { virtual int numObj() { return 2000; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { @@ -493,7 +494,7 @@ namespace QueryStageSortTests { virtual int numObj() { return 100; } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Database* db = ctx.db(); Collection* coll = db->getCollection(ns()); if (!coll) { diff --git a/src/mongo/dbtests/query_stage_subplan.cpp b/src/mongo/dbtests/query_stage_subplan.cpp index 9a564c60b47..34dce80ca57 100644 --- a/src/mongo/dbtests/query_stage_subplan.cpp +++ b/src/mongo/dbtests/query_stage_subplan.cpp @@ -28,6 +28,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/subplan.h" #include "mongo/db/jsobj.h" @@ -45,7 +46,7 @@ namespace QueryStageSubplan { : _client(&_txn) { } virtual ~QueryStageSubplanBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -75,7 +76,7 @@ namespace QueryStageSubplan { class QueryStageSubplanGeo2dOr : public QueryStageSubplanBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); addIndex(BSON("a" << "2d" << "b" << 1)); addIndex(BSON("a" << "2d")); @@ -108,7 +109,7 @@ namespace QueryStageSubplan { class QueryStageSubplanPlanFromCache : public QueryStageSubplanBase { public: void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); addIndex(BSON("a" << 1 << "b" << 1)); addIndex(BSON("a" << 1 << "c" << 1)); diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp index 71490621109..83298723775 100644 --- a/src/mongo/dbtests/query_stage_tests.cpp +++ b/src/mongo/dbtests/query_stage_tests.cpp @@ -27,7 +27,9 @@ */ #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/index_scan.h" #include "mongo/db/exec/plan_stage.h" @@ -35,7 +37,6 @@ #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/operation_context_impl.h" #include "mongo/db/query/plan_executor.h" -#include "mongo/db/catalog/collection.h" #include "mongo/dbtests/dbtests.h" /** @@ -49,7 +50,7 @@ namespace QueryStageTests { class IndexScanBase { public: IndexScanBase() : _client(&_txn) { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); for (int i = 0; i < numObj(); ++i) { BSONObjBuilder bob; @@ -64,7 +65,7 @@ namespace QueryStageTests { } virtual ~IndexScanBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -100,7 +101,7 @@ namespace QueryStageTests { } void makeGeoData() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); for (int i = 0; i < numObj(); ++i) { double lat = double(rand()) / RAND_MAX; diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp index 1fbf1647d5c..752cb6d7dc5 100644 --- a/src/mongo/dbtests/query_stage_update.cpp +++ b/src/mongo/dbtests/query_stage_update.cpp @@ -34,6 +34,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/eof.h" @@ -60,13 +61,13 @@ namespace QueryStageUpdate { : _client(&_txn), _ns("unittests.QueryStageUpdate"), _nsString(StringData(ns())) { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); _client.createCollection(ns()); } virtual ~QueryStageUpdateBase() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); _client.dropCollection(ns()); } @@ -186,7 +187,7 @@ namespace QueryStageUpdate { void run() { // Run the update. { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); Client& c = cc(); CurOp& curOp = *c.curop(); OpDebug* opDebug = &curOp.debug(); @@ -248,7 +249,7 @@ namespace QueryStageUpdate { void run() { // Run the update. { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // Populate the collection. for (int i = 0; i < 10; ++i) { diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index 9cd30c38ec4..cdc3dcd244d 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -33,7 +33,9 @@ #include <iostream> #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/clientcursor.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_environment_d.h" @@ -41,10 +43,9 @@ #include "mongo/db/global_optime.h" #include "mongo/db/json.h" #include "mongo/db/lasterror.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/find.h" #include "mongo/db/query/lite_parsed_query.h" -#include "mongo/db/catalog/collection.h" -#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/timer.h" @@ -125,7 +126,7 @@ namespace QueryTests { OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::GlobalWrite _lk; - Client::Context _context; + OldClientContext _context; Database* _database; Collection* _collection; @@ -183,7 +184,7 @@ namespace QueryTests { // an empty object (one might be allowed inside a reserved namespace at some point). ScopedTransaction transaction(&_txn, MODE_X); Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, "unittests.querytests" ); + OldClientContext ctx(&_txn, "unittests.querytests" ); { WriteUnitOfWork wunit(&_txn); @@ -276,7 +277,7 @@ namespace QueryTests { { // Check internal server handoff to getmore. - Client::WriteContext ctx(&_txn, ns); + OldClientWriteContext ctx(&_txn, ns); ClientCursorPin clientCursor( ctx.getCollection()->getCursorManager(), cursorId ); // pq doesn't exist if it's a runner inside of the clientcursor. // ASSERT( clientCursor.c()->pq ); @@ -656,7 +657,7 @@ namespace QueryTests { const char *ns = "unittests.querytests.OplogReplaySlaveReadTill"; ScopedTransaction transaction(&_txn, MODE_IX); Lock::DBLock lk(_txn.lockState(), "unittests", MODE_X); - Client::Context ctx(&_txn, ns ); + OldClientContext ctx(&_txn, ns ); BSONObj info; _client.runCommand( "unittests", @@ -1096,7 +1097,7 @@ namespace QueryTests { void run() { ScopedTransaction transaction(&_txn, MODE_X); Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, "unittests.DirectLocking"); + OldClientContext ctx(&_txn, "unittests.DirectLocking"); _client.remove( "a.b", BSONObj() ); ASSERT_EQUALS( "unittests", ctx.db()->name() ); } @@ -1221,7 +1222,7 @@ namespace QueryTests { } void run() { string err; - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); // note that extents are always at least 4KB now - so this will get rounded up // a bit. @@ -1275,7 +1276,7 @@ namespace QueryTests { } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); for ( int i=0; i<50; i++ ) { insert( ns() , BSON( "_id" << i << "x" << i * 2 ) ); @@ -1326,7 +1327,7 @@ namespace QueryTests { } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); for ( int i=0; i<1000; i++ ) { insert( ns() , BSON( "_id" << i << "x" << i * 2 ) ); @@ -1349,7 +1350,7 @@ namespace QueryTests { } void run() { - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); for ( int i=0; i<1000; i++ ) { insert( ns() , BSON( "_id" << i << "x" << i * 2 ) ); @@ -1487,7 +1488,7 @@ namespace QueryTests { private: ScopedTransaction _scopedXact; Lock::DBLock _lk; - Client::Context _ctx; + OldClientContext _ctx; }; class Exhaust : public CollectionInternalBase { @@ -1565,7 +1566,7 @@ namespace QueryTests { long long cursorId = cursor->getCursorId(); { - Client::WriteContext ctx(&_txn, ns() ); + OldClientWriteContext ctx(&_txn, ns() ); ClientCursorPin pinCursor( ctx.db()->getCollection( ns() ) ->getCursorManager(), cursorId ); diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp index 8e976261c5f..8b85906cf18 100644 --- a/src/mongo/dbtests/repltests.cpp +++ b/src/mongo/dbtests/repltests.cpp @@ -35,20 +35,20 @@ #include "mongo/bson/mutable/document.h" #include "mongo/bson/mutable/mutable_bson_test_utils.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" +#include "mongo/db/ops/update.h" #include "mongo/db/repl/master_slave.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/repl/replication_coordinator_mock.h" #include "mongo/db/repl/sync.h" -#include "mongo/db/ops/update.h" -#include "mongo/db/catalog/collection.h" -#include "mongo/db/operation_context_impl.h" -#include "mongo/util/log.h" - #include "mongo/dbtests/dbtests.h" +#include "mongo/util/log.h" using namespace mongo::repl; @@ -82,7 +82,7 @@ namespace ReplTests { setOplogCollectionName(); createOplog(&_txn); - Client::WriteContext ctx(&_txn, ns()); + OldClientWriteContext ctx(&_txn, ns()); WriteUnitOfWork wuow(&_txn); Collection* c = ctx.db()->getCollection(ns()); @@ -139,7 +139,7 @@ namespace ReplTests { int count() const { ScopedTransaction transaction(&_txn, MODE_X); Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, ns() ); + OldClientContext ctx(&_txn, ns() ); Database* db = ctx.db(); Collection* coll = db->getCollection( ns() ); if ( !coll ) { @@ -159,7 +159,7 @@ namespace ReplTests { int opCount() { ScopedTransaction transaction(&_txn, MODE_X); Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, cllNS() ); + OldClientContext ctx(&_txn, cllNS() ); Database* db = ctx.db(); Collection* coll = db->getCollection( cllNS() ); @@ -182,7 +182,7 @@ namespace ReplTests { Lock::GlobalWrite lk(_txn.lockState()); vector< BSONObj > ops; { - Client::Context ctx(&_txn, cllNS() ); + OldClientContext ctx(&_txn, cllNS() ); Database* db = ctx.db(); Collection* coll = db->getCollection( cllNS() ); @@ -194,7 +194,7 @@ namespace ReplTests { delete it; } { - Client::Context ctx(&_txn, ns() ); + OldClientContext ctx(&_txn, ns() ); BSONObjBuilder b; b.append("host", "localhost"); b.appendTimestamp("syncedTo", 0); @@ -210,7 +210,7 @@ namespace ReplTests { void printAll( const char *ns ) { ScopedTransaction transaction(&_txn, MODE_X); Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, ns ); + OldClientContext ctx(&_txn, ns ); Database* db = ctx.db(); Collection* coll = db->getCollection( ns ); @@ -232,7 +232,7 @@ namespace ReplTests { void deleteAll( const char *ns ) const { ScopedTransaction transaction(&_txn, MODE_X); Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, ns ); + OldClientContext ctx(&_txn, ns ); WriteUnitOfWork wunit(&_txn); Database* db = ctx.db(); Collection* coll = db->getCollection( ns ); @@ -254,7 +254,7 @@ namespace ReplTests { void insert( const BSONObj &o ) const { ScopedTransaction transaction(&_txn, MODE_X); Lock::GlobalWrite lk(_txn.lockState()); - Client::Context ctx(&_txn, ns() ); + OldClientContext ctx(&_txn, ns() ); WriteUnitOfWork wunit(&_txn); Database* db = ctx.db(); Collection* coll = db->getCollection( ns() ); @@ -1425,7 +1425,7 @@ namespace ReplTests { try { Sync badSource("localhost:123"); - Client::Context ctx(&_txn, ns()); + OldClientContext ctx(&_txn, ns()); badSource.getMissingDoc(&_txn, ctx.db(), o); } catch (DBException&) { diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp index b28ce38755b..2f3180f749a 100644 --- a/src/mongo/dbtests/rollbacktests.cpp +++ b/src/mongo/dbtests/rollbacktests.cpp @@ -36,6 +36,7 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/head_manager.h" #include "mongo/db/catalog/index_create.h" +#include "mongo/db/db_raii.h" #include "mongo/db/operation_context_impl.h" #include "mongo/db/record_id.h" #include "mongo/dbtests/dbtests.h" @@ -57,7 +58,7 @@ namespace { dropDatabase( txn, db ); } } - bool collectionExists( Client::Context* ctx, const string& ns ) { + bool collectionExists( OldClientContext* ctx, const string& ns ) { const DatabaseCatalogEntry* dbEntry = ctx->db()->getDatabaseCatalogEntry(); list<string> names; dbEntry->getCollectionNamespaces( &names ); @@ -66,7 +67,7 @@ namespace { void createCollection( OperationContext* txn, const NamespaceString& nss ) { ScopedTransaction transaction( txn, MODE_IX ); Lock::DBLock dbXLock( txn->lockState(), nss.db(), MODE_X ); - Client::Context ctx( txn, nss.ns() ); + OldClientContext ctx( txn, nss.ns() ); { WriteUnitOfWork uow( txn ); ASSERT( !collectionExists( &ctx, nss.ns() ) ); @@ -162,7 +163,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dbXLock( txn.lockState(), nss.db(), MODE_X ); - Client::Context ctx( &txn, ns ); + OldClientContext ctx( &txn, ns ); { WriteUnitOfWork uow( &txn ); ASSERT( !collectionExists( &ctx, ns ) ); @@ -192,7 +193,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dbXLock( txn.lockState(), nss.db(), MODE_X ); - Client::Context ctx( &txn, ns ); + OldClientContext ctx( &txn, ns ); { WriteUnitOfWork uow( &txn ); ASSERT( !collectionExists( &ctx, ns ) ); @@ -234,7 +235,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_X); Lock::GlobalWrite globalWriteLock( txn.lockState() ); - Client::Context ctx( &txn, source ); + OldClientContext ctx( &txn, source ); { WriteUnitOfWork uow( &txn ); @@ -282,7 +283,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_X); Lock::GlobalWrite globalWriteLock( txn.lockState() ); - Client::Context ctx( &txn, source ); + OldClientContext ctx( &txn, source ); BSONObj sourceDoc = BSON( "_id" << "source" ); BSONObj targetDoc = BSON( "_id" << "target" ); @@ -343,7 +344,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dbXLock( txn.lockState(), nss.db(), MODE_X ); - Client::Context ctx( &txn, nss ); + OldClientContext ctx( &txn, nss ); BSONObj oldDoc = BSON( "_id" << "old" ); BSONObj newDoc = BSON( "_id" << "new" ); @@ -394,7 +395,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dbXLock( txn.lockState(), nss.db(), MODE_X ); - Client::Context ctx( &txn, nss ); + OldClientContext ctx( &txn, nss ); BSONObj doc = BSON( "_id" << "example string" ); @@ -429,7 +430,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dbXLock( txn.lockState(), nss.db(), MODE_X ); - Client::Context ctx( &txn, nss ); + OldClientContext ctx( &txn, nss ); BSONObj doc = BSON( "_id" << "foo" ); @@ -680,7 +681,7 @@ namespace { ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock dbXLock( txn.lockState(), nss.db(), MODE_X ); - Client::Context ctx( &txn, nss.ns() ); + OldClientContext ctx( &txn, nss.ns() ); string idxNameA = "indexA"; string idxNameB = "indexB"; diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 46967e8bed5..8cecd9461be 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -57,20 +57,21 @@ #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" #include "mongo/db/concurrency/lock_state.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/exec/plan_stage.h" -#include "mongo/db/storage/mmap_v1/dur.h" #include "mongo/db/field_parser.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/hasher.h" #include "mongo/db/jsobj.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/delete.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/query/query_knobs.h" #include "mongo/db/range_deleter_service.h" #include "mongo/db/repl/replication_coordinator_global.h" -#include "mongo/db/operation_context_impl.h" +#include "mongo/db/storage/mmap_v1/dur.h" #include "mongo/db/write_concern.h" #include "mongo/logger/ramlog.h" #include "mongo/s/catalog/catalog_manager.h" @@ -375,7 +376,7 @@ namespace mongo { if (op == 'u') { BSONObj fullDoc; - Client::Context ctx(txn, _ns); + OldClientContext ctx(txn, _ns); if (!Helpers::findById(txn, ctx.db(), _ns.c_str(), idObj, fullDoc)) { warning() << "logOpForSharding couldn't find: " << idObj << " even though should have" << migrateLog; @@ -1951,7 +1952,7 @@ namespace mongo { { // 0. copy system.namespaces entry if collection doesn't already exist - Client::WriteContext ctx(txn, ns ); + OldClientWriteContext ctx(txn, ns ); if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( nsToDatabaseSubstring(ns))) { @@ -2000,7 +2001,7 @@ namespace mongo { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock lk(txn->lockState(), nsToDatabaseSubstring(ns), MODE_X); - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( nsToDatabaseSubstring(ns))) { errmsg = str::stream() << "Not primary during migration: " << ns; @@ -2160,7 +2161,7 @@ namespace mongo { BSONObj docToClone = i.next().Obj(); { - Client::WriteContext cx(txn, ns ); + OldClientWriteContext cx(txn, ns ); BSONObj localDoc; if (willOverrideLocalId(txn, @@ -2405,7 +2406,7 @@ namespace mongo { BSONObjIterator i( xfer["deleted"].Obj() ); while ( i.more() ) { Lock::CollectionLock clk(txn->lockState(), ns, MODE_X); - Client::Context ctx(txn, ns); + OldClientContext ctx(txn, ns); BSONObj id = i.next().Obj(); @@ -2441,7 +2442,7 @@ namespace mongo { if ( xfer["reload"].isABSONObj() ) { BSONObjIterator i( xfer["reload"].Obj() ); while ( i.more() ) { - Client::WriteContext cx(txn, ns); + OldClientWriteContext cx(txn, ns); BSONObj updatedDoc = i.next().Obj(); diff --git a/src/mongo/s/d_split.cpp b/src/mongo/s/d_split.cpp index e4816822502..3c9975c87a0 100644 --- a/src/mongo/s/d_split.cpp +++ b/src/mongo/s/d_split.cpp @@ -40,11 +40,12 @@ #include "mongo/client/dbclientcursor.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" -#include "mongo/db/auth/privilege.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_session.h" +#include "mongo/db/auth/privilege.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" +#include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/index_legacy.h" #include "mongo/db/instance.h" diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index eb3dca62040..3f942f6a748 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -44,28 +44,29 @@ #include <string> #include <vector> +#include "mongo/client/connpool.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/commands.h" -#include "mongo/db/jsobj.h" #include "mongo/db/db.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/jsobj.h" #include "mongo/db/operation_context.h" -#include "mongo/db/wire_version.h" #include "mongo/db/repl/replication_coordinator_global.h" -#include "mongo/client/connpool.h" +#include "mongo/db/wire_version.h" #include "mongo/s/chunk_version.h" #include "mongo/s/client/shard_connection.h" #include "mongo/s/config.h" #include "mongo/s/grid.h" #include "mongo/s/metadata_loader.h" #include "mongo/s/stale_exception.h" -#include "mongo/util/queue.h" #include "mongo/util/concurrency/mutex.h" #include "mongo/util/concurrency/ticketholder.h" #include "mongo/util/log.h" +#include "mongo/util/queue.h" #include "mongo/util/stringutils.h" namespace mongo { @@ -1301,7 +1302,7 @@ namespace mongo { bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); - Client::Context ctx(txn, dbname); + OldClientContext ctx(txn, dbname); shardingState.appendInfo( result ); return true; diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index c6bc28e5d8f..3a4fd229ac7 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -112,7 +112,6 @@ namespace mongo { static ExitCode initService(); #endif - Database *database = 0; string mongosCommand; bool dbexitCalled = false; |