Permalink
Browse files

auto-reload chunk manager to check version not reset after third stal…

…econfig SERVER-3889
  • Loading branch information...
1 parent fec06cf commit 0b2cd79560d425fd1b86c1db05e598bc400b13e8 gregs committed Sep 28, 2011
Showing with 33 additions and 20 deletions.
  1. +20 −9 s/config.cpp
  2. +2 −2 s/config.h
  3. +3 −3 s/request.cpp
  4. +1 −1 s/request.h
  5. +2 −2 shell/mongo_vstudio.cpp
  6. +3 −1 shell/servers.js
  7. +2 −2 shell/utils.js
View
@@ -185,17 +185,17 @@ namespace mongo {
return true;
}
- ChunkManagerPtr DBConfig::getChunkManagerIfExists( const string& ns, bool shouldReload ){
+ ChunkManagerPtr DBConfig::getChunkManagerIfExists( const string& ns, bool shouldReload, bool forceReload ){
try{
- return getChunkManager( ns, shouldReload );
+ return getChunkManager( ns, shouldReload, forceReload );
}
catch( AssertionException& e ){
warning() << "chunk manager not found for " << ns << causedBy( e ) << endl;
return ChunkManagerPtr();
}
}
- ChunkManagerPtr DBConfig::getChunkManager( const string& ns , bool shouldReload ) {
+ ChunkManagerPtr DBConfig::getChunkManager( const string& ns , bool shouldReload, bool forceReload ) {
BSONObj key;
bool unique;
ShardChunkVersion oldVersion;
@@ -205,7 +205,7 @@ namespace mongo {
CollectionInfo& ci = _collections[ns];
- bool earlyReload = ! ci.isSharded() && shouldReload;
+ bool earlyReload = ! ci.isSharded() && ( shouldReload || forceReload );
if ( earlyReload ) {
// this is to catch cases where there this is a new sharded collection
_reload();
@@ -214,7 +214,7 @@ namespace mongo {
massert( 10181 , (string)"not sharded:" + ns , ci.isSharded() );
assert( ! ci.key().isEmpty() );
- if ( ! shouldReload || earlyReload )
+ if ( ! ( shouldReload || forceReload ) || earlyReload )
return ci.getCM();
key = ci.key().copy();
@@ -225,7 +225,7 @@ namespace mongo {
assert( ! key.isEmpty() );
- if ( oldVersion > 0 ) {
+ if ( oldVersion > 0 && ! forceReload ) {
ScopedDbConnection conn( configServer.modelServer() , 30.0 );
BSONObj newest = conn->findOne( ShardNS::chunk ,
Query( BSON( "ns" << ns ) ).sort( "lastmod" , -1 ) );
@@ -240,7 +240,11 @@ namespace mongo {
return ci.getCM();
}
}
-
+
+ }
+ else if( oldVersion == 0 ){
+ warning() << "version 0 found when " << ( forceReload ? "reloading" : "checking" ) << " chunk manager"
+ << ", collection '" << ns << "' initially detected as sharded" << endl;
}
// we are not locked now, and want to load a new ChunkManager
@@ -257,8 +261,15 @@ namespace mongo {
CollectionInfo& ci = _collections[ns];
massert( 14822 , (string)"state changed in the middle: " + ns , ci.isSharded() );
- if ( temp->getVersion() > ci.getCM()->getVersion() ) {
- // we only want to reset if we're newer
+ bool forced = false;
+ if ( temp->getVersion() > ci.getCM()->getVersion() ||
+ (forced = (temp->getVersion() == ci.getCM()->getVersion() && forceReload ) ) ) {
+
+ if( forced ){
+ warning() << "chunk manager reload forced for collection '" << ns << "', config version is " << temp->getVersion() << endl;
+ }
+
+ // we only want to reset if we're newer or equal and forced
// otherwise we go into a bad cycle
ci.resetCM( temp.release() );
}
View
@@ -142,8 +142,8 @@ namespace mongo {
*/
bool isSharded( const string& ns );
- ChunkManagerPtr getChunkManager( const string& ns , bool reload = false );
- ChunkManagerPtr getChunkManagerIfExists( const string& ns , bool reload = false );
+ ChunkManagerPtr getChunkManager( const string& ns , bool reload = false, bool forceReload = false );
+ ChunkManagerPtr getChunkManagerIfExists( const string& ns , bool reload = false, bool forceReload = false );
/**
* @return the correct for shard for the ns
View
@@ -58,7 +58,7 @@ namespace mongo {
reset();
}
- void Request::reset( bool reload ) {
+ void Request::reset( bool reload, bool forceReload ) {
if ( _m.operation() == dbKillCursors ) {
return;
}
@@ -70,7 +70,7 @@ namespace mongo {
_config = grid.getDBConfig( nsStr );
if ( reload ) {
if ( _config->isSharded( nsStr ) )
- _config->getChunkManager( nsStr , true );
+ _config->getChunkManager( nsStr , true, forceReload );
else
_config->reload();
}
@@ -137,7 +137,7 @@ namespace mongo {
ShardConnection::checkMyConnectionVersions( getns() );
if (!staleConfig.justConnection() )
sleepsecs( attempt );
- reset( ! staleConfig.justConnection() );
+ reset( ! staleConfig.justConnection(), attempt >= 2 );
_d.markReset();
process( attempt + 1 );
return;
View
@@ -91,7 +91,7 @@ namespace mongo {
void init();
- void reset( bool reload=false );
+ void reset( bool reload=false, bool forceReload = false );
private:
Message& _m;
View
@@ -1005,8 +1005,8 @@ const StringData _jscode_raw_utils =
"return {}\n"
"}\n"
"\n"
-"testLog = function(x){\n"
-"print( jsTestFile() + \" - \" + x )\n"
+"jsTestLog = function(msg){\n"
+"print( \"\\n\\n----\\n\" + msg + \"\\n----\\n\\n\" )\n"
"}\n"
"\n"
"shellPrintHelper = function (x) {\n"
View
@@ -235,7 +235,8 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
rs.awaitReplication();
var xxx = new Mongo( rs.getURL() );
xxx.name = rs.getURL();
- this._connections.push( xxx );
+ this._connections.push( xxx )
+ this["shard" + i] = xxx
}
this._configServers = []
@@ -260,6 +261,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
var conn = startMongodTest( 30000 + i , testName + i, 0, options );
this._alldbpaths.push( testName +i )
this._connections.push( conn );
+ this["shard" + i] = conn
}
if ( otherParams.sync ){
View
@@ -1000,8 +1000,8 @@ jsTestOptions = function(){
return {}
}
-testLog = function(x){
- print( jsTestFile() + " - " + x )
+jsTestLog = function(msg){
+ print( "\n\n----\n" + msg + "\n----\n\n" )
}
shellPrintHelper = function (x) {

0 comments on commit 0b2cd79

Please sign in to comment.