blob: 2850f756912ebfff3463bb5cf3525391f1621f36 (
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// test initial sync failing
// try running as :
//
// mongo --nodb two_initsync.js | tee out | grep -v ^m31
//
var debugging = 0;
function pause(s) {
print(s);
while (debugging) {
sleep(3000);
print(s);
}
}
function deb(obj) {
if (debugging) {
print("\n\n\n" + obj + "\n\n");
}
}
w = 0;
function wait(f) {
w++;
var n = 0;
while (!f()) {
if (n % 4 == 0)
print("twoinitsync waiting " + w);
if (++n == 4) {
print("" + f);
}
assert(n < 200, 'tried 200 times, giving up');
sleep(1000);
}
}
doTest = function(signal) {
if (!(typeof TestData.setParameters === 'string') ||
!TestData.setParameters.includes("use3dot2InitialSync=true")) {
print("Test should only run with 3.2 style initial sync.");
return;
}
var replTest = new ReplSetTest({name: 'testSet', nodes: 0});
var first = replTest.add();
// Initiate replica set
assert.soon(function() {
var res = first.getDB("admin").runCommand({replSetInitiate: null});
return res['ok'] == 1;
});
// Get status
assert.soon(function() {
var result = first.getDB("admin").runCommand({replSetGetStatus: true});
return result['ok'] == 1;
});
var a = replTest.getPrimary().getDB("two");
for (var i = 0; i < 20000; i++)
assert.writeOK(a.coll.insert({
i: i,
s: "a b"
}));
assert.eq(20000, a.coll.find().itcount());
// Start a second node
var second = replTest.add();
// Add the second node.
// This runs the equivalent of rs.add(newNode);
replTest.reInitiate(60000);
var b = second.getDB("admin");
// attempt to interfere with the initial sync
b._adminCommand({replSetTest: 1, forceInitialSyncFailure: 1});
// wait(function () { return a._adminCommand("replSetGetStatus").members.length == 2; });
wait(function() {
return b.isMaster().secondary || b.isMaster().ismaster;
});
print("b.isMaster:");
printjson(b.isMaster());
second.setSlaveOk();
print("b.isMaster:");
printjson(b.isMaster());
wait(function() {
var c = b.getSisterDB("two").coll.find().itcount();
print(c);
return c == 20000;
});
print("two_initsync.js SUCCESS");
replTest.stopSet(signal);
};
print("two_initsync.js");
doTest(15);
|