File: move_chunk_missing_idx.js

package info (click to toggle)
mongodb 1%3A3.2.11-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 196,404 kB
  • sloc: cpp: 1,412,793; ansic: 504,961; python: 78,522; perl: 5,837; sh: 5,661; java: 4,202; makefile: 1,784; pascal: 617; xml: 176; asm: 128
file content (41 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
 * 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'});
st.ensurePrimaryShard(testDB.toString(), "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();