diff options
author | Eric Milkie <milkie@10gen.com> | 2016-04-19 08:28:56 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2016-04-19 08:28:56 -0400 |
commit | 35ea899074d1bf93e78177cac1155b4471cbaa7d (patch) | |
tree | fce52bf3d3b3fcd270d33ab228babf6ea6602e22 | |
parent | 0ab34aa7b9c3c48ea6cf17888620fca455284d35 (diff) | |
download | mongo-35ea899074d1bf93e78177cac1155b4471cbaa7d.tar.gz |
Revert "SERVER-23779 Replace direct instantiation of OperationContextImpl with cc().makeOperationContext()."
This reverts commit 0ab34aa7b9c3c48ea6cf17888620fca455284d35.
89 files changed, 241 insertions, 373 deletions
diff --git a/src/mongo/db/auth/auth_index_d.cpp b/src/mongo/db/auth/auth_index_d.cpp index ac3d38ebf03..546df4c1da9 100644 --- a/src/mongo/db/auth/auth_index_d.cpp +++ b/src/mongo/db/auth/auth_index_d.cpp @@ -28,8 +28,6 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kAccessControl -#include "mongo/platform/basic.h" - #include "mongo/db/auth/auth_index_d.h" #include "mongo/base/init.h" @@ -39,10 +37,10 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/client.h" -#include "mongo/db/client.h" -#include "mongo/db/db_raii.h" #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/catalog/apply_ops.cpp b/src/mongo/db/catalog/apply_ops.cpp index 39a6ee25740..df7f90cb7b6 100644 --- a/src/mongo/db/catalog/apply_ops.cpp +++ b/src/mongo/db/catalog/apply_ops.cpp @@ -41,6 +41,7 @@ #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/matcher/matcher.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/service_context.h" diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp index b11a17dd1cd..4b1e983ecd5 100644 --- a/src/mongo/db/catalog/capped_utils.cpp +++ b/src/mongo/db/catalog/capped_utils.cpp @@ -43,6 +43,7 @@ #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" #include "mongo/db/index_builder.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/query/plan_yield_policy.h" #include "mongo/db/repl/replication_coordinator_global.h" diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 32bc00edf90..857ba7252a9 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -41,6 +41,7 @@ #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" #include "mongo/db/index_builder.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/server_options.h" #include "mongo/db/service_context.h" diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp index 8b8a992ce5e..5db42695d78 100644 --- a/src/mongo/db/catalog/drop_database.cpp +++ b/src/mongo/db/catalog/drop_database.cpp @@ -42,6 +42,7 @@ #include "mongo/db/db_raii.h" #include "mongo/db/index_builder.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/service_context.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp index 52081f2976b..9dab496b5c4 100644 --- a/src/mongo/db/clientcursor.cpp +++ b/src/mongo/db/clientcursor.cpp @@ -46,6 +46,7 @@ #include "mongo/db/commands/server_status.h" #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/jsobj.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/server_parameters.h" @@ -269,8 +270,7 @@ public: const int Secs = 4; while (!inShutdown()) { { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; cursorStatsTimedOut.increment( CursorManager::timeoutCursorsGlobal(&txn, t.millisReset())); } diff --git a/src/mongo/db/commands/clone_collection.cpp b/src/mongo/db/commands/clone_collection.cpp index 63d4b193605..85bd9c6b1ab 100644 --- a/src/mongo/db/commands/clone_collection.cpp +++ b/src/mongo/db/commands/clone_collection.cpp @@ -50,6 +50,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/db/repl/isself.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/insert.h" #include "mongo/db/storage/storage_options.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 59866778ab1..03d8552e2ae 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -39,6 +39,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/index_builder.h" #include "mongo/db/op_observer.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" diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index bc8061dfaa5..a87f2167be6 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -45,6 +45,7 @@ #include "mongo/db/db_raii.h" #include "mongo/db/index_builder.h" #include "mongo/db/jsobj.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index c5e67f6c833..6032aa2c340 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -41,6 +41,7 @@ #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" #include "mongo/db/service_context.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/op_observer.h" #include "mongo/db/ops/insert.h" #include "mongo/db/repl/repl_client_info.h" diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 7bd1c824102..950cf437750 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -53,6 +53,7 @@ #include "mongo/db/index/index_descriptor.h" #include "mongo/db/index_builder.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp index 0cb5f32f83f..d8545f0853d 100644 --- a/src/mongo/db/commands/fsync.cpp +++ b/src/mongo/db/commands/fsync.cpp @@ -39,6 +39,7 @@ #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/audit.h" +#include "mongo/db/db.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/authorization_manager.h" @@ -48,7 +49,7 @@ #include "mongo/db/commands.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" -#include "mongo/db/db.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/mmap_v1/dur.h" #include "mongo/db/storage/storage_engine.h" @@ -232,8 +233,7 @@ SimpleMutex filesLockedFsync; void FSyncLockThread::doRealWork() { stdx::lock_guard<SimpleMutex> lkf(filesLockedFsync); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_X); Lock::GlobalWrite global(txn.lockState()); // No WriteUnitOfWork needed diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index 0a3bd23ac88..9e5e6259d3e 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -41,7 +41,6 @@ #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/document_validation.h" -#include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -49,23 +48,24 @@ #include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/exec/working_set_common.h" +#include "mongo/db/service_context.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/instance.h" -#include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/matcher/matcher.h" +#include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/namespace_string.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/insert.h" -#include "mongo/db/query/find_common.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/query_planner.h" +#include "mongo/db/query/find_common.h" #include "mongo/db/range_preserver.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/s/collection_metadata.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/s/sharding_state.h" -#include "mongo/db/service_context.h" #include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/chunk_manager.h" #include "mongo/s/client/shard_registry.h" diff --git a/src/mongo/db/commands/rename_collection_cmd.cpp b/src/mongo/db/commands/rename_collection_cmd.cpp index 8b764169ad9..eb42664c57b 100644 --- a/src/mongo/db/commands/rename_collection_cmd.cpp +++ b/src/mongo/db/commands/rename_collection_cmd.cpp @@ -45,6 +45,7 @@ #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/insert.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/scopeguard.h" diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index f7fc056a931..58d554cef84 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -44,6 +44,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/index_builder.h" #include "mongo/db/op_observer.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" diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp index 0ad5056ccad..520f74e64a1 100644 --- a/src/mongo/db/commands/touch.cpp +++ b/src/mongo/db/commands/touch.cpp @@ -46,6 +46,7 @@ #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" #include "mongo/util/touch_pages.h" diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index 0037eba6d58..12e9cb7209a 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -33,9 +33,9 @@ #include "mongo/platform/basic.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/operation_context_impl.h" #include "mongo/db/query/internal_plans.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp index d1ff24fdecb..b347c5de7d2 100644 --- a/src/mongo/db/index_builder.cpp +++ b/src/mongo/db/index_builder.cpp @@ -40,6 +40,7 @@ #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" #include "mongo/util/mongoutils/str.h" @@ -81,8 +82,7 @@ void IndexBuilder::run() { Client::initThread(name().c_str()); LOG(2) << "IndexBuilder building index " << _index; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; txn.lockState()->setIsBatchWriter(true); AuthorizationSession::get(txn.getClient())->grantInternalAuthorization(); diff --git a/src/mongo/db/index_rebuilder.cpp b/src/mongo/db/index_rebuilder.cpp index cbc90157404..d416d9fe087 100644 --- a/src/mongo/db/index_rebuilder.cpp +++ b/src/mongo/db/index_rebuilder.cpp @@ -45,6 +45,7 @@ #include "mongo/db/db_raii.h" #include "mongo/db/service_context.h" #include "mongo/db/instance.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 947f0485c2c..d3cac033950 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -42,7 +42,6 @@ #include "mongo/db/auth/authz_manager_external_state_d.h" #include "mongo/db/background.h" #include "mongo/db/catalog/index_create.h" -#include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" #include "mongo/db/commands/fsync.h" @@ -67,6 +66,7 @@ #include "mongo/db/mongod_options.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_request.h" #include "mongo/db/ops/insert.h" #include "mongo/db/ops/parsed_delete.h" diff --git a/src/mongo/db/operation_context_impl.h b/src/mongo/db/operation_context_impl.h index e3474939d7b..b24772d1313 100644 --- a/src/mongo/db/operation_context_impl.h +++ b/src/mongo/db/operation_context_impl.h @@ -35,6 +35,8 @@ namespace mongo { class OperationContextImpl : public OperationContext { public: + OperationContextImpl(); + virtual ~OperationContextImpl(); virtual RecoveryUnit* recoveryUnit() const override; @@ -61,10 +63,6 @@ public: virtual bool writesAreReplicated() const override; private: - friend class ServiceContextMongoD; - - OperationContextImpl(); - std::unique_ptr<RecoveryUnit> _recovery; bool _writesAreReplicated; }; diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp index 94caffaed71..df64f72b232 100644 --- a/src/mongo/db/ops/update.cpp +++ b/src/mongo/db/ops/update.cpp @@ -38,11 +38,11 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" -#include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/exec/update.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/op_observer.h" #include "mongo/db/ops/update_driver.h" #include "mongo/db/ops/update_lifecycle.h" diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index cd25fbe664f..4e1b724d767 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -42,6 +42,7 @@ #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/dbhelpers.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/oplog_interface_local.h" #include "mongo/db/repl/replication_coordinator_global.h" @@ -247,8 +248,7 @@ void BackgroundSync::_producerThread() { } // we want to start when we're no longer primary // start() also loads _lastOpTimeFetched, which we know is set from the "if" - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; if (isStopped()) { start(&txn); } diff --git a/src/mongo/db/repl/initial_sync.cpp b/src/mongo/db/repl/initial_sync.cpp index c1e9c9269ce..09553e3d93e 100644 --- a/src/mongo/db/repl/initial_sync.cpp +++ b/src/mongo/db/repl/initial_sync.cpp @@ -32,15 +32,17 @@ #include "mongo/db/repl/initial_sync.h" -#include "mongo/db/client.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/optime.h" -#include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator_global.h" +#include "mongo/db/repl/repl_client_info.h" + #include "mongo/util/exit.h" #include "mongo/util/log.h" + namespace mongo { namespace repl { diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index 4aa6ed40159..e716cf58b3e 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -51,13 +51,13 @@ #include "mongo/db/catalog/database_catalog_entry.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/document_validation.h" -#include "mongo/db/client.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/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" @@ -1274,8 +1274,7 @@ static void replMasterThread() { // Write a keep-alive like entry to the log. This will make things like // printReplicationStatus() and printSlaveReplicationStatus() stay up-to-date even // when things are idle. - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; AuthorizationSession::get(txn.getClient())->grantInternalAuthorization(); Lock::GlobalWrite globalWrite(txn.lockState(), 1); @@ -1300,8 +1299,7 @@ static void replSlaveThread() { sleepsecs(1); Client::initThread("replslave"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; AuthorizationSession::get(txn.getClient())->grantInternalAuthorization(); DisableDocumentValidation validationDisabler(&txn); @@ -1358,8 +1356,7 @@ int _dummy_z; void pretouchN(vector<BSONObj>& v, unsigned a, unsigned b) { Client::initThreadIfNotAlready("pretouchN"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; // XXX + OperationContextImpl txn; // XXX ScopedTransaction transaction(&txn, MODE_S); Lock::GlobalRead lk(txn.lockState()); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 5acc636c0cb..e0a7aa19737 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -41,21 +41,20 @@ #include "mongo/bson/util/bson_extract.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_manager_global.h" +#include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/background.h" #include "mongo/db/catalog/apply_ops.h" #include "mongo/db/catalog/capped_utils.h" #include "mongo/db/catalog/coll_mod.h" -#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog_entry.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/create_collection.h" #include "mongo/db/catalog/drop_collection.h" #include "mongo/db/catalog/drop_database.h" #include "mongo/db/catalog/drop_indexes.h" #include "mongo/db/catalog/rename_collection.h" -#include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/commands/dbhash.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -63,14 +62,15 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/global_timestamp.h" -#include "mongo/db/index/index_access_method.h" #include "mongo/db/index_builder.h" +#include "mongo/db/index/index_access_method.h" #include "mongo/db/keypattern.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/update.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/oplogreader.h" #include "mongo/db/repl/optime.h" @@ -81,8 +81,8 @@ #include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" #include "mongo/db/stats/counters.h" -#include "mongo/db/storage/storage_engine.h" #include "mongo/db/storage/storage_options.h" +#include "mongo/db/storage/storage_engine.h" #include "mongo/platform/random.h" #include "mongo/scripting/engine.h" #include "mongo/stdx/memory.h" 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 79eea7fcc31..c7ef3033c83 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -45,6 +45,7 @@ #include "mongo/db/dbhelpers.h" #include "mongo/db/jsobj.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/isself.h" #include "mongo/db/repl/last_vote.h" diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index 6c450ce34ba..9852803a3b3 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -32,13 +32,13 @@ #include <vector> #include "mongo/client/connpool.h" -#include "mongo/db/client.h" #include "mongo/db/commands/server_status.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/jsobj.h" #include "mongo/db/lasterror.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/repl/is_master_response.h" #include "mongo/db/repl/master_slave.h" diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp index cb4cd2826d5..88f99294755 100644 --- a/src/mongo/db/repl/rs_initialsync.cpp +++ b/src/mongo/db/repl/rs_initialsync.cpp @@ -45,6 +45,8 @@ #include "mongo/db/dbhelpers.h" #include "mongo/db/service_context.h" #include "mongo/db/op_observer.h" +#include "mongo/db/operation_context_impl.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/initial_sync.h" #include "mongo/db/repl/oplog.h" @@ -309,8 +311,7 @@ Status _initialSync() { log() << "initial sync pending"; BackgroundSync* bgsync(BackgroundSync::get()); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; txn.setReplicatedWrites(false); DisableDocumentValidation validationDisabler(&txn); ReplicationCoordinator* replCoord(getGlobalReplicationCoordinator()); @@ -466,8 +467,7 @@ void syncDoInitialSync() { } { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; createOplog(&txn); } diff --git a/src/mongo/db/repl/rs_sync.cpp b/src/mongo/db/repl/rs_sync.cpp index cc8eaa320e5..82762d3733e 100644 --- a/src/mongo/db/repl/rs_sync.cpp +++ b/src/mongo/db/repl/rs_sync.cpp @@ -52,6 +52,7 @@ #include "mongo/db/repl/sync_tail.h" #include "mongo/db/server_parameters.h" #include "mongo/db/stats/timer_stats.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/storage_options.h" #include "mongo/util/exit.h" #include "mongo/util/fail_point_service.h" diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp index ef9935ae86f..23f9d4ce0b7 100644 --- a/src/mongo/db/repl/storage_interface_impl.cpp +++ b/src/mongo/db/repl/storage_interface_impl.cpp @@ -38,7 +38,7 @@ #include "mongo/db/curop.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/jsobj.h" -#include "mongo/db/operation_context.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/service_context.h" #include "mongo/util/assert_util.h" diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp index 136978df15b..43a9b077d83 100644 --- a/src/mongo/db/repl/sync_source_feedback.cpp +++ b/src/mongo/db/repl/sync_source_feedback.cpp @@ -33,6 +33,7 @@ #include "mongo/db/repl/sync_source_feedback.h" #include "mongo/db/client.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/repl/bgsync.h" #include "mongo/db/repl/replica_set_config.h" #include "mongo/db/repl/replication_coordinator.h" diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index 0c8d5af2264..e6e9e69cca0 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -40,18 +40,18 @@ #include "mongo/base/counter.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/catalog/collection.h" -#include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" +#include "mongo/db/catalog/database.h" #include "mongo/db/catalog/document_validation.h" -#include "mongo/db/client.h" #include "mongo/db/commands/fsync.h" #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/dbhelpers.h" #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" -#include "mongo/db/dbhelpers.h" #include "mongo/db/global_timestamp.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/prefetch.h" #include "mongo/db/query/query_knobs.h" #include "mongo/db/repl/bgsync.h" @@ -418,8 +418,7 @@ void prefetchOp(const BSONObj& op) { try { // one possible tweak here would be to stay in the read lock for this database // for multiple prefetches if they are for the same database. - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; AutoGetCollectionForRead ctx(&txn, ns); Database* db = ctx.getDb(); if (db) { @@ -612,8 +611,7 @@ public: private: void run() { Client::initThread("ReplBatcher"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; auto replCoord = ReplicationCoordinator::get(&txn); while (!_inShutdown.load()) { @@ -685,8 +683,7 @@ private: void SyncTail::oplogApplication() { OpQueueBatcher batcher(this); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; auto replCoord = ReplicationCoordinator::get(&txn); std::unique_ptr<ApplyBatchFinalizer> finalizer{ getGlobalServiceContext()->getGlobalStorageEngine()->isDurable() @@ -986,8 +983,7 @@ void multiSyncApply(const std::vector<OplogEntry>& ops) { } initializeWriterThread(); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; txn.setReplicatedWrites(false); DisableDocumentValidation validationDisabler(&txn); @@ -1093,8 +1089,7 @@ void multiSyncApply(const std::vector<OplogEntry>& ops) { void multiInitialSyncApply(const std::vector<OplogEntry>& ops) { initializeWriterThread(); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; txn.setReplicatedWrites(false); DisableDocumentValidation validationDisabler(&txn); diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index ecb449e7adb..ea05ccacaf6 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -320,7 +320,7 @@ void ServiceContextMongoD::registerKillOpListener(KillOpListenerInterface* liste std::unique_ptr<OperationContext> ServiceContextMongoD::_newOpCtx(Client* client) { invariant(&cc() == client); - return std::unique_ptr<OperationContextImpl>(new OperationContextImpl()); + return stdx::make_unique<OperationContextImpl>(); } void ServiceContextMongoD::setOpObserver(std::unique_ptr<OpObserver> opObserver) { diff --git a/src/mongo/db/service_context_d_test_fixture.cpp b/src/mongo/db/service_context_d_test_fixture.cpp index a588a708ca5..b281cc8994e 100644 --- a/src/mongo/db/service_context_d_test_fixture.cpp +++ b/src/mongo/db/service_context_d_test_fixture.cpp @@ -32,13 +32,13 @@ #include "mongo/base/checked_cast.h" #include "mongo/db/catalog/database.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/db/operation_context.h" -#include "mongo/db/service_context.h" #include "mongo/db/service_context_d.h" +#include "mongo/db/service_context.h" #include "mongo/db/storage/storage_options.h" #include "mongo/unittest/temp_dir.h" @@ -63,19 +63,19 @@ void ServiceContextMongoDTest::tearDown() { } void ServiceContextMongoDTest::_dropAllDBs() { - const auto txn = cc().makeOperationContext(); - dropAllDatabasesExceptLocal(txn.get()); + OperationContextImpl txn; + dropAllDatabasesExceptLocal(&txn); - ScopedTransaction transaction(txn.get(), MODE_X); - Lock::GlobalWrite lk(txn->lockState()); - AutoGetDb autoDBLocal(txn.get(), "local", MODE_X); + ScopedTransaction transaction(&txn, MODE_X); + Lock::GlobalWrite lk(txn.lockState()); + AutoGetDb autoDBLocal(&txn, "local", MODE_X); const auto localDB = autoDBLocal.getDb(); if (localDB) { MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { // Do not wrap in a WriteUnitOfWork until SERVER-17103 is addressed. - autoDBLocal.getDb()->dropDatabase(txn.get(), localDB); + autoDBLocal.getDb()->dropDatabase(&txn, localDB); } - MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn.get(), "_dropAllDBs", "local"); + MONGO_WRITE_CONFLICT_RETRY_LOOP_END(&txn, "_dropAllDBs", "local"); } } diff --git a/src/mongo/db/storage/mmap_v1/dur.cpp b/src/mongo/db/storage/mmap_v1/dur.cpp index fee1652b440..f50be1ce146 100644 --- a/src/mongo/db/storage/mmap_v1/dur.cpp +++ b/src/mongo/db/storage/mmap_v1/dur.cpp @@ -81,6 +81,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands/server_status.h" #include "mongo/db/concurrency/lock_state.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/mmap_v1/aligned_builder.h" #include "mongo/db/storage/mmap_v1/dur_commitjob.h" #include "mongo/db/storage/mmap_v1/dur_journal.h" @@ -715,8 +716,7 @@ static void durThread() { Timer t; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; AutoAcquireFlushLockForMMAPV1Commit autoFlushLock(txn.lockState()); // We need to snapshot the commitNumber after the flush lock has been obtained, diff --git a/src/mongo/db/storage/mmap_v1/dur_recover.cpp b/src/mongo/db/storage/mmap_v1/dur_recover.cpp index 69e700bc187..72c37788b37 100644 --- a/src/mongo/db/storage/mmap_v1/dur_recover.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_recover.cpp @@ -40,8 +40,7 @@ #include <iostream> #include <sys/stat.h> -#include "mongo/db/client.h" -#include "mongo/db/operation_context.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/mmap_v1/compress.h" #include "mongo/db/storage/mmap_v1/dur_commitjob.h" #include "mongo/db/storage/mmap_v1/dur_journal.h" @@ -629,8 +628,7 @@ void _recover() { void replayJournalFilesAtStartup() { // we use a lock so that exitCleanly will wait for us // to finish (or at least to notice what is up and stop) - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_X); Lock::GlobalWrite lk(txn.lockState()); diff --git a/src/mongo/db/storage/mmap_v1/record_store_v1_capped.cpp b/src/mongo/db/storage/mmap_v1/record_store_v1_capped.cpp index 350a9fc1cdf..a21b7bab880 100644 --- a/src/mongo/db/storage/mmap_v1/record_store_v1_capped.cpp +++ b/src/mongo/db/storage/mmap_v1/record_store_v1_capped.cpp @@ -32,7 +32,7 @@ #include "mongo/db/storage/mmap_v1/record_store_v1_capped.h" -#include "mongo/db/client.h" +#include "mongo/db/operation_context_impl.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.h" 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 4d2bb460585..ce089a38ce9 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp @@ -40,6 +40,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/db_raii.h" #include "mongo/db/namespace_string.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" @@ -76,8 +77,7 @@ public: return false; } - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; try { ScopedTransaction transaction(&txn, MODE_IX); diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index 108c86d4e0f..9ee42d649a6 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -48,6 +48,7 @@ #include "mongo/db/db_raii.h" #include "mongo/db/exec/delete.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/insert.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/namespace_string.h" @@ -120,8 +121,7 @@ public: private: void doTTLPass() { // Count it as active from the moment the TTL thread wakes up - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; // if part of replSet but not in a readable state (e.g. during initial sync), skip. if (repl::getGlobalReplicationCoordinator()->getReplicationMode() == diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp index a0b915027fa..613eef57475 100644 --- a/src/mongo/dbtests/basictests.cpp +++ b/src/mongo/dbtests/basictests.cpp @@ -33,7 +33,7 @@ #include <iostream> -#include "mongo/db/client.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/paths.h" #include "mongo/db/storage/mmap_v1/compress.h" #include "mongo/dbtests/dbtests.h" diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp index 7764f5697c1..789a995e0eb 100644 --- a/src/mongo/dbtests/clienttests.cpp +++ b/src/mongo/dbtests/clienttests.cpp @@ -28,14 +28,12 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" namespace ClientTests { @@ -47,16 +45,14 @@ using std::vector; class Base { public: Base(string coll) : _ns("test." + coll) { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient db(&txn); db.dropDatabase("test"); } virtual ~Base() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient db(&txn); db.dropCollection(_ns); @@ -74,8 +70,7 @@ class DropIndex : public Base { public: DropIndex() : Base("dropindex") {} void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient db(&txn); db.insert(ns(), BSON("x" << 2)); @@ -104,8 +99,7 @@ class BuildIndex : public Base { public: BuildIndex() : Base("buildIndex") {} void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; OldClientWriteContext ctx(&txn, ns()); DBDirectClient db(&txn); @@ -138,8 +132,7 @@ class CS_10 : public Base { public: CS_10() : Base("CS_10") {} void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient db(&txn); const string longs(770, 'c'); @@ -158,8 +151,7 @@ class PushBack : public Base { public: PushBack() : Base("PushBack") {} void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient db(&txn); for (int i = 0; i < 10; ++i) { @@ -204,8 +196,7 @@ class Create : public Base { public: Create() : Base("Create") {} void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient db(&txn); db.createCollection("unittests.clienttests.create", 4096, true); diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp index 7bde7892429..c09fd1a3de1 100644 --- a/src/mongo/dbtests/commandtests.cpp +++ b/src/mongo/dbtests/commandtests.cpp @@ -28,10 +28,9 @@ #include "mongo/platform/basic.h" -#include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/dbdirectclient.h" -#include "mongo/db/operation_context.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" using namespace mongo; @@ -52,8 +51,7 @@ struct Base { return "test.fs.chunks"; } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient db; }; struct Type0 : Base { @@ -128,8 +126,7 @@ public: return "symbolarg"; } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient db; }; diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp index f6f0f48c858..855113d66ec 100644 --- a/src/mongo/dbtests/counttests.cpp +++ b/src/mongo/dbtests/counttests.cpp @@ -28,15 +28,13 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/db/catalog/collection.h" -#include "mongo/db/client.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/operation_context_impl.h" #include "mongo/stdx/thread.h" #include "mongo/dbtests/dbtests.h" @@ -46,7 +44,8 @@ namespace CountTests { class Base { public: Base() - : _scopedXact(&_txn, MODE_IX), + : _txn(), + _scopedXact(&_txn, MODE_IX), _lk(_txn.lockState(), nsToDatabaseSubstring(ns()), MODE_X), _context(&_txn, ns()), _client(&_txn) { @@ -105,8 +104,7 @@ protected: } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::DBLock _lk; diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp index aee6a0f406a..8d7909eac65 100644 --- a/src/mongo/dbtests/dbhelper_tests.cpp +++ b/src/mongo/dbtests/dbhelper_tests.cpp @@ -31,10 +31,10 @@ #include "mongo/client/dbclientcursor.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database_holder.h" -#include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/range_arithmetic.h" #include "mongo/db/write_concern_options.h" #include "mongo/dbtests/dbtests.h" @@ -58,8 +58,7 @@ public: RemoveRange() : _min(4), _max(8) {} void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); for (int i = 0; i < 10; ++i) { diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp index e420ac1f0ab..fd32e9b57d1 100644 --- a/src/mongo/dbtests/directclienttests.cpp +++ b/src/mongo/dbtests/directclienttests.cpp @@ -38,6 +38,7 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/json.h" #include "mongo/db/lasterror.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/timer.h" @@ -61,8 +62,7 @@ const char* ns = "a.b"; class Capped : public ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); for (int pass = 0; pass < 3; pass++) { client.createCollection(ns, 1024 * 1024, true, 999); @@ -89,8 +89,7 @@ public: class InsertMany : ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); vector<BSONObj> objs; @@ -114,8 +113,7 @@ public: class BadNSCmd : ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); BSONObj result; @@ -128,8 +126,7 @@ public: class BadNSQuery : ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); unique_ptr<DBClientCursor> cursor = client.query("", Query(), 1); @@ -143,8 +140,7 @@ public: class BadNSGetMore : ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); unique_ptr<DBClientCursor> cursor = client.getMore("", 1, 1); @@ -158,8 +154,7 @@ public: class BadNSInsert : ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.insert("", BSONObj(), 0); @@ -170,8 +165,7 @@ public: class BadNSUpdate : ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.update("", Query(), BSON("$set" << BSON("x" << 1))); @@ -182,8 +176,7 @@ public: class BadNSRemove : ClientBase { public: virtual void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.remove("", Query()); diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp index 4a777296e2b..27e2e2dc93b 100644 --- a/src/mongo/dbtests/documentsourcetests.cpp +++ b/src/mongo/dbtests/documentsourcetests.cpp @@ -30,17 +30,16 @@ #include "mongo/platform/basic.h" -#include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/pipeline/dependencies.h" #include "mongo/db/pipeline/document_source.h" #include "mongo/db/pipeline/expression_context.h" #include "mongo/db/pipeline/pipeline.h" #include "mongo/db/query/get_executor.h" #include "mongo/dbtests/dbtests.h" - namespace DocumentSourceCursorTests { using boost::intrusive_ptr; @@ -67,8 +66,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _opCtxPtr = cc().makeOperationContext(); - OperationContext& _opCtx = *_opCtxPtr; + OperationContextImpl _opCtx; DBDirectClient client; }; diff --git a/src/mongo/dbtests/executor_registry.cpp b/src/mongo/dbtests/executor_registry.cpp index 564ddcc7da6..46735b627b5 100644 --- a/src/mongo/dbtests/executor_registry.cpp +++ b/src/mongo/dbtests/executor_registry.cpp @@ -31,21 +31,19 @@ * ClientCursor::deregisterExecutor. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/plan_stage.h" +#include "mongo/db/service_context.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/plan_executor.h" -#include "mongo/db/service_context.h" #include "mongo/dbtests/dbtests.h" namespace ExecutorRegistry { @@ -120,8 +118,7 @@ public: } // Order of these is important for initialization - const ServiceContext::UniqueOperationContext _opCtxPtr = cc().makeOperationContext(); - OperationContext& _opCtx = *_opCtxPtr; + OperationContextImpl _opCtx; unique_ptr<OldClientWriteContext> _ctx; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/extensions_callback_real_test.cpp b/src/mongo/dbtests/extensions_callback_real_test.cpp index abe62080fbe..d1284f7aea4 100644 --- a/src/mongo/dbtests/extensions_callback_real_test.cpp +++ b/src/mongo/dbtests/extensions_callback_real_test.cpp @@ -28,12 +28,12 @@ #include "mongo/platform/basic.h" -#include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_text.h" #include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/namespace_string.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/unittest/unittest.h" @@ -72,8 +72,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; const NamespaceString _nss; }; diff --git a/src/mongo/dbtests/framework_options.cpp b/src/mongo/dbtests/framework_options.cpp index c51bc34e00f..7a6d8867c64 100644 --- a/src/mongo/dbtests/framework_options.cpp +++ b/src/mongo/dbtests/framework_options.cpp @@ -28,9 +28,6 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault -#include "mongo/platform/basic.h" - - #include "mongo/dbtests/framework_options.h" #include <boost/filesystem/operations.hpp> diff --git a/src/mongo/dbtests/framework_options_init.cpp b/src/mongo/dbtests/framework_options_init.cpp index d6f0771d5dc..d2764e6b46a 100644 --- a/src/mongo/dbtests/framework_options_init.cpp +++ b/src/mongo/dbtests/framework_options_init.cpp @@ -26,11 +26,10 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" +#include "mongo/dbtests/framework_options.h" #include <iostream> -#include "mongo/dbtests/framework_options.h" #include "mongo/util/options_parser/startup_option_init.h" #include "mongo/util/options_parser/startup_options.h" #include "mongo/util/quick_exit.h" diff --git a/src/mongo/dbtests/gle_test.cpp b/src/mongo/dbtests/gle_test.cpp index 18c721a404f..4e01ed15c18 100644 --- a/src/mongo/dbtests/gle_test.cpp +++ b/src/mongo/dbtests/gle_test.cpp @@ -26,10 +26,8 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - -#include "mongo/db/client.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/assert_util.h" @@ -50,8 +48,7 @@ static const char* const _ns = "unittests.gle"; class GetLastErrorCommandFailure { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.insert(_ns, @@ -70,8 +67,7 @@ public: class GetLastErrorClean { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.insert(_ns, @@ -90,8 +86,7 @@ public: class GetLastErrorFromDup { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.insert(_ns, BSON("_id" << 1)); diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp index 23d6e6f092a..39bea85d55e 100644 --- a/src/mongo/dbtests/indexcatalogtests.cpp +++ b/src/mongo/dbtests/indexcatalogtests.cpp @@ -16,16 +16,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "mongo/platform/basic.h" - #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/index_catalog.h" -#include "mongo/db/client.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 { @@ -35,8 +33,7 @@ static const char* const _ns = "unittests.indexcatalog"; class IndexIteratorTests { public: IndexIteratorTests() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); OldClientContext ctx(&txn, _ns); @@ -49,8 +46,7 @@ public: } ~IndexIteratorTests() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); OldClientContext ctx(&txn, _ns); @@ -61,8 +57,7 @@ public: } void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; OldClientWriteContext ctx(&txn, _ns); int numFinishedIndexesStart = _catalog->numIndexesReady(&txn); @@ -104,8 +99,7 @@ private: class RefreshEntry { public: RefreshEntry() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); OldClientContext ctx(&txn, _ns); @@ -118,8 +112,7 @@ public: } ~RefreshEntry() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X); OldClientContext ctx(&txn, _ns); @@ -130,8 +123,7 @@ public: } void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; OldClientWriteContext ctx(&txn, _ns); const std::string indexName = "x_1"; diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index e81c45bdd94..9b16f7c2769 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -28,20 +28,18 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include <cstdint> #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_create.h" -#include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" -#include "mongo/db/index/index_descriptor.h" -#include "mongo/db/service_context.h" #include "mongo/db/service_context_d.h" +#include "mongo/db/service_context.h" +#include "mongo/db/index/index_descriptor.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" namespace IndexUpdateTests { @@ -117,8 +115,7 @@ protected: return false; } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; OldClientWriteContext _ctx; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp index f3b64598fdc..fee13dde315 100644 --- a/src/mongo/dbtests/jstests.cpp +++ b/src/mongo/dbtests/jstests.cpp @@ -37,9 +37,9 @@ #include <limits> #include "mongo/base/parse_number.h" -#include "mongo/db/client.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/platform/decimal128.h" #include "mongo/scripting/engine.h" @@ -986,8 +986,7 @@ public: string utf8ObjSpec = "{'_id':'\\u0001\\u007f\\u07ff\\uffff'}"; BSONObj utf8Obj = fromjson(utf8ObjSpec); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.insert(ns(), utf8Obj); @@ -1007,8 +1006,7 @@ private: } void reset() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.dropCollection(ns()); @@ -1031,8 +1029,7 @@ public: if (!globalScriptEngine->utf8Ok()) return; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.eval("unittest", @@ -1041,8 +1038,7 @@ public: private: void reset() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.dropCollection(ns()); @@ -1121,8 +1117,7 @@ public: // Insert in Javascript -> Find using DBDirectClient // Drop the collection - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.dropCollection("unittest.testroundtrip"); @@ -2230,8 +2225,7 @@ public: update.appendCode("value", "function () { db.test.find().forEach(function(obj) { continue; }); }"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient client(&txn); client.update("test.system.js", query.obj(), update.obj(), true /* upsert */); diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp index ef4c6498384..fc2ca4049c6 100644 --- a/src/mongo/dbtests/matchertests.cpp +++ b/src/mongo/dbtests/matchertests.cpp @@ -29,16 +29,14 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include <iostream> -#include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/json.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/matcher/matcher.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/timer.h" @@ -215,8 +213,7 @@ template <typename M> class WhereSimple1 { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; const NamespaceString nss("unittests.matchertests"); AutoGetCollectionForRead ctx(&txn, nss); diff --git a/src/mongo/dbtests/mock_dbclient_conn_test.cpp b/src/mongo/dbtests/mock_dbclient_conn_test.cpp index 60a5dba7220..7dd6520cd2e 100644 --- a/src/mongo/dbtests/mock_dbclient_conn_test.cpp +++ b/src/mongo/dbtests/mock_dbclient_conn_test.cpp @@ -29,8 +29,6 @@ * This file includes integration testing between the MockDBClientBase and MockRemoteDB. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientinterface.h" #include "mongo/db/jsobj.h" #include "mongo/dbtests/mock/mock_dbclient_connection.h" diff --git a/src/mongo/dbtests/mock_replica_set_test.cpp b/src/mongo/dbtests/mock_replica_set_test.cpp index 0ead3d418ab..3b0ac16074c 100644 --- a/src/mongo/dbtests/mock_replica_set_test.cpp +++ b/src/mongo/dbtests/mock_replica_set_test.cpp @@ -25,8 +25,6 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientinterface.h" #include "mongo/dbtests/mock/mock_replica_set.h" #include "mongo/unittest/unittest.h" diff --git a/src/mongo/dbtests/namespacetests.cpp b/src/mongo/dbtests/namespacetests.cpp index eadb0a4d85e..f83f5335e53 100644 --- a/src/mongo/dbtests/namespacetests.cpp +++ b/src/mongo/dbtests/namespacetests.cpp @@ -37,12 +37,12 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database_holder.h" -#include "mongo/db/client.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/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" @@ -68,8 +68,7 @@ namespace MissingFieldTests { class BtreeIndexMissingField { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; BSONObj spec(BSON("key" << BSON("a" << 1))); ASSERT_EQUALS(jstNULL, IndexLegacy::getMissingField(&txn, NULL, spec).firstElement().type()); @@ -80,8 +79,7 @@ public: class TwoDIndexMissingField { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; BSONObj spec(BSON("key" << BSON("a" << "2d"))); ASSERT_EQUALS(jstNULL, @@ -93,8 +91,7 @@ public: class HashedIndexMissingField { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; BSONObj spec(BSON("key" << BSON("a" << "hashed"))); BSONObj nullObj = BSON("a" << BSONNULL); @@ -120,8 +117,7 @@ public: class HashedIndexMissingFieldAlternateSeed { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; BSONObj spec(BSON("key" << BSON("a" << "hashed") << "seed" << 0x5eed)); BSONObj nullObj = BSON("a" << BSONNULL); @@ -153,7 +149,7 @@ namespace NamespaceDetailsTests { public: Base( const char *ns = "unittests.NamespaceDetailsTests" ) : ns_( ns ) , _context( ns ) {} virtual ~Base() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; if ( !nsd() ) return; _context.db()->dropCollection( &txn, ns() ); @@ -161,7 +157,7 @@ namespace NamespaceDetailsTests { protected: void create() { Lock::GlobalWrite lk; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; ASSERT( userCreateNS( &txn, db(), ns(), fromjson( spec() ), false ).isOK() ); } virtual string spec() const = 0; @@ -244,7 +240,7 @@ namespace NamespaceDetailsTests { class SingleAlloc : public Base { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; create(); BSONObj b = bigObj(); ASSERT( collection()->insertDocument( &txn, b, true ).isOK() ); @@ -256,7 +252,7 @@ namespace NamespaceDetailsTests { class Realloc : public Base { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; create(); const int N = 20; @@ -281,7 +277,7 @@ namespace NamespaceDetailsTests { class TwoExtent : public Base { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; create(); ASSERT_EQUALS( 2, nExtents() ); @@ -329,7 +325,7 @@ namespace NamespaceDetailsTests { class AllocCappedNotQuantized : public Base { public: void run() { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; create(); ASSERT( nsd()->isCapped() ); ASSERT( !nsd()->isUserFlagSet( NamespaceDetails::Flag_UsePowerOf2Sizes ) ); @@ -352,7 +348,7 @@ namespace NamespaceDetailsTests { return "{\"capped\":true,\"size\":512,\"$nExtents\":2}"; } void pass(int p) { - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; create(); ASSERT_EQUALS( 2, nExtents() ); @@ -497,7 +493,7 @@ namespace NamespaceDetailsTests { create(); NamespaceDetails *nsd = collection()->detailsWritable(); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; + OperationContextImpl txn; // Set 2 & 54 as multikey nsd->setIndexIsMultikey(&txn, 2, true); nsd->setIndexIsMultikey(&txn, 54, true); @@ -538,8 +534,7 @@ public: const string committedName = dbName + ".committed"; const string rolledBackName = dbName + ".rolled_back"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), dbName, MODE_X); @@ -583,8 +578,7 @@ public: const string droppedName = dbName + ".dropped"; const string rolledBackName = dbName + ".rolled_back"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_IX); Lock::DBLock lk(txn.lockState(), dbName, MODE_X); diff --git a/src/mongo/dbtests/oplogstarttests.cpp b/src/mongo/dbtests/oplogstarttests.cpp index b1bfad6b010..ddb6422fc86 100644 --- a/src/mongo/dbtests/oplogstarttests.cpp +++ b/src/mongo/dbtests/oplogstarttests.cpp @@ -20,20 +20,20 @@ * be replayed from for replication. */ -#include "mongo/platform/basic.h" +#include "mongo/dbtests/dbtests.h" + #include "mongo/db/catalog/collection.h" -#include "mongo/db/client.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/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/service_context.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/service_context.h" -#include "mongo/dbtests/dbtests.h" namespace OplogStartTests { @@ -45,7 +45,8 @@ static const NamespaceString nss("unittests.oplogstarttests"); class Base { public: Base() - : _scopedXact(&_txn, MODE_X), + : _txn(), + _scopedXact(&_txn, MODE_X), _lk(_txn.lockState()), _context(&_txn, nss.ns()), _client(&_txn) { @@ -97,8 +98,7 @@ protected: private: // The order of these is important in order to ensure order of destruction - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::GlobalWrite _lk; OldClientContext _context; diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp index 943f0a124fd..f4955d67edd 100644 --- a/src/mongo/dbtests/pdfiletests.cpp +++ b/src/mongo/dbtests/pdfiletests.cpp @@ -32,10 +32,10 @@ #include "mongo/platform/basic.h" #include "mongo/db/catalog/collection.h" -#include "mongo/db/client.h" #include "mongo/db/db.h" #include "mongo/db/db_raii.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/insert.h" #include "mongo/dbtests/dbtests.h" @@ -62,8 +62,7 @@ protected: return _context.db()->getCollection(ns()); } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::GlobalWrite _lk; OldClientContext _context; diff --git a/src/mongo/dbtests/perftests.cpp b/src/mongo/dbtests/perftests.cpp index 3c62cffc5f3..33aa029996b 100644 --- a/src/mongo/dbtests/perftests.cpp +++ b/src/mongo/dbtests/perftests.cpp @@ -51,6 +51,7 @@ #include "mongo/db/db.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/lasterror.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/storage/mmap_v1/dur_stats.h" #include "mongo/db/storage/mmap_v1/mmap.h" #include "mongo/db/storage/storage_options.h" @@ -105,8 +106,7 @@ protected: } private: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient _client; }; @@ -327,8 +327,7 @@ public: srand(++z ^ (unsigned)time(0)); #endif Client::initThreadIfNotAlready("perftestthr"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; DBDirectClient c(&txn); const unsigned int Batch = batchSize(); diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp index 9c9d52bccf4..5012816caa4 100644 --- a/src/mongo/dbtests/plan_ranking.cpp +++ b/src/mongo/dbtests/plan_ranking.cpp @@ -30,20 +30,18 @@ * This file tests db/query/plan_ranker.cpp and db/query/multi_plan_runner.cpp. */ -#include "mongo/platform/basic.h" - #include <iostream> #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/multi_plan.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/json.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/query_knobs.h" #include "mongo/db/query/query_planner.h" @@ -154,8 +152,7 @@ protected: // determining the number of documents in the tests below. static const int N; - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: // Holds the value of global "internalQueryForceIntersectionPlans" setParameter flag. diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp index ffc2557cda4..744ec5cb461 100644 --- a/src/mongo/dbtests/query_plan_executor.cpp +++ b/src/mongo/dbtests/query_plan_executor.cpp @@ -27,11 +27,8 @@ */ -#include "mongo/platform/basic.h" - #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" -#include "mongo/db/client.h" #include "mongo/db/clientcursor.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" @@ -44,6 +41,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/pipeline/expression_context.h" #include "mongo/db/pipeline/pipeline.h" #include "mongo/db/query/plan_executor.h" @@ -187,8 +185,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: IndexDescriptor* getIndex(Database* db, const BSONObj& obj) { diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp index 365b58f6ef0..1b9ada903e4 100644 --- a/src/mongo/dbtests/query_stage_and.cpp +++ b/src/mongo/dbtests/query_stage_and.cpp @@ -32,12 +32,9 @@ */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/and_hash.h" @@ -48,6 +45,7 @@ #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" #include "mongo/util/mongoutils/str.h" @@ -149,8 +147,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_cached_plan.cpp b/src/mongo/dbtests/query_stage_cached_plan.cpp index be91a55fdf1..132859afb92 100644 --- a/src/mongo/dbtests/query_stage_cached_plan.cpp +++ b/src/mongo/dbtests/query_stage_cached_plan.cpp @@ -26,19 +26,17 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/catalog/collection.h" #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/exec/cached_plan.h" #include "mongo/db/exec/queued_data_stage.h" +#include "mongo/db/db_raii.h" #include "mongo/db/jsobj.h" #include "mongo/db/json.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/canonical_query.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/plan_cache.h" @@ -98,8 +96,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; WorkingSet _ws; }; diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index c233155af77..5154470fad4 100644 --- a/src/mongo/dbtests/query_stage_collscan.cpp +++ b/src/mongo/dbtests/query_stage_collscan.cpp @@ -30,12 +30,10 @@ * This file tests db/exec/collection_scan.cpp. */ -#include "mongo/platform/basic.h" #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" @@ -43,6 +41,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.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" @@ -146,8 +145,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp index de3d484dbaa..cfdcf6ffab8 100644 --- a/src/mongo/dbtests/query_stage_count.cpp +++ b/src/mongo/dbtests/query_stage_count.cpp @@ -28,9 +28,6 @@ #include <memory> -#include "mongo/platform/basic.h" - -#include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/exec/collection_scan.h" #include "mongo/db/exec/collection_scan_common.h" @@ -41,6 +38,7 @@ #include "mongo/db/matcher/expression.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" namespace QueryStageCount { @@ -54,7 +52,8 @@ const int kInterjections = kDocuments; class CountStageTest { public: CountStageTest() - : _scopedXact(&_txn, MODE_IX), + : _txn(), + _scopedXact(&_txn, MODE_IX), _dbLock(_txn.lockState(), nsToDatabaseSubstring(ns()), MODE_X), _ctx(&_txn, ns()), _coll(NULL) {} @@ -225,8 +224,7 @@ public: protected: vector<RecordId> _recordIds; - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::DBLock _dbLock; OldClientContext _ctx; diff --git a/src/mongo/dbtests/query_stage_count_scan.cpp b/src/mongo/dbtests/query_stage_count_scan.cpp index 67f20ce4d0f..e499e06cbdc 100644 --- a/src/mongo/dbtests/query_stage_count_scan.cpp +++ b/src/mongo/dbtests/query_stage_count_scan.cpp @@ -27,12 +27,9 @@ */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" @@ -41,6 +38,7 @@ #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/dbtests/dbtests.h" #include "mongo/util/fail_point.h" #include "mongo/util/fail_point_registry.h" @@ -100,8 +98,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_delete.cpp b/src/mongo/dbtests/query_stage_delete.cpp index 4c3e2b873aa..c35536708ca 100644 --- a/src/mongo/dbtests/query_stage_delete.cpp +++ b/src/mongo/dbtests/query_stage_delete.cpp @@ -30,11 +30,9 @@ * This file tests db/exec/delete.cpp. */ -#include "mongo/platform/basic.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" -#include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" @@ -42,6 +40,7 @@ #include "mongo/db/exec/delete.h" #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/canonical_query.h" #include "mongo/db/service_context.h" #include "mongo/dbtests/dbtests.h" @@ -115,8 +114,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_distinct.cpp b/src/mongo/dbtests/query_stage_distinct.cpp index 417fd317362..43c3d3b7fe8 100644 --- a/src/mongo/dbtests/query_stage_distinct.cpp +++ b/src/mongo/dbtests/query_stage_distinct.cpp @@ -26,17 +26,15 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/distinct_scan.h" #include "mongo/db/exec/plan_stage.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/index_bounds_builder.h" #include "mongo/db/query/plan_executor.h" #include "mongo/dbtests/dbtests.h" @@ -95,8 +93,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index 451b4b3069a..079be7c5244 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -30,12 +30,10 @@ * This file tests db/exec/fetch.cpp. Fetch goes to disk so we cannot test outside of a dbtest. */ -#include "mongo/platform/basic.h" #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/fetch.h" @@ -44,6 +42,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" @@ -82,8 +81,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/query_stage_ixscan.cpp b/src/mongo/dbtests/query_stage_ixscan.cpp index 12e8f33fb3c..97f77af78e6 100644 --- a/src/mongo/dbtests/query_stage_ixscan.cpp +++ b/src/mongo/dbtests/query_stage_ixscan.cpp @@ -34,6 +34,7 @@ #include "mongo/db/exec/working_set.h" #include "mongo/db/jsobj.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" namespace QueryStageIxscan { @@ -41,7 +42,8 @@ namespace QueryStageIxscan { class IndexScanTest { public: IndexScanTest() - : _scopedXact(&_txn, MODE_IX), + : _txn(), + _scopedXact(&_txn, MODE_IX), _dbLock(_txn.lockState(), nsToDatabaseSubstring(ns()), MODE_X), _ctx(&_txn, ns()), _coll(NULL) {} @@ -137,8 +139,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::DBLock _dbLock; diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp index 56c8c1d7387..a304a13ae2a 100644 --- a/src/mongo/dbtests/query_stage_keep.cpp +++ b/src/mongo/dbtests/query_stage_keep.cpp @@ -30,12 +30,10 @@ * This file tests db/exec/keep_mutations.cpp. */ -#include "mongo/platform/basic.h" #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" @@ -45,11 +43,12 @@ #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/dbtests/dbtests.h" -#include "mongo/stdx/memory.h" #include "mongo/util/fail_point.h" #include "mongo/util/fail_point_registry.h" #include "mongo/util/fail_point_service.h" +#include "mongo/stdx/memory.h" namespace QueryStageKeep { @@ -97,8 +96,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/query_stage_limit_skip.cpp b/src/mongo/dbtests/query_stage_limit_skip.cpp index 2bb8e3b1faf..39c04796fea 100644 --- a/src/mongo/dbtests/query_stage_limit_skip.cpp +++ b/src/mongo/dbtests/query_stage_limit_skip.cpp @@ -31,8 +31,6 @@ */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #include "mongo/db/exec/limit.h" #include "mongo/db/exec/plan_stage.h" diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp index 841d2ea56f7..5a4ebe4f02e 100644 --- a/src/mongo/dbtests/query_stage_merge_sort.cpp +++ b/src/mongo/dbtests/query_stage_merge_sort.cpp @@ -26,12 +26,9 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/fetch.h" @@ -39,6 +36,7 @@ #include "mongo/db/exec/merge_sort.h" #include "mongo/db/exec/plan_stage.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/collation/collator_interface_mock.h" #include "mongo/db/query/plan_executor.h" #include "mongo/dbtests/dbtests.h" @@ -106,8 +104,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_multiplan.cpp b/src/mongo/dbtests/query_stage_multiplan.cpp index a26a657d4b5..9ccc6fe91ee 100644 --- a/src/mongo/dbtests/query_stage_multiplan.cpp +++ b/src/mongo/dbtests/query_stage_multiplan.cpp @@ -26,11 +26,8 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #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/dbdirectclient.h" #include "mongo/db/exec/collection_scan.h" @@ -42,6 +39,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/plan_executor.h" #include "mongo/db/query/query_knobs.h" @@ -104,8 +102,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/query_stage_near.cpp b/src/mongo/dbtests/query_stage_near.cpp index 58833e6a2bf..1d114dbf58f 100644 --- a/src/mongo/dbtests/query_stage_near.cpp +++ b/src/mongo/dbtests/query_stage_near.cpp @@ -31,8 +31,6 @@ */ -#include "mongo/platform/basic.h" - #include "mongo/base/owned_pointer_vector.h" #include "mongo/db/exec/near.h" #include "mongo/db/exec/queued_data_stage.h" diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp index 676da68abcd..e82333b40d6 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -26,12 +26,9 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/fetch.h" @@ -39,6 +36,7 @@ #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/sort.h" #include "mongo/db/json.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/plan_executor.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" @@ -218,8 +216,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/query_stage_subplan.cpp b/src/mongo/dbtests/query_stage_subplan.cpp index a5253a5ee94..7a61f48a873 100644 --- a/src/mongo/dbtests/query_stage_subplan.cpp +++ b/src/mongo/dbtests/query_stage_subplan.cpp @@ -32,7 +32,6 @@ #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/dbdirectclient.h" #include "mongo/db/exec/subplan.h" @@ -40,6 +39,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" #include "mongo/db/matcher/extensions_callback_noop.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/canonical_query.h" #include "mongo/db/query/get_executor.h" #include "mongo/dbtests/dbtests.h" @@ -81,8 +81,7 @@ protected: return cq; } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp index 5e3bdbb50fc..3a3ff3be40e 100644 --- a/src/mongo/dbtests/query_stage_tests.cpp +++ b/src/mongo/dbtests/query_stage_tests.cpp @@ -26,12 +26,9 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/exec/index_scan.h" @@ -39,6 +36,7 @@ #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/query/plan_executor.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" @@ -128,8 +126,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp index 94632afb4a7..ff232f4cb2a 100644 --- a/src/mongo/dbtests/query_stage_update.cpp +++ b/src/mongo/dbtests/query_stage_update.cpp @@ -30,22 +30,21 @@ * This file tests db/exec/update.cpp (UpdateStage). */ -#include "mongo/platform/basic.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" -#include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.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" -#include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/update.h" +#include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/exec/working_set.h" #include "mongo/db/jsobj.h" #include "mongo/db/json.h" #include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/db/ops/update_driver.h" #include "mongo/db/ops/update_lifecycle_impl.h" #include "mongo/db/ops/update_request.h" @@ -170,8 +169,7 @@ public: } protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; private: DBDirectClient _client; diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index 49c11d6dd44..e799118ef41 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -34,18 +34,18 @@ #include "mongo/client/dbclientcursor.h" #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/dbdirectclient.h" #include "mongo/db/dbhelpers.h" +#include "mongo/db/service_context_d.h" +#include "mongo/db/service_context.h" #include "mongo/db/global_timestamp.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/service_context.h" -#include "mongo/db/service_context_d.h" #include "mongo/dbtests/dbtests.h" #include "mongo/util/timer.h" @@ -113,8 +113,7 @@ protected: } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; ScopedTransaction _scopedXact; Lock::GlobalWrite _lk; OldClientContext _context; @@ -233,8 +232,7 @@ protected: return !_client.getPrevError().getField("err").isNull(); } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/replica_set_monitor_test.cpp b/src/mongo/dbtests/replica_set_monitor_test.cpp index 68d36194b8f..1e5a7699bea 100644 --- a/src/mongo/dbtests/replica_set_monitor_test.cpp +++ b/src/mongo/dbtests/replica_set_monitor_test.cpp @@ -26,8 +26,6 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/client/connpool.h" #include "mongo/client/dbclientinterface.h" #include "mongo/client/dbclient_rs.h" diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp index 0becd7c9fba..52d30995fd7 100644 --- a/src/mongo/dbtests/repltests.cpp +++ b/src/mongo/dbtests/repltests.cpp @@ -36,11 +36,11 @@ #include "mongo/bson/mutable/document.h" #include "mongo/bson/mutable/mutable_bson_test_utils.h" #include "mongo/db/catalog/collection.h" -#include "mongo/db/client.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" @@ -66,8 +66,7 @@ BSONObj f(const char* s) { class Base { protected: - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + mutable OperationContextImpl _txn; mutable DBDirectClient _client; public: diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp index 41405295e14..0432b8b30e1 100644 --- a/src/mongo/dbtests/rollbacktests.cpp +++ b/src/mongo/dbtests/rollbacktests.cpp @@ -34,8 +34,8 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/head_manager.h" #include "mongo/db/catalog/index_create.h" -#include "mongo/db/client.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" #include "mongo/unittest/unittest.h" @@ -145,8 +145,7 @@ class CreateCollection { public: void run() { string ns = "unittests.rollback_create_collection"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; NamespaceString nss(ns); dropDatabase(&txn, nss); @@ -175,8 +174,7 @@ class DropCollection { public: void run() { string ns = "unittests.rollback_drop_collection"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; NamespaceString nss(ns); dropDatabase(&txn, nss); @@ -216,8 +214,7 @@ public: void run() { NamespaceString source("unittests.rollback_rename_collection_src"); NamespaceString target("unittests.rollback_rename_collection_dest"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; dropDatabase(&txn, source); dropDatabase(&txn, target); @@ -263,8 +260,7 @@ public: void run() { NamespaceString source("unittests.rollback_rename_droptarget_collection_src"); NamespaceString target("unittests.rollback_rename_droptarget_collection_dest"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; dropDatabase(&txn, source); dropDatabase(&txn, target); @@ -326,8 +322,7 @@ class ReplaceCollection { public: void run() { NamespaceString nss("unittests.rollback_replace_collection"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; dropDatabase(&txn, nss); ScopedTransaction transaction(&txn, MODE_IX); @@ -377,8 +372,7 @@ class CreateDropCollection { public: void run() { NamespaceString nss("unittests.rollback_create_drop_collection"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; dropDatabase(&txn, nss); ScopedTransaction transaction(&txn, MODE_IX); @@ -413,8 +407,7 @@ class TruncateCollection { public: void run() { NamespaceString nss("unittests.rollback_truncate_collection"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; dropDatabase(&txn, nss); ScopedTransaction transaction(&txn, MODE_IX); @@ -463,8 +456,7 @@ class CreateIndex { public: void run() { string ns = "unittests.rollback_create_index"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; NamespaceString nss(ns); dropDatabase(&txn, nss); createCollection(&txn, nss); @@ -504,8 +496,7 @@ class DropIndex { public: void run() { string ns = "unittests.rollback_drop_index"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; NamespaceString nss(ns); dropDatabase(&txn, nss); createCollection(&txn, nss); @@ -557,8 +548,7 @@ class CreateDropIndex { public: void run() { string ns = "unittests.rollback_create_drop_index"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; NamespaceString nss(ns); dropDatabase(&txn, nss); createCollection(&txn, nss); @@ -601,8 +591,7 @@ class SetIndexHead { public: void run() { string ns = "unittests.rollback_set_index_head"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; NamespaceString nss(ns); dropDatabase(&txn, nss); createCollection(&txn, nss); @@ -664,8 +653,7 @@ class CreateCollectionAndIndexes { public: void run() { string ns = "unittests.rollback_create_collection_and_indexes"; - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; NamespaceString nss(ns); dropDatabase(&txn, nss); diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp index 943bfffed15..1ad45c337bf 100644 --- a/src/mongo/dbtests/threadedtests.cpp +++ b/src/mongo/dbtests/threadedtests.cpp @@ -41,15 +41,16 @@ #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/lock_state.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/bits.h" #include "mongo/stdx/functional.h" #include "mongo/stdx/thread.h" #include "mongo/util/concurrency/old_thread_pool.h" -#include "mongo/util/concurrency/old_thread_pool.h" #include "mongo/util/concurrency/rwlock.h" #include "mongo/util/concurrency/synchronization.h" +#include "mongo/util/concurrency/old_thread_pool.h" #include "mongo/util/concurrency/ticketholder.h" #include "mongo/util/log.h" #include "mongo/util/timer.h" @@ -118,8 +119,7 @@ private: virtual void subthread(int tnumber) { Client::initThread("mongomutextest"); - const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); - OperationContext& txn = *txnPtr; + OperationContextImpl txn; sleepmillis(0); for (int i = 0; i < N; i++) { diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp index c21b70a551f..efd90ce8820 100644 --- a/src/mongo/dbtests/updatetests.cpp +++ b/src/mongo/dbtests/updatetests.cpp @@ -35,12 +35,12 @@ #include "mongo/bson/mutable/mutable_bson_test_utils.h" #include "mongo/client/dbclientcursor.h" -#include "mongo/db/client.h" #include "mongo/db/db.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/json.h" #include "mongo/db/lasterror.h" #include "mongo/db/ops/update.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" namespace UpdateTests { @@ -71,8 +71,7 @@ protected: return !_client.getPrevError().getField("err").isNull(); } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; DBDirectClient _client; }; diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp index fe82b1c5589..532a0abbfea 100644 --- a/src/mongo/dbtests/validate_tests.cpp +++ b/src/mongo/dbtests/validate_tests.cpp @@ -26,20 +26,18 @@ * then also delete it in the license file. */ -#include "mongo/platform/basic.h" - #include <cstdint> #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_create.h" -#include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" -#include "mongo/db/index/index_descriptor.h" -#include "mongo/db/service_context.h" #include "mongo/db/service_context_d.h" +#include "mongo/db/service_context.h" +#include "mongo/db/index/index_descriptor.h" +#include "mongo/db/operation_context_impl.h" #include "mongo/dbtests/dbtests.h" namespace ValidateTests { @@ -88,8 +86,7 @@ protected: return results.valid; } - const ServiceContext::UniqueOperationContext _txnPtr = cc().makeOperationContext(); - OperationContext& _txn = *_txnPtr; + OperationContextImpl _txn; OldClientWriteContext _ctx; DBDirectClient _client; bool _full; |