diff options
author | Geert Bosch <geert@mongodb.com> | 2014-12-10 17:15:45 -0500 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2014-12-12 18:05:34 -0500 |
commit | e067fff4e3f3079d070ec168f32c24db9a51a944 (patch) | |
tree | 5ccdf8c4cbae815a7d485a30c4d2d5bfbdf3aaaa /src/mongo/db/client.cpp | |
parent | 2a148f717998b77199c3dd3d7d4e4e47eb1141ef (diff) | |
download | mongo-e067fff4e3f3079d070ec168f32c24db9a51a944.tar.gz |
SERVER-16493: Have Client own Locker to amortize initialization cost
Diffstat (limited to 'src/mongo/db/client.cpp')
-rw-r--r-- | src/mongo/db/client.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index f7722b7dbec..1b4efbb5281 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -51,8 +51,10 @@ #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/global_environment_experiment.h" #include "mongo/db/instance.h" #include "mongo/db/json.h" #include "mongo/db/jsobj.h" @@ -107,6 +109,17 @@ namespace mongo { clients.insert(client); } +namespace { + // Create an appropriate new locker for the storage engine in use. Caller owns. + Locker* newLocker() { + if (isMMAPV1()) { + return new MMAPV1LockerImpl(); + } + + return new LockerImpl<false>(); + } +} + Client::Client(const string& desc, AbstractMessagingPort *p) : ClientBasic(p), _desc(desc), @@ -114,6 +127,7 @@ namespace mongo { _connectionId(p ? p->connectionId() : 0), _god(0), _txn(NULL), + _locker(newLocker()), _lastOp(0), _shutdown(false) { @@ -335,13 +349,19 @@ namespace mongo { } void Client::setOperationContext(OperationContext* txn) { - // We can only set or unset the OperationContexts, never swap them. - invariant((txn == NULL) ^ (_txn == NULL)); + // We can only set the OperationContext once before resetting it. + invariant(txn != NULL && _txn == NULL); boost::unique_lock<SpinLock> uniqueLock(_lock); _txn = txn; } + void Client::resetOperationContext() { + invariant(_txn != NULL); + boost::unique_lock<SpinLock> uniqueLock(_lock); + _txn = NULL; + } + string Client::clientAddress(bool includePort) const { if( _curOp ) return _curOp->getRemoteString(includePort); |