summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync3.js
blob: 471aa161e270b1e5c702f9db2e0a81ff09406693 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* test initial sync options
 *
 * {state : 1}
 * {state : 2}
 * {name : host+":"+port}
 * {_id : 2}
 * {optime : now}
 * {optime : 1970}
 */

load("jstests/replsets/rslib.js");
var name = "initialsync3";
var host = getHostName();
var port = allocatePorts(7);

print("Start set with three nodes");
var replTest = new ReplSetTest( {name: name, nodes: 7} );
var nodes = replTest.startSet();
replTest.initiate({
    _id : name,
    members : [
               {_id:0, host : host+":"+port[0]},
               {_id:1, host : host+":"+port[1], initialSync : {state : 1}},
               {_id:2, host : host+":"+port[2], initialSync : {state : 2}},
               {_id:3, host : host+":"+port[3], initialSync : {name : host+":"+port[2]}},
               {_id:4, host : host+":"+port[4], initialSync : {_id : 2}},
               {_id:5, host : host+":"+port[5], initialSync : {optime : new Date()}},
               {_id:6, host : host+":"+port[6], initialSync : {optime : new Date(0)}}
               ]});

var master = replTest.getMaster();

print("Initial sync");
master.getDB("foo").bar.baz.insert({x:1});

print("Make sure everyone's secondary");
wait(function() {
    var status = master.getDB("admin").runCommand({replSetGetStatus:1});
    occasionally(function() {
        printjson(status);
      });

    if (!status.members) {
      return false;
    }
    
    for (i=0; i<7; i++) {
      if (status.members[i].state != 1 && status.members[i].state != 2) {
        return false;
      }
    }
    return true;
    
  });

replTest.awaitReplication();

replTest.stopSet();

print("reconfig");

var rs2 = new ReplSetTest( {name: 'reconfig-isync3', nodes: 3} );
rs2.startSet();
rs2.initiate();

master = rs2.getMaster();
var config = master.getDB("local").system.replset.findOne();
config.version++;
config.members[0].initialSync = {state : 2};
config.members[1].initialSync = {state : 1};
try {
    master.getDB("admin").runCommand({replSetReconfig : config});
}
catch(e) {
    print("trying to reconfigure: "+e);
}

master = rs2.getMaster();
config = master.getDB("local").system.replset.findOne();

assert(typeof(config.members[0].initialSync) == "object");
assert.eq(config.members[0].initialSync.state, 2);
assert.eq(config.members[1].initialSync.state, 1);

rs2.stopSet();

print("initialSync3 success!");