From b3ee68fcf2b20cb9846d98bbc0ec60c76f93bb0f Mon Sep 17 00:00:00 2001 From: Andy Schwerin Date: Fri, 27 Mar 2015 17:43:14 -0400 Subject: SERVER-17817 Move Locker cache in Client onto a decoration. --- src/mongo/db/client.cpp | 24 ------------------------ src/mongo/db/client.h | 9 --------- src/mongo/db/operation_context_impl.cpp | 30 ++++++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 35 deletions(-) (limited to 'src/mongo/db') 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(); - } - -} // 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 #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; - // 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 + #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 newLocker() { + if (isMMAPV1()) return stdx::make_unique(); + return stdx::make_unique(); + } + + class ClientOperationInfo { + public: + Locker* getLocker() { + if (!_locker) { + _locker = newLocker(); + } + return _locker.get(); + } + + private: + std::unique_ptr _locker; + }; + + const auto clientOperationInfoDecoration = Client::declareDecoration(); + +} // namespace + using std::string; OperationContextImpl::OperationContextImpl() : _client(currentClient.get()), - _locker(_client->getLocker()) { + _locker(clientOperationInfoDecoration(_client).getLocker()) { invariant(_locker); -- cgit v1.2.1