summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/replsets/print_secondary_replication_info_unreachable_secondary.js25
-rw-r--r--src/mongo/shell/db.js27
2 files changed, 33 insertions, 19 deletions
diff --git a/jstests/replsets/print_secondary_replication_info_unreachable_secondary.js b/jstests/replsets/print_secondary_replication_info_unreachable_secondary.js
new file mode 100644
index 00000000000..4948ac85801
--- /dev/null
+++ b/jstests/replsets/print_secondary_replication_info_unreachable_secondary.js
@@ -0,0 +1,25 @@
+// Tests the output of db.printSecondaryReplicationInfo() for unreachable secondaries.
+
+(function() {
+"use strict";
+const name = "printSecondaryReplicationInfo";
+const replSet = new ReplSetTest({name: name, nodes: 2});
+replSet.startSet();
+replSet.initiateWithHighElectionTimeout();
+
+const primary = replSet.getPrimary();
+primary.getDB('test').foo.insert({a: 1});
+replSet.awaitReplication();
+
+const secondary = replSet.getSecondary();
+replSet.stop(replSet.getNodeId(secondary));
+replSet.waitForState(secondary, ReplSetTest.State.DOWN);
+
+const joinShell =
+ startParallelShell("db.getSiblingDB('admin').printSecondaryReplicationInfo();", primary.port);
+joinShell();
+assert(
+ rawMongoProgramOutput().match("no replication info, yet. State: \\(not reachable/healthy\\)"));
+
+replSet.stopSet();
+})();
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index 73fdb9c25e2..477dc95a60c 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -1091,28 +1091,17 @@ DB.prototype.printSecondaryReplicationInfo = function() {
return null;
}
- function g(x) {
- assert(x, "how could this be null (printSecondaryReplicationInfo gx)");
- print("source: " + x.host);
- if (x.syncedTo) {
- var st = new Date(DB.tsToSeconds(x.syncedTo) * 1000);
- getReplLag(st);
- } else {
- print("\tdoing initial sync");
- }
- }
-
- function r(x) {
- assert(x, "how could this be null (printSecondaryReplicationInfo rx)");
- if (x.state == 1 || x.state == 7) { // ignore primaries (1) and arbiters (7)
+ function printNodeReplicationInfo(node) {
+ assert(node);
+ if (node.state === 1 || node.state === 7) { // ignore primaries (1) and arbiters (7)
return;
}
- print("source: " + x.name);
- if (x.optime) {
- getReplLag(x.optimeDate);
+ print("source: " + node.name);
+ if (node.optime && node.health != 0) {
+ getReplLag(node.optimeDate);
} else {
- print("\tno replication info, yet. State: " + x.stateStr);
+ print("\tno replication info, yet. State: " + node.stateStr);
}
}
@@ -1136,7 +1125,7 @@ DB.prototype.printSecondaryReplicationInfo = function() {
}
for (i in status.members) {
- r(status.members[i]);
+ printNodeReplicationInfo(status.members[i]);
}
}
};