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
|
/**
* Initial sync runs in several phases - the first 3 are as follows:
* 1) fetches the last oplog entry (op_start1) on the source;
* 2) copies all non-local databases from the source and fetches operations from sync source; and
* 3) applies operations from the source after op_start1.
*
* This test renames a collection on the source between phases 1 and 2, but renameCollection is not
* supported in initial sync. The secondary will initially fail to apply the command in phase 3
* and subsequently have to retry the initial sync.
*/
(function() {
"use strict";
var parameters = TestData.setParameters;
if (parameters && parameters.indexOf("use3dot2InitialSync=true") != -1) {
jsTest.log("Skipping this test because use3dot2InitialSync was provided.");
return;
}
var name = 'initial_sync_applier_error';
var replSet = new ReplSetTest({
name: name,
nodes: [{}, {rsConfig: {arbiterOnly: true}}],
});
replSet.startSet();
replSet.initiate();
var primary = replSet.getPrimary();
var coll = primary.getDB('test').getCollection(name);
assert.writeOK(coll.insert({_id: 0, content: "hi"}));
// Add a secondary node but make it hang after retrieving the last op on the source
// but before copying databases.
var secondary = replSet.add({setParameter: "numInitialSyncAttempts=2"});
secondary.setSlaveOk();
assert.commandWorked(secondary.getDB('admin').runCommand(
{configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'alwaysOn'}));
replSet.reInitiate();
// Wait for fail point message to be logged.
var checkLog = function(node, msg) {
assert.soon(function() {
var logMessages = assert.commandWorked(node.adminCommand({getLog: 'global'})).log;
for (var i = 0; i < logMessages.length; i++) {
if (logMessages[i].indexOf(msg) != -1) {
return true;
}
}
return false;
}, 'Did not see a log entry containing the following message: ' + msg, 60000, 1000);
};
checkLog(secondary, 'initial sync - initialSyncHangBeforeCopyingDatabases fail point enabled');
var newCollName = name + '_2';
assert.commandWorked(coll.renameCollection(newCollName, true));
assert.commandWorked(secondary.getDB('admin').runCommand(
{configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'off'}));
checkLog(secondary, 'Applying renameCollection not supported');
checkLog(secondary, 'initial sync done');
replSet.awaitReplication();
replSet.awaitSecondaryNodes();
assert.eq(0, secondary.getDB('test').getCollection(name).count());
assert.eq(1, secondary.getDB('test').getCollection(newCollName).count());
assert.eq("hi", secondary.getDB('test').getCollection(newCollName).findOne({_id: 0}).content);
})();
|