summaryrefslogtreecommitdiff
path: root/jstests/hooks
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2016-07-19 09:44:37 -0400
committerJudah Schvimer <judah@mongodb.com>2016-07-19 09:44:37 -0400
commit433ffe0574f19f879b16d195068ce81ee55ee681 (patch)
tree420b39857177c7f87039156b54ee69d39f9fecd3 /jstests/hooks
parent5f57ee740b1eaa188532363fc363f42234057748 (diff)
downloadmongo-433ffe0574f19f879b16d195068ce81ee55ee681.tar.gz
SERVER-24538 Add small_oplog_rs_initsync_static passthrough to include periodic initial sync members
Diffstat (limited to 'jstests/hooks')
-rw-r--r--jstests/hooks/check_repl_dbhash.js36
-rw-r--r--jstests/hooks/run_check_repl_dbhash.js40
-rw-r--r--jstests/hooks/run_initial_sync_node_validation.js47
3 files changed, 87 insertions, 36 deletions
diff --git a/jstests/hooks/check_repl_dbhash.js b/jstests/hooks/check_repl_dbhash.js
index b518d131507..76504d4a1f8 100644
--- a/jstests/hooks/check_repl_dbhash.js
+++ b/jstests/hooks/check_repl_dbhash.js
@@ -75,6 +75,42 @@ function dumpCollectionDiff(primary, secondary, dbName, collName) {
}
}
+function checkDBHashesFsyncLocked(rst) {
+ // Call getPrimary to populate rst with information about the nodes.
+ var primary = rst.getPrimary();
+ assert(primary, 'calling getPrimary() failed');
+
+ var activeException = false;
+
+ try {
+ // Lock the primary to prevent the TTL monitor from deleting expired documents in
+ // the background while we are getting the dbhashes of the replica set members.
+ assert.commandWorked(primary.adminCommand({fsync: 1, lock: 1}),
+ 'failed to lock the primary');
+ rst.awaitReplication(60 * 1000 * 5);
+
+ var phaseName = 'after test hook';
+ var blacklist = [];
+ checkDBHashes(rst, blacklist, phaseName);
+ } catch (e) {
+ activeException = true;
+ throw e;
+ } finally {
+ // Allow writes on the primary.
+ var res = primary.adminCommand({fsyncUnlock: 1});
+
+ if (!res.ok) {
+ var msg = 'failed to unlock the primary, which may cause this' +
+ ' test to hang: ' + tojson(res);
+ if (activeException) {
+ print(msg);
+ } else {
+ throw new Error(msg);
+ }
+ }
+ }
+}
+
function checkDBHashes(rst, dbBlacklist, phase) {
// We don't expect the local database to match because some of its collections are not
// replicated.
diff --git a/jstests/hooks/run_check_repl_dbhash.js b/jstests/hooks/run_check_repl_dbhash.js
index 258ce17a13a..d378584061d 100644
--- a/jstests/hooks/run_check_repl_dbhash.js
+++ b/jstests/hooks/run_check_repl_dbhash.js
@@ -47,7 +47,7 @@
};
this.awaitReplication = function() {
- assert.commandWorked(primary.adminCommand({fsyncUnlock: 1}),
+ assert.commandWorked(master.adminCommand({fsyncUnlock: 1}),
'failed to unlock the primary');
print('Starting fsync on master to flush all pending writes');
@@ -65,7 +65,7 @@
'Awaiting replication failed');
}
print('Finished awaiting replication');
- assert.commandWorked(primary.adminCommand({fsync: 1, lock: 1}),
+ assert.commandWorked(master.adminCommand({fsync: 1, lock: 1}),
'failed to re-lock the primary');
};
};
@@ -88,40 +88,8 @@
rst = new ReplSetTest(db.getMongo().host);
}
- // Call getPrimary to populate rst with information about the nodes.
- var primary = rst.getPrimary();
- assert(primary, 'calling getPrimary() failed');
-
- var activeException = false;
-
- try {
- // Lock the primary to prevent the TTL monitor from deleting expired documents in
- // the background while we are getting the dbhashes of the replica set members.
- assert.commandWorked(primary.adminCommand({fsync: 1, lock: 1}),
- 'failed to lock the primary');
- rst.awaitReplication(60 * 1000 * 5); // 5min timeout
-
- var phaseName = 'after test hook';
- load('jstests/hooks/check_repl_dbhash.js');
- var blacklist = [];
- checkDBHashes(rst, blacklist, phaseName);
- } catch (e) {
- activeException = true;
- throw e;
- } finally {
- // Allow writes on the primary.
- var res = primary.adminCommand({fsyncUnlock: 1});
-
- if (!res.ok) {
- var msg = 'failed to unlock the primary, which may cause this' +
- ' test to hang: ' + tojson(res);
- if (activeException) {
- print(msg);
- } else {
- throw new Error(msg);
- }
- }
- }
+ load('jstests/hooks/check_repl_dbhash.js');
+ checkDBHashesFsyncLocked(rst);
var totalTime = Date.now() - startTime;
print('Finished consistency checks of cluster in ' + totalTime + ' ms.');
diff --git a/jstests/hooks/run_initial_sync_node_validation.js b/jstests/hooks/run_initial_sync_node_validation.js
new file mode 100644
index 00000000000..f22e36b921b
--- /dev/null
+++ b/jstests/hooks/run_initial_sync_node_validation.js
@@ -0,0 +1,47 @@
+// Runner that runs full validation on all collections of the initial sync node and checks the
+// dbhashes of all of the nodes including the initial sync node.
+'use strict';
+
+(function() {
+ var startTime = Date.now();
+
+ var primaryInfo = db.isMaster();
+ assert(primaryInfo.ismaster,
+ 'shell is not connected to the primary node: ' + tojson(primaryInfo));
+
+ var cmdLineOpts = db.adminCommand('getCmdLineOpts');
+ assert.commandWorked(cmdLineOpts);
+ var isMasterSlave = cmdLineOpts.parsed.master === true;
+ assert(!isMasterSlave, 'Master/Slave is not supported with initial sync hooks');
+
+ // The initial sync hooks only work for replica sets.
+ var rst = new ReplSetTest(db.getMongo().host);
+
+ // Call getPrimary to populate rst with information about the nodes.
+ var primary = rst.getPrimary();
+ assert(primary, 'calling getPrimary() failed');
+
+ // Find the hidden node.
+ var hiddenNode;
+ for (var secondary of rst.liveNodes.slaves) {
+ var isMasterRes = secondary.getDB('admin').isMaster();
+ if (isMasterRes.hidden) {
+ hiddenNode = secondary;
+ break;
+ }
+ }
+
+ assert(hiddenNode, 'No hidden initial sync node was found in the replica set');
+
+ // Confirm that the hidden node is in SECONDARY state.
+ var res = assert.commandWorked(hiddenNode.adminCommand({replSetGetStatus: 1}));
+ assert.eq(res.myState, ReplSetTest.State.SECONDARY, tojson(res));
+
+ load('jstests/hooks/run_validate_collections.js');
+
+ load('jstests/hooks/check_repl_dbhash.js'); // For checkDBHashesFsyncLocked
+ checkDBHashesFsyncLocked(rst);
+
+ var totalTime = Date.now() - startTime;
+ print('Finished consistency checks of initial sync node in ' + totalTime + ' ms.');
+})();