From 1d5cbc113d4318b79831113790c3abd09ba25098 Mon Sep 17 00:00:00 2001 From: Andrew Shuvalov Date: Wed, 21 Apr 2021 20:05:39 +0000 Subject: SERVER-56217 SERVER-56147: maxed out connection pool should respect get() timeout and CV should be notified on connection release --- src/mongo/client/connpool.cpp | 2 +- src/mongo/client/connpool.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp index 0bca8143836..2407162daf6 100644 --- a/src/mongo/client/connpool.cpp +++ b/src/mongo/client/connpool.cpp @@ -574,7 +574,7 @@ bool DBConnectionPool::poolKeyCompare::operator()(const PoolKey& a, const PoolKe if (DBConnectionPool::serverNameCompare()(b.ident, a.ident)) return false; - return a.timeoutTenthSecond < b.timeoutTenthSecond; + return a.socketTimeoutMs < b.socketTimeoutMs; } bool DBConnectionPool::isConnectionGood(const string& hostName, DBClientBase* conn) { diff --git a/src/mongo/client/connpool.h b/src/mongo/client/connpool.h index 8e2bd517068..0d58a849c99 100644 --- a/src/mongo/client/connpool.h +++ b/src/mongo/client/connpool.h @@ -373,12 +373,15 @@ private: DBClientBase* _finishCreate(const std::string& ident, double socketTimeout, DBClientBase* conn); struct PoolKey { - PoolKey(const std::string& i, double t) - : ident(i), timeoutTenthSecond(static_cast(t * 10.)) {} + PoolKey(const std::string& i, double socketTimeoutSec) + : ident(i), + // Rounds up with presision 0.001, e.g. value between 0.99991 and 1.0008 to 1000. + socketTimeoutMs(static_cast(socketTimeoutSec * 10.001) * 100) {} std::string ident; // To make the key to have a descrete value the double timeout - // is rounded up to 100 ms. - int64_t timeoutTenthSecond; + // is rounded up to 100 ms. This prevents from creating a potentially + // unlimited number of pools. + int64_t socketTimeoutMs; }; struct poolKeyCompare { -- cgit v1.2.1