diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-11-06 12:13:11 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-11-11 10:16:33 -0500 |
commit | 67b68b5f094d88753ae2fe14f6d708c9e5b4bfbd (patch) | |
tree | 17b708763cec3f17e0028c02edd3f54559a4804a /src/mongo/client/dbclient_rs.cpp | |
parent | 3c090e1ad8b0f6d555396554abad7ea3747961af (diff) | |
download | mongo-67b68b5f094d88753ae2fe14f6d708c9e5b4bfbd.tar.gz |
SERVER-21272 Make replica set monitor retry finding hosts
This change makes the replica set monitor retry more than once to find
hosts suitable for a given read preference and fail quickly if none of the
hosts for a given replica set can be reached.
Diffstat (limited to 'src/mongo/client/dbclient_rs.cpp')
-rw-r--r-- | src/mongo/client/dbclient_rs.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp index b3b39ce2a32..022f13e041f 100644 --- a/src/mongo/client/dbclient_rs.cpp +++ b/src/mongo/client/dbclient_rs.cpp @@ -391,7 +391,7 @@ DBClientConnection& DBClientReplicaSet::slaveConn() { bool DBClientReplicaSet::connect() { // Returns true if there are any up hosts. const ReadPreferenceSetting anyUpHost(ReadPreference::Nearest, TagSet()); - return !_getMonitor()->getHostOrRefresh(anyUpHost).empty(); + return _getMonitor()->getHostOrRefresh(anyUpHost).isOK(); } static bool isAuthenticationException(const DBException& ex) { @@ -657,20 +657,22 @@ void DBClientReplicaSet::isntSecondary() { DBClientConnection* DBClientReplicaSet::selectNodeUsingTags( shared_ptr<ReadPreferenceSetting> readPref) { if (checkLastHost(readPref.get())) { - LOG(3) << "dbclient_rs selecting compatible last used node " << _lastSlaveOkHost << endl; + LOG(3) << "dbclient_rs selecting compatible last used node " << _lastSlaveOkHost; return _lastSlaveOkConn.get(); } ReplicaSetMonitorPtr monitor = _getMonitor(); - HostAndPort selectedNode = monitor->getHostOrRefresh(*readPref); - if (selectedNode.empty()) { - LOG(3) << "dbclient_rs no compatible node found" << endl; - - return NULL; + auto selectedNodeStatus = monitor->getHostOrRefresh(*readPref); + if (!selectedNodeStatus.isOK()) { + LOG(3) << "dbclient_rs no compatible node found" + << causedBy(selectedNodeStatus.getStatus()); + return nullptr; } + const HostAndPort selectedNode = std::move(selectedNodeStatus.getValue()); + // We are now about to get a new connection from the pool, so cleanup // the current one and release it back to the pool. resetSlaveOkConn(); |