summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-10-11 19:19:38 +0000
committerevergreen <evergreen@mongodb.com>2019-10-11 19:19:38 +0000
commitcf4c944977a348494d81eeaf7eddb96ef0457876 (patch)
tree2f038795f6dcd631a6391de6cc1bbb12c7b40f85 /src/mongo/db/concurrency
parent6b345cce214efb1b3f9dcffc2f25a833d1caa100 (diff)
downloadmongo-cf4c944977a348494d81eeaf7eddb96ef0457876.tar.gz
SERVER-43910 lockInfo command obtains lock to client info mapping from LockManager
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r--src/mongo/db/concurrency/lock_manager.cpp26
-rw-r--r--src/mongo/db/concurrency/lock_manager.h8
2 files changed, 34 insertions, 0 deletions
diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp
index b8f97d47461..7f2dc7335b1 100644
--- a/src/mongo/db/concurrency/lock_manager.cpp
+++ b/src/mongo/db/concurrency/lock_manager.cpp
@@ -400,6 +400,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 e8cbfd39054..a8387fdb4ec 100644
--- a/src/mongo/db/concurrency/lock_manager.h
+++ b/src/mongo/db/concurrency/lock_manager.h
@@ -47,6 +47,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 {
LockManager& operator=(const LockManager&) = delete;
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();