summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordwight <dwight@10gen.com>2011-09-27 21:08:21 -0400
committerEliot Horowitz <eliot@10gen.com>2011-10-08 23:32:01 -0400
commit8814b71b260805dd6afc0cea13acce37cf328e15 (patch)
tree67992e514edaa25687f190b33c6af3500645d8c3
parent17caecbd77d209202939107bbbaaf297692ac41e (diff)
downloadmongo-8814b71b260805dd6afc0cea13acce37cf328e15.tar.gz
SERVER-3962 very high extraneous ismaster type commands from mongos to repl set if slaveok and no pure secondary is up
-rw-r--r--client/dbclient_rs.cpp37
1 files changed, 11 insertions, 26 deletions
diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp
index 2cab1f7b0d5..a1d9d879360 100644
--- a/client/dbclient_rs.cpp
+++ b/client/dbclient_rs.cpp
@@ -247,35 +247,20 @@ namespace mongo {
}
HostAndPort ReplicaSetMonitor::getSlave() {
+ LOG(2) << "selecting a slave from replica set " << getServerAddress() << endl;
- LOG(2) << "selecting new slave from replica set " << getServerAddress() << endl;
-
- // Logic is to retry three times for any secondary node, if we can't find any secondary, we'll take
- // any "ok" node
- // TODO: Could this query hidden nodes?
- const int MAX = 3;
- for ( int xxx=0; xxx<MAX; xxx++ ) {
+ scoped_lock lk( _lock );
- {
- scoped_lock lk( _lock );
-
- unsigned i = 0;
- for ( ; i<_nodes.size(); i++ ) {
- _nextSlave = ( _nextSlave + 1 ) % _nodes.size();
- if ( _nextSlave == _master ){
- LOG(2) << "not selecting " << _nodes[_nextSlave] << " as it is the current master" << endl;
- continue;
- }
- if ( _nodes[ _nextSlave ].okForSecondaryQueries() || ( _nodes[ _nextSlave ].ok && ( xxx + 1 ) >= MAX ) )
- return _nodes[ _nextSlave ].addr;
-
- LOG(2) << "not selecting " << _nodes[_nextSlave] << " as it is not ok to use" << endl;
- }
-
+ for ( unsigned i = 0; i < _nodes.size(); i++ ) {
+ _nextSlave = ( _nextSlave + 1 ) % _nodes.size();
+ if ( i == _master ){
+ LOG(2) << "not selecting " << _nodes[i] << " as it is the current master" << endl;
+ continue;
}
-
- check(false);
- }
+ if ( _nodes[ i ].okForSecondaryQueries() )
+ return _nodes[ _nextSlave ].addr;
+ LOG(2) << "not selecting " << _nodes[i] << " as it is not ok to use" << endl;
+ }
LOG(2) << "no suitable slave nodes found, returning default node " << _nodes[ 0 ] << endl;