From ce0a2242ca1d939cc2102857d5def9e068ebebe8 Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Fri, 11 Oct 2019 21:26:36 +0000 Subject: SERVER-43910 LockManager::dump() includes client info (cherry picked from commit 1245770e0ac12d09bceec097fcf66865b040a463) --- src/mongo/db/concurrency/lock_manager.cpp | 28 ++++++++++++++++++++++------ src/mongo/db/concurrency/lock_manager.h | 3 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp index 16341611a7c..49711a7637a 100644 --- a/src/mongo/db/concurrency/lock_manager.cpp +++ b/src/mongo/db/concurrency/lock_manager.cpp @@ -844,12 +844,13 @@ LockManager::Partition* LockManager::_getPartition(LockRequest* request) const { void LockManager::dump() const { log() << "Dumping LockManager @ " << static_cast(this) << '\n'; + auto lockToClientMap = getLockToClientMap(getGlobalServiceContext()); for (unsigned i = 0; i < _numLockBuckets; i++) { LockBucket* bucket = &_lockBuckets[i]; stdx::lock_guard scopedLock(bucket->mutex); if (!bucket->data.empty()) { - _dumpBucket(bucket); + _dumpBucket(lockToClientMap, bucket); } } } @@ -919,7 +920,8 @@ void LockManager::getLockInfoBSON(const std::map& lockToClien result->append("lockInfo", lockInfo.arr()); } -void LockManager::_dumpBucket(const LockBucket* bucket) const { +void LockManager::_dumpBucket(const std::map& lockToClientMap, + const LockBucket* bucket) const { for (LockBucket::Map::const_iterator it = bucket->data.begin(); it != bucket->data.end(); it++) { const LockHead* lock = it->second; @@ -938,13 +940,20 @@ void LockManager::_dumpBucket(const LockBucket* bucket) const { std::stringstream threadId; threadId << iter->locker->getThreadId() << " | " << std::showbase << std::hex << iter->locker->getThreadId(); - sb << '\t' << "LockRequest " << iter->locker->getId() << " @ " << iter->locker << ": " + auto lockerId = iter->locker->getId(); + sb << '\t' << "LockRequest " << lockerId << " @ " << iter->locker << ": " << "Mode = " << modeName(iter->mode) << "; " << "Thread = " << threadId.str() << "; " << "ConvertMode = " << modeName(iter->convertMode) << "; " << "EnqueueAtFront = " << iter->enqueueAtFront << "; " << "CompatibleFirst = " << iter->compatibleFirst << "; " - << "DebugInfo = " << iter->locker->getDebugInfo() << '\n'; + << "DebugInfo = " << iter->locker->getDebugInfo(); + auto it = lockToClientMap.find(lockerId); + if (it != lockToClientMap.end()) { + sb << "; ClientInfo = "; + sb << it->second; + } + sb << '\n'; } sb << "PENDING:\n"; @@ -953,13 +962,20 @@ void LockManager::_dumpBucket(const LockBucket* bucket) const { std::stringstream threadId; threadId << iter->locker->getThreadId() << " | " << std::showbase << std::hex << iter->locker->getThreadId(); - sb << '\t' << "LockRequest " << iter->locker->getId() << " @ " << iter->locker << ": " + auto lockerId = iter->locker->getId(); + sb << '\t' << "LockRequest " << lockerId << " @ " << iter->locker << ": " << "Mode = " << modeName(iter->mode) << "; " << "Thread = " << threadId.str() << "; " << "ConvertMode = " << modeName(iter->convertMode) << "; " << "EnqueueAtFront = " << iter->enqueueAtFront << "; " << "CompatibleFirst = " << iter->compatibleFirst << "; " - << "DebugInfo = " << iter->locker->getDebugInfo() << '\n'; + << "DebugInfo = " << iter->locker->getDebugInfo(); + auto it = lockToClientMap.find(lockerId); + if (it != lockToClientMap.end()) { + sb << "; ClientInfo = "; + sb << it->second; + } + sb << '\n'; } sb << "-----------------------------------------------------------\n"; diff --git a/src/mongo/db/concurrency/lock_manager.h b/src/mongo/db/concurrency/lock_manager.h index 5777998c00c..23603eaea3c 100644 --- a/src/mongo/db/concurrency/lock_manager.h +++ b/src/mongo/db/concurrency/lock_manager.h @@ -183,7 +183,8 @@ private: /** * Prints the contents of a bucket to the log. */ - void _dumpBucket(const LockBucket* bucket) const; + void _dumpBucket(const std::map& lockToClientMap, + const LockBucket* bucket) const; /** * Dump the contents of a bucket to the BSON. -- cgit v1.2.1