diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-08-16 13:07:52 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-08-17 17:50:14 -0400 |
commit | ab99c11b3f212b8656d0b8bad31832d2e98d3f6c (patch) | |
tree | a8e7d4755c0b723e68c47cbca65e216330a608ba /jstests/sharding/movechunk_interrupt_at_primary_stepdown.js | |
parent | 6dd7af76e48c27edb0dbe3b8ff9bd7b1178c3727 (diff) | |
download | mongo-ab99c11b3f212b8656d0b8bad31832d2e98d3f6c.tar.gz |
SERVER-24852 Add means to interrupt the sharding balancer
Diffstat (limited to 'jstests/sharding/movechunk_interrupt_at_primary_stepdown.js')
-rw-r--r-- | jstests/sharding/movechunk_interrupt_at_primary_stepdown.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/sharding/movechunk_interrupt_at_primary_stepdown.js b/jstests/sharding/movechunk_interrupt_at_primary_stepdown.js new file mode 100644 index 00000000000..123c052eab2 --- /dev/null +++ b/jstests/sharding/movechunk_interrupt_at_primary_stepdown.js @@ -0,0 +1,52 @@ +// Ensures that all pending move chunk operations get interrupted when the primary of the config +// server steps down and then becomes primary again + +load('./jstests/libs/chunk_manipulation_util.js'); + +(function() { + 'use strict'; + + // Intentionally use a config server with 1 node so that the step down and promotion to primary + // are guaranteed to happen on the same host + var st = new ShardingTest({config: 1, shards: 2}); + + assert.commandWorked(st.s0.adminCommand({enableSharding: 'TestDB'})); + st.ensurePrimaryShard('TestDB', st.shard0.shardName); + assert.commandWorked(st.s0.adminCommand({shardCollection: 'TestDB.TestColl', key: {Key: 1}})); + + var coll = st.s0.getDB('TestDB').TestColl; + + // We have one chunk initially + assert.writeOK(coll.insert({Key: 0, Value: 'Test value'})); + + pauseMigrateAtStep(st.shard1, migrateStepNames.deletedPriorDataInRange); + + // For startParallelOps to write its state + var staticMongod = MongoRunner.runMongod({}); + + var joinMoveChunk = moveChunkParallel( + staticMongod, st.s0.host, {Key: 0}, null, 'TestDB.TestColl', st.shard1.shardName); + waitForMigrateStep(st.shard1, migrateStepNames.deletedPriorDataInRange); + + // Stepdown the primary in order to force the balancer to stop + assert.throws(function() { + assert.commandWorked( + st.configRS.getPrimary().adminCommand({replSetStepDown: 10, force: true})); + }); + + // Ensure a new primary is found promptly + st.configRS.getPrimary(30000); + + assert.eq(1, st.s0.getDB('config').chunks.find({shard: st.shard0.shardName}).itcount()); + assert.eq(0, st.s0.getDB('config').chunks.find({shard: st.shard1.shardName}).itcount()); + + unpauseMigrateAtStep(st.shard1, migrateStepNames.deletedPriorDataInRange); + + // Ensure that migration succeeded + joinMoveChunk(); + + assert.eq(0, st.s0.getDB('config').chunks.find({shard: st.shard0.shardName}).itcount()); + assert.eq(1, st.s0.getDB('config').chunks.find({shard: st.shard1.shardName}).itcount()); + + st.stop(); +})(); |