summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2015-03-27 17:43:14 -0400
committerAndy Schwerin <schwerin@mongodb.com>2015-04-06 10:16:28 -0400
commitb3ee68fcf2b20cb9846d98bbc0ec60c76f93bb0f (patch)
tree49de5fa145af4a484e02a22c47714fa0dcf1a197 /src/mongo/db
parent90b7f774b818a1038cc525a9fca14207d8d5ff71 (diff)
downloadmongo-b3ee68fcf2b20cb9846d98bbc0ec60c76f93bb0f.tar.gz
SERVER-17817 Move Locker cache in Client onto a decoration.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/client.cpp24
-rw-r--r--src/mongo/db/client.h9
-rw-r--r--src/mongo/db/operation_context_impl.cpp30
3 files changed, 28 insertions, 35 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);