summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAli Mir <ali.mir@mongodb.com>2020-08-11 11:34:10 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-02 19:29:04 +0000
commit91563e0f58c8e3e2e3473283a5c14a3abc4bc25c (patch)
treeafc96c75e5b171c9e0f778139d24e56d1c9aa070 /src
parent4e0bb24f64db02c8dde9967c9571e08fb16bcec3 (diff)
downloadmongo-91563e0f58c8e3e2e3473283a5c14a3abc4bc25c.tar.gz
SERVER-49990 Alias setSlaveOk() and getSlaveOk() shell helpers
(cherry picked from commit d6fe50035aff8026937dff9d8544ff213ad05152)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/shell/collection.js26
-rw-r--r--src/mongo/shell/db.js24
-rw-r--r--src/mongo/shell/mongo.js18
-rw-r--r--src/mongo/shell/replsettest.js4
-rw-r--r--src/mongo/shell/utils.js15
5 files changed, 65 insertions, 22 deletions
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js
index 452a2361f30..00143600595 100644
--- a/src/mongo/shell/collection.js
+++ b/src/mongo/shell/collection.js
@@ -1509,20 +1509,32 @@ DBCollection.prototype.getSplitKeysForChunks = function(chunkSize) {
};
DBCollection.prototype.setSlaveOk = function(value) {
- if (value == undefined)
- value = true;
- this._slaveOk = value;
+ print(
+ "WARNING: setSlaveOk() is deprecated and may be removed in the next major release. Please use setSecondaryOk() instead.");
+ this.setSecondaryOk(value);
};
DBCollection.prototype.getSlaveOk = function() {
- if (this._slaveOk != undefined)
- return this._slaveOk;
- return this._db.getSlaveOk();
+ print(
+ "WARNING: getSlaveOk() is deprecated and may be removed in the next major release. Please use getSecondaryOk() instead.");
+ return this.getSecondaryOk();
+};
+
+DBCollection.prototype.setSecondaryOk = function(value) {
+ if (value === undefined)
+ value = true;
+ this._secondaryOk = value;
+};
+
+DBCollection.prototype.getSecondaryOk = function() {
+ if (this._secondaryOk !== undefined)
+ return this._secondaryOk;
+ return this._db.getSecondaryOk();
};
DBCollection.prototype.getQueryOptions = function() {
// inherit this method from DB but use apply so
- // that slaveOk will be set if is overridden on this DBCollection
+ // that secondaryOk will be set if is overridden on this DBCollection
return this._db.getQueryOptions.apply(this, arguments);
};
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index f417f40060d..dcd23b26b25 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -1331,20 +1331,32 @@ var DB;
};
DB.prototype.setSlaveOk = function(value) {
+ print(
+ "WARNING: setSlaveOk() is deprecated and may be removed in the next major release. Please use setSecondaryOk() instead.");
+ this.setSecondaryOk(value);
+ };
+
+ DB.prototype.getSlaveOk = function() {
+ print(
+ "WARNING: getSlaveOk() is deprecated and may be removed in the next major release. Please use getSecondaryOk() instead.");
+ return this.getSecondaryOk();
+ };
+
+ DB.prototype.setSecondaryOk = function(value) {
if (value == undefined)
value = true;
- this._slaveOk = value;
+ this._secondaryOk = value;
};
- DB.prototype.getSlaveOk = function() {
- if (this._slaveOk != undefined)
- return this._slaveOk;
- return this._mongo.getSlaveOk();
+ DB.prototype.getSecondaryOk = function() {
+ if (this._secondaryOk != undefined)
+ return this._secondaryOk;
+ return this._mongo.getSecondaryOk();
};
DB.prototype.getQueryOptions = function() {
var options = 0;
- if (this.getSlaveOk())
+ if (this.getSecondaryOk())
options |= 4;
return options;
};
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index ecd09f6bab3..bd79191af76 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -33,13 +33,25 @@ if (typeof mongoInject == "function") {
}
Mongo.prototype.setSlaveOk = function(value) {
+ print(
+ "WARNING: setSlaveOk() is deprecated and may be removed in the next major release. Please use setSecondaryOk() instead.");
+ this.setSecondaryOk(value);
+};
+
+Mongo.prototype.getSlaveOk = function() {
+ print(
+ "WARNING: getSlaveOk() is deprecated and may be removed in the next major release. Please use getSecondaryOk() instead.");
+ return this.getSecondaryOk();
+};
+
+Mongo.prototype.setSecondaryOk = function(value) {
if (value == undefined)
value = true;
- this.slaveOk = value;
+ this.secondaryOk = value;
};
-Mongo.prototype.getSlaveOk = function() {
- return this.slaveOk || false;
+Mongo.prototype.getSecondaryOk = function() {
+ return this.secondaryOk || false;
};
Mongo.prototype.getDB = function(name) {
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 52573614e29..c089df69472 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -125,7 +125,7 @@ var ReplSetTest = function(opts) {
var twoPrimaries = false;
self.nodes.forEach(function(node) {
try {
- node.setSlaveOk();
+ node.setSecondaryOk();
var n = node.getDB('admin').runCommand({ismaster: 1});
if (n.ismaster == true) {
if (self.liveNodes.master) {
@@ -1239,7 +1239,7 @@ var ReplSetTest = function(opts) {
print("ReplSetTest awaitReplication: checking secondary #" + secondaryCount +
": " + slaveName);
- slave.getDB("admin").getMongo().setSlaveOk();
+ slave.getDB("admin").getMongo().setSecondaryOk();
var slaveOpTime;
if (secondaryOpTimeType == ReplSetTest.OpTimeType.LAST_DURABLE) {
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index 4b5e59b9156..a7e991ad048 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -1296,7 +1296,7 @@ rs.help = function() {
"\trs.freeze(secs) make a node ineligible to become primary for the time specified");
print(
"\trs.remove(hostportstr) remove a host from the replica set (disconnects)");
- print("\trs.slaveOk() allow queries on secondary nodes");
+ print("\trs.secondaryOk() allow queries on secondary nodes");
print();
print("\trs.printReplicationInfo() check oplog size and time range");
print(
@@ -1307,8 +1307,15 @@ rs.help = function() {
print("\tan error, even if the command succeeds.");
};
rs.slaveOk = function(value) {
- return db.getMongo().setSlaveOk(value);
+ print(
+ "WARNING: slaveOk() is deprecated and may be removed in the next major release. Please use secondaryOk() instead.");
+ return db.getMongo().setSecondaryOk(value);
+};
+
+rs.secondaryOk = function(value) {
+ return db.getMongo().setSecondaryOk(value);
};
+
rs.status = function() {
return db._adminCommand("replSetGetStatus");
};
@@ -1436,7 +1443,7 @@ rs.debug = {};
rs.debug.nullLastOpWritten = function(primary, secondary) {
var p = connect(primary + "/local");
var s = connect(secondary + "/local");
- s.getMongo().setSlaveOk();
+ s.getMongo().setSecondaryOk();
var secondToLast = s.oplog.rs.find().sort({$natural: -1}).limit(1).next();
var last = p.runCommand({
@@ -1461,7 +1468,7 @@ rs.debug.getLastOpWritten = function(server) {
if (server) {
s = connect(server + "/local");
}
- s.getMongo().setSlaveOk();
+ s.getMongo().setSecondaryOk();
return s.oplog.rs.find().sort({$natural: -1}).limit(1).next();
};