summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorPavithra Vetriselvan <pavithra.vetriselvan@mongodb.com>2017-11-27 13:58:42 -0500
committerPavithra Vetriselvan <pavithra.vetriselvan@mongodb.com>2017-11-27 13:58:42 -0500
commit838745e7728c854d2ea3f29d174de3b768d65776 (patch)
treece397e0de3032bc2b60f202c216b9eaae4c06569 /jstests
parente03a936e50d40cac82685965bdcba9b4d08d553b (diff)
downloadmongo-838745e7728c854d2ea3f29d174de3b768d65776.tar.gz
SERVER-30869 Adds fail point to initial_sync_rename_collection js test
Diffstat (limited to 'jstests')
-rw-r--r--jstests/replsets/initial_sync_rename_collection.js102
1 files changed, 70 insertions, 32 deletions
diff --git a/jstests/replsets/initial_sync_rename_collection.js b/jstests/replsets/initial_sync_rename_collection.js
index fdb77ea6da4..5d30d7121f9 100644
--- a/jstests/replsets/initial_sync_rename_collection.js
+++ b/jstests/replsets/initial_sync_rename_collection.js
@@ -1,64 +1,102 @@
-// SERVER-4941 Test collection rename during initial sync
+/**
+ * Tests that initial sync is completed successfully if a 'renameCollection' operation
+ * occurs on the sync source during initial sync.
+ * See SERVER-4941.
+ */
(function() {
'use strict';
load('jstests/replsets/rslib.js');
const basename = 'initial_sync_rename_collection';
- const numColls = 100;
- jsTestLog('Bring up set');
+ jsTestLog('Bring up a replica set');
const rst = new ReplSetTest({name: basename, nodes: 1});
rst.startSet();
rst.initiate();
+ const db0_name = "db0";
+ const db1_name = "db1";
+
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({}));
+ // Create two separate databases so that we can rename a collection across databases.
+ const primary_db0 = primary.getDB(db0_name);
+ const primary_db1 = primary.getDB(db1_name);
+
+ jsTestLog("Create collections on primary");
+ const collRenameWithinDB_name = 'coll_1';
+ const collRenameAcrossDBs_name = 'coll_2';
+ const collWithinFinal_name = 'renamed';
+ const collAcrossFinal_name = 'renamed_across';
+
+ // Create two collections on the same database. One will be renamed within the database
+ // and the other will be renamed to a different database.
+ assert.writeOK(primary_db0[collRenameWithinDB_name].save({}));
+ assert.writeOK(primary_db0[collRenameAcrossDBs_name].save({}));
- jsTestLog('Make sure synced');
+ jsTestLog('Waiting for replication');
rst.awaitReplication();
jsTestLog('Bring up a new node');
const secondary = rst.add({setParameter: 'numInitialSyncAttempts=1'});
+
+ // Add a fail point that causes the secondary's initial sync to hang before
+ // copying databases.
+ assert.commandWorked(secondary.adminCommand(
+ {configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'alwaysOn'}));
+
+ jsTestLog('Begin initial sync on secondary');
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()
+ // Confirm that initial sync started on the secondary node.
+ jsTestLog('Waiting for initial sync to start');
+ checkLog.contains(secondary,
+ 'initial sync - initialSyncHangBeforeCopyingDatabases fail point enabled');
+
+ // Start renaming collections while initial sync is hanging.
+ jsTestLog('Rename collection ' + db0_name + '.' + collRenameWithinDB_name + ' to ' + db0_name +
+ '.' + collWithinFinal_name + ' on the sync source ' + db0_name);
+ assert.commandWorked(
+ primary_db0[collRenameWithinDB_name].renameCollection(collWithinFinal_name));
+
+ jsTestLog('Rename collection ' + db0_name + '.' + collRenameAcrossDBs_name + ' to ' + db1_name +
+ '.' + collAcrossFinal_name + ' on the sync source ' + db0_name);
+ assert.commandWorked(primary.adminCommand({
+ renameCollection: primary_db0[collRenameAcrossDBs_name].getFullName(),
+ to: primary_db1[collAcrossFinal_name]
+ .getFullName() // Collection 'renamed_across' is implicitly created.
}));
+ // Disable fail point so that the secondary can finish its initial sync.
+ assert.commandWorked(secondary.adminCommand(
+ {configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'off'}));
+
jsTestLog('Wait for both nodes to be up-to-date');
rst.awaitSecondaryNodes();
rst.awaitReplication();
- jsTestLog('Check that all collections where renamed correctly on the secondary');
- assert.eq(secondaryDB['renamed'].find().itcount(), 1, 'renamed collection does not exist');
- assert.eq(secondaryDB[lastCollName].find().itcount(),
+ const secondary_db0 = secondary.getDB(db0_name);
+ const secondary_db1 = secondary.getDB(db1_name);
+
+ jsTestLog('Check that collection was renamed correctly on the secondary');
+ assert.eq(secondary_db0[collWithinFinal_name].find().itcount(),
1,
- 'collection ' + lastCollName + ' expected to exist after rename across databases');
- assert.eq(secondaryExtraDB['renameAcrossDatabases'].find().itcount(),
+ 'renamed collection does not exist');
+ assert.eq(secondary_db1[collAcrossFinal_name].find().itcount(),
+ 1,
+ 'renamed_across collection does not exist');
+ assert.eq(secondary_db0[collRenameWithinDB_name].find().itcount(),
+ 0,
+ 'collection ' + collRenameWithinDB_name +
+ ' still exists after it was supposed to be renamed');
+ assert.eq(secondary_db0[collRenameAcrossDBs_name].find().itcount(),
0,
- 'collection RenameAcrossDatabases still exists after it was supposed to be renamed');
+ 'collection ' + collRenameAcrossDBs_name +
+ ' still exists after it was supposed to be renamed');
rst.checkReplicatedDataHashes();
- rst.stopSet(15);
+ rst.checkOplogs();
+ rst.stopSet();
})();