File: migration_failure.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 (68 lines) | stat: -rw-r--r-- 2,530 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Tests that migration failures before and after commit correctly roll back
// when possible
//

var st = new ShardingTest({shards: 2, mongos: 1});
st.stopBalancer();

var mongos = st.s0;
var admin = mongos.getDB("admin");
var shards = mongos.getCollection("config.shards").find().toArray();
var coll = mongos.getCollection("foo.bar");

assert(admin.runCommand({enableSharding: coll.getDB() + ""}).ok);
printjson(admin.runCommand({movePrimary: coll.getDB() + "", to: shards[0]._id}));
assert(admin.runCommand({shardCollection: coll + "", key: {_id: 1}}).ok);
assert(admin.runCommand({split: coll + "", middle: {_id: 0}}).ok);

st.printShardingStatus();

jsTest.log("Testing failed migrations...");

var version = null;
var failVersion = null;

assert.commandWorked(st.shard0.getDB("admin").runCommand(
    {configureFailPoint: 'failMigrationCommit', mode: 'alwaysOn'}));

version = st.shard0.getDB("admin").runCommand({getShardVersion: coll.toString()});

assert.commandFailed(admin.runCommand({moveChunk: coll + "", find: {_id: 0}, to: shards[1]._id}));

failVersion = st.shard0.getDB("admin").runCommand({getShardVersion: coll.toString()});

assert.commandWorked(st.shard0.getDB("admin")
                         .runCommand({configureFailPoint: 'failMigrationCommit', mode: 'off'}));

assert.commandWorked(st.shard0.getDB("admin").runCommand(
    {configureFailPoint: 'failMigrationConfigWritePrepare', mode: 'alwaysOn'}));

version = st.shard0.getDB("admin").runCommand({getShardVersion: coll.toString()});

assert.commandFailed(admin.runCommand({moveChunk: coll + "", find: {_id: 0}, to: shards[1]._id}));

failVersion = st.shard0.getDB("admin").runCommand({getShardVersion: coll.toString()});

assert.eq(version.global, failVersion.global);

assert.commandWorked(st.shard0.getDB("admin").runCommand(
    {configureFailPoint: 'failMigrationConfigWritePrepare', mode: 'off'}));

assert.commandWorked(st.shard0.getDB("admin")
                         .runCommand({configureFailPoint: 'failApplyChunkOps', mode: 'alwaysOn'}));

version = st.shard0.getDB("admin").runCommand({getShardVersion: coll.toString()});

assert.commandWorked(admin.runCommand({moveChunk: coll + "", find: {_id: 0}, to: shards[1]._id}));

failVersion = st.shard0.getDB("admin").runCommand({getShardVersion: coll.toString()});

assert.neq(version.global, failVersion.global);

assert.commandWorked(st.shard0.getDB("admin")
                         .runCommand({configureFailPoint: 'failApplyChunkOps', mode: 'off'}));

jsTest.log("DONE!");

st.stop();