diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-12-03 10:17:12 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-12-03 19:48:31 -0500 |
commit | a07f232ff52244a70244afe0b0ba00f77fe044ae (patch) | |
tree | c94f287284037793b8beafe9782014590a1f51b0 /src/mongo/db/stats | |
parent | 3b1d97d430a229bf57c46bc7bc4977801b5bb553 (diff) | |
download | mongo-a07f232ff52244a70244afe0b0ba00f77fe044ae.tar.gz |
SERVER-14062 Remove the global OperationContext registry
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r-- | src/mongo/db/stats/lock_server_status_section.cpp | 122 |
1 files changed, 62 insertions, 60 deletions
diff --git a/src/mongo/db/stats/lock_server_status_section.cpp b/src/mongo/db/stats/lock_server_status_section.cpp index 322e5322ad9..6cd04143133 100644 --- a/src/mongo/db/stats/lock_server_status_section.cpp +++ b/src/mongo/db/stats/lock_server_status_section.cpp @@ -28,47 +28,12 @@ #include "mongo/platform/basic.h" +#include "mongo/db/client.h" #include "mongo/db/commands/server_status.h" -#include "mongo/db/global_environment_experiment.h" #include "mongo/db/operation_context.h" - namespace mongo { - /** - * This is passed to the iterator for global environments and aggregates information about the - * locks which are currently being held or waited on. - */ - class LockStateAggregator : public GlobalEnvironmentExperiment::ProcessOperationContext { - public: - LockStateAggregator(bool blockedOnly) - : numWriteLocked(0), - numReadLocked(0), - _blockedOnly(blockedOnly) { - - } - - virtual void processOpContext(OperationContext* txn) { - if (_blockedOnly && !txn->lockState()->hasLockPending()) { - return; - } - - if (txn->lockState()->isWriteLocked()) { - numWriteLocked++; - } - else { - numReadLocked++; - } - } - - int numWriteLocked; - int numReadLocked; - - private: - const bool _blockedOnly; - }; - - class GlobalLockServerStatusSection : public ServerStatusSection { public: GlobalLockServerStatusSection() : ServerStatusSection("globalLock"){ @@ -80,41 +45,78 @@ namespace mongo { virtual BSONObj generateSection(OperationContext* txn, const BSONElement& configElement) const { - BSONObjBuilder t; - - t.append("totalTime", (long long)(1000 * (curTimeMillis64() - _started))); - - // SERVER-14978: Need to report the global lock statistics somehow - // - // t.append( "lockTime" , qlk.stats.getTimeLocked( 'W' ) ); + int numTotal = 0; + int numWriteLocked = 0; + int numReadLocked = 0; + int numWaitingRead = 0; + int numWaitingWrite = 0; // This returns the blocked lock states { - BSONObjBuilder ttt(t.subobjStart("currentQueue")); + boost::mutex::scoped_lock scopedLock(Client::clientsMutex); + + // Count all clients + numTotal = Client::clients.size(); + + ClientSet::const_iterator it = Client::clients.begin(); + for (; it != Client::clients.end(); it++) { + Client* client = *it; + invariant(client); + + boost::unique_lock<Client> uniqueLock(*client); + + const OperationContext* opCtx = client->getOperationContext(); + if (opCtx == NULL) continue; + + if (opCtx->lockState()->getWaitingResource().isValid()) { + // Count client as blocked + if (opCtx->lockState()->isWriteLocked()) { + numWaitingWrite++; + numWriteLocked++; + } + else { + numWaitingRead++; + numReadLocked++; + } + } + else { + // Count client as not blocked + if (opCtx->lockState()->isWriteLocked()) { + numWriteLocked++; + } + else { + numReadLocked++; + } + } + } + } - LockStateAggregator blocked(true); - getGlobalEnvironment()->forEachOperationContext(&blocked); + // Construct the actual return value out of the mutex + BSONObjBuilder ret; - ttt.append("total", blocked.numReadLocked + blocked.numWriteLocked); - ttt.append("readers", blocked.numReadLocked); - ttt.append("writers", blocked.numWriteLocked); - ttt.done(); - } + ret.append("totalTime", (long long)(1000 * (curTimeMillis64() - _started))); - // This returns all the active clients (including those holding locks) { - BSONObjBuilder ttt(t.subobjStart("activeClients")); + BSONObjBuilder currentQueueBuilder(ret.subobjStart("currentQueue")); + + currentQueueBuilder.append("total", numWaitingRead + numWaitingWrite); + currentQueueBuilder.append("readers", numWaitingRead); + currentQueueBuilder.append("writers", numWaitingWrite); + currentQueueBuilder.done(); + } - LockStateAggregator active(false); - getGlobalEnvironment()->forEachOperationContext(&active); + { + BSONObjBuilder activeClientsBuilder(ret.subobjStart("activeClients")); - ttt.append("total", active.numReadLocked + active.numWriteLocked); - ttt.append("readers", active.numReadLocked); - ttt.append("writers", active.numWriteLocked); - ttt.done(); + activeClientsBuilder.append("total", numTotal); + activeClientsBuilder.append("readers", numReadLocked); + activeClientsBuilder.append("writers", numWriteLocked); + activeClientsBuilder.done(); } - return t.obj(); + ret.done(); + + return ret.obj(); } private: |