summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-02-05 17:51:36 -0500
committerEliot Horowitz <eliot@10gen.com>2011-02-05 17:52:36 -0500
commit471fd7da06644d80c906e2ac69190216791ef450 (patch)
tree96110e3e49b7ec43fdb2b03bf89e1acac71b702a
parent2949494e2c245461f9a91b3e705aec966f0109ed (diff)
downloadmongo-471fd7da06644d80c906e2ac69190216791ef450.tar.gz
added option paral to call to specify server address where was sent if different
-rw-r--r--client/dbclient.cpp2
-rw-r--r--client/dbclient.h5
-rw-r--r--client/dbclient_rs.cpp9
-rw-r--r--client/dbclient_rs.h2
-rw-r--r--client/syncclusterconnection.cpp7
-rw-r--r--client/syncclusterconnection.h2
-rw-r--r--db/instance.cpp2
-rw-r--r--db/instance.h2
8 files changed, 20 insertions, 11 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp
index da0c84f3745..cc8a3bf857b 100644
--- a/client/dbclient.cpp
+++ b/client/dbclient.cpp
@@ -859,7 +859,7 @@ namespace mongo {
port().recv(m);
}
- bool DBClientConnection::call( Message &toSend, Message &response, bool assertOk ) {
+ bool DBClientConnection::call( Message &toSend, Message &response, bool assertOk , string * actualServer ) {
/* todo: this is very ugly messagingport::call returns an error code AND can throw
an exception. we should make it return void and just throw an exception anytime
it fails
diff --git a/client/dbclient.h b/client/dbclient.h
index b731604aca8..8339a0806d0 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -347,7 +347,8 @@ namespace mongo {
class DBConnector {
public:
virtual ~DBConnector() {}
- virtual bool call( Message &toSend, Message &response, bool assertOk=true ) = 0;
+ /** 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 sayPiggyBack( Message &toSend ) = 0;
virtual void checkResponse( const char* data, int nReturned ) {}
@@ -891,7 +892,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 bool call( Message &toSend, Message &response, bool assertOk = true );
+ virtual bool call( Message &toSend, Message &response, bool assertOk = true , string * actualServer = 0 );
virtual ConnectionString::ConnectionType type() const { return ConnectionString::MASTER; }
virtual void checkResponse( const char *data, int nReturned );
void setSoTimeout(double to) { _so_timeout = to; }
diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp
index 748a1f3f52a..d3d50d39ef6 100644
--- a/client/dbclient_rs.cpp
+++ b/client/dbclient_rs.cpp
@@ -526,7 +526,7 @@ namespace mongo {
}
- bool DBClientReplicaSet::call( Message &toSend, Message &response, bool assertOk ) {
+ bool DBClientReplicaSet::call( Message &toSend, Message &response, bool assertOk , string * actualServer ) {
if ( toSend.operation() == dbQuery ) {
// TODO: might be possible to do this faster by changing api
DbMessage dm( toSend );
@@ -534,10 +534,15 @@ namespace mongo {
if ( qm.queryOptions & QueryOption_SlaveOk ) {
for ( int i=0; i<2; i++ ) {
try {
- return checkSlave()->call( toSend , response , assertOk );
+ DBClientConnection* s = checkSlave();
+ if ( actualServer )
+ *actualServer = s->getServerAddress();
+ return s->call( toSend , response , assertOk );
}
catch ( DBException & ) {
log(1) << "can't query replica set slave: " << _slaveHost << endl;
+ if ( actualServer )
+ *actualServer = "";
}
}
}
diff --git a/client/dbclient_rs.h b/client/dbclient_rs.h
index 3bbb91e8cc7..b461478f90a 100644
--- a/client/dbclient_rs.h
+++ b/client/dbclient_rs.h
@@ -227,7 +227,7 @@ namespace mongo {
// ---- low level ------
- virtual bool call( Message &toSend, Message &response, bool assertOk=true );
+ virtual bool call( Message &toSend, Message &response, bool assertOk=true , string * actualServer = 0 );
virtual void say( Message &toSend ) { checkMaster()->say( toSend ); }
virtual bool callRead( Message& toSend , Message& response ) { return checkMaster()->callRead( toSend , response ); }
diff --git a/client/syncclusterconnection.cpp b/client/syncclusterconnection.cpp
index f378ca0b317..69ad8539bae 100644
--- a/client/syncclusterconnection.cpp
+++ b/client/syncclusterconnection.cpp
@@ -313,7 +313,7 @@ namespace mongo {
return ss.str();
}
- bool SyncClusterConnection::call( Message &toSend, Message &response, bool assertOk ) {
+ bool SyncClusterConnection::call( Message &toSend, Message &response, bool assertOk , string * actualServer ) {
uassert( 8006 , "SyncClusterConnection::call can only be used directly for dbQuery" ,
toSend.operation() == dbQuery );
@@ -323,8 +323,11 @@ namespace mongo {
for ( size_t i=0; i<_conns.size(); i++ ) {
try {
bool ok = _conns[i]->call( toSend , response , assertOk );
- if ( ok )
+ if ( ok ) {
+ if ( actualServer )
+ *actualServer = _connAddresses[i];
return ok;
+ }
log() << "call failed to: " << _conns[i]->toString() << " no data" << endl;
}
catch ( ... ) {
diff --git a/client/syncclusterconnection.h b/client/syncclusterconnection.h
index 7d2c2abfe36..c946073319a 100644
--- a/client/syncclusterconnection.h
+++ b/client/syncclusterconnection.h
@@ -75,7 +75,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 );
+ virtual bool call( Message &toSend, Message &response, bool assertOk , string * actualServer );
virtual void say( Message &toSend );
virtual void sayPiggyBack( Message &toSend );
diff --git a/db/instance.cpp b/db/instance.cpp
index 9e5d6ab5da2..65e422c5a40 100644
--- a/db/instance.cpp
+++ b/db/instance.cpp
@@ -644,7 +644,7 @@ namespace mongo {
return false;
}
- bool DBDirectClient::call( Message &toSend, Message &response, bool assertOk ) {
+ bool DBDirectClient::call( Message &toSend, Message &response, bool assertOk , string * actualServer ) {
if ( lastError._get() )
lastError.startRequest( toSend, lastError._get() );
DbResponse dbResponse;
diff --git a/db/instance.h b/db/instance.h
index 1c7e6105453..b9b1fe5921b 100644
--- a/db/instance.h
+++ b/db/instance.h
@@ -127,7 +127,7 @@ namespace mongo {
virtual string getServerAddress() const {
return "localhost"; // TODO: should this have the port?
}
- virtual bool call( Message &toSend, Message &response, bool assertOk=true );
+ virtual bool call( Message &toSend, Message &response, bool assertOk=true , string * actualServer = 0 );
virtual void say( Message &toSend );
virtual void sayPiggyBack( Message &toSend ) {
// don't need to piggy back when connected locally