diff options
author | Randolph Tan <randolph@10gen.com> | 2017-09-28 16:33:27 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2017-09-28 16:51:00 -0400 |
commit | f88f6f43b7ae2af0286437da8f00c0079ed99145 (patch) | |
tree | ec22edf29d746877baa697f80bc10d0b40ebb616 /jstests/sharding/write_transactions_during_migration.js | |
parent | 0309fa8091bdf7d6663a02fefd5d61ae0965e7b1 (diff) | |
download | mongo-f88f6f43b7ae2af0286437da8f00c0079ed99145.tar.gz |
SERVER-30894/SERVER-31290 Implement command for transferring session information during migration
This reverts commit f24fbb0011c6ded9101f08574e7cd07e63690a9b.
This reverts commit d293f6857bcb36b26ca8fa03d90299714fe060de.
Diffstat (limited to 'jstests/sharding/write_transactions_during_migration.js')
-rw-r--r-- | jstests/sharding/write_transactions_during_migration.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/jstests/sharding/write_transactions_during_migration.js b/jstests/sharding/write_transactions_during_migration.js new file mode 100644 index 00000000000..7c52628e05e --- /dev/null +++ b/jstests/sharding/write_transactions_during_migration.js @@ -0,0 +1,84 @@ +/** + * Tests that session information are properly transferred to the destination shard while + * new writes are being sent to the source shard. + */ + +load('./jstests/libs/chunk_manipulation_util.js'); + +/** + * Test outline: + * 1. Pause migration. + * 2. Perform writes and allow it to be capture via OpObserver + * 3. Unpause migration. + * 4. Retry writes and confirm that writes are not duplicated. + */ +(function() { + + "use strict"; + + var staticMongod = MongoRunner.runMongod({}); // For startParallelOps. + + var st = new ShardingTest({shards: {rs0: {nodes: 1}, rs1: {nodes: 1}}}); + st.adminCommand({enableSharding: 'test'}); + st.ensurePrimaryShard('test', st.shard0.shardName); + st.adminCommand({shardCollection: 'test.user', key: {x: 1}}); + + pauseMoveChunkAtStep(st.shard0, moveChunkStepNames.reachedSteadyState); + var joinMoveChunk = + moveChunkParallel(staticMongod, st.s.host, {x: 0}, null, 'test.user', st.shard1.shardName); + + var insertCmd = { + insert: 'user', + documents: [{x: 10}, {x: 30}], + ordered: false, + lsid: {id: UUID()}, + txnNumber: NumberLong(34), + }; + + var testDB = st.getDB('test'); + var insertResult = assert.commandWorked(testDB.runCommand(insertCmd)); + + var findAndModCmd = { + findAndModify: 'user', + query: {x: 30}, + update: {$inc: {y: 1}}, + new: true, + upsert: true, + lsid: {id: UUID()}, + txnNumber: NumberLong(37), + }; + + var findAndModifyResult = assert.commandWorked(testDB.runCommand(findAndModCmd)); + + unpauseMoveChunkAtStep(st.shard0, moveChunkStepNames.reachedSteadyState); + joinMoveChunk(); + + var insertRetryResult = assert.commandWorked(testDB.runCommand(insertCmd)); + + assert.eq(insertResult.ok, insertRetryResult.ok); + assert.eq(insertResult.n, insertRetryResult.n); + assert.eq(insertResult.writeErrors, insertRetryResult.writeErrors); + assert.eq(insertResult.writeConcernErrors, insertRetryResult.writeConcernErrors); + + assert.eq(1, testDB.user.find({x: 10}).itcount()); + assert.eq(1, testDB.user.find({x: 30}).itcount()); + + var findAndModifyRetryResult = assert.commandWorked(testDB.runCommand(findAndModCmd)); + + assert.eq(findAndModifyResult.ok, findAndModifyRetryResult.ok); + assert.eq(findAndModifyResult.value, findAndModifyRetryResult.value); + + // TODO: SERVER-30532: after adding upserted, just compare the entire lastErrorObject + var expectedLE = findAndModifyResult.lastErrorObject; + var toCheckLE = findAndModifyRetryResult.lastErrorObject; + + assert.neq(null, toCheckLE); + assert.eq(findAndModifyResult.updatedExisting, findAndModifyRetryResult.updatedExisting); + assert.eq(findAndModifyResult.n, findAndModifyRetryResult.n); + + assert.eq(1, testDB.user.findOne({x: 30}).y); + + st.stop(); + + MongoRunner.stopMongod(staticMongod); +})(); |