From 71e0a2469126353455d5df3ecce8be103018f933 Mon Sep 17 00:00:00 2001 From: Yoonsoo Kim Date: Mon, 28 Jun 2021 07:00:07 +0000 Subject: SERVER-57388 Remove readMode/writeMode/rpcProtocols/useLegacyWriteOps shell command-line parameters --- src/mongo/shell/bridge.js | 5 +- src/mongo/shell/bulk_api.js | 20 --- src/mongo/shell/collection.js | 197 +++++++++++----------------- src/mongo/shell/encrypted_dbclient_base.cpp | 3 - src/mongo/shell/mongo.js | 65 --------- src/mongo/shell/replsettest.js | 4 - src/mongo/shell/shell_options.cpp | 29 ---- src/mongo/shell/shell_options.h | 3 - src/mongo/shell/shell_options.idl | 17 --- src/mongo/shell/shell_utils.cpp | 15 --- src/mongo/shell/utils.js | 35 ----- 11 files changed, 77 insertions(+), 316 deletions(-) (limited to 'src/mongo/shell') diff --git a/src/mongo/shell/bridge.js b/src/mongo/shell/bridge.js index 588989a86d5..5c6ed2102ef 100644 --- a/src/mongo/shell/bridge.js +++ b/src/mongo/shell/bridge.js @@ -137,10 +137,7 @@ function MongoBridge(options) { function runBridgeCommand(conn, cmdName, cmdArgs) { // The wire version of this mongobridge is detected as the wire version of the corresponding // mongod or mongos process because the message is simply forwarded to that process. - // Commands to configure the mongobridge process must support being sent as an OP_QUERY - // message in order to handle when the mongobridge is a proxy for a mongos process or when - // --readMode=legacy is passed to the mongo shell. Create a new Object with 'cmdName' as the - // first key and $forBridge=true. + // Create a new Object with 'cmdName' as the first key and $forBridge=true. var cmdObj = {}; cmdObj[cmdName] = 1; cmdObj.$forBridge = true; diff --git a/src/mongo/shell/bulk_api.js b/src/mongo/shell/bulk_api.js index c4224a32955..95a1a40d4e7 100644 --- a/src/mongo/shell/bulk_api.js +++ b/src/mongo/shell/bulk_api.js @@ -758,31 +758,11 @@ var _bulk_api_module = (function() { }, collation: function(collationSpec) { - if (!collection.getMongo().hasWriteCommands()) { - throw new Error( - "cannot use collation if server does not support write commands"); - } - - if (collection.getMongo().writeMode() !== "commands") { - throw new Error("write mode must be 'commands' in order to use collation, " + - "but found write mode: " + collection.getMongo().writeMode()); - } - currentOp.collation = collationSpec; return findOperations; }, arrayFilters: function(filters) { - if (!collection.getMongo().hasWriteCommands()) { - throw new Error( - "cannot use arrayFilters if server does not support write commands"); - } - - if (collection.getMongo().writeMode() !== "commands") { - throw new Error("write mode must be 'commands' in order to use arrayFilters, " + - "but found write mode: " + collection.getMongo().writeMode()); - } - currentOp.arrayFilters = filters; return findOperations; }, diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js index 1bb14424ba2..50f7aa4f5dc 100644 --- a/src/mongo/shell/collection.js +++ b/src/mongo/shell/collection.js @@ -307,47 +307,31 @@ DBCollection.prototype.insert = function(obj, options) { var startTime = (typeof (_verboseShell) === 'undefined' || !_verboseShell) ? 0 : new Date().getTime(); - if (this.getMongo().writeMode() != "legacy") { - // Bit 1 of option flag is continueOnError. Bit 0 (stop on error) is the default. - var bulk = ordered ? this.initializeOrderedBulkOp() : this.initializeUnorderedBulkOp(); - var isMultiInsert = Array.isArray(obj); - - if (isMultiInsert) { - obj.forEach(function(doc) { - bulk.insert(doc); - }); - } else { - bulk.insert(obj); - } + // Bit 1 of option flag is continueOnError. Bit 0 (stop on error) is the default. + var bulk = ordered ? this.initializeOrderedBulkOp() : this.initializeUnorderedBulkOp(); + var isMultiInsert = Array.isArray(obj); - try { - result = bulk.execute(wc); - if (!isMultiInsert) - result = result.toSingleResult(); - } catch (ex) { - if (ex instanceof BulkWriteError) { - result = isMultiInsert ? ex.toResult() : ex.toSingleResult(); - } else if (ex instanceof WriteCommandError) { - result = ex; - } else { - // Other exceptions rethrown as-is. - throw ex; - } - } + if (isMultiInsert) { + obj.forEach(function(doc) { + bulk.insert(doc); + }); } else { - if (typeof (obj._id) == "undefined" && !Array.isArray(obj)) { - var tmp = obj; // don't want to modify input - obj = {_id: new ObjectId()}; - for (var key in tmp) { - obj[key] = tmp[key]; - } + bulk.insert(obj); + } + + try { + result = bulk.execute(wc); + if (!isMultiInsert) + result = result.toSingleResult(); + } catch (ex) { + if (ex instanceof BulkWriteError) { + result = isMultiInsert ? ex.toResult() : ex.toSingleResult(); + } else if (ex instanceof WriteCommandError) { + result = ex; + } else { + // Other exceptions rethrown as-is. + throw ex; } - - this.getMongo().insert(this._fullName, obj, flags); - - // enforce write concern, if required - if (wc) - result = this.runCommand("getLastError", wc instanceof WriteConcern ? wc.toJSON() : wc); } this._lastID = obj._id; @@ -402,46 +386,34 @@ DBCollection.prototype.remove = function(t, justOne) { var startTime = (typeof (_verboseShell) === 'undefined' || !_verboseShell) ? 0 : new Date().getTime(); - if (this.getMongo().writeMode() != "legacy") { - var bulk = this.initializeOrderedBulkOp(); + var bulk = this.initializeOrderedBulkOp(); - if (letParams) { - bulk.setLetParams(letParams); - } - var removeOp = bulk.find(query); - - if (collation) { - removeOp.collation(collation); - } + if (letParams) { + bulk.setLetParams(letParams); + } + var removeOp = bulk.find(query); - if (justOne) { - removeOp.removeOne(); - } else { - removeOp.remove(); - } + if (collation) { + removeOp.collation(collation); + } - try { - result = bulk.execute(wc).toSingleResult(); - } catch (ex) { - if (ex instanceof BulkWriteError) { - result = ex.toSingleResult(); - } else if (ex instanceof WriteCommandError) { - result = ex; - } else { - // Other exceptions thrown - throw ex; - } - } + if (justOne) { + removeOp.removeOne(); } else { - if (collation) { - throw new Error("collation requires use of write commands"); - } - - this.getMongo().remove(this._fullName, query, justOne); + removeOp.remove(); + } - // enforce write concern, if required - if (wc) - result = this.runCommand("getLastError", wc instanceof WriteConcern ? wc.toJSON() : wc); + try { + result = bulk.execute(wc).toSingleResult(); + } catch (ex) { + if (ex instanceof BulkWriteError) { + result = ex.toSingleResult(); + } else if (ex instanceof WriteCommandError) { + result = ex; + } else { + // Other exceptions thrown + throw ex; + } } this._printExtraInfo("Removed", startTime); @@ -522,62 +494,45 @@ DBCollection.prototype.update = function(query, updateSpec, upsert, multi) { var startTime = (typeof (_verboseShell) === 'undefined' || !_verboseShell) ? 0 : new Date().getTime(); - if (this.getMongo().writeMode() != "legacy") { - var bulk = this.initializeOrderedBulkOp(); - - if (letParams) { - bulk.setLetParams(letParams); - } - var updateOp = bulk.find(query); + var bulk = this.initializeOrderedBulkOp(); - if (hint) { - updateOp.hint(hint); - } + if (letParams) { + bulk.setLetParams(letParams); + } + var updateOp = bulk.find(query); - if (upsert) { - updateOp = updateOp.upsert(); - } + if (hint) { + updateOp.hint(hint); + } - if (collation) { - updateOp.collation(collation); - } + if (upsert) { + updateOp = updateOp.upsert(); + } - if (arrayFilters) { - updateOp.arrayFilters(arrayFilters); - } + if (collation) { + updateOp.collation(collation); + } - if (multi) { - updateOp.update(updateSpec); - } else { - updateOp.updateOne(updateSpec); - } + if (arrayFilters) { + updateOp.arrayFilters(arrayFilters); + } - try { - result = bulk.execute(wc).toSingleResult(); - } catch (ex) { - if (ex instanceof BulkWriteError) { - result = ex.toSingleResult(); - } else if (ex instanceof WriteCommandError) { - result = ex; - } else { - // Other exceptions thrown - throw ex; - } - } + if (multi) { + updateOp.update(updateSpec); } else { - if (collation) { - throw new Error("collation requires use of write commands"); - } - - if (arrayFilters) { - throw new Error("arrayFilters requires use of write commands"); - } - - this.getMongo().update(this._fullName, query, updateSpec, upsert, multi); + updateOp.updateOne(updateSpec); + } - // Enforce write concern, if required - if (wc) { - result = this.runCommand("getLastError", wc instanceof WriteConcern ? wc.toJSON() : wc); + try { + result = bulk.execute(wc).toSingleResult(); + } catch (ex) { + if (ex instanceof BulkWriteError) { + result = ex.toSingleResult(); + } else if (ex instanceof WriteCommandError) { + result = ex; + } else { + // Other exceptions thrown + throw ex; } } diff --git a/src/mongo/shell/encrypted_dbclient_base.cpp b/src/mongo/shell/encrypted_dbclient_base.cpp index 5a33892cd3c..92cd47413cc 100644 --- a/src/mongo/shell/encrypted_dbclient_base.cpp +++ b/src/mongo/shell/encrypted_dbclient_base.cpp @@ -94,9 +94,6 @@ EncryptedDBClientBase::EncryptedDBClientBase(std::unique_ptr conn, : _conn(std::move(conn)), _encryptionOptions(std::move(encryptionOptions)), _cx(cx) { validateCollection(cx, collection); _collection = JS::Heap(collection); - uassert(31078, - "Cannot use WriteMode Legacy with Field Level Encryption", - shellGlobalParams.writeMode != "legacy"); }; std::string EncryptedDBClientBase::getServerAddress() const { diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js index b195a51b6c6..cf05337eead 100644 --- a/src/mongo/shell/mongo.js +++ b/src/mongo/shell/mongo.js @@ -418,76 +418,11 @@ connect = function(url, user, pass, apiParameters) { return db; }; -Mongo.prototype.hasWriteCommands = function() { - var hasWriteCommands = (this.getMinWireVersion() <= 2 && 2 <= this.getMaxWireVersion()); - return hasWriteCommands; -}; - Mongo.prototype.hasExplainCommand = function() { var hasExplain = (this.getMinWireVersion() <= 3 && 3 <= this.getMaxWireVersion()); return hasExplain; }; -/** - * {String} Returns the current mode set. Will be commands/legacy/compatibility - * - * Sends isMaster to determine if the connection is capable of using bulk write operations, and - * caches the result. - */ - -Mongo.prototype.writeMode = function() { - if ('_writeMode' in this) { - return this._writeMode; - } - - // get default from shell params - if (_writeMode) - this._writeMode = _writeMode(); - - // can't use "commands" mode unless server version is good. - if (this.hasWriteCommands()) { - // good with whatever is already set - } else if (this._writeMode == "commands") { - this._writeMode = "compatibility"; - } - - return this._writeMode; -}; - -/** - * Get the readMode string (either "commands" for find/getMore commands, "legacy" for OP_QUERY find - * and OP_GET_MORE, or "compatibility" for detecting based on wire version). - */ -Mongo.prototype.readMode = function() { - // Get the readMode from the shell params if we don't have one yet. - if (typeof _readMode === "function" && !this.hasOwnProperty("_readMode")) { - this._readMode = _readMode(); - } - - if (this.hasOwnProperty("_readMode") && this._readMode !== "compatibility") { - // We already have determined our read mode. Just return it. - return this._readMode; - } else { - // We're in compatibility mode. Determine whether the server supports the find/getMore - // commands. If it does, use commands mode. If not, degrade to legacy mode. - try { - var hasReadCommands = (this.getMinWireVersion() <= 4 && 4 <= this.getMaxWireVersion()); - if (hasReadCommands) { - this._readMode = "commands"; - } else { - this._readMode = "legacy"; - } - } catch (e) { - // We failed trying to determine whether the remote node supports the find/getMore - // commands. In this case, we keep _readMode as "compatibility" and the shell should - // issue legacy reads. Next time around we will issue another isMaster to try to - // determine the readMode decisively. - } - } - - return this._readMode; -}; - // // 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 ab52798788b..e921f97c310 100644 --- a/src/mongo/shell/replsettest.js +++ b/src/mongo/shell/replsettest.js @@ -2554,10 +2554,6 @@ var ReplSetTest = function(opts) { // to time out since it may take a while to process each batch and a test may have // 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 - // _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"); }; diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp index fb88be3fd6c..6f3e6991930 100644 --- a/src/mongo/shell/shell_options.cpp +++ b/src/mongo/shell/shell_options.cpp @@ -183,38 +183,9 @@ Status storeMongoShellOptions(const moe::Environment& params, if (params.count("files")) { shellGlobalParams.files = params["files"].as>(); } - if (params.count("useLegacyWriteOps")) { - shellGlobalParams.writeMode = "legacy"; - } - if (params.count("writeMode")) { - std::string mode = params["writeMode"].as(); - if (mode != "commands" && mode != "legacy" && mode != "compatibility") { - uasserted(17396, str::stream() << "Unknown writeMode option: " << mode); - } - shellGlobalParams.writeMode = mode; - } - if (params.count("readMode")) { - std::string mode = params["readMode"].as(); - if (mode != "commands" && mode != "compatibility" && mode != "legacy") { - uasserted(17397, - str::stream() << "Unknown readMode option: '" << mode - << "'. Valid modes are: {commands, compatibility, legacy}"); - } - shellGlobalParams.readMode = mode; - } if (params.count("disableImplicitSessions")) { shellGlobalParams.shouldUseImplicitSessions = false; } - if (params.count("rpcProtocols")) { - std::string protos = params["rpcProtocols"].as(); - auto parsedRPCProtos = rpc::parseProtocolSet(protos); - if (!parsedRPCProtos.isOK()) { - uasserted(28653, - str::stream() << "Unknown RPC Protocols: '" << protos - << "'. Valid values are {none, opQueryOnly, opMsgOnly, all}"); - } - shellGlobalParams.rpcProtocols = parsedRPCProtos.getValue(); - } /* This is a bit confusing, here are the rules: * diff --git a/src/mongo/shell/shell_options.h b/src/mongo/shell/shell_options.h index 5cb04176aec..190ff831e47 100644 --- a/src/mongo/shell/shell_options.h +++ b/src/mongo/shell/shell_options.h @@ -73,10 +73,7 @@ struct ShellGlobalParams { bool apiDeprecationErrors; bool autoKillOp = false; - bool useWriteCommandsDefault = true; - std::string writeMode = "commands"; - std::string readMode = "commands"; bool shouldRetryWrites = false; bool shouldUseImplicitSessions = true; diff --git a/src/mongo/shell/shell_options.idl b/src/mongo/shell/shell_options.idl index 965c5da660f..fe7c9d9121b 100644 --- a/src/mongo/shell/shell_options.idl +++ b/src/mongo/shell/shell_options.idl @@ -135,19 +135,6 @@ configs: cpp_varname: shellGlobalParams.autoKillOp hidden: true - "useLegacyWriteOps": - description: "use legacy write ops instead of write commands" - arg_vartype: Switch - hidden: true - "writeMode": - description: "mode to determine how writes are done: commands, compatibility, legacy" - arg_vartype: String - hidden: true - "readMode": - description: "mode to determine how .find() querues are done: commands, compatibility, legacy" - arg_vartype: String - hidden: true - "retryWrites": description: "automatically retry write operations upon transient network errors" arg_vartype: Switch @@ -155,10 +142,6 @@ configs: "disableImplicitSessions": description: "do not automatically create and use implicit sessions" arg_vartype: Switch - "rpcProtocols": - description: " none, opQueryOnly, opMsgOnly, all" - arg_vartype: String - hidden: true "jsHeapLimitMB": description: "set the js scope's heap size limit" arg_vartype: Int diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp index c6e0126b4ff..c0d256c5d21 100644 --- a/src/mongo/shell/shell_utils.cpp +++ b/src/mongo/shell/shell_utils.cpp @@ -424,18 +424,6 @@ BSONObj replMonitorStats(const BSONObj& a, void* data) { return result.obj()[name].Obj().getOwned(); } -BSONObj useWriteCommandsDefault(const BSONObj& a, void* data) { - return BSON("" << shellGlobalParams.useWriteCommandsDefault); -} - -BSONObj writeMode(const BSONObj&, void*) { - return BSON("" << shellGlobalParams.writeMode); -} - -BSONObj readMode(const BSONObj&, void*) { - return BSON("" << shellGlobalParams.readMode); -} - BSONObj shouldRetryWrites(const BSONObj&, void* data) { return BSON("" << shellGlobalParams.shouldRetryWrites); } @@ -496,9 +484,6 @@ void initializeEnterpriseScope(Scope& scope) { void initScope(Scope& scope) { // Need to define this method before JSFiles::utils is executed. - scope.injectNative("_useWriteCommandsDefault", useWriteCommandsDefault); - scope.injectNative("_writeMode", writeMode); - scope.injectNative("_readMode", readMode); scope.injectNative("_shouldRetryWrites", shouldRetryWrites); scope.injectNative("_shouldUseImplicitSessions", shouldUseImplicitSessions); scope.injectNative("_apiParameters", apiParameters); diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index 300152be1ee..48146288e65 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -601,30 +601,6 @@ helloStatePrompt = function(helloReply) { return state + '> '; }; -if (typeof _useWriteCommandsDefault === "undefined") { - // We ensure the _useWriteCommandsDefault() function is always defined, in case the JavaScript - // engine is being used from someplace other than the mongo shell (e.g. map-reduce). - _useWriteCommandsDefault = function _useWriteCommandsDefault() { - return false; - }; -} - -if (typeof _writeMode === "undefined") { - // We ensure the _writeMode() function is always defined, in case the JavaScript engine is being - // used from someplace other than the mongo shell (e.g. map-reduce). - _writeMode = function _writeMode() { - return "commands"; - }; -} - -if (typeof _readMode === "undefined") { - // We ensure the _readMode() function is always defined, in case the JavaScript engine is being - // used from someplace other than the mongo shell (e.g. map-reduce). - _readMode = function _readMode() { - return "legacy"; - }; -} - if (typeof _shouldRetryWrites === 'undefined') { // We ensure the _shouldRetryWrites() function is always defined, in case the JavaScript engine // is being used from someplace other than the mongo shell (e.g. map-reduce). @@ -645,17 +621,6 @@ if (typeof _shouldUseImplicitSessions === 'undefined') { shellPrintHelper = function(x) { if (typeof (x) == "undefined") { - // Make sure that we have a db var before we use it - // TODO: This implicit calling of GLE can cause subtle, hard to track issues - remove? - if (__callLastError && typeof (db) != "undefined" && db.getMongo && - db.getMongo().writeMode() == "legacy") { - __callLastError = false; - // explicit w:1 so that replset getLastErrorDefaults aren't used here which would be bad - var err = db.getLastError(1); - if (err != null) { - print(err); - } - } return; } -- cgit v1.2.1