diff options
author | Maria van Keulen <maria.vankeulen@mongodb.com> | 2016-09-19 17:15:20 -0400 |
---|---|---|
committer | Maria van Keulen <maria.vankeulen@mongodb.com> | 2016-09-26 15:06:25 -0400 |
commit | aa9ea14a57181f098a32f24a734f2c81563bee5c (patch) | |
tree | 8b1e6e86472bd98aef01de75dc255fe8e82d8452 /jstests | |
parent | da47772085eb028c32b19984edda51b15e44a8ec (diff) | |
download | mongo-aa9ea14a57181f098a32f24a734f2c81563bee5c.tar.gz |
SERVER-26156 Add migration tests for collections with V2 indexes
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/multiVersion/index_v2_migration.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/jstests/multiVersion/index_v2_migration.js b/jstests/multiVersion/index_v2_migration.js new file mode 100644 index 00000000000..ea0fd1b9390 --- /dev/null +++ b/jstests/multiVersion/index_v2_migration.js @@ -0,0 +1,72 @@ +// Test chunk migration from collections with V2 indexes. + +(function() { + 'use strict'; + load('jstests/libs/get_index_helpers.js'); + load('jstests/libs/override_methods/multiversion_override_balancer_control.js'); + const latest = 'latest'; + const downgrade = '3.2'; + var testDb = 'test'; + + // + // Ensure that we can successfully migrate a chunk of a collection with a V2 index between 3.4 + // shards with featureCompatibilityVersion 3.2. + // + + // Create a 3.4 sharded cluster. + var st = new ShardingTest({mongos: 1, shards: 2}); + var shard0 = st.shard0.shardName; + var shard1 = st.shard1.shardName; + + // Create a sharded collection with a V2 index. + assert.commandWorked(st.s.adminCommand({enableSharding: testDb})); + st.ensurePrimaryShard(testDb, shard1); + assert.commandWorked(st.s.getDB(testDb).createCollection('foo')); + assert.commandWorked(st.s.getDB(testDb).foo.createIndex({a: 1}, {v: 2})); + assert.commandWorked(st.s.adminCommand({shardCollection: testDb + '.foo', key: {a: 1}})); + var indexSpec = GetIndexHelpers.findByName(st.shard1.getDB(testDb).foo.getIndexes(), 'a_1'); + assert.neq(null, indexSpec); + assert.eq(2, indexSpec.v, tojson(indexSpec)); + + // Successfully migrate a chunk from the collection with a V2 index between shards. + assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: '3.2'})); + assert.commandWorked(st.s.adminCommand({moveChunk: testDb + '.foo', find: {a: 1}, to: shard0})); + + // Make sure the index is V2 on the destination shard. + indexSpec = GetIndexHelpers.findByName(st.shard0.getDB(testDb).foo.getIndexes(), 'a_1'); + assert.neq(null, indexSpec); + assert.eq(2, indexSpec.v, tojson(indexSpec)); + st.stop(); + + // + // Ensure that we fail to migrate a chunk of a collection with a V2 index from a 3.4 mongod + // shard to a 3.2 mongod shard. + // + + // Create a 3.4 mongod with a collection that has a V2 index. + var chunkSource = MongoRunner.runMongod({shardsvr: '', binVersion: latest}); + assert.neq(null, chunkSource); + assert.commandWorked(chunkSource.adminCommand({setFeatureCompatibilityVersion: '3.4'})); + assert.commandWorked(chunkSource.getDB(testDb).createCollection('foo')); + assert.commandWorked(chunkSource.getDB(testDb).foo.createIndex({a: 1}, {v: 2})); + + // Set mongod's featureCompatibilityVersion to 3.2 so that we can add it to a 3.2 cluster. + assert.commandWorked(chunkSource.adminCommand({setFeatureCompatibilityVersion: '3.2'})); + + // Create a 3.2 sharded cluster with one shard and add the 3.4 mongod to it. + st = new ShardingTest({ + shards: 1, + other: {mongosOptions: {binVersion: downgrade}, shardOptions: {binVersion: downgrade}} + }); + assert.commandWorked(st.s.adminCommand({addShard: chunkSource.name})); + assert.commandWorked(st.s.adminCommand({enableSharding: testDb})); + st.ensurePrimaryShard(testDb, shard1); + assert.commandWorked(st.s.adminCommand({shardCollection: testDb + '.foo', key: {a: 1}})); + + // Fail to migrate a chunk of the collection with a V2 index to the 3.2 shard. + assert.commandFailedWithCode( + st.s.adminCommand({moveChunk: testDb + '.foo', find: {a: 1}, to: shard0}), + ErrorCodes.OperationFailed, + 'Move chunk unexpectedly succeeded. Expected to fail since 3.2 cannot build V2 indexes.'); + st.stop(); +})(); |