summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavi Vetriselvan <pavithra.vetriselvan@mongodb.com>2020-08-10 10:22:13 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-16 12:12:26 +0000
commit268081db9538c5db216c83a1b63f83540be0075c (patch)
tree8d5eebfdc665f6d6de9f074d308bf02786c7e362
parent25e3aeda438f7144b6771618ce1c9dd4dbee3f7e (diff)
downloadmongo-268081db9538c5db216c83a1b63f83540be0075c.tar.gz
SERVER-49991 Alias db. and rs.printSlaveReplicationInfo() to printSecondaryReplicationInfo()
(cherry picked from commit 996dcdc3d96346d71f012388eccc79c691619340)
-rw-r--r--jstests/replsets/get_replication_info_helper.js14
-rw-r--r--src/mongo/shell/db.js20
-rw-r--r--src/mongo/shell/utils.js9
3 files changed, 33 insertions, 10 deletions
diff --git a/jstests/replsets/get_replication_info_helper.js b/jstests/replsets/get_replication_info_helper.js
index 0fed84db2c4..f22a3852024 100644
--- a/jstests/replsets/get_replication_info_helper.js
+++ b/jstests/replsets/get_replication_info_helper.js
@@ -1,4 +1,5 @@
-// Tests the output of db.getReplicationInfo() and tests db.printSlaveReplicationInfo().
+// Tests the output of db.getReplicationInfo(), db.printSlaveReplicationInfo(), and the latter's
+// alias, db.printSecondaryReplicationInfo().
(function() {
"use strict";
@@ -43,10 +44,21 @@
} catch (e) {
}
+ // printSlaveReplicationInfo is deprecated and aliased to printSecondaryReplicationInfo, but
+ // ensure it still works for backwards compatibility.
mongo =
startParallelShell("db.getSiblingDB('admin').printSlaveReplicationInfo();", primary.port);
mongo();
assert(rawMongoProgramOutput().match("behind the freshest"));
+ clearRawMongoProgramOutput();
+ assert.eq(rawMongoProgramOutput().match("behind the freshest"), null);
+
+ // Ensure that the new helper, printSecondaryReplicationInfo works the same.
+ mongo = startParallelShell("db.getSiblingDB('admin').printSecondaryReplicationInfo();",
+ primary.port);
+ mongo();
+ assert(rawMongoProgramOutput().match("behind the freshest"));
+
replSet.stopSet();
})();
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index 6ec674be46a..c5dd29922d5 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -635,7 +635,7 @@ var DB;
print("\tdb.printCollectionStats()");
print("\tdb.printReplicationInfo()");
print("\tdb.printShardingStatus()");
- print("\tdb.printSlaveReplicationInfo()");
+ print("\tdb.printSecondaryReplicationInfo(()");
print("\tdb.dropUser(username)");
print("\tdb.repairDatabase()");
print("\tdb.resetError()");
@@ -1183,8 +1183,8 @@ var DB;
print("cannot provide replication status from an arbiter.");
return;
} else if (!isMaster.ismaster) {
- print("this is a slave, printing slave replication info.");
- this.printSlaveReplicationInfo();
+ print("this is a secondary, printing secondary replication info.");
+ this.printSecondaryReplicationInfo();
return;
}
print(tojson(result));
@@ -1199,6 +1199,12 @@ var DB;
};
DB.prototype.printSlaveReplicationInfo = function() {
+ print(
+ "WARNING: printSlaveReplicationInfo is deprecated and may be removed in the next major release. Please use printSecondaryReplicationInfo instead.");
+ this.printSecondaryReplicationInfo();
+ };
+
+ DB.prototype.printSecondaryReplicationInfo = function() {
var startOptimeDate = null;
var primary = null;
@@ -1216,7 +1222,7 @@ var DB;
print("\t" + Math.round(ago) + " secs (" + hrs + " hrs) behind the " + suffix);
}
- function getMaster(members) {
+ function getPrimary(members) {
for (i in members) {
var row = members[i];
if (row.state === 1) {
@@ -1228,7 +1234,7 @@ var DB;
}
function g(x) {
- assert(x, "how could this be null (printSlaveReplicationInfo gx)");
+ 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);
@@ -1239,7 +1245,7 @@ var DB;
}
function r(x) {
- assert(x, "how could this be null (printSlaveReplicationInfo rx)");
+ assert(x, "how could this be null (printSecondaryReplicationInfo rx)");
if (x.state == 1 || x.state == 7) { // ignore primaries (1) and arbiters (7)
return;
}
@@ -1256,7 +1262,7 @@ var DB;
if (L.system.replset.count() != 0) {
var status = this.adminCommand({'replSetGetStatus': 1});
- primary = getMaster(status.members);
+ primary = getPrimary(status.members);
if (primary) {
startOptimeDate = primary.optimeDate;
}
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index 13c8f2f8a4f..9418a5aec77 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -1392,7 +1392,7 @@ rs.help = function() {
print();
print("\trs.printReplicationInfo() check oplog size and time range");
print(
- "\trs.printSlaveReplicationInfo() check replica set members and replication lag");
+ "\trs.printSecondaryReplicationInfo() check replica set members and replication lag");
print("\tdb.isMaster() check who is primary");
print("\tdb.hello() check who is primary");
print();
@@ -1422,7 +1422,12 @@ rs.initiate = function(c) {
return db._adminCommand({replSetInitiate: c});
};
rs.printSlaveReplicationInfo = function() {
- return db.printSlaveReplicationInfo();
+ print(
+ "WARNING: printSlaveReplicationInfo is deprecated and may be removed in the next major release. Please use printSecondaryReplicationInfo instead.");
+ return db.printSecondaryReplicationInfo();
+};
+rs.printSecondaryReplicationInfo = function() {
+ return db.printSecondaryReplicationInfo();
};
rs.printReplicationInfo = function() {
return db.printReplicationInfo();