summaryrefslogtreecommitdiff
path: root/jstests/sharding/migration_critical_section_concurrency.js
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-04-07 10:48:19 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-04-07 10:50:13 -0400
commitc48f2983e1a525394449fd2f2f1323b964bc8968 (patch)
tree9591d32e82f5e16235eb545f2bd1814d22963bc6 /jstests/sharding/migration_critical_section_concurrency.js
parent50474a3282dbda452d91754e07d6fed5f3f8ccab (diff)
downloadmongo-c48f2983e1a525394449fd2f2f1323b964bc8968.tar.gz
SERVER-28447 Forward-port migration_critical_section_concurrency.js
This test ensures that while query and write on one collection are stuck in the migration critical section, other collections are not impacted.
Diffstat (limited to 'jstests/sharding/migration_critical_section_concurrency.js')
-rw-r--r--jstests/sharding/migration_critical_section_concurrency.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/jstests/sharding/migration_critical_section_concurrency.js b/jstests/sharding/migration_critical_section_concurrency.js
new file mode 100644
index 00000000000..059d6a0e32e
--- /dev/null
+++ b/jstests/sharding/migration_critical_section_concurrency.js
@@ -0,0 +1,63 @@
+// This test ensures that if one collection is its migration critical section, this won't stall
+// operations for other sharded or unsharded collections
+
+load('./jstests/libs/chunk_manipulation_util.js');
+
+(function() {
+ 'use strict';
+
+ var staticMongod = MongoRunner.runMongod({}); // For startParallelOps.
+
+ var st = new ShardingTest({mongos: 1, shards: 2});
+ assert.commandWorked(st.s0.adminCommand({enableSharding: 'TestDB'}));
+ st.ensurePrimaryShard('TestDB', st.shard0.shardName);
+
+ var testDB = st.s0.getDB('TestDB');
+
+ assert.commandWorked(st.s0.adminCommand({shardCollection: 'TestDB.Coll0', key: {Key: 1}}));
+ assert.commandWorked(st.s0.adminCommand({split: 'TestDB.Coll0', middle: {Key: 0}}));
+
+ var coll0 = testDB.Coll0;
+ assert.writeOK(coll0.insert({Key: -1, Value: '-1'}));
+ assert.writeOK(coll0.insert({Key: 1, Value: '1'}));
+
+ assert.commandWorked(st.s0.adminCommand({shardCollection: 'TestDB.Coll1', key: {Key: 1}}));
+ assert.commandWorked(st.s0.adminCommand({split: 'TestDB.Coll1', middle: {Key: 0}}));
+
+ var coll1 = testDB.Coll1;
+ assert.writeOK(coll1.insert({Key: -1, Value: '-1'}));
+ assert.writeOK(coll1.insert({Key: 1, Value: '1'}));
+
+ // Ensure that coll0 has chunks on both shards so we can test queries against both donor and
+ // recipient for Coll1's migration below
+ assert.commandWorked(
+ st.s0.adminCommand({moveChunk: 'TestDB.Coll0', find: {Key: 1}, to: st.shard1.shardName}));
+
+ // Pause the move chunk operation in the critical section
+ pauseMigrateAtStep(st.shard1, migrateStepNames.done);
+ var joinMoveChunk = moveChunkParallel(
+ staticMongod, st.s0.host, {Key: 1}, null, 'TestDB.Coll1', st.shard1.shardName);
+
+ // Wait till the donor reaches the critical section
+ waitForMoveChunkStep(st.shard0, moveChunkStepNames.reachedSteadyState);
+
+ // Ensure that operations for 'Coll0' are not stalled
+ assert.eq(1, coll0.find({Key: {$lte: -1}}).maxTimeMS(5000).itcount());
+ assert.eq(1, coll0.find({Key: {$gte: 1}}).maxTimeMS(5000).itcount());
+ assert.writeOK(coll0.insert({Key: -2, Value: '-2'}, {writeConcern: {wtimeout: 5000}}));
+ assert.writeOK(coll0.insert({Key: 2, Value: '2'}, {writeConcern: {wtimeout: 5000}}));
+ assert.eq(2, coll0.find({Key: {$lte: -1}}).maxTimeMS(5000).itcount());
+ assert.eq(2, coll0.find({Key: {$gte: 1}}).maxTimeMS(5000).itcount());
+
+ // Ensure that operations for non-sharded collections are not stalled
+ var collUnsharded = testDB.CollUnsharded;
+ assert.eq(0, collUnsharded.find({}).maxTimeMS(5000).itcount());
+ assert.writeOK(
+ collUnsharded.insert({TestKey: 0, Value: 'Zero'}, {writeConcern: {wtimeout: 5000}}));
+ assert.eq(1, collUnsharded.find({}).maxTimeMS(5000).itcount());
+
+ unpauseMigrateAtStep(st.shard1, migrateStepNames.done);
+ joinMoveChunk();
+
+ st.stop();
+})();