blob: 3ef968f3a53d7a958cdb74b13d21950d4efb2b13 (
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
|
load("jstests/replsets/rslib.js");
var name = "slaveDelay2";
var host = getHostName();
var initialize = function() {
var replTest = new ReplSetTest( {name: name, nodes: 1} );
var nodes = replTest.startSet();
replTest.initiate();
var master = replTest.getMaster().getDB(name);
waitForAllMembers(master);
return replTest;
};
var populate = function(master) {
// insert records
for (var i =0; i<1000; i++) {
master.foo.insert({_id:1});
}
master.runCommand({getlasterror:1});
}
doTest = function( signal ) {
var replTest = initialize();
var master = replTest.getMaster().getDB(name);
populate(master);
var admin = master.getSisterDB("admin");
/**
* start a slave with a long delay (1 hour) and do some writes while it is
* initializing. Make sure it syncs all of these writes before going into
* syncDelay.
*/
var conn = MongoRunner.runMongod({port : 31008, dbpath : name + "-sd", useHostname: true,
replSet: name, oplogSize : 128});
conn.setSlaveOk();
config = master.getSisterDB("local").system.replset.findOne();
config.version++;
config.members.push({_id : 1, host : host+":31008",priority:0, slaveDelay:3600});
var ok = admin.runCommand({replSetReconfig : config});
assert.eq(ok.ok,1);
// do inserts during initial sync
var count = 0;
while (count < 10) {
for (var i = 100*count; i<100*(count+1); i++) {
master.foo.insert({x:i});
}
//check if initial sync is done
var state = master.getSisterDB("admin").runCommand({replSetGetStatus:1});
printjson(state);
if (state.members[1].state == 2) {
break;
}
count++;
}
// throw out last 100 inserts, but make sure the others were applied
if (count == 0) {
print("NOTHING TO CHECK");
replTest.stopSet();
return;
}
// wait a bit for the syncs to be applied
waitForAllMembers(master);
for (var i=0; i<(100*count); i++) {
var obj = conn.getDB(name).foo.findOne({x : i});
assert(obj);
}
replTest.stopSet();
}
doTest(15);
|