diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2015-03-27 17:43:14 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2015-04-06 10:16:28 -0400 |
commit | b3ee68fcf2b20cb9846d98bbc0ec60c76f93bb0f (patch) | |
tree | 49de5fa145af4a484e02a22c47714fa0dcf1a197 | |
parent | 90b7f774b818a1038cc525a9fca14207d8d5ff71 (diff) | |
download | mongo-b3ee68fcf2b20cb9846d98bbc0ec60c76f93bb0f.tar.gz |
SERVER-17817 Move Locker cache in Client onto a decoration.
-rw-r--r-- | src/mongo/db/client.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/client.h | 9 | ||||
-rw-r--r-- | src/mongo/db/operation_context_impl.cpp | 30 | ||||
-rw-r--r-- | src/mongo/s/client/shard_connection_test.cpp | 34 |
4 files changed, 49 insertions, 48 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index ea7ad692dc0..85617b55df5 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -49,7 +49,6 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/commands.h" -#include "mongo/db/concurrency/lock_state.h" #include "mongo/db/curop.h" #include "mongo/db/dbwebserver.h" #include "mongo/db/instance.h" @@ -71,21 +70,6 @@ namespace mongo { using logger::LogComponent; -namespace { - - /** - * Create an appropriate new locker for the storage engine in use. Caller owns the return. - */ - Locker* newLocker() { - if (isMMAPV1()) { - return new MMAPV1LockerImpl(); - } - - return new LockerImpl<false>(); - } - -} // namespace - boost::mutex Client::clientsMutex; ClientSet Client::clients; @@ -164,14 +148,6 @@ namespace { return false; } - Locker* Client::getLocker() { - if (!_locker) { - _locker.reset(newLocker()); - } - - return _locker.get(); - } - void Client::reportState(BSONObjBuilder& builder) { builder.append("desc", desc()); diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index 90cc2ff669f..b37b86bb4e9 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -40,7 +40,6 @@ #include <boost/thread/thread.hpp> #include "mongo/db/client_basic.h" -#include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/lasterror.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" @@ -53,7 +52,6 @@ namespace mongo { class CurOp; class Collection; class AbstractMessagingPort; - class Locker; TSP_DECLARE(Client, currentClient) @@ -103,9 +101,6 @@ namespace mongo { CurOp* curop() const { return _curOp; } const std::string& desc() const { return _desc; } - // Return a reference to the Locker for this client. Client retains ownership. - Locker* getLocker(); - void reportState(BSONObjBuilder& builder); // Ensures stability of the client's OperationContext. When the client is locked, @@ -153,10 +148,6 @@ namespace mongo { // Changes, based on what operation is running. Some of this should be in OperationContext. CurOp* _curOp; - // By having Client, rather than the OperationContext, own the Locker, setup cost such as - // allocating OS resources can be amortized over multiple operations. - boost::scoped_ptr<Locker> _locker; - // Tracks if Client::shutdown() gets called (TODO: Is this necessary?) bool _shutdown; }; diff --git a/src/mongo/db/operation_context_impl.cpp b/src/mongo/db/operation_context_impl.cpp index 47a04b191d5..8c7a793ca86 100644 --- a/src/mongo/db/operation_context_impl.cpp +++ b/src/mongo/db/operation_context_impl.cpp @@ -32,6 +32,8 @@ #include "mongo/db/operation_context_impl.h" +#include <memory> + #include "mongo/db/client.h" #include "mongo/db/concurrency/lock_state.h" #include "mongo/db/curop.h" @@ -40,16 +42,40 @@ #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/platform/random.h" -#include "mongo/util/log.h" +#include "mongo/stdx/memory.h" #include "mongo/util/fail_point_service.h" +#include "mongo/util/log.h" namespace mongo { +namespace { + std::unique_ptr<Locker> newLocker() { + if (isMMAPV1()) return stdx::make_unique<MMAPV1LockerImpl>(); + return stdx::make_unique<DefaultLockerImpl>(); + } + + class ClientOperationInfo { + public: + Locker* getLocker() { + if (!_locker) { + _locker = newLocker(); + } + return _locker.get(); + } + + private: + std::unique_ptr<Locker> _locker; + }; + + const auto clientOperationInfoDecoration = Client::declareDecoration<ClientOperationInfo>(); + +} // namespace + using std::string; OperationContextImpl::OperationContextImpl() : _client(currentClient.get()), - _locker(_client->getLocker()) { + _locker(clientOperationInfoDecoration(_client).getLocker()) { invariant(_locker); diff --git a/src/mongo/s/client/shard_connection_test.cpp b/src/mongo/s/client/shard_connection_test.cpp index 233f7c6e9e2..9468f778afc 100644 --- a/src/mongo/s/client/shard_connection_test.cpp +++ b/src/mongo/s/client/shard_connection_test.cpp @@ -29,12 +29,15 @@ #include "mongo/client/connpool.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_global.h" -#include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/auth/authz_manager_external_state_mock.h" +#include "mongo/db/service_context.h" +#include "mongo/db/service_context_noop.h" #include "mongo/dbtests/mock/mock_conn_registry.h" #include "mongo/dbtests/mock/mock_dbclient_connection.h" #include "mongo/platform/cstdint.h" #include "mongo/s/client/shard_connection.h" +#include "mongo/s/client_info.h" +#include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" #include <vector> @@ -47,31 +50,37 @@ * the internal connections together, like in client/scoped_db_conn_test.cpp. */ -using boost::scoped_ptr; -using mongo::DBClientBase; -using mongo::MockRemoteDBServer; -using mongo::ShardConnection; -using std::string; -using std::vector; - +namespace mongo { namespace { + + using std::string; + using std::vector; + const string TARGET_HOST = "$dummy:27017"; + MONGO_INITIALIZER(SCFTestGlobalServiceContext)(InitializerContext*) { + invariant(!hasGlobalServiceContext()); + mongo::setGlobalAuthorizationManager(new mongo::AuthorizationManager( + new mongo::AuthzManagerExternalStateMock())); + setGlobalServiceContext(stdx::make_unique<ServiceContextNoop>()); + return Status::OK(); + } + /** * Warning: cannot run in parallel */ class ShardConnFixture: public mongo::unittest::Test { public: void setUp() { + if (!ClientInfo::exists()) { + ClientInfo::create(getGlobalServiceContext(), NULL); + } _maxPoolSizePerHost = mongo::shardConnectionPool.getMaxPoolSize(); mongo::ConnectionString::setConnectionHook( mongo::MockConnRegistry::get()->getConnStrHook()); _dummyServer = new MockRemoteDBServer(TARGET_HOST); mongo::MockConnRegistry::get()->addServer(_dummyServer); - - mongo::setGlobalAuthorizationManager(new mongo::AuthorizationManager( - new mongo::AuthzManagerExternalStateMock())); } void tearDown() { @@ -81,8 +90,6 @@ namespace { delete _dummyServer; mongo::shardConnectionPool.setMaxPoolSize(_maxPoolSizePerHost); - - mongo::clearGlobalAuthorizationManager(); } void killServer() { @@ -313,3 +320,4 @@ namespace { } } // namespace +} // namespace mongo |