summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-01-25 01:22:18 -0500
committerEliot Horowitz <eliot@10gen.com>2012-01-25 01:22:18 -0500
commit72231559d2727473f3fccada4bf8dd94f42a1ea9 (patch)
treec64b2920ca3476349f1544d8b783c5de1cc20cc7
parent5d7fa5c8f25bc8e78c4cabf29a382c6950b720b5 (diff)
downloadmongo-72231559d2727473f3fccada4bf8dd94f42a1ea9.tar.gz
fix slave ok getMore cursors via mongos by storing actual server used
-rw-r--r--src/mongo/client/dbclient.cpp2
-rw-r--r--src/mongo/client/dbclient.h4
-rw-r--r--src/mongo/client/dbclient_rs.cpp7
-rw-r--r--src/mongo/client/dbclient_rs.h2
-rw-r--r--src/mongo/client/dbclientcursor.cpp10
-rw-r--r--src/mongo/client/dbclientcursor.h6
-rw-r--r--src/mongo/client/syncclusterconnection.cpp4
-rw-r--r--src/mongo/client/syncclusterconnection.h2
-rw-r--r--src/mongo/db/instance.cpp2
-rw-r--r--src/mongo/db/instance.h2
-rw-r--r--src/mongo/s/cursors.cpp4
-rw-r--r--src/mongo/s/strategy_shard.cpp2
12 files changed, 33 insertions, 14 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index abd46a4e3a3..f4d44581302 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -953,7 +953,7 @@ namespace mongo {
toSend.setData(dbQuery, b.buf(), b.len());
}
- void DBClientConnection::say( Message &toSend, bool isRetry ) {
+ void DBClientConnection::say( Message &toSend, bool isRetry , string * actualServer ) {
checkConnection();
try {
port().say( toSend );
diff --git a/src/mongo/client/dbclient.h b/src/mongo/client/dbclient.h
index ed3bfe106be..073a8e232ae 100644
--- a/src/mongo/client/dbclient.h
+++ b/src/mongo/client/dbclient.h
@@ -408,7 +408,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, bool isRetry = false ) = 0;
+ virtual void say( Message &toSend, bool isRetry = false , string * actualServer = 0 ) = 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; }
@@ -969,7 +969,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, bool isRetry = false );
+ virtual void say( Message &toSend, bool isRetry = false , string * actualServer = 0 );
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/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp
index 0688720a8fc..0ff07fdb030 100644
--- a/src/mongo/client/dbclient_rs.cpp
+++ b/src/mongo/client/dbclient_rs.cpp
@@ -829,7 +829,7 @@ namespace mongo {
_slave.reset();
}
- void DBClientReplicaSet::say( Message& toSend, bool isRetry ) {
+ void DBClientReplicaSet::say( Message& toSend, bool isRetry , string * actualServer ) {
if( ! isRetry )
_lazyState = LazyState();
@@ -846,6 +846,8 @@ namespace mongo {
for ( int i = _lazyState._retries; i < 3; i++ ) {
try {
DBClientConnection* slave = checkSlave();
+ if ( actualServer )
+ *actualServer = slave->getServerAddress();
slave->say( toSend );
_lazyState._lastOp = lastOp;
@@ -862,6 +864,9 @@ namespace mongo {
}
DBClientConnection* master = checkMaster();
+ if ( actualServer )
+ *actualServer = master->getServerAddress();
+
master->say( toSend );
_lazyState._lastOp = lastOp;
diff --git a/src/mongo/client/dbclient_rs.h b/src/mongo/client/dbclient_rs.h
index 0edcea42716..8e60775033f 100644
--- a/src/mongo/client/dbclient_rs.h
+++ b/src/mongo/client/dbclient_rs.h
@@ -259,7 +259,7 @@ namespace mongo {
// ---- callback pieces -------
- virtual void say( Message &toSend, bool isRetry = false );
+ virtual void say( Message &toSend, bool isRetry = false , string* actualServer = 0);
virtual bool recv( Message &toRecv );
virtual void checkResponse( const char* data, int nReturned, bool* retry = NULL, string* targetHost = NULL );
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp
index 79510b766d8..589c4743802 100644
--- a/src/mongo/client/dbclientcursor.cpp
+++ b/src/mongo/client/dbclientcursor.cpp
@@ -27,6 +27,10 @@ namespace mongo {
void assembleRequest( const string &ns, BSONObj query, int nToReturn, int nToSkip, const BSONObj *fieldsToReturn, int queryOptions, Message &toSend );
+ void DBClientCursor::_finishConsInit() {
+ _originalHost = _client->toString();
+ }
+
int DBClientCursor::nextBatchSize() {
if ( nToReturn == 0 )
@@ -55,8 +59,8 @@ namespace mongo {
bool DBClientCursor::init() {
Message toSend;
_assembleInit( toSend );
-
- if ( !_client->call( toSend, *batch.m, false ) ) {
+ assert( _client );
+ if ( !_client->call( toSend, *batch.m, false, &_originalHost ) ) {
// log msg temp?
log() << "DBClientCursor::init call() failed" << endl;
return false;
@@ -74,7 +78,7 @@ namespace mongo {
verify( 15875 , _client->lazySupported() );
Message toSend;
_assembleInit( toSend );
- _client->say( toSend, isRetry );
+ _client->say( toSend, isRetry, &_originalHost );
}
bool DBClientCursor::initLazyFinish( bool& retry ) {
diff --git a/src/mongo/client/dbclientcursor.h b/src/mongo/client/dbclientcursor.h
index 31bf1bb1d5e..d7661438516 100644
--- a/src/mongo/client/dbclientcursor.h
+++ b/src/mongo/client/dbclientcursor.h
@@ -138,6 +138,7 @@ namespace mongo {
cursorId(),
_ownCursor( true ),
wasError( false ) {
+ _finishConsInit();
}
DBClientCursor( DBClientBase* client, const string &_ns, long long _cursorId, int _nToReturn, int options ) :
@@ -148,6 +149,7 @@ namespace mongo {
opts( options ),
cursorId(_cursorId),
_ownCursor( true ) {
+ _finishConsInit();
}
virtual ~DBClientCursor();
@@ -161,6 +163,8 @@ namespace mongo {
void attach( AScopedConnection * conn );
+ string originalHost() const { return _originalHost; }
+
Message* getMessage(){ return batch.m.get(); }
/**
@@ -186,9 +190,11 @@ namespace mongo {
friend class DBClientConnection;
int nextBatchSize();
+ void _finishConsInit();
Batch batch;
DBClientBase* _client;
+ string _originalHost;
string ns;
BSONObj query;
int nToReturn;
diff --git a/src/mongo/client/syncclusterconnection.cpp b/src/mongo/client/syncclusterconnection.cpp
index 601cdcbd758..67857ce3fcc 100644
--- a/src/mongo/client/syncclusterconnection.cpp
+++ b/src/mongo/client/syncclusterconnection.cpp
@@ -361,7 +361,7 @@ namespace mongo {
throw UserException( 8008 , "all servers down!" );
}
- void SyncClusterConnection::say( Message &toSend, bool isRetry ) {
+ void SyncClusterConnection::say( Message &toSend, bool isRetry , string * actualServer ) {
string errmsg;
if ( ! prepare( errmsg ) )
throw UserException( 13397 , (string)"SyncClusterConnection::say prepare failed: " + errmsg );
@@ -370,6 +370,8 @@ namespace mongo {
_conns[i]->say( toSend );
}
+ // TODO: should we set actualServer??
+
_checkLast();
}
diff --git a/src/mongo/client/syncclusterconnection.h b/src/mongo/client/syncclusterconnection.h
index d2374ddaa45..b9b1a8de266 100644
--- a/src/mongo/client/syncclusterconnection.h
+++ b/src/mongo/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, bool isRetry = false );
+ virtual void say( Message &toSend, bool isRetry = false , string * actualServer = 0 );
virtual void sayPiggyBack( Message &toSend );
virtual void killCursor( long long cursorID );
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index 5d3a30057a2..806721b4ac1 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -796,7 +796,7 @@ namespace mongo {
return true;
}
- void DBDirectClient::say( Message &toSend, bool isRetry ) {
+ void DBDirectClient::say( Message &toSend, bool isRetry, string * actualServer ) {
if ( lastError._get() )
lastError.startRequest( toSend, lastError._get() );
DbResponse dbResponse;
diff --git a/src/mongo/db/instance.h b/src/mongo/db/instance.h
index 1c12ff39355..e57eccd1b5b 100644
--- a/src/mongo/db/instance.h
+++ b/src/mongo/db/instance.h
@@ -98,7 +98,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, bool isRetry = false );
+ virtual void say( Message &toSend, bool isRetry = false , string * actualServer = 0 );
virtual void sayPiggyBack( Message &toSend ) {
// don't need to piggy back when connected locally
return say( toSend );
diff --git a/src/mongo/s/cursors.cpp b/src/mongo/s/cursors.cpp
index 5ae99cff06b..e56b4101d32 100644
--- a/src/mongo/s/cursors.cpp
+++ b/src/mongo/s/cursors.cpp
@@ -172,10 +172,12 @@ namespace mongo {
}
string CursorCache::getRef( long long id ) const {
- LOG(_myLogLevel) << "CursorCache::getRef id: " << id << endl;
assert( id );
scoped_lock lk( _mutex );
MapNormal::const_iterator i = _refs.find( id );
+
+ LOG(_myLogLevel) << "CursorCache::getRef id: " << id << " out: " << ( i == _refs.end() ? " NONE " : i->second ) << endl;
+
if ( i == _refs.end() )
return "";
return i->second;
diff --git a/src/mongo/s/strategy_shard.cpp b/src/mongo/s/strategy_shard.cpp
index 9cc664651cd..81fe78c7c5d 100644
--- a/src/mongo/s/strategy_shard.cpp
+++ b/src/mongo/s/strategy_shard.cpp
@@ -95,7 +95,7 @@ namespace mongo {
// TODO: Better merge this logic. We potentially can now use the same cursor logic for everything.
ShardPtr primary = cursor->getPrimary();
DBClientCursorPtr shardCursor = cursor->getShardCursor( *primary );
- r.reply( *(shardCursor->getMessage()) , primary->getConnString() );
+ r.reply( *(shardCursor->getMessage()) , shardCursor->originalHost() );
}
}