diff options
-rw-r--r-- | jstests/sharding/features3.js | 4 | ||||
-rw-r--r-- | jstests/sharding/findandmodify1.js | 4 | ||||
-rw-r--r-- | jstests/sharding/remove1.js | 16 | ||||
-rw-r--r-- | jstests/slowNightly/sharding_balance1.js | 8 | ||||
-rw-r--r-- | jstests/slowNightly/sharding_balance2.js | 2 | ||||
-rw-r--r-- | jstests/slowNightly/sharding_balance3.js | 2 | ||||
-rw-r--r-- | jstests/slowNightly/sharding_balance4.js | 7 | ||||
-rw-r--r-- | s/commands_admin.cpp | 19 | ||||
-rw-r--r-- | s/config.cpp | 25 | ||||
-rw-r--r-- | s/config.h | 18 |
10 files changed, 68 insertions, 37 deletions
diff --git a/jstests/sharding/features3.js b/jstests/sharding/features3.js index ab28030c7fb..412d0d1c641 100644 --- a/jstests/sharding/features3.js +++ b/jstests/sharding/features3.js @@ -19,8 +19,8 @@ for ( i=0; i<N; i++ ) x = db.foo.stats(); assert.eq( N , x.count , "total count" ) -assert.eq( N / 2 , x.shards.shard0.count , "count on shard0" ) -assert.eq( N / 2 , x.shards.shard1.count , "count on shard0" ) +assert.eq( N / 2 , x.shards.shard0000.count , "count on shard0000" ) +assert.eq( N / 2 , x.shards.shard0001.count , "count on shard0001" ) start = new Date() diff --git a/jstests/sharding/findandmodify1.js b/jstests/sharding/findandmodify1.js index cf21b11a408..437ec8133e3 100644 --- a/jstests/sharding/findandmodify1.js +++ b/jstests/sharding/findandmodify1.js @@ -27,8 +27,8 @@ for (var i=2; i < numObjs; i+=2){ s.printChunks(); assert.eq( numObjs/2, s.config.chunks.count(), "split failed" ); -assert.eq( numObjs/4, s.config.chunks.count({ shard: "shard0" }) ); -assert.eq( numObjs/4, s.config.chunks.count({ shard: "shard1" }) ); +assert.eq( numObjs/4, s.config.chunks.count({ shard: "shard0000" }) ); +assert.eq( numObjs/4, s.config.chunks.count({ shard: "shard0001" }) ); // update for (var i=0; i < numObjs; i++){ diff --git a/jstests/sharding/remove1.js b/jstests/sharding/remove1.js index 43f5f0415a3..c26736a92a1 100644 --- a/jstests/sharding/remove1.js +++ b/jstests/sharding/remove1.js @@ -2,13 +2,15 @@ s = new ShardingTest( "remove_shard1", 2 ); assert.eq( 2, s.config.shards.count() , "initial server count wrong" ); -// first remove puts in draining mode, second remove -assert( s.admin.runCommand( { removeshard: "shard0" } ).ok , "failed to start draining shard" ); -assert( s.admin.runCommand( { removeshard: "shard0" } ).ok , "failed to remove shard" ); +// first remove puts in draining mode, the second actually removes +assert( s.admin.runCommand( { removeshard: "shard0000" } ).ok , "failed to start draining shard" ); +assert( s.admin.runCommand( { removeshard: "shard0000" } ).ok , "failed to remove shard" ); assert.eq( 1, s.config.shards.count() , "removed server still appears in count" ); -// to fix in SERVER-1418 -// assert( s.admin.runCommand( { addshard: "127.0.0.1:43415", allowLocal : true } ).ok, "failed to add shard" ); -// assert.eq( 2, s.config.shards.count(), "new server does not appear in count" ); +// should create a shard0002 shard +conn = startMongodTest( 29000 ); +assert( s.admin.runCommand( { addshard: "localhost:29000", allowLocal: true } ).ok, "failed to add shard" ); +assert.eq( 2, s.config.shards.count(), "new server does not appear in count" ); -s.stop()
\ No newline at end of file +stopMongod( 29000 ); +s.stop();
\ No newline at end of file diff --git a/jstests/slowNightly/sharding_balance1.js b/jstests/slowNightly/sharding_balance1.js index 66b1563e177..840aaff39b4 100644 --- a/jstests/slowNightly/sharding_balance1.js +++ b/jstests/slowNightly/sharding_balance1.js @@ -27,12 +27,12 @@ assert.lt( 20 , s.config.chunks.count() , "setup2" ); function diff(){ var x = s.chunkCounts( "foo" ); printjson( x ) - return Math.max( x.shard0 , x.shard1 ) - Math.min( x.shard0 , x.shard1 ); + return Math.max( x.shard0000 , x.shard0001 ) - Math.min( x.shard0000 , x.shard0001 ); } function sum(){ var x = s.chunkCounts( "foo" ); - return x.shard0 + x.shard1; + return x.shard0000 + x.shard0001; } assert.lt( 20 , diff() , "big differential here" ); @@ -44,12 +44,12 @@ assert.soon( function(){ } , "balance didn't happen" , 1000 * 60 * 3 , 5000 ); var chunkCount = sum(); -s.adminCommand( { removeshard: "shard0" } ); +s.adminCommand( { removeshard: "shard0000" } ); assert.soon( function(){ printjson(s.chunkCounts( "foo" )); s.config.shards.find().forEach(function(z){printjson(z);}); - return chunkCount == s.config.chunks.count({shard: "shard1"}); + return chunkCount == s.config.chunks.count({shard: "shard0001"}); } , "removeshard didn't happen" , 1000 * 60 * 3 , 5000 ); s.stop(); diff --git a/jstests/slowNightly/sharding_balance2.js b/jstests/slowNightly/sharding_balance2.js index f263ab39a9e..06fc5467e41 100644 --- a/jstests/slowNightly/sharding_balance2.js +++ b/jstests/slowNightly/sharding_balance2.js @@ -38,7 +38,7 @@ assert.lt( 20 , s.config.chunks.count() , "setup2" ); function diff(){ var x = s.chunkCounts( "foo" ); printjson( x ) - return Math.max( x.shard0 , x.shard1 ) - Math.min( x.shard0 , x.shard1 ); + return Math.max( x.shard0000 , x.shard0001 ) - Math.min( x.shard0000 , x.shard0001 ); } assert.lt( 10 , diff() ); diff --git a/jstests/slowNightly/sharding_balance3.js b/jstests/slowNightly/sharding_balance3.js index efc389d04d8..5cb26e4470f 100644 --- a/jstests/slowNightly/sharding_balance3.js +++ b/jstests/slowNightly/sharding_balance3.js @@ -26,7 +26,7 @@ assert.lt( 20 , s.config.chunks.count() , "setup2" ); function diff(){ var x = s.chunkCounts( "foo" ); printjson( x ) - return Math.max( x.shard0 , x.shard1 ) - Math.min( x.shard0 , x.shard1 ); + return Math.max( x.shard0000 , x.shard0001 ) - Math.min( x.shard0000 , x.shard0001 ); } assert.lt( 10 , diff() ); diff --git a/jstests/slowNightly/sharding_balance4.js b/jstests/slowNightly/sharding_balance4.js index 46c3915926b..1f7d53a8ae9 100644 --- a/jstests/slowNightly/sharding_balance4.js +++ b/jstests/slowNightly/sharding_balance4.js @@ -1,5 +1,4 @@ -// sharding_balance3.js - +// sharding_balance4.js s = new ShardingTest( "slow_sharding_balance3" , 2 , 2 , 1 , { chunksize : 1 } ) @@ -88,12 +87,12 @@ function diff(){ var x = dist(); if ( Math.random() > .999 ) printjson( x ) - return Math.max( x.shard0 , x.shard1 ) - Math.min( x.shard0 , x.shard1 ); + return Math.max( x.shard0000 , x.shard0001 ) - Math.min( x.shard0000 , x.shard0001 ); } function sum(){ var x = dist(); - return x.shard0 + x.shard1; + return x.shard0000 + x.shard0001; } assert.lt( 20 , diff() ,"initial load" ); diff --git a/s/commands_admin.cpp b/s/commands_admin.cpp index 2adddf0d55b..afe47aa29ac 100644 --- a/s/commands_admin.cpp +++ b/s/commands_admin.cpp @@ -624,7 +624,6 @@ namespace mongo { ScopedDbConnection conn( configServer.getPrimary() ); string host = cmdObj.firstElement().valuestrsafe(); - if ( host == "localhost" || host.find( "localhost:" ) == 0 || host == "127.0.0.1" || host.find( "127.0.0.1:" ) == 0 ){ if ( ! cmdObj["allowLocal"].trueValue() ){ @@ -634,22 +633,22 @@ namespace mongo { return false; } } - if ( host.find( ":" ) == string::npos ){ stringstream ss; ss << host << ":" << CmdLine::ShardServerPort; host = ss.str(); } - string name = ""; - if ( cmdObj["name"].type() == String ) + string name; + if ( cmdObj["name"].type() == String ) { name = cmdObj["name"].valuestrsafe(); - - if ( name.size() == 0 ){ - stringstream ss; - ss << "shard"; - ss << conn->count( "config.shards" ); - name = ss.str(); + } else { + name = grid.getNewShardName(); + if ( name.empty() ){ + result.append( "msg" , "cant generate new shard name" ); + conn.done(); + return false; + } } BSONObj shard; diff --git a/s/config.cpp b/s/config.cpp index 30d4ba03a4c..de023060db1 100644 --- a/s/config.cpp +++ b/s/config.cpp @@ -337,13 +337,34 @@ namespace mongo { /* --- Grid --- */ - bool Grid::knowAboutShard( string name ) const{ + bool Grid::knowAboutShard( const string& name ) const{ ShardConnection conn( configServer.getPrimary() , "" ); - BSONObj shard = conn->findOne( "config.shards" , BSON( "host" << name ) ); + BSONObj shard = conn->findOne( ShardNS::shard , BSON( "host" << name ) ); conn.done(); return ! shard.isEmpty(); } + string Grid::getNewShardName() const{ + ShardConnection conn( configServer.getPrimary() , "" ); + + string shardName; + int count = 0; + BSONObj o = conn->findOne( ShardNS::shard , Query( fromjson ( "{_id: /^shard/}" ) ).sort( BSON( "_id" << -1 ) ) ); + if ( ! o.isEmpty() ) { + string last = o["_id"].String(); + istringstream is( last.substr( 5 ) ); + is >> count; + count++; + } + if (count < 9999) { + stringstream ss; + ss << "shard" << setfill('0') << setw(4) << count; + shardName = ss.str(); + } + conn.done(); + return shardName; + } + DBConfigPtr Grid::getDBConfig( string database , bool create ){ { string::size_type i = database.find( "." ); diff --git a/s/config.h b/s/config.h index bad081bf44f..f0a717a0282 100644 --- a/s/config.h +++ b/s/config.h @@ -172,8 +172,8 @@ namespace mongo { Grid() : _lock("Grid") { } /** - gets the config the db. - will return an empty DBConfig if not in db already + * gets the config the db. + * will return an empty DBConfig if not in db already */ DBConfigPtr getDBConfig( string ns , bool create=true); @@ -182,10 +182,20 @@ namespace mongo { * on next getDBConfig call will fetch from db */ void removeDB( string db ); + + /** + * returns true if the config database knows about a host 'name' + */ + bool knowAboutShard( const string& name ) const; - bool knowAboutShard( string name ) const; - + /** + * returns the next available shard name or an empty string, if there are + * no more shard names available. + */ + string getNewShardName() const; + unsigned long long getNextOpTime() const; + private: map<string, DBConfigPtr > _databases; mongo::mutex _lock; // TODO: change to r/w lock ?? |