Permalink
Browse files

fix replica set cursor cleaning through mongos SERVER-2505

fix cursor cleaning in mongos generally by not doing lazy cleaning
  • Loading branch information...
1 parent e0c8d9a commit 37b11e4dde95b6f93032448d48d0190045aebe54 @erh erh committed Feb 10, 2011
Showing with 37 additions and 4 deletions.
  1. +6 −2 client/dbclient.cpp
  2. +4 −0 client/dbclient.h
  3. +9 −1 client/dbclient_rs.cpp
  4. +3 −0 jstests/slowNightly/sharding_rs2.js
  5. +8 −0 s/cursors.cpp
  6. +2 −0 s/cursors.h
  7. +5 −1 s/server.cpp
View
@@ -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 ) {
View
@@ -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
View
@@ -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 );
}
}
@@ -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" )
View
@@ -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; i<n; i++ ) {
long long id = cursors[i];
+ LOG(_myLogLevel) << "CursorCache::gotKillCursors id: " << id << endl;
+
if ( ! id ) {
log( LL_WARNING ) << " got cursor id of 0 to kill" << endl;
continue;
@@ -239,6 +243,8 @@ namespace mongo {
_refs.erase( j );
}
+ LOG(_myLogLevel) << "CursorCache::found gotKillCursors id: " << id << " server: " << server << endl;
+
assert( server.size() );
ScopedDbConnection conn( server );
conn->killCursor( 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"; }
View
@@ -98,6 +98,8 @@ namespace mongo {
MapNormal _refs;
long long _shardedTotal;
+
+ static int _myLogLevel;
};
extern CursorCache cursorCache;
View
@@ -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;

0 comments on commit 37b11e4

Please sign in to comment.