diff options
Diffstat (limited to 'jstests/sharding/hash_basic.js')
-rw-r--r-- | jstests/sharding/hash_basic.js | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/jstests/sharding/hash_basic.js b/jstests/sharding/hash_basic.js index bffada99eef..1435611e7fb 100644 --- a/jstests/sharding/hash_basic.js +++ b/jstests/sharding/hash_basic.js @@ -1,57 +1,56 @@ (function() { - 'use strict'; +'use strict'; - var st = new ShardingTest({shards: 2, chunkSize: 1}); +var st = new ShardingTest({shards: 2, chunkSize: 1}); - assert.commandWorked(st.s0.adminCommand({enableSharding: 'test'})); - st.ensurePrimaryShard('test', st.shard1.shardName); - assert.commandWorked(st.s0.adminCommand({shardCollection: 'test.user', key: {x: 'hashed'}})); +assert.commandWorked(st.s0.adminCommand({enableSharding: 'test'})); +st.ensurePrimaryShard('test', st.shard1.shardName); +assert.commandWorked(st.s0.adminCommand({shardCollection: 'test.user', key: {x: 'hashed'}})); - var configDB = st.s0.getDB('config'); - var chunkCountBefore = configDB.chunks.count({ns: 'test.user'}); - assert.gt(chunkCountBefore, 1); +var configDB = st.s0.getDB('config'); +var chunkCountBefore = configDB.chunks.count({ns: 'test.user'}); +assert.gt(chunkCountBefore, 1); - var testDB = st.s0.getDB('test'); - for (var x = 0; x < 1000; x++) { - testDB.user.insert({x: x}); - } +var testDB = st.s0.getDB('test'); +for (var x = 0; x < 1000; x++) { + testDB.user.insert({x: x}); +} - var chunkDoc = configDB.chunks.find({ns: 'test.user'}).sort({min: 1}).next(); - var min = chunkDoc.min; - var max = chunkDoc.max; +var chunkDoc = configDB.chunks.find({ns: 'test.user'}).sort({min: 1}).next(); +var min = chunkDoc.min; +var max = chunkDoc.max; - // Assumption: There are documents in the MinKey chunk, otherwise, splitVector will fail. - // - // Note: This chunk will have 267 documents if collection was presplit to 4. - var cmdRes = - assert.commandWorked(st.s0.adminCommand({split: 'test.user', bounds: [min, max]}), - 'Split on bounds failed for chunk [' + tojson(chunkDoc) + ']'); +// Assumption: There are documents in the MinKey chunk, otherwise, splitVector will fail. +// +// Note: This chunk will have 267 documents if collection was presplit to 4. +var cmdRes = assert.commandWorked(st.s0.adminCommand({split: 'test.user', bounds: [min, max]}), + 'Split on bounds failed for chunk [' + tojson(chunkDoc) + ']'); - chunkDoc = configDB.chunks.find({ns: 'test.user'}).sort({min: 1}).skip(1).next(); +chunkDoc = configDB.chunks.find({ns: 'test.user'}).sort({min: 1}).skip(1).next(); - var middle = NumberLong(chunkDoc.min.x + 1000000); - cmdRes = assert.commandWorked(st.s0.adminCommand({split: 'test.user', middle: {x: middle}}), - 'Split failed with middle [' + middle + ']'); +var middle = NumberLong(chunkDoc.min.x + 1000000); +cmdRes = assert.commandWorked(st.s0.adminCommand({split: 'test.user', middle: {x: middle}}), + 'Split failed with middle [' + middle + ']'); - cmdRes = assert.commandWorked(st.s0.adminCommand({split: 'test.user', find: {x: 7}}), - 'Split failed with find.'); +cmdRes = assert.commandWorked(st.s0.adminCommand({split: 'test.user', find: {x: 7}}), + 'Split failed with find.'); - var chunkList = configDB.chunks.find({ns: 'test.user'}).sort({min: 1}).toArray(); - assert.eq(chunkCountBefore + 3, chunkList.length); +var chunkList = configDB.chunks.find({ns: 'test.user'}).sort({min: 1}).toArray(); +assert.eq(chunkCountBefore + 3, chunkList.length); - chunkList.forEach(function(chunkToMove) { - var toShard = configDB.shards.findOne({_id: {$ne: chunkToMove.shard}})._id; +chunkList.forEach(function(chunkToMove) { + var toShard = configDB.shards.findOne({_id: {$ne: chunkToMove.shard}})._id; - print('Moving chunk ' + chunkToMove._id + ' from shard ' + chunkToMove.shard + ' to ' + - toShard + ' ...'); + print('Moving chunk ' + chunkToMove._id + ' from shard ' + chunkToMove.shard + ' to ' + + toShard + ' ...'); - assert.commandWorked(st.s0.adminCommand({ - moveChunk: 'test.user', - bounds: [chunkToMove.min, chunkToMove.max], - to: toShard, - _waitForDelete: true - })); - }); + assert.commandWorked(st.s0.adminCommand({ + moveChunk: 'test.user', + bounds: [chunkToMove.min, chunkToMove.max], + to: toShard, + _waitForDelete: true + })); +}); - st.stop(); +st.stop(); })(); |