summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/dbclient.cpp2
-rw-r--r--client/dbclient.h4
-rw-r--r--client/dbclient_rs.cpp31
-rw-r--r--client/dbclient_rs.h2
-rw-r--r--client/dbclientcursor.cpp10
-rw-r--r--client/dbclientcursor.h2
-rw-r--r--client/parallel.cpp5
-rw-r--r--client/syncclusterconnection.cpp2
-rw-r--r--client/syncclusterconnection.h2
-rw-r--r--db/instance.cpp2
-rw-r--r--db/instance.h2
11 files changed, 34 insertions, 30 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp
index b5d908daab6..3c27efd1696 100644
--- a/client/dbclient.cpp
+++ b/client/dbclient.cpp
@@ -902,7 +902,7 @@ namespace mongo {
toSend.setData(dbQuery, b.buf(), b.len());
}
- void DBClientConnection::say( Message &toSend ) {
+ void DBClientConnection::say( Message &toSend, bool isRetry ) {
checkConnection();
try {
port().say( toSend );
diff --git a/client/dbclient.h b/client/dbclient.h
index d7b15089cb7..2e1392bc0cb 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -341,7 +341,7 @@ namespace mongo {
virtual ~DBConnector() {}
/** actualServer is set to the actual server where they call went if there was a choice (SlaveOk) */
virtual bool call( Message &toSend, Message &response, bool assertOk=true , string * actualServer = 0 ) = 0;
- virtual void say( Message &toSend ) = 0;
+ virtual void say( Message &toSend, bool isRetry = false ) = 0;
virtual void sayPiggyBack( Message &toSend ) = 0;
/* used by QueryOption_Exhaust. To use that your subclass must implement this. */
virtual bool recv( Message& m ) { assert(false); return false; }
@@ -907,7 +907,7 @@ namespace mongo {
virtual void killCursor( long long cursorID );
virtual bool callRead( Message& toSend , Message& response ) { return call( toSend , response ); }
- virtual void say( Message &toSend );
+ virtual void say( Message &toSend, bool isRetry = false );
virtual bool recv( Message& m );
virtual void checkResponse( const char *data, int nReturned, bool* retry = NULL, string* host = NULL );
virtual bool call( Message &toSend, Message &response, bool assertOk = true , string * actualServer = 0 );
diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp
index 798a3791fc3..66576a2deba 100644
--- a/client/dbclient_rs.cpp
+++ b/client/dbclient_rs.cpp
@@ -436,7 +436,6 @@ namespace mongo {
}
DBClientConnection * DBClientReplicaSet::checkMaster() {
- if( _lazyState._lastClient ) _lazyState = LazyState();
HostAndPort h = _monitor->getMaster();
if ( h == _masterHost && _master ) {
@@ -458,7 +457,6 @@ namespace mongo {
}
DBClientConnection * DBClientReplicaSet::checkSlave() {
- if( _lazyState._lastClient ) _lazyState = LazyState();
HostAndPort h = _monitor->getSlave( _slaveHost );
if ( h == _slaveHost && _slave ) {
@@ -613,7 +611,10 @@ namespace mongo {
_slave.reset();
}
- void DBClientReplicaSet::say( Message& toSend ) {
+ void DBClientReplicaSet::say( Message& toSend, bool isRetry ) {
+
+ if( ! isRetry )
+ _lazyState = LazyState();
int lastOp = -1;
bool slaveOk = false;
@@ -682,30 +683,24 @@ namespace mongo {
else *targetHost = "";
if( ! _lazyState._lastClient ) return;
- if( nReturned > 1 ) return;
+ if( nReturned != 1 && nReturned != -1 ) return;
BSONObj dataObj;
- if( nReturned == 1 && data )
- dataObj = BSONObj( data );
+ if( nReturned == 1 ) dataObj = BSONObj( data );
// Check if we should retry here
if( _lazyState._lastOp == dbQuery && _lazyState._slaveOk ){
- bool mayRetry = false;
- if( dataObj.isEmpty() ){
- warning() << "no data received from " << _lazyState._lastClient->toString() << endl;
- mayRetry = true;
- }
// Check the error code for a slave not secondary error
- else if( hasErrField( dataObj ) && ! dataObj["code"].eoo() && dataObj["code"].Int() == 13436 ){
- mayRetry = true;
- }
+ if( nReturned == -1 ||
+ ( hasErrField( dataObj ) && ! dataObj["code"].eoo() && dataObj["code"].Int() == 13436 ) ){
- if( mayRetry ){
+ bool wasMaster = false;
if( _lazyState._lastClient == _slave.get() ){
isntSecondary();
}
else if( _lazyState._lastClient == _master.get() ){
+ wasMaster = true;
isntMaster();
}
else
@@ -715,7 +710,11 @@ namespace mongo {
_lazyState._retries++;
*retry = true;
}
- else log() << "Could not slave retries!" << endl;
+ else{
+ // assert( wasMaster );
+ // printStackTrace();
+ log() << "too many retries (" << _lazyState._retries << "), could not get data from replica set" << endl;
+ }
}
}
}
diff --git a/client/dbclient_rs.h b/client/dbclient_rs.h
index b49e12f7b28..d59bab0bb5c 100644
--- a/client/dbclient_rs.h
+++ b/client/dbclient_rs.h
@@ -210,7 +210,7 @@ namespace mongo {
// ---- callback pieces -------
- virtual void say( Message &toSend );
+ virtual void say( Message &toSend, bool isRetry = false );
virtual bool recv( Message &toRecv );
virtual void checkResponse( const char* data, int nReturned, bool* retry = NULL, string* targetHost = NULL );
diff --git a/client/dbclientcursor.cpp b/client/dbclientcursor.cpp
index 92b2dfe2c5f..f1685637311 100644
--- a/client/dbclientcursor.cpp
+++ b/client/dbclientcursor.cpp
@@ -69,10 +69,10 @@ namespace mongo {
return true;
}
- void DBClientCursor::initLazy() {
+ void DBClientCursor::initLazy( bool isRetry ) {
Message toSend;
_assembleInit( toSend );
- _client->say( toSend );
+ _client->say( toSend, isRetry );
}
bool DBClientCursor::initLazyFinish( bool& retry ) {
@@ -87,12 +87,14 @@ namespace mongo {
if( b.m->empty() )
log() << "DBClientCursor::init message from say() was empty" << endl;
- _client->checkResponse( NULL, 0, &retry, &_lazyHost );
+ _client->checkResponse( NULL, -1, &retry, &_lazyHost );
+
return false;
+
}
dataReceived( retry, _lazyHost );
- return !retry;
+ return ! retry;
}
void DBClientCursor::requestMore() {
diff --git a/client/dbclientcursor.h b/client/dbclientcursor.h
index fe7816142cb..2c4b9129010 100644
--- a/client/dbclientcursor.h
+++ b/client/dbclientcursor.h
@@ -164,7 +164,7 @@ namespace mongo {
*/
bool init();
- void initLazy();
+ void initLazy( bool isRetry = false );
bool initLazyFinish( bool& retry );
class Batch : boost::noncopyable {
diff --git a/client/parallel.cpp b/client/parallel.cpp
index 94453403067..f157927703f 100644
--- a/client/parallel.cpp
+++ b/client/parallel.cpp
@@ -506,7 +506,7 @@ namespace mongo {
) );
try{
- _cursors[i].raw()->initLazy();
+ _cursors[i].raw()->initLazy( ! firstPass );
}
catch( SocketException& e ){
socketExs.push_back( e.what() + errLoc );
@@ -645,6 +645,9 @@ namespace mongo {
warning() << errMsg.str() << endl;
}
+ if( retries > 0 )
+ log() << "successfully finished parallel query after " << retries << " retries" << endl;
+
}
ParallelSortClusteredCursor::~ParallelSortClusteredCursor() {
diff --git a/client/syncclusterconnection.cpp b/client/syncclusterconnection.cpp
index 80c3c5e4dee..efe37c84ec1 100644
--- a/client/syncclusterconnection.cpp
+++ b/client/syncclusterconnection.cpp
@@ -348,7 +348,7 @@ namespace mongo {
throw UserException( 8008 , "all servers down!" );
}
- void SyncClusterConnection::say( Message &toSend ) {
+ void SyncClusterConnection::say( Message &toSend, bool isRetry ) {
string errmsg;
if ( ! prepare( errmsg ) )
throw UserException( 13397 , (string)"SyncClusterConnection::say prepare failed: " + errmsg );
diff --git a/client/syncclusterconnection.h b/client/syncclusterconnection.h
index 556b122f208..173b21672bb 100644
--- a/client/syncclusterconnection.h
+++ b/client/syncclusterconnection.h
@@ -76,7 +76,7 @@ namespace mongo {
virtual void update( const string &ns , Query query , BSONObj obj , bool upsert , bool multi );
virtual bool call( Message &toSend, Message &response, bool assertOk , string * actualServer );
- virtual void say( Message &toSend );
+ virtual void say( Message &toSend, bool isRetry = false );
virtual void sayPiggyBack( Message &toSend );
virtual void killCursor( long long cursorID );
diff --git a/db/instance.cpp b/db/instance.cpp
index a3b9918e7d5..7c4863f185f 100644
--- a/db/instance.cpp
+++ b/db/instance.cpp
@@ -687,7 +687,7 @@ namespace mongo {
return true;
}
- void DBDirectClient::say( Message &toSend ) {
+ void DBDirectClient::say( Message &toSend, bool isRetry ) {
if ( lastError._get() )
lastError.startRequest( toSend, lastError._get() );
DbResponse dbResponse;
diff --git a/db/instance.h b/db/instance.h
index 7bf163eb6ae..f5133b18ca9 100644
--- a/db/instance.h
+++ b/db/instance.h
@@ -130,7 +130,7 @@ namespace mongo {
return "localhost"; // TODO: should this have the port?
}
virtual bool call( Message &toSend, Message &response, bool assertOk=true , string * actualServer = 0 );
- virtual void say( Message &toSend );
+ virtual void say( Message &toSend, bool isRetry = false );
virtual void sayPiggyBack( Message &toSend ) {
// don't need to piggy back when connected locally
return say( toSend );