diff options
author | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2020-08-10 10:22:13 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-16 01:39:49 +0000 |
commit | 5e56df1dfc7c5edd3ba1ccce1b64cc9fa361a988 (patch) | |
tree | efbd3e0607c3e934d91ab614a6fd6a87e00b58b9 | |
parent | b8b6d9fe5a5fb27efcdde48811b0eb9c9ca6a4a5 (diff) | |
download | mongo-5e56df1dfc7c5edd3ba1ccce1b64cc9fa361a988.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.yml | 2 | ||||
-rw-r--r-- | jstests/replsets/get_replication_info_helper.js | 14 | ||||
-rw-r--r-- | src/mongo/shell/db.js | 20 | ||||
-rw-r--r-- | src/mongo/shell/utils.js | 9 |
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 971416d58f3..988850040d7 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -72,6 +72,8 @@ all: test_file: jstests/sharding/ismaster.js - ticket: SERVER-49987 test_file: jstests/replsets/ismaster1.js + - ticket: SERVER-49991 + test_file: jstests/replsets/get_replication_info_helper.js # Tests that should only be excluded from particular suites should be listed under that suite. 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 4c0c7df6a15..763f5fedcb7 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -603,7 +603,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}"); @@ -1065,8 +1065,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)); @@ -1080,6 +1080,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; @@ -1097,7 +1103,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) { @@ -1109,7 +1115,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); @@ -1120,7 +1126,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; } @@ -1137,7 +1143,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 5cc1481e7b3..ac7255f806b 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -1419,7 +1419,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(); @@ -1449,7 +1449,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(); |