diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-01-21 14:19:20 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-01-21 14:19:49 -0500 |
commit | b331e1c7aed7d85dd14f86e1396f5c091aaa3f0f (patch) | |
tree | bed9d99f5714067d312e8f5c28220dd72687696e /s/client.cpp | |
parent | 124193c25929b70baa9fdd00127d87159b9b64ca (diff) | |
download | mongo-b331e1c7aed7d85dd14f86e1396f5c091aaa3f0f.tar.gz |
make sure getLastError fields are correct after writeback SERVER-1467
Diffstat (limited to 's/client.cpp')
-rw-r--r-- | s/client.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/s/client.cpp b/s/client.cpp index c1c3da8ea7e..18f598a03d3 100644 --- a/s/client.cpp +++ b/s/client.cpp @@ -39,6 +39,7 @@ namespace mongo { ClientInfo::ClientInfo( int clientId ) : _id( clientId ) { _cur = &_a; _prev = &_b; + _autoSplitOk = true; newRequest(); } @@ -123,14 +124,13 @@ namespace mongo { _clients.erase( i ); } - void ClientInfo::_addWriteBack( vector<WBInfo>& all , const BSONObj& o ) { - BSONElement w = o["writeback"]; + void ClientInfo::_addWriteBack( vector<WBInfo>& all , const BSONObj& gle ) { + BSONElement w = gle["writeback"]; if ( w.type() != jstOID ) return; - BSONElement cid = o["connectionId"]; - cout << "ELIOT : " << cid << endl; + BSONElement cid = gle["connectionId"]; if ( cid.eoo() ) { error() << "getLastError writeback can't work because of version mis-match" << endl; @@ -140,13 +140,17 @@ namespace mongo { all.push_back( WBInfo( cid.numberLong() , w.OID() ) ); } - void ClientInfo::_handleWriteBacks( vector<WBInfo>& all ) { + vector<BSONObj> ClientInfo::_handleWriteBacks( vector<WBInfo>& all ) { + vector<BSONObj> res; + if ( all.size() == 0 ) - return; + return res; for ( unsigned i=0; i<all.size(); i++ ) { - WriteBackListener::waitFor( all[i].connectionId , all[i].id ); + res.push_back( WriteBackListener::waitFor( all[i].connectionId , all[i].id ) ); } + + return res; } @@ -164,14 +168,15 @@ namespace mongo { // handle single server if ( shards->size() == 1 ) { string theShard = *(shards->begin() ); - result.append( "theshard" , theShard.c_str() ); + ShardConnection conn( theShard , "" ); + BSONObj res; bool ok = conn->runCommand( "admin" , options , res ); - //log() << "\t" << res << endl; - result.appendElements( res ); + res = res.getOwned(); conn.done(); - result.append( "singleShard" , theShard ); + + _addWriteBack( writebacks , res ); // hit other machines just to block @@ -185,7 +190,19 @@ namespace mongo { conn.done(); } clearSinceLastGetError(); - _handleWriteBacks( writebacks ); + + if ( writebacks.size() ){ + vector<BSONObj> v = _handleWriteBacks( writebacks ); + assert( v.size() == 1 ); + result.appendElements( v[0] ); + result.appendElementsUnique( res ); + result.append( "initialGLEHost" , theShard ); + } + else { + result.append( "singleShard" , theShard ); + result.appendElements( res ); + } + return ok; } |