summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-05-26 11:32:36 -0400
committerEliot Horowitz <eliot@10gen.com>2010-05-26 11:32:36 -0400
commita1c8d1b2c34a995d1928538af101c87e43f52c14 (patch)
tree044fb1fabc11d76cd7e3fd5c87930d5dd3667fcd
parent0f04c206d94512341a31c8104b62900c37e29478 (diff)
downloadmongo-a1c8d1b2c34a995d1928538af101c87e43f52c14.tar.gz
balancing functional test
-rw-r--r--jstests/slow/sharding_balance1.js56
-rw-r--r--s/balance.cpp16
2 files changed, 64 insertions, 8 deletions
diff --git a/jstests/slow/sharding_balance1.js b/jstests/slow/sharding_balance1.js
new file mode 100644
index 00000000000..184864a2f9f
--- /dev/null
+++ b/jstests/slow/sharding_balance1.js
@@ -0,0 +1,56 @@
+// sharding_balance1.js
+
+
+s = new ShardingTest( "slow_sharding_balance1" , 2 , 2 , 1 , { chunksize : 1 } )
+
+s.adminCommand( { enablesharding : "test" } );
+s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
+assert.eq( 1 , s.config.chunks.count() , "setup1" );
+
+s.config.settings.find().forEach( printjson )
+
+db = s.getDB( "test" );
+
+bigString = ""
+while ( bigString.length < 10000 )
+ bigString += "asdasdasdasdadasdasdasdasdasdasdasdasda";
+
+inserted = 0;
+num = 0;
+while ( inserted < ( 20 * 1024 * 1024 ) ){
+ db.foo.insert( { _id : num++ , s : bigString } );
+ inserted += bigString.length;
+}
+
+db.getLastError();
+assert.lt( 20 , s.config.chunks.count() , "setup2" );
+
+function dist(){
+ var x = {}
+ s.config.chunks.find( { ns : "test.foo" } ).forEach(
+ function(z){
+ if ( x[z.shard] )
+ x[z.shard]++
+ else
+ x[z.shard] = 1;
+ }
+ );
+ return x;
+}
+
+function diff(){
+ var x = dist();
+ printjson( x )
+ return Math.max( x.shard0 , x.shard1 ) - Math.min( x.shard0 , x.shard1 );
+}
+
+assert.lt( 20 , diff() );
+print( diff() )
+
+assert.soon( function(){
+ var d = diff();
+ return d < 5;
+} , "balance didn't happen" , 1000 * 60 * 3 , 5000 );
+
+
+s.stop();
diff --git a/s/balance.cpp b/s/balance.cpp
index 7816814671d..6a3955be4df 100644
--- a/s/balance.cpp
+++ b/s/balance.cpp
@@ -37,11 +37,11 @@ namespace mongo {
bool Balancer::shouldIBalance( DBClientBase& conn ){
BSONObj x = conn.findOne( ShardNS::settings , BSON( "_id" << "balancer" ) );
- log(3) << "balancer: " << x << endl;
+ log(2) << "balancer: " << x << endl;
if ( ! x.isEmpty() ){
if ( x["who"].String() == _myid ){
- log(3) << "balancer: i'm the current balancer" << endl;
+ log(2) << "balancer: i'm the current balancer" << endl;
return true;
}
@@ -49,7 +49,7 @@ namespace mongo {
massert( 13125 , (string)"can't find mongos: " + x["who"].String() , ! other.isEmpty() );
int secsSincePing = (int)(( jsTime() - other["ping"].Date() ) / 1000 );
- log(3) << "current balancer is: " << other << " ping delay(secs): " << secsSincePing << endl;
+ log(2) << "current balancer is: " << other << " ping delay(secs): " << secsSincePing << endl;
if ( secsSincePing < ( 60 * 10 ) ){
return false;
@@ -94,7 +94,7 @@ namespace mongo {
BSONElement shardedColls = db["sharded"];
if ( shardedColls.eoo() ){
- log(3) << "balancer: skipping database with no sharded collection ("
+ log(2) << "balancer: skipping database with no sharded collection ("
<< db["_id"].str() << ")" << endl;
continue;
}
@@ -114,7 +114,7 @@ namespace mongo {
}
bool Balancer::balance( DBClientBase& conn , const string& ns , const BSONObj& data ){
- log(4) << "balancer: balance(" << ns << ")" << endl;
+ log(3) << "balancer: balance(" << ns << ")" << endl;
map< string,vector<BSONObj> > shards;
{
@@ -157,8 +157,8 @@ namespace mongo {
}
}
- log(6) << "min: " << min.first << "\t" << min.second << endl;
- log(6) << "max: " << max.first << "\t" << max.second << endl;
+ log(4) << "min: " << min.first << "\t" << min.second << endl;
+ log(4) << "max: " << max.first << "\t" << max.second << endl;
if( (int)( max.second - min.second) < ( _balancedLastTime ? 2 : 8 ) )
return false;
@@ -280,7 +280,7 @@ namespace mongo {
checkOIDs();
while ( ! inShutdown() ){
- sleepsecs( 15 );
+ sleepsecs( 10 );
try {
ScopedDbConnection conn( configServer.getPrimary() );