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-18 03:51:31 +0000
commit27cd2ae2d01095ff36cc183fbebeafd333d3ee41 (patch)
treebdc10e3a1d41f809b2ca080065c6ae454c874a49
parent48f1cdf6c9cff10639c4a8eeebe72394a4f5cabb (diff)
downloadmongo-27cd2ae2d01095ff36cc183fbebeafd333d3ee41.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.js17
-rw-r--r--src/mongo/shell/db.js20
-rw-r--r--src/mongo/shell/utils.js9
3 files changed, 36 insertions, 10 deletions
diff --git a/jstests/replsets/get_replication_info_helper.js b/jstests/replsets/get_replication_info_helper.js
index 920b729f636..16d6bb04ce2 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";
@@ -45,11 +46,25 @@
} 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.soon(function() {
return 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.soon(function() {
+ return rawMongoProgramOutput().match("behind the freshest");
+ });
+
replSet.stopSet();
})();
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index 685abc2e839..fe714d73076 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -630,7 +630,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()");
@@ -1123,8 +1123,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));
@@ -1139,6 +1139,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;
@@ -1156,7 +1162,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) {
@@ -1168,7 +1174,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);
@@ -1179,7 +1185,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;
}
@@ -1196,7 +1202,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 8774335bd15..ee008055307 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -1300,7 +1300,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();
@@ -1330,7 +1330,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();