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
|
// SERVER-4941 Test collection rename during initial sync
(function() {
'use strict';
load('jstests/replsets/rslib.js');
const basename = 'initial_sync_rename_collection';
const numColls = 100;
jsTestLog('Bring up set');
const rst = new ReplSetTest({name: basename, nodes: 1});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const primaryDB = primary.getDB('d');
const primaryExtraDB = primary.getDB('e');
jsTestLog('Create a bunch of collections');
for (let i = 0; i < numColls; ++i) {
assert.writeOK(primaryDB['c' + i].save({}));
}
assert.writeOK(primaryExtraDB['renameAcrossDatabases'].save({}));
jsTestLog('Make sure synced');
rst.awaitReplication();
jsTestLog('Bring up a new node');
// TODO(SERVER-4941): Only a single initial sync attempt should be necessary.
const secondary = rst.add({setParameter: 'numInitialSyncAttempts=3'});
rst.reInitiate();
assert.eq(primary, rst.getPrimary(), 'Primary changed after reconfig');
jsTestLog('Wait for new node to start cloning');
secondary.setSlaveOk();
const secondaryDB = secondary.getDB('d');
const secondaryExtraDB = secondary.getDB('e');
wait(function() {
return secondaryDB.stats().collections >= 1;
}, 'never saw new node starting to clone, was waiting for docs in ' + secondaryDB['c0']);
jsTestLog('Rename collections on the primary');
const lastCollName = 'c' + (numColls - 1);
assert.commandWorked(primaryDB[lastCollName].renameCollection('renamed'));
assert.commandWorked(primaryExtraDB.adminCommand({
renameCollection: primaryExtraDB['renameAcrossDatabases'].getFullName(),
to: primaryDB[lastCollName].getFullName()
}));
jsTestLog('Wait for both nodes to be up-to-date');
assert.writeOK(primaryDB["c0"].update({}, {ready: true}, {writeConcern: {w: 2}}));
jsTestLog('Check that all collections where renamed correctly on the secondary');
assert.eq(secondaryExtraDB['renameAcrossDatabases'].find().itcount(),
0,
'collection RenameAcrossDatabases still exists after it was supposed to be renamed');
assert.eq(secondaryDB['renamed'].find().itcount(), 1, 'renamed collection does not exist');
assert.eq(secondaryDB[lastCollName].find().itcount(),
1,
'collection ' + lastCollName + ' expected to exist after rename across databases');
rst.checkReplicatedDataHashes();
rst.stopSet(15);
})();
|