diff options
author | dwight <dwight@dwights-MacBook-Pro.local> | 2011-04-29 22:49:09 -0400 |
---|---|---|
committer | dwight <dwight@dwights-MacBook-Pro.local> | 2011-04-29 22:49:09 -0400 |
commit | 0797232ce9144257dae4f7ddc5e97b07ff0dd9b8 (patch) | |
tree | b71fbcf6623b4924b0711e8f528d3e3fda05d550 | |
parent | eb964f15842390f4790ad0572107fa40fd98f6c1 (diff) | |
parent | c574959c57f3f66dcdd41a244f08b687ca03480b (diff) | |
download | mongo-0797232ce9144257dae4f7ddc5e97b07ff0dd9b8.tar.gz |
Merge branch 'master' of git@github.com:mongodb/mongo
-rw-r--r-- | jstests/sharding/shard3.js | 9 | ||||
-rw-r--r-- | jstests/slowNightly/sharding_balance1.js | 3 | ||||
-rw-r--r-- | s/balance.cpp | 45 | ||||
-rw-r--r-- | s/strategy_shard.cpp | 4 | ||||
-rw-r--r-- | shell/mongo_vstudio.cpp | 16 | ||||
-rw-r--r-- | shell/utils_sh.js | 16 |
6 files changed, 67 insertions, 26 deletions
diff --git a/jstests/sharding/shard3.js b/jstests/sharding/shard3.js index 71325637baf..0a4bc2ff75f 100644 --- a/jstests/sharding/shard3.js +++ b/jstests/sharding/shard3.js @@ -4,9 +4,18 @@ s = new ShardingTest( "shard3" , 2 , 1 , 2 ); s2 = s._mongos[1]; +db = s.getDB( "test" ) s.adminCommand( { enablesharding : "test" } ); s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } ); +assert( sh.getBalancerState() , "A1" ) +sh.setBalancerState( false ) +assert( ! sh.getBalancerState() , "A2" ) +sh.setBalancerState( true ) +assert( sh.getBalancerState() , "A3" ) +sh.setBalancerState( false ) +assert( ! sh.getBalancerState() , "A4" ) + s.config.databases.find().forEach( printjson ) a = s.getDB( "test" ).foo; diff --git a/jstests/slowNightly/sharding_balance1.js b/jstests/slowNightly/sharding_balance1.js index 9379c4fa310..c50148c0400 100644 --- a/jstests/slowNightly/sharding_balance1.js +++ b/jstests/slowNightly/sharding_balance1.js @@ -41,7 +41,8 @@ print( diff() ) assert.soon( function(){ var d = diff(); return d < 5; -} , "balance didn't happen" , 1000 * 60 * 3 , 5000 ); +// Make sure there's enough time here, since balancing can sleep for 15s or so between balances. +} , "balance didn't happen" , 1000 * 60 * 5 , 5000 ); var chunkCount = sum(); s.adminCommand( { removeshard: "shard0000" } ); diff --git a/s/balance.cpp b/s/balance.cpp index ffa23ed794b..fba325ed5ae 100644 --- a/s/balance.cpp +++ b/s/balance.cpp @@ -294,29 +294,32 @@ namespace mongo { // use fresh shard state Shard::reloadShardInfo(); - dist_lock_try lk( &balanceLock , "doing balance round" ); - if ( ! lk.got() ) { - log(1) << "skipping balancing round because another balancer is active" << endl; - conn.done(); - - sleepsecs( 30 ); // no need to wake up soon - continue; - } - - log(1) << "*** start balancing round" << endl; - - vector<CandidateChunkPtr> candidateChunks; - _doBalanceRound( conn.conn() , &candidateChunks ); - if ( candidateChunks.size() == 0 ) { - log(1) << "no need to move any chunk" << endl; - } - else { - _balancedLastTime = _moveChunks( &candidateChunks ); + { + dist_lock_try lk( &balanceLock , "doing balance round" ); + if ( ! lk.got() ) { + log(1) << "skipping balancing round because another balancer is active" << endl; + conn.done(); + + sleepsecs( 30 ); // no need to wake up soon + continue; + } + + log(1) << "*** start balancing round" << endl; + + vector<CandidateChunkPtr> candidateChunks; + _doBalanceRound( conn.conn() , &candidateChunks ); + if ( candidateChunks.size() == 0 ) { + log(1) << "no need to move any chunk" << endl; + } + else { + _balancedLastTime = _moveChunks( &candidateChunks ); + } + + log(1) << "*** end of balancing round" << endl; } - - log(1) << "*** end of balancing round" << endl; + conn.done(); - + sleepsecs( _balancedLastTime ? 5 : 10 ); } catch ( std::exception& e ) { diff --git a/s/strategy_shard.cpp b/s/strategy_shard.cpp index 4e0c76312cd..2b36025d4a2 100644 --- a/s/strategy_shard.cpp +++ b/s/strategy_shard.cpp @@ -166,8 +166,8 @@ namespace mongo { gotThrough = true; break; } - catch ( StaleConfigException& ) { - log( i < ( maxTries / 2 ) ) << "retrying insert because of StaleConfigException: " << o << endl; + catch ( StaleConfigException& e ) { + log( i < ( maxTries / 2 ) ) << "retrying insert because of StaleConfigException: " << e << " object: " << o << endl; r.reset(); manager = r.getChunkManager(); } diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp index 175ac004e00..02ded05a1e7 100644 --- a/shell/mongo_vstudio.cpp +++ b/shell/mongo_vstudio.cpp @@ -1534,7 +1534,10 @@ const StringData _jscode_raw_utils_sh = "print( \"\\tsh.enableSharding(dbname) enables sharding on the database dbname\" )\n" "print( \"\\tsh.shardCollection(fullName,key,unique) shards the collection\" );\n" "print( \"\\tsh.splitFind(fullName,find) splits the chunk that find is in at the median\" );\n" -"print( \"\\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle\" );\n" +"print( \"\\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle\" );\n" +"\n" +"print( \"\\tsh.setBalancerState( <bool on or not> ) turns the balancer on or off true=on, false=off\" );\n" +"print( \"\\tsh.getBalancerState( <bool on or not> ) return true if on, off if not\" );\n" "\n" "print( \"\\tsh.status() prints a general overview of the cluster\" )\n" "}\n" @@ -1575,6 +1578,17 @@ const StringData _jscode_raw_utils_sh = "sh._checkFullName( fullName )\n" "sh._adminCommand( { split : fullName , middle : middle } )\n" "}\n" +"\n" +"sh.setBalancerState = function( onOrNot ) {\n" +"db.getSisterDB( \"config\" ).settings.update({ _id: \"balancer\" }, { $set : { stopped: onOrNot ? false : true } }, true );\n" +"}\n" +"\n" +"sh.getBalancerState = function() {\n" +"var x = db.getSisterDB( \"config\" ).settings.findOne({ _id: \"balancer\" } )\n" +"if ( x == null )\n" +"return true;\n" +"return ! x.stopped;\n" +"}\n" ; extern const JSFile utils_sh; const JSFile utils_sh = { "shell/utils_sh.js" , _jscode_raw_utils_sh }; diff --git a/shell/utils_sh.js b/shell/utils_sh.js index 8644fcbe6ca..b66929ced05 100644 --- a/shell/utils_sh.js +++ b/shell/utils_sh.js @@ -28,7 +28,10 @@ sh.help = function() { print( "\tsh.enableSharding(dbname) enables sharding on the database dbname" ) print( "\tsh.shardCollection(fullName,key,unique) shards the collection" ); print( "\tsh.splitFind(fullName,find) splits the chunk that find is in at the median" ); - print( "\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle" ); + print( "\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle" ); + + print( "\tsh.setBalancerState( <bool on or not> ) turns the balancer on or off true=on, false=off" ); + print( "\tsh.getBalancerState() return true if on, off if not" ); print( "\tsh.status() prints a general overview of the cluster" ) } @@ -69,3 +72,14 @@ sh.splitAt = function( fullName , middle ) { sh._checkFullName( fullName ) sh._adminCommand( { split : fullName , middle : middle } ) } + +sh.setBalancerState = function( onOrNot ) { + db.getSisterDB( "config" ).settings.update({ _id: "balancer" }, { $set : { stopped: onOrNot ? false : true } }, true ); +} + +sh.getBalancerState = function() { + var x = db.getSisterDB( "config" ).settings.findOne({ _id: "balancer" } ) + if ( x == null ) + return true; + return ! x.stopped; +} |