From a480255301b12df04ae55a1de0445f13f3d4d8a0 Mon Sep 17 00:00:00 2001 From: Alexander Korepanov Date: Fri, 19 Feb 2016 14:25:24 +0300 Subject: [PATCH] Add an ability to set timeout between mongos and shards --- src/mongo/s/shard.h | 3 +++ src/mongo/s/shardconnection.cpp | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mongo/s/shard.h b/src/mongo/s/shard.h index 9f159166cc..58851e2197 100644 --- a/src/mongo/s/shard.h +++ b/src/mongo/s/shard.h @@ -297,6 +297,9 @@ namespace mongo { // Controls whether we throw on initially failing to set a version static bool ignoreInitialVersionFailure; + // Use for settings timeout for connections between mongos and mongod + static double shardConnectionTimeout; + /** checks all of my thread local connections for the version of this ns */ static void checkMyConnectionVersions( const string & ns ); diff --git a/src/mongo/s/shardconnection.cpp b/src/mongo/s/shardconnection.cpp index 4fa9f3e8a4..fcd3239122 100644 --- a/src/mongo/s/shardconnection.cpp +++ b/src/mongo/s/shardconnection.cpp @@ -36,6 +36,8 @@ namespace mongo { bool ShardConnection::ignoreInitialVersionFailure( false ); + double ShardConnection::shardConnectionTimeout(1.0); + ExportedServerParameter _ignoreInitialVersionFailure( ServerParameterSet::getGlobal(), "ignoreInitialVersionFailure", @@ -43,6 +45,13 @@ namespace mongo { true, true ); + ExportedServerParameter + _shardConnectionTimeout( ServerParameterSet::getGlobal(), + "shardConnectionTimeout", + &ShardConnection::shardConnectionTimeout, + true, + true ); + DBConnectionPool shardConnectionPool; class ClientConnections; @@ -171,7 +180,7 @@ namespace mongo { s->avail = 0; shardConnectionPool.onHandedOut( c.get() ); // May throw an exception } else { - c.reset( shardConnectionPool.get( addr ) ); + c.reset( shardConnectionPool.get( addr, ShardConnection::shardConnectionTimeout ) ); s->created++; // After, so failed creation doesn't get counted } return c.release(); @@ -249,7 +258,7 @@ namespace mongo { Status* s = _getStatus( sconnString ); if( ! s->avail ) { - s->avail = shardConnectionPool.get( sconnString ); + s->avail = shardConnectionPool.get( sconnString, ShardConnection::shardConnectionTimeout ); s->created++; // After, so failed creation doesn't get counted }