diff --git a/client/dbclient.cpp b/client/dbclient.cpp index cc8a3bf857b45..631c6e6ccb53e 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -902,11 +902,15 @@ namespace mongo { Message m; m.setData( dbKillCursors , b.buf() , b.len() ); - - sayPiggyBack( m ); + + if ( _lazyKillCursor ) + sayPiggyBack( m ); + else + say(m); } AtomicUInt DBClientConnection::_numConnections; + bool DBClientConnection::_lazyKillCursor = true; bool serverAlive( const string &uri ) { diff --git a/client/dbclient.h b/client/dbclient.h index 8339a0806d0bf..d1b049619ce97 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -900,6 +900,9 @@ namespace mongo { static int getNumConnections() { return _numConnections; } + + static void setLazyKillCursor( bool lazy ) { _lazyKillCursor = lazy; } + static bool getLazyKillCursor() { return _lazyKillCursor; } protected: friend class SyncClusterConnection; @@ -924,6 +927,7 @@ namespace mongo { bool _connect( string& errmsg ); static AtomicUInt _numConnections; + static bool _lazyKillCursor; // lazy means we piggy back kill cursors on next op }; /** pings server to check if it's up diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp index f5aafb0c56876..7b25d2307eb7a 100644 --- a/client/dbclient_rs.cpp +++ b/client/dbclient_rs.cpp @@ -522,6 +522,10 @@ namespace mongo { } void DBClientReplicaSet::killCursor( long long cursorID ) { + // we should neve call killCursor on a replica set conncetion + // since we don't know which server it belongs to + // can't assume master because of slave ok + // and can have a cursor survive a master change assert(0); } @@ -547,7 +551,11 @@ namespace mongo { } } } - return checkMaster()->call( toSend , response , assertOk ); + + DBClientConnection* m = checkMaster(); + if ( actualServer ) + *actualServer = m->getServerAddress(); + return m->call( toSend , response , assertOk ); } } diff --git a/jstests/slowNightly/sharding_rs2.js b/jstests/slowNightly/sharding_rs2.js index d71b3d0aebd8b..ebff712c4b4c5 100644 --- a/jstests/slowNightly/sharding_rs2.js +++ b/jstests/slowNightly/sharding_rs2.js @@ -95,6 +95,9 @@ assert.eq( 100 , ts.count() , "B4" ) assert.eq( 100 , ts.find().itcount() , "B5" ) assert.eq( 100 , ts.find().batchSize(5).itcount() , "B6" ) +t.find().batchSize(3).next(); +gc(); gc(); gc(); + // --- sharded ---- assert.eq( 100 , db.foo.count() , "C1" ) diff --git a/s/cursors.cpp b/s/cursors.cpp index 903d588f77ab9..4ca824087c78a 100644 --- a/s/cursors.cpp +++ b/s/cursors.cpp @@ -163,12 +163,14 @@ namespace mongo { } void CursorCache::storeRef( const string& server , long long id ) { + LOG(_myLogLevel) << "CursorCache::storeRef server: " << server << " id: " << id << endl; assert( id ); scoped_lock lk( _mutex ); _refs[id] = server; } 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 ); @@ -215,6 +217,8 @@ namespace mongo { long long * cursors = (long long *)x; for ( int i=0; ikillCursor( id ); @@ -269,6 +275,8 @@ namespace mongo { CursorCache cursorCache; + int CursorCache::_myLogLevel = 3; + class CursorTimeoutTask : public task::Task { public: virtual string name() const { return "cursorTimeout"; } diff --git a/s/cursors.h b/s/cursors.h index f11d3fb7b6987..7b54af6e0e20c 100644 --- a/s/cursors.h +++ b/s/cursors.h @@ -98,6 +98,8 @@ namespace mongo { MapNormal _refs; long long _shardedTotal; + + static int _myLogLevel; }; extern CursorCache cursorCache; diff --git a/s/server.cpp b/s/server.cpp index a71bbf48d2b78..9bdeedeec6d46 100644 --- a/s/server.cpp +++ b/s/server.cpp @@ -276,12 +276,16 @@ int _main(int argc, char* argv[]) { return 9; } } + + // set some global state pool.addHook( &shardingConnectionHook ); pool.setName( "mongos connectionpool" ); + + DBClientConnection::setLazyKillCursor( false ); ReplicaSetMonitor::setConfigChangeHook( boost::bind( &ConfigServer::replicaSetChange , &configServer , _1 ) ); - + if ( argc <= 1 ) { usage( argv ); return 3;