summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync_rename_collection.js
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2017-08-01 20:25:31 -0400
committerGeert Bosch <geert@mongodb.com>2017-08-23 10:52:16 -0400
commitc13fc3f7b63c279927e8d9c1d9251631c1d85069 (patch)
treec7e196b31e5c64d814588f9b3b00ba6fcfa6dc18 /jstests/replsets/initial_sync_rename_collection.js
parent0890aff3e8ed432fc08a2e5d6569b07976668463 (diff)
downloadmongo-c13fc3f7b63c279927e8d9c1d9251631c1d85069.tar.gz
SERVER-30478 New test for rename during initial sync
Diffstat (limited to 'jstests/replsets/initial_sync_rename_collection.js')
-rw-r--r--jstests/replsets/initial_sync_rename_collection.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/jstests/replsets/initial_sync_rename_collection.js b/jstests/replsets/initial_sync_rename_collection.js
new file mode 100644
index 00000000000..56f96353023
--- /dev/null
+++ b/jstests/replsets/initial_sync_rename_collection.js
@@ -0,0 +1,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);
+})();