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-08-20 23:59:51 +0000
commitcdc593761b6b7cb491ccda19270517b377440bf2 (patch)
tree7a15f1a9ba312a6a1f24f6e79f28563705a6a482
parent7157e90233ddc3b1b208564a711289a2d99e5ee5 (diff)
downloadmongo-cdc593761b6b7cb491ccda19270517b377440bf2.tar.gz
SERVER-49991 Alias db. and rs.printSlaveReplicationInfo() to printSecondaryReplicationInfo()
(cherry picked from commit 996dcdc3d96346d71f012388eccc79c691619340)
-rw-r--r--etc/backports_required_for_multiversion_tests.yml2
-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
4 files changed, 35 insertions, 10 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index 31b74a6d243..f2b0e2cd502 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -91,6 +91,8 @@ all:
test_file: jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js
- ticket: SERVER-49986
test_file: jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js
+ - ticket: SERVER-49991
+ test_file: jstests/replsets/get_replication_info_helper.js
suites:
diff --git a/jstests/replsets/get_replication_info_helper.js b/jstests/replsets/get_replication_info_helper.js
index 32b0c2af766..39355e2ceda 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";
@@ -40,9 +41,20 @@ for (i in replSet._slaves) {
}
assert.commandWorked(primary.getDB('admin').runCommand({replSetStepDown: 120, force: true}));
+// 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 5a10d55ff5f..29cd3861290 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -575,7 +575,7 @@ DB.prototype.help = function() {
print("\tdb.printCollectionStats()");
print("\tdb.printReplicationInfo()");
print("\tdb.printShardingStatus()");
- print("\tdb.printSlaveReplicationInfo()");
+ print("\tdb.printSecondaryReplicationInfo()");
print("\tdb.resetError()");
print(
"\tdb.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into {cmdObj: 1}");
@@ -1033,8 +1033,8 @@ DB.prototype.printReplicationInfo = function() {
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));
@@ -1048,6 +1048,12 @@ DB.prototype.printReplicationInfo = function() {
};
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;
@@ -1065,7 +1071,7 @@ DB.prototype.printSlaveReplicationInfo = function() {
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) {
@@ -1077,7 +1083,7 @@ DB.prototype.printSlaveReplicationInfo = function() {
}
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);
@@ -1088,7 +1094,7 @@ DB.prototype.printSlaveReplicationInfo = function() {
}
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;
}
@@ -1105,7 +1111,7 @@ DB.prototype.printSlaveReplicationInfo = function() {
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 6cb99d96c23..9b2f9dae9e1 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -1471,7 +1471,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();
print("\treconfiguration helpers disconnect from the database so the shell will display");
@@ -1490,7 +1490,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();