summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-10-11 19:19:38 +0000
committerBenety Goh <benety@mongodb.com>2020-01-15 14:04:51 -0500
commite4fd2a68f21e10573dfb1b2ed509b3ca102a466e (patch)
tree0cb5a853c414c73978e5675f105513bb57432ad1
parent3f80c90ce6b96ffba44f97f93dfbb7aa7fc85608 (diff)
downloadmongo-e4fd2a68f21e10573dfb1b2ed509b3ca102a466e.tar.gz
SERVER-43910 lockInfo command obtains lock to client info mapping from LockManager
(cherry picked from commit cf4c944977a348494d81eeaf7eddb96ef0457876)
-rw-r--r--src/mongo/db/commands/lock_info.cpp22
-rw-r--r--src/mongo/db/concurrency/lock_manager.cpp26
-rw-r--r--src/mongo/db/concurrency/lock_manager.h8
3 files changed, 35 insertions, 21 deletions
diff --git a/src/mongo/db/commands/lock_info.cpp b/src/mongo/db/commands/lock_info.cpp
index 23d8256db6b..b6941b4bcdf 100644
--- a/src/mongo/db/commands/lock_info.cpp
+++ b/src/mongo/db/commands/lock_info.cpp
@@ -81,27 +81,7 @@ public:
const string& dbname,
const BSONObj& jsobj,
BSONObjBuilder& result) {
- std::map<LockerId, BSONObj> lockToClientMap;
-
- for (ServiceContext::LockedClientsCursor cursor(opCtx->getClient()->getServiceContext());
- Client* client = cursor.next();) {
- invariant(client);
-
- stdx::lock_guard<Client> lk(*client);
- const OperationContext* clientOpCtx = client->getOperationContext();
-
- // Operation context specific information
- if (clientOpCtx) {
- BSONObjBuilder infoBuilder;
- // The client information
- client->reportState(infoBuilder);
-
- infoBuilder.append("opid", static_cast<int>(clientOpCtx->getOpID()));
- LockerId lockerId = clientOpCtx->lockState()->getId();
- lockToClientMap.insert({lockerId, infoBuilder.obj()});
- }
- }
-
+ auto lockToClientMap = LockManager::getLockToClientMap(opCtx->getServiceContext());
getGlobalLockManager()->getLockInfoBSON(lockToClientMap, &result);
return true;
}
diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp
index d5524799cfc..16341611a7c 100644
--- a/src/mongo/db/concurrency/lock_manager.cpp
+++ b/src/mongo/db/concurrency/lock_manager.cpp
@@ -416,6 +416,32 @@ const unsigned LockManager::_numLockBuckets(128);
// The exact value doesn't appear very important, but should be power of two
const unsigned LockManager::_numPartitions = 32;
+// static
+std::map<LockerId, BSONObj> LockManager::getLockToClientMap(ServiceContext* serviceContext) {
+ std::map<LockerId, BSONObj> lockToClientMap;
+
+ for (ServiceContext::LockedClientsCursor cursor(serviceContext);
+ Client* client = cursor.next();) {
+ invariant(client);
+
+ stdx::lock_guard<Client> lk(*client);
+ const OperationContext* clientOpCtx = client->getOperationContext();
+
+ // Operation context specific information
+ if (clientOpCtx) {
+ BSONObjBuilder infoBuilder;
+ // The client information
+ client->reportState(infoBuilder);
+
+ infoBuilder.append("opid", static_cast<int>(clientOpCtx->getOpID()));
+ LockerId lockerId = clientOpCtx->lockState()->getId();
+ lockToClientMap.insert({lockerId, infoBuilder.obj()});
+ }
+ }
+
+ return lockToClientMap;
+}
+
LockManager::LockManager() {
_lockBuckets = new LockBucket[_numLockBuckets];
_partitions = new Partition[_numPartitions];
diff --git a/src/mongo/db/concurrency/lock_manager.h b/src/mongo/db/concurrency/lock_manager.h
index 7b137715412..5777998c00c 100644
--- a/src/mongo/db/concurrency/lock_manager.h
+++ b/src/mongo/db/concurrency/lock_manager.h
@@ -48,6 +48,8 @@
namespace mongo {
+class ServiceContext;
+
/**
* Entry point for the lock manager scheduling functionality. Don't use it directly, but
* instead go through the Locker interface.
@@ -56,6 +58,12 @@ class LockManager {
MONGO_DISALLOW_COPYING(LockManager);
public:
+ /**
+ * Gets a mapping of lock to client info.
+ * Used by dump() and the lockInfo command.
+ */
+ static std::map<LockerId, BSONObj> getLockToClientMap(ServiceContext* serviceContext);
+
LockManager();
~LockManager();