diff options
author | Randolph Tan <randolph@10gen.com> | 2013-04-05 11:30:08 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2013-05-22 16:50:40 -0400 |
commit | e73f081b184431b97f81e98d6eca097a2195f6e8 (patch) | |
tree | 10a61e96e6a7dabb8214b1bcbbe8e09c01679c42 | |
parent | c88286c3695eeadb237a7d82c86d738fe2261843 (diff) | |
download | mongo-e73f081b184431b97f81e98d6eca097a2195f6e8.tar.gz |
SERVER-9260 Race in hash_presplit.js
Split the each test case into different files to isolate them from each other.
-rw-r--r-- | jstests/sharding/hash_presplit.js | 104 | ||||
-rw-r--r-- | jstests/sharding/hash_shard_non_empty.js | 22 | ||||
-rw-r--r-- | jstests/sharding/hash_shard_num_chunks.js | 35 | ||||
-rw-r--r-- | jstests/sharding/hash_single_shard.js | 14 |
4 files changed, 71 insertions, 104 deletions
diff --git a/jstests/sharding/hash_presplit.js b/jstests/sharding/hash_presplit.js deleted file mode 100644 index da9007328c2..00000000000 --- a/jstests/sharding/hash_presplit.js +++ /dev/null @@ -1,104 +0,0 @@ -// Test that sharding a new collection with a hashed shard key pre-splits chunk ranges and -// distributes initial chunks evenly. - -var s = new ShardingTest( { name : jsTestName() , shards : 3 , mongos : 1, verbose : 1 } ); -var dbname = "test"; -var coll = "foo"; -var db = s.getDB( dbname ); -db.adminCommand( { enablesharding : dbname } ); - -//for simplicity turn off balancer -s.stopBalancer(); - - -// Test 1 -// Using hashed shard key, but collection is non-empty, so should not pre-split. -print("****** Test 1 *******"); - -db.getCollection( coll ).drop(); -db.getCollection( coll ).insert( { a : 1 } ); - -db.getCollection( coll ).ensureIndex( { a: "hashed"} ); -var res = db.adminCommand( { shardcollection : dbname + "." + coll , key : { a : "hashed" } } ); -assert.eq( res.ok , 1 , "shardcollection didn't work" ); -db.printShardingStatus(); -var numChunks = s.config.chunks.count(); -assert.eq( numChunks , 1 , "sharding non-empty collection should not pre-split" ); - - -// Test 2 -// Using hashed shard key, collection is empty, and numInitialChunks specified. -print("****** Test 2 *******"); - -db.getCollection( coll ).drop(); - -var res = db.adminCommand( { shardcollection : dbname + "." + coll , - key : { a : "hashed" } , - numInitialChunks : 500 } ); -assert.eq( res.ok , 1 , "shardcollection didn't work" ); -db.printShardingStatus(); -var numChunks = s.config.chunks.count(); -assert.eq( numChunks , 500 , "should be exactly 500 chunks" ); - -var shards = s.config.shards.find(); -shards.forEach( - // check that each shard has one third the numInitialChunks - function( shard ){ - var numChunksOnShard = s.config.chunks.find( {"shard" : shard._id} ).count(); - assert.gte( numChunksOnShard , Math.floor( 500/3 ) ); - } -); - - -// Test 3 -// Using hashed shard key, collection is empty, and using default numInitialChunks. -print("****** Test 3 *******"); - -db.getCollection( coll ).drop(); - -// create an unrelated index. later check that pre-splitting creates index on shards with chunks -db.getCollection( coll ).ensureIndex( { dummy : 1 } ); - -var res = db.adminCommand( { shardcollection : dbname + "." + coll , key : { a : "hashed" } } ); -assert.eq( res.ok , 1 , "shardcollection didn't work" ); -db.printShardingStatus(); -var numChunks = s.config.chunks.count(); -assert.gt( numChunks , 1 , "should be multiple chunks" ); - -var shards = s.config.shards.find(); -shards.forEach( - function( shard ){ - // check that each shard has one third of the chunks - var numChunksOnShard = s.config.chunks.find( { "shard" : shard._id } ).count(); - assert.gte( numChunksOnShard , Math.floor( numChunks/3 ) ); - - // and the unrelated index - var conn = new Mongo ( shard.host ); - printjson( conn.getDB( dbname ).getCollection( coll ).getIndexes() ); - assert.eq( 1 , conn.getDB( dbname ).system.indexes.find( { key : { dummy : 1 } } ).count(), - "shard missing dummy index" ); - } -); - -// finally, check that the collection gets dropped correctly (which doesn't happen if pre-splitting -// fails to create the collection on all shards). -var res = db.runCommand( { "drop" : coll } ); -assert.eq( res.ok , 1 , "couldn't drop empty, pre-split collection"); - -s.stop(); - -(function() { - jsTest.log('Test hashed presplit with 1 shard.'); - var st = new ShardingTest({ shards: 1 }); - var testDB = st.getDB('test'); - - //create hashed shard key and enable sharding - testDB.adminCommand({ enablesharding: "test" }); - testDB.adminCommand({ shardCollection: "test.collection", key: { a: "hashed" }}); - - //check the number of initial chunks. - assert.eq(2, st.getDB('config').chunks.count(), - 'Using hashed shard key but failing to do correct presplitting'); - st.stop(); -})(); - diff --git a/jstests/sharding/hash_shard_non_empty.js b/jstests/sharding/hash_shard_non_empty.js new file mode 100644 index 00000000000..f45e1c2113c --- /dev/null +++ b/jstests/sharding/hash_shard_non_empty.js @@ -0,0 +1,22 @@ +// Hash sharding on a non empty collection should not pre-split. + +var s = new ShardingTest({ name : jsTestName(), shards : 3, mongos : 1, verbose : 1 }); +var dbname = "test"; +var coll = "foo"; +var db = s.getDB(dbname); +db.adminCommand({ enablesharding : dbname }); + +//for simplicity turn off balancer +s.stopBalancer(); + +db.getCollection(coll).insert({ a : 1 }); + +db.getCollection(coll).ensureIndex({ a: "hashed"}); +var res = db.adminCommand({ shardcollection : dbname + "." + coll, key : { a : "hashed" } }); +assert.eq(res.ok, 1, "shardcollection didn't work"); +db.printShardingStatus(); +var numChunks = s.config.chunks.count(); +assert.eq(numChunks, 1 , "sharding non-empty collection should not pre-split"); + +s.stop(); + diff --git a/jstests/sharding/hash_shard_num_chunks.js b/jstests/sharding/hash_shard_num_chunks.js new file mode 100644 index 00000000000..cf4bb481c14 --- /dev/null +++ b/jstests/sharding/hash_shard_num_chunks.js @@ -0,0 +1,35 @@ +// Hash sharding with initial chunk count set. + +var s = new ShardingTest({ shards : 3, mongos : 1, verbose : 1 }); +var dbname = "test"; +var coll = "foo"; +var db = s.getDB(dbname); +db.adminCommand({ enablesharding : dbname }); + +//for simplicity turn off balancer +s.stopBalancer(); + +var res = db.adminCommand({ shardcollection : dbname + "." + coll, + key : { a : "hashed" }, + numInitialChunks : 500 }); +assert.eq(res.ok, 1, "shardcollection didn't work"); +db.printShardingStatus(); +var numChunks = s.config.chunks.count(); +assert.eq(numChunks, 500 , "should be exactly 500 chunks"); + +var shards = s.config.shards.find(); +shards.forEach( + // check that each shard has one third the numInitialChunks + function (shard){ + var numChunksOnShard = s.config.chunks.find({"shard" : shard._id}).count(); + assert.gte(numChunksOnShard, Math.floor(500/3)); + } +); + +// Check that the collection gets dropped correctly (which doesn't happen if pre-splitting +// fails to create the collection on all shards). +res = db.runCommand({ "drop" : coll }); +assert.eq(res.ok, 1, "couldn't drop empty, pre-split collection"); + +s.stop(); + diff --git a/jstests/sharding/hash_single_shard.js b/jstests/sharding/hash_single_shard.js new file mode 100644 index 00000000000..7dc9d6df078 --- /dev/null +++ b/jstests/sharding/hash_single_shard.js @@ -0,0 +1,14 @@ +// Test hashed presplit with 1 shard. + +var st = new ShardingTest({ shards: 1 }); +var testDB = st.getDB('test'); + +//create hashed shard key and enable sharding +testDB.adminCommand({ enablesharding: "test" }); +testDB.adminCommand({ shardCollection: "test.collection", key: { a: "hashed" }}); + +//check the number of initial chunks. +assert.eq(2, st.getDB('config').chunks.count(), + 'Using hashed shard key but failing to do correct presplitting'); +st.stop(); + |