diff options
author | dwight <dwight@10gen.com> | 2010-10-31 19:12:12 -0400 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2010-10-31 19:12:12 -0400 |
commit | 279d33bee6d8dbc3c35e5cb43fccc8ddf7a230fe (patch) | |
tree | 1fd43134fe46dcb6ce84ba413c44ca4a9310d46f /client | |
parent | 50d72f3f01ffa05772b154bf23bc1069fd58cb98 (diff) | |
download | mongo-279d33bee6d8dbc3c35e5cb43fccc8ddf7a230fe.tar.gz |
dbclient: once a connection in failed state be sure not to use it. this is a fairly big change in a way because it now throws mroe often. affects replica sets.
Diffstat (limited to 'client')
-rw-r--r-- | client/dbclient.cpp | 12 | ||||
-rw-r--r-- | client/dbclient.h | 6 |
2 files changed, 12 insertions, 6 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp index b2ad3451613..0114ce7a8d7 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -520,18 +520,22 @@ namespace mongo { void DBClientConnection::_checkConnection() { if ( !failed ) return; - if ( lastReconnectTry && time(0)-lastReconnectTry < 2 ) - return; + if ( lastReconnectTry && time(0)-lastReconnectTry < 2 ) { + // we wait a little before reconnect attempt to avoid constant hammering. + // but we throw we don't want to try to use a connection in a bad state + throw SocketException(SocketException::FAILED_STATE); + } if ( !autoReconnect ) - return; + throw SocketException(SocketException::FAILED_STATE); lastReconnectTry = time(0); log(_logLevel) << "trying reconnect to " << _serverString << endl; string errmsg; failed = false; if ( ! _connect(errmsg) ) { + failed = true; log(_logLevel) << "reconnect " << _serverString << " failed " << errmsg << endl; - return; + throw SocketException(SocketException::CONNECT_ERROR); } log(_logLevel) << "reconnect " << _serverString << " ok" << endl; diff --git a/client/dbclient.h b/client/dbclient.h index 7f8c09df90f..76eff17e5dd 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -884,14 +884,16 @@ namespace mongo { DBClientReplicaSet *clientSet; boost::scoped_ptr<MessagingPort> p; boost::scoped_ptr<SockAddr> server; - bool failed; // true if some sort of fatal error has ever happened + bool failed; const bool autoReconnect; time_t lastReconnectTry; HostAndPort _server; // remember for reconnects string _serverString; - //int _port; void _checkConnection(); + + // throws SocketException if in failed state and not reconnecting or if waiting to reconnect void checkConnection() { if( failed ) _checkConnection(); } + map< string, pair<string,string> > authCache; const double _so_timeout; bool _connect( string& errmsg ); |