summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2020-02-20 21:42:07 +1100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-05 13:03:43 +0000
commit747ff353cbc819d032fa727d4bd7ffad16ea0437 (patch)
treed9b3d7e9af26138d7b74e0416a93d6110e326af0 /src/mongo/shell
parent7c4b875a8858c5bd5efc9bf4f285f7f440fdfdc0 (diff)
downloadmongo-747ff353cbc819d032fa727d4bd7ffad16ea0437.tar.gz
SERVER-45692 add explicit RWC to inter-node commands (even if merely kImplicitDefault)
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/encrypted_dbclient_base.cpp26
-rw-r--r--src/mongo/shell/encrypted_dbclient_base.h16
-rw-r--r--src/mongo/shell/feature_compatibility_version.js8
-rw-r--r--src/mongo/shell/mongo.js16
-rw-r--r--src/mongo/shell/replsettest.js61
5 files changed, 75 insertions, 52 deletions
diff --git a/src/mongo/shell/encrypted_dbclient_base.cpp b/src/mongo/shell/encrypted_dbclient_base.cpp
index 883453e11db..f08af53e152 100644
--- a/src/mongo/shell/encrypted_dbclient_base.cpp
+++ b/src/mongo/shell/encrypted_dbclient_base.cpp
@@ -500,15 +500,23 @@ JS::Value EncryptedDBClientBase::getCollection() const {
}
-std::unique_ptr<DBClientCursor> EncryptedDBClientBase::query(const NamespaceStringOrUUID& nsOrUuid,
- Query query,
- int nToReturn,
- int nToSkip,
- const BSONObj* fieldsToReturn,
- int queryOptions,
- int batchSize) {
- return _conn->query(
- nsOrUuid, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
+std::unique_ptr<DBClientCursor> EncryptedDBClientBase::query(
+ const NamespaceStringOrUUID& nsOrUuid,
+ Query query,
+ int nToReturn,
+ int nToSkip,
+ const BSONObj* fieldsToReturn,
+ int queryOptions,
+ int batchSize,
+ boost::optional<BSONObj> readConcernObj) {
+ return _conn->query(nsOrUuid,
+ query,
+ nToReturn,
+ nToSkip,
+ fieldsToReturn,
+ queryOptions,
+ batchSize,
+ readConcernObj);
}
bool EncryptedDBClientBase::isFailed() const {
diff --git a/src/mongo/shell/encrypted_dbclient_base.h b/src/mongo/shell/encrypted_dbclient_base.h
index 518c3631a5f..406c5884391 100644
--- a/src/mongo/shell/encrypted_dbclient_base.h
+++ b/src/mongo/shell/encrypted_dbclient_base.h
@@ -118,13 +118,15 @@ public:
void trace(JSTracer* trc) final;
using DBClientBase::query;
- std::unique_ptr<DBClientCursor> query(const NamespaceStringOrUUID& nsOrUuid,
- Query query,
- int nToReturn,
- int nToSkip,
- const BSONObj* fieldsToReturn,
- int queryOptions,
- int batchSize) final;
+ std::unique_ptr<DBClientCursor> query(
+ const NamespaceStringOrUUID& nsOrUuid,
+ Query query,
+ int nToReturn,
+ int nToSkip,
+ const BSONObj* fieldsToReturn,
+ int queryOptions,
+ int batchSize,
+ boost::optional<BSONObj> readConcernObj = boost::none) final;
bool isFailed() const final;
diff --git a/src/mongo/shell/feature_compatibility_version.js b/src/mongo/shell/feature_compatibility_version.js
index 0894a2a0fd2..599e7a4c79f 100644
--- a/src/mongo/shell/feature_compatibility_version.js
+++ b/src/mongo/shell/feature_compatibility_version.js
@@ -25,7 +25,13 @@ function checkFCV(adminDB, version, targetVersion) {
assert.eq(res.featureCompatibilityVersion.version, version, tojson(res));
assert.eq(res.featureCompatibilityVersion.targetVersion, targetVersion, tojson(res));
- let doc = adminDB.system.version.findOne({_id: "featureCompatibilityVersion"});
+ // This query specifies an explicit readConcern because some FCV tests pass a connection that
+ // has manually run isMaster with internalClient, and mongod expects internalClients (ie. other
+ // cluster members) to include read/write concern (on commands that accept read/write concern).
+ let doc = adminDB.system.version.find({_id: "featureCompatibilityVersion"})
+ .limit(1)
+ .readConcern("local")
+ .next();
assert.eq(doc.version, version, tojson(doc));
assert.eq(doc.targetVersion, targetVersion, tojson(doc));
}
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 2503a989d74..1fe4a678b20 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -484,6 +484,22 @@ Mongo.prototype.readMode = function() {
return this._readMode;
};
+/**
+ * Run a function while forcing a certain readMode, and then return the readMode to its original
+ * setting afterwards. Passes this connection to the given function, and returns the function's
+ * result.
+ */
+Mongo.prototype._runWithForcedReadMode = function(forcedReadMode, fn) {
+ let origReadMode = this.readMode();
+ this.forceReadMode(forcedReadMode);
+ try {
+ var res = fn(this);
+ } finally {
+ this.forceReadMode(origReadMode);
+ }
+ return res;
+};
+
//
// Write Concern can be set at the connection level, and is used for all write operations unless
// overridden at the collection level.
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 46f1e7bbab5..e20de8ff38f 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -1672,17 +1672,6 @@ var ReplSetTest = function(opts) {
"established on " + id);
};
- function _runInCommandReadMode(conn, fn) {
- let origReadMode = conn.readMode();
- conn.forceReadMode("commands");
- try {
- var res = fn();
- } finally {
- conn.forceReadMode(origReadMode);
- }
- return res;
- }
-
// Wait until the optime of the specified type reaches the primary's last applied optime. Blocks
// on all secondary nodes or just 'slaves', if specified. The timeout will reset if any of the
// secondaries makes progress.
@@ -1747,13 +1736,13 @@ var ReplSetTest = function(opts) {
var slaveName = slave.host;
var slaveConfigVersion =
- _runInCommandReadMode(slave,
- () => slave.getDB("local")['system.replset']
- .find()
- .readConcern("local")
- .limit(1)
- .next()
- .version);
+ slave._runWithForcedReadMode("commands",
+ () => slave.getDB("local")['system.replset']
+ .find()
+ .readConcern("local")
+ .limit(1)
+ .next()
+ .version);
if (masterConfigVersion != slaveConfigVersion) {
print("ReplSetTest awaitReplication: secondary #" + secondaryCount + ", " +
@@ -1763,13 +1752,13 @@ var ReplSetTest = function(opts) {
if (slaveConfigVersion > masterConfigVersion) {
master = self.getPrimary();
masterConfigVersion =
- _runInCommandReadMode(master,
- () => master.getDB("local")['system.replset']
- .find()
- .readConcern("local")
- .limit(1)
- .next()
- .version);
+ master._runWithForcedReadMode("commands",
+ () => master.getDB("local")['system.replset']
+ .find()
+ .readConcern("local")
+ .limit(1)
+ .next()
+ .version);
masterName = master.host;
print("ReplSetTest awaitReplication: optime for primary, " + masterName +
@@ -2455,7 +2444,8 @@ var ReplSetTest = function(opts) {
}
try {
- return _runInCommandReadMode(this.mongo, () => operation(this.cursor));
+ return this.mongo._runWithForcedReadMode("commands",
+ () => operation(this.cursor));
} catch (err) {
print("Error: " + name + " threw '" + err.message + "' on " + this.mongo.host);
// Occasionally, the capped collection will get truncated while we are iterating
@@ -2491,20 +2481,21 @@ var ReplSetTest = function(opts) {
// changed "cursorTimeoutMillis" to a short time period.
this._cursorExhausted = false;
// Although this line sets the read concern, it does not need to be called via
- // _runInCommandReadMode() because it only creates the client-side cursor. It's not
- // until next()/hasNext() are called that the find command gets sent to the server.
+ // _runWithForcedReadMode() because it only creates the client-side cursor. It's
+ // not until next()/hasNext() are called that the find command gets sent to the
+ // server.
this.cursor =
coll.find(query).sort({$natural: -1}).noCursorTimeout().readConcern("local");
};
this.getFirstDoc = function() {
- return _runInCommandReadMode(this.mongo,
- () => this.getOplogColl()
- .find()
- .sort({$natural: 1})
- .readConcern("local")
- .limit(-1)
- .next());
+ return this.mongo._runWithForcedReadMode("commands",
+ () => this.getOplogColl()
+ .find()
+ .sort({$natural: 1})
+ .readConcern("local")
+ .limit(-1)
+ .next());
};
this.getOplogColl = function() {