summaryrefslogtreecommitdiff
path: root/jstests/sharding/move_chunk_missing_idx.js
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2014-08-13 17:48:31 -0400
committerRandolph Tan <randolph@10gen.com>2014-08-15 15:26:07 -0400
commit39d5795eab4da921e2c813b3c99ae52a0d913f6b (patch)
tree005b6574075feb10493dd270a69a42bd0a6497b0 /jstests/sharding/move_chunk_missing_idx.js
parente4c72a04f7dab7ab747f59306cabd36cff3f3e16 (diff)
downloadmongo-39d5795eab4da921e2c813b3c99ae52a0d913f6b.tar.gz
SERVER-12472 Fail MoveChunk if an index is needed on TO shard and data exists
Diffstat (limited to 'jstests/sharding/move_chunk_missing_idx.js')
-rw-r--r--jstests/sharding/move_chunk_missing_idx.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/jstests/sharding/move_chunk_missing_idx.js b/jstests/sharding/move_chunk_missing_idx.js
new file mode 100644
index 00000000000..6171bb539a7
--- /dev/null
+++ b/jstests/sharding/move_chunk_missing_idx.js
@@ -0,0 +1,46 @@
+/**
+ * Test that migration should fail if the destination shard does not
+ * have the index and is not empty.
+ */
+
+var st = new ShardingTest({ shards: 2 });
+
+var testDB = st.s.getDB('test');
+
+testDB.adminCommand({ enableSharding: 'test' });
+testDB.adminCommand({ movePrimary: 'test', to: 'shard0001' });
+testDB.adminCommand({ shardCollection: 'test.user', key: { x: 1 }});
+
+// Test procedure:
+// 1. Create index (index should now be in primary shard).
+// 2. Split chunk into 3 parts.
+// 3. Move 1 chunk to 2nd shard - should have no issues
+
+testDB.user.ensureIndex({ a: 1, b: 1 });
+
+testDB.adminCommand({ split: 'test.user', middle: { x: 0 }});
+testDB.adminCommand({ split: 'test.user', middle: { x: 10 }});
+
+// Collection does not exist, no chunk, index missing case at destination case.
+assert.commandWorked(testDB.adminCommand({ moveChunk: 'test.user',
+ find: { x: 0 },
+ to: 'shard0000' }));
+
+// Drop index since last moveChunk created this.
+st.d0.getDB('test').user.dropIndex({ a: 1, b: 1 });
+
+// Collection exist but empty, index missing at destination case.
+assert.commandWorked(testDB.adminCommand({ moveChunk: 'test.user',
+ find: { x: 10 },
+ to: 'shard0000' }));
+
+// Drop index since last moveChunk created this.
+st.d0.getDB('test').user.dropIndex({ a: 1, b: 1 });
+
+// Collection not empty, index missing at destination case.
+testDB.user.insert({ x: 10 });
+assert.commandFailed(testDB.adminCommand({ moveChunk: 'test.user',
+ find: { x: -10 },
+ to: 'shard0000' }));
+
+st.stop();