diff options
Diffstat (limited to 'jstests/sharding/sharding_rs1.js')
-rw-r--r-- | jstests/sharding/sharding_rs1.js | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/jstests/sharding/sharding_rs1.js b/jstests/sharding/sharding_rs1.js index c5022348fa6..af021bf9741 100644 --- a/jstests/sharding/sharding_rs1.js +++ b/jstests/sharding/sharding_rs1.js @@ -2,60 +2,59 @@ * tests sharding with replica sets */ (function() { - 'use strict'; +'use strict'; - var s = new ShardingTest({shards: 3, other: {rs: true, chunkSize: 1, enableBalancer: true}}); +var s = new ShardingTest({shards: 3, other: {rs: true, chunkSize: 1, enableBalancer: true}}); - s.adminCommand({enablesharding: "test"}); - s.ensurePrimaryShard('test', s.shard0.shardName); - s.config.settings.update({_id: "balancer"}, {$set: {_waitForDelete: true}}, true); +s.adminCommand({enablesharding: "test"}); +s.ensurePrimaryShard('test', s.shard0.shardName); +s.config.settings.update({_id: "balancer"}, {$set: {_waitForDelete: true}}, true); - var db = s.getDB("test"); +var db = s.getDB("test"); - var bigString = "X".repeat(256 * 1024); +var bigString = "X".repeat(256 * 1024); - var insertedBytes = 0; - var num = 0; +var insertedBytes = 0; +var num = 0; - // Insert 10 MB of data to result in 10+ chunks - var bulk = db.foo.initializeUnorderedBulkOp(); - while (insertedBytes < (10 * 1024 * 1024)) { - bulk.insert({_id: num++, s: bigString, x: Math.random()}); - insertedBytes += bigString.length; - } - assert.writeOK(bulk.execute({w: 3})); - - assert.commandWorked(s.s.adminCommand({shardcollection: "test.foo", key: {_id: 1}})); +// Insert 10 MB of data to result in 10+ chunks +var bulk = db.foo.initializeUnorderedBulkOp(); +while (insertedBytes < (10 * 1024 * 1024)) { + bulk.insert({_id: num++, s: bigString, x: Math.random()}); + insertedBytes += bigString.length; +} +assert.writeOK(bulk.execute({w: 3})); - jsTest.log("Waiting for balance to complete"); - s.awaitBalance('foo', 'test', 5 * 60 * 1000); +assert.commandWorked(s.s.adminCommand({shardcollection: "test.foo", key: {_id: 1}})); - jsTest.log("Stopping balancer"); - s.stopBalancer(); +jsTest.log("Waiting for balance to complete"); +s.awaitBalance('foo', 'test', 5 * 60 * 1000); - jsTest.log("Balancer stopped, checking dbhashes"); - s._rs.forEach(function(rsNode) { - rsNode.test.awaitReplication(); +jsTest.log("Stopping balancer"); +s.stopBalancer(); - var dbHashes = rsNode.test.getHashes("test"); - print(rsNode.url + ': ' + tojson(dbHashes)); +jsTest.log("Balancer stopped, checking dbhashes"); +s._rs.forEach(function(rsNode) { + rsNode.test.awaitReplication(); - for (var j = 0; j < dbHashes.slaves.length; j++) { - assert.eq(dbHashes.master.md5, - dbHashes.slaves[j].md5, - "hashes not same for: " + rsNode.url + " slave: " + j); - } - }); + var dbHashes = rsNode.test.getHashes("test"); + print(rsNode.url + ': ' + tojson(dbHashes)); - assert.eq(num, db.foo.find().count(), "C1"); - assert.eq(num, db.foo.find().itcount(), "C2"); - assert.eq(num, db.foo.find().sort({_id: 1}).itcount(), "C3"); - assert.eq(num, db.foo.find().sort({_id: -1}).itcount(), "C4"); + for (var j = 0; j < dbHashes.slaves.length; j++) { + assert.eq(dbHashes.master.md5, + dbHashes.slaves[j].md5, + "hashes not same for: " + rsNode.url + " slave: " + j); + } +}); - db.foo.ensureIndex({x: 1}); - assert.eq(num, db.foo.find().sort({x: 1}).itcount(), "C5"); - assert.eq(num, db.foo.find().sort({x: -1}).itcount(), "C6"); +assert.eq(num, db.foo.find().count(), "C1"); +assert.eq(num, db.foo.find().itcount(), "C2"); +assert.eq(num, db.foo.find().sort({_id: 1}).itcount(), "C3"); +assert.eq(num, db.foo.find().sort({_id: -1}).itcount(), "C4"); - s.stop(); +db.foo.ensureIndex({x: 1}); +assert.eq(num, db.foo.find().sort({x: 1}).itcount(), "C5"); +assert.eq(num, db.foo.find().sort({x: -1}).itcount(), "C6"); +s.stop(); })(); |