summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2021-04-21 20:05:39 +0000
committerAndrew Shuvalov <andrew.shuvalov@mongodb.com>2021-04-25 16:42:13 +0000
commit1d5cbc113d4318b79831113790c3abd09ba25098 (patch)
tree856a3caa53bbe445b6202b87093e83151834b131
parent5c8ec91022cd185490fb960a5a7fdaf1c58f94d7 (diff)
downloadmongo-1d5cbc113d4318b79831113790c3abd09ba25098.tar.gz
SERVER-56217 SERVER-56147: maxed out connection pool should respect get() timeout and CV should be notified on connection release
-rw-r--r--src/mongo/client/connpool.cpp2
-rw-r--r--src/mongo/client/connpool.h11
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<int64_t>(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<int64_t>(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 {