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
|
/**
* Test dropping collections during initial sync, before using the 'find' and 'count'
* commands using UUIDs instead of namespaces. This verifies initial sync behavior in
* cases where using UUIDs results in NamespaceNotFound while using namespace strings
* results in an empty result or zero count.
*/
(function() {
'use strict';
load('jstests/libs/check_log.js');
const basename = 'initial_sync_rename_collection';
jsTestLog('Bring up set');
const rst = new ReplSetTest(
{name: basename, nodes: [{}, {rsConfig: {priority: 0}}, {rsConfig: {priority: 0}}]});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const primaryDB = primary.getDB('d');
const primaryColl = primaryDB.coll;
jsTestLog('Create a collection (with a UUID) and insert a document.');
assert.writeOK(primaryColl.insert({_id: 0}));
const collInfo = primaryDB.getCollectionInfos({name: primaryColl.getName()})[0];
assert(collInfo.info.uuid,
'newly created collection expected to have a UUID: ' + tojson(collInfo));
jsTestLog('Make sure synced');
rst.awaitReplication();
jsTestLog('Resync the secondary enabling failpoint');
function ResyncWithFailpoint(failpointName, failpointData) {
let setParameter = {numInitialSyncAttempts: 1};
setParameter['failpoint.' + failpointName] =
tojson({mode: 'alwaysOn', data: failpointData});
rst.restart(1, {startClean: true, setParameter});
const secondary = rst.nodes[1];
assert.eq(primary, rst.getPrimary(), 'Primary changed after reconfig');
jsTestLog('Wait for new node to start cloning');
secondary.setSlaveOk();
const secondaryDB = secondary.getDB(primaryDB.getName());
const secondaryColl = secondaryDB[primaryColl.getName()];
rst.reInitiate();
checkLog.contains(secondary, 'initial sync - ' + failpointName + ' fail point enabled');
jsTestLog('Remove collection on the primary and insert a new document, recreating it.');
assert(primaryColl.drop());
assert.writeOK(primaryColl.insert({_id: 0}, {writeConcern: {w: 'majority'}}));
const newCollInfo = primaryDB.getCollectionInfos({name: primaryColl.getName()})[0];
assert(collInfo.info.uuid,
'recreated collection expected to have a UUID: ' + tojson(collInfo));
assert.neq(collInfo.info.uuid,
newCollInfo.info.uuid,
'recreated collection expected to have different UUID');
jsTestLog('Disable failpoint and resume initial sync');
assert.commandWorked(
secondary.adminCommand({configureFailPoint: failpointName, mode: 'off'}));
jsTestLog('Wait for both nodes to be up-to-date');
rst.awaitSecondaryNodes();
rst.awaitReplication();
jsTestLog('Check consistency and shut down replica-set');
rst.checkReplicatedDataHashes();
}
ResyncWithFailpoint('initialSyncHangBeforeCollectionClone',
{namespace: primaryColl.getFullName()});
ResyncWithFailpoint('initialSyncHangAfterListCollections', {database: primaryDB.getName()});
rst.stopSet();
})();
|