summaryrefslogtreecommitdiff
path: root/src/mongo/executor/connection_pool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/executor/connection_pool.cpp')
-rw-r--r--src/mongo/executor/connection_pool.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp
index 1fa7790a300..9e562057d38 100644
--- a/src/mongo/executor/connection_pool.cpp
+++ b/src/mongo/executor/connection_pool.cpp
@@ -61,6 +61,8 @@ namespace mongo {
namespace {
+MONGO_FAIL_POINT_DEFINE(refreshConnectionAfterEveryCommand);
+
auto makeSeveritySuppressor() {
return std::make_unique<logv2::KeyedSeveritySuppressor<HostAndPort>>(
Seconds{1}, logv2::LogSeverity::Log(), logv2::LogSeverity::Debug(2));
@@ -306,6 +308,11 @@ public:
size_t refreshingConnections() const;
/**
+ * Returns the number of all refreshed connections in the pool.
+ */
+ size_t refreshedConnections() const;
+
+ /**
* Returns the total number of connections ever created in this pool.
*/
size_t createdConnections() const;
@@ -428,6 +435,8 @@ private:
size_t _created = 0;
+ size_t _refreshed = 0;
+
transport::Session::TagMask _tags = transport::Session::kPending;
HostHealth _health;
@@ -582,7 +591,8 @@ void ConnectionPool::appendConnectionStats(ConnectionPoolStats* stats) const {
ConnectionStatsPer hostStats{pool->inUseConnections(),
pool->availableConnections(),
pool->createdConnections(),
- pool->refreshingConnections()};
+ pool->refreshingConnections(),
+ pool->refreshedConnections()};
stats->updateStatsForHost(_name, host, hostStats);
}
}
@@ -630,6 +640,10 @@ size_t ConnectionPool::SpecificPool::refreshingConnections() const {
return _processingPool.size();
}
+size_t ConnectionPool::SpecificPool::refreshedConnections() const {
+ return _refreshed;
+}
+
size_t ConnectionPool::SpecificPool::createdConnections() const {
return _created;
}
@@ -730,6 +744,10 @@ ConnectionPool::ConnectionHandle ConnectionPool::SpecificPool::tryGetConnection(
void ConnectionPool::SpecificPool::finishRefresh(ConnectionInterface* connPtr, Status status) {
auto conn = takeFromProcessingPool(connPtr);
+ // We increment the total number of refreshed connections right upfront to track all completed
+ // refreshes.
+ _refreshed++;
+
// If we're in shutdown, we don't need refreshed connections
if (_health.isShutdown) {
return;
@@ -814,10 +832,15 @@ void ConnectionPool::SpecificPool::returnConnection(ConnectionInterface* connPtr
return;
}
- auto now = _parent->_factory->now();
- if (needsRefreshTP <= now) {
- // If we need to refresh this connection
+ // If we need to refresh this connection
+ bool shouldRefreshConnection = needsRefreshTP <= _parent->_factory->now();
+
+ if (MONGO_unlikely(refreshConnectionAfterEveryCommand.shouldFail())) {
+ LOGV2(5505501, "refresh connection after every command is on");
+ shouldRefreshConnection = true;
+ }
+ if (shouldRefreshConnection) {
auto controls = _parent->_controller->getControls(_id);
if (_readyPool.size() + _processingPool.size() + _checkedOutPool.size() >=
controls.targetConnections) {