summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorYoonsoo Kim <yoonsoo.kim@mongodb.com>2021-06-28 07:00:07 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-30 23:41:39 +0000
commit0d37de1e3f89c6257f2cd66f9bf530cc80859717 (patch)
tree591d2c96007d9e7eb04a1ad06086ad804fadc477 /src/mongo/shell
parentd635f733ad873fd469cf3e35e27452c45f1597c9 (diff)
downloadmongo-0d37de1e3f89c6257f2cd66f9bf530cc80859717.tar.gz
SERVER-58103 Remove test cases which test legacy op behaviors
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/bulk_api.js115
-rw-r--r--src/mongo/shell/mongo.js50
-rw-r--r--src/mongo/shell/query.js75
-rw-r--r--src/mongo/shell/replsettest.js47
-rw-r--r--src/mongo/shell/servers.js11
-rw-r--r--src/mongo/shell/session.js7
6 files changed, 43 insertions, 262 deletions
diff --git a/src/mongo/shell/bulk_api.js b/src/mongo/shell/bulk_api.js
index 4f19dc952d0..b843b543c3d 100644
--- a/src/mongo/shell/bulk_api.js
+++ b/src/mongo/shell/bulk_api.js
@@ -1047,112 +1047,6 @@ var _bulk_api_module = (function() {
return db.runCommand(cmd);
};
- // Execute the operations, serially
- var executeBatchWithLegacyOps = function(batch) {
- var batchResult = {n: 0, writeErrors: [], upserted: []};
-
- var extractedErr = null;
-
- var totalToExecute = batch.operations.length;
- // Run over all the operations
- for (var i = 0; i < batch.operations.length; i++) {
- if (batchResult.writeErrors.length > 0 && ordered)
- break;
-
- var _legacyOp = new LegacyOp(batch.batchType, batch.operations[i], i);
- executeLegacyOp(_legacyOp);
-
- var result = executeGetLastError(collection.getDB(), {w: 1});
- extractedErr = extractGLEErrors(result);
-
- if (extractedErr.unknownError) {
- throw new WriteCommandError({
- ok: 0.0,
- code: extractedErr.unknownError.code,
- errmsg: extractedErr.unknownError.errmsg
- });
- }
-
- if (extractedErr.writeError != null) {
- // Create the emulated result set
- var errResult = {
- index: _legacyOp.index,
- code: extractedErr.writeError.code,
- errmsg: extractedErr.writeError.errmsg,
- op: batch.operations[_legacyOp.index]
- };
-
- batchResult.writeErrors.push(errResult);
- } else if (_legacyOp.batchType == INSERT) {
- // Inserts don't give us "n" back, so we can only infer
- batchResult.n = batchResult.n + 1;
- }
-
- if (_legacyOp.batchType == UPDATE) {
- // Unfortunately v2.4 GLE does not include the upserted field when
- // the upserted _id is non-OID type. We can detect this by the
- // updatedExisting field + an n of 1
- var upserted = result.upserted !== undefined ||
- (result.updatedExisting === false && result.n == 1);
-
- if (upserted) {
- batchResult.n = batchResult.n + 1;
-
- // If we don't have an upserted value, see if we can pull it from the update
- // or the
- // query
- if (result.upserted === undefined) {
- result.upserted = _legacyOp.operation.u._id;
- if (result.upserted === undefined) {
- result.upserted = _legacyOp.operation.q._id;
- }
- }
-
- batchResult.upserted.push({index: _legacyOp.index, _id: result.upserted});
- } else if (result.n) {
- batchResult.n = batchResult.n + result.n;
- }
- }
-
- if (_legacyOp.batchType == REMOVE && result.n) {
- batchResult.n = batchResult.n + result.n;
- }
- }
-
- var needToEnforceWC = writeConcern != null &&
- bsonWoCompare(writeConcern, {w: 1}) != 0 &&
- bsonWoCompare(writeConcern, {w: 0}) != 0;
-
- extractedErr = null;
- if (needToEnforceWC &&
- (batchResult.writeErrors.length == 0 ||
- (!ordered &&
- // not all errored.
- batchResult.writeErrors.length < batch.operations.length))) {
- var hadError = batchResult.writeErrors.length > 0;
- var lastErrorIndex = batchResult.writeErrors.length - 1;
- var didAllOperationsFail = hadError &&
- batchResult.writeErrors[lastErrorIndex].index == (batch.operations.length - 1);
-
- if (!didAllOperationsFail) {
- result = executeGetLastError(collection.getDB(), writeConcern);
- extractedErr = extractGLEErrors(result);
-
- if (extractedErr.unknownError) {
- // Report as a wc failure
- extractedErr.wcError = extractedErr.unknownError;
- }
- }
- }
-
- if (extractedErr != null && extractedErr.wcError != null) {
- bulkResult.writeConcernErrors.push(extractedErr.wcError);
- }
-
- // Merge the results
- mergeBatchResults(batch, bulkResult, batchResult);
- };
-
//
// Execute the batch
this.execute = function(_writeConcern) {
@@ -1172,17 +1066,10 @@ var _bulk_api_module = (function() {
// Total number of batches to execute
var totalNumberToExecute = batches.length;
- var useWriteCommands = collection.getMongo().useWriteCommands();
-
// Execute all the batches
for (var i = 0; i < batches.length; i++) {
// Execute the batch
- if (collection.getMongo().hasWriteCommands() &&
- collection.getMongo().writeMode() == "commands") {
- executeBatch(batches[i]);
- } else {
- executeBatchWithLegacyOps(batches[i]);
- }
+ executeBatch(batches[i]);
// If we are ordered and have errors and they are
// not all replication errors terminate the operation
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 898e90a3fe2..b195a51b6c6 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -418,18 +418,6 @@ connect = function(url, user, pass, apiParameters) {
return db;
};
-/**
- * deprecated, use writeMode below
- *
- */
-Mongo.prototype.useWriteCommands = function() {
- return (this.writeMode() != "legacy");
-};
-
-Mongo.prototype.forceWriteMode = function(mode) {
- this._writeMode = mode;
-};
-
Mongo.prototype.hasWriteCommands = function() {
var hasWriteCommands = (this.getMinWireVersion() <= 2 && 2 <= this.getMaxWireVersion());
return hasWriteCommands;
@@ -467,28 +455,6 @@ Mongo.prototype.writeMode = function() {
};
/**
- * Returns true if the shell is configured to use find/getMore commands rather than the C++ client.
- *
- * Currently, the C++ client will always use OP_QUERY find and OP_GET_MORE.
- */
-Mongo.prototype.useReadCommands = function() {
- return (this.readMode() === "commands");
-};
-
-/**
- * For testing, forces the shell to use the readMode specified in 'mode'. Must be either "commands"
- * (use the find/getMore commands), "legacy" (use legacy OP_QUERY/OP_GET_MORE wire protocol reads),
- * or "compatibility" (auto-detect mode based on wire version).
- */
-Mongo.prototype.forceReadMode = function(mode) {
- if (mode !== "commands" && mode !== "compatibility" && mode !== "legacy") {
- throw new Error("Mode must be one of {commands, compatibility, legacy}, but got: " + mode);
- }
-
- this._readMode = mode;
-};
-
-/**
* 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).
*/
@@ -522,22 +488,6 @@ 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/query.js b/src/mongo/shell/query.js
index 1dd05947b4d..e5516958452 100644
--- a/src/mongo/shell/query.js
+++ b/src/mongo/shell/query.js
@@ -106,7 +106,7 @@ DBQuery.prototype._exec = function() {
assert.eq(0, this._numReturned);
this._cursorSeen = 0;
- if (this._mongo.useReadCommands() && this._canUseFindCommand()) {
+ if (this._canUseFindCommand()) {
var canAttachReadPref = true;
var findCmd = this._convertToCommand(canAttachReadPref);
var cmdRes = this._db.runReadCommand(findCmd, null, this._options);
@@ -722,26 +722,20 @@ function DBCommandCursor(db, cmdResult, batchSize, maxAwaitTimeMS, txnNumber) {
// If the command result represents a change stream cursor, update our postBatchResumeToken.
this._updatePostBatchResumeToken(cmdResult.cursor);
- if (db.getMongo().useReadCommands()) {
- this._useReadCommands = true;
- this._cursorid = cmdResult.cursor.id;
- this._batchSize = batchSize;
- this._maxAwaitTimeMS = maxAwaitTimeMS;
- this._txnNumber = txnNumber;
-
- this._ns = cmdResult.cursor.ns;
- this._db = db;
- this._collName = this._ns.substr(this._ns.indexOf(".") + 1);
-
- if (cmdResult.cursor.id) {
- // Note that setting this._cursorid to 0 should be accompanied by
- // this._cursorHandle.zeroCursorId().
- this._cursorHandle =
- this._db.getMongo().cursorHandleFromId(cmdResult.cursor.ns, cmdResult.cursor.id);
- }
- } else {
- this._cursor =
- db.getMongo().cursorFromId(cmdResult.cursor.ns, cmdResult.cursor.id, batchSize);
+ this._cursorid = cmdResult.cursor.id;
+ this._batchSize = batchSize;
+ this._maxAwaitTimeMS = maxAwaitTimeMS;
+ this._txnNumber = txnNumber;
+
+ this._ns = cmdResult.cursor.ns;
+ this._db = db;
+ this._collName = this._ns.substr(this._ns.indexOf(".") + 1);
+
+ if (cmdResult.cursor.id) {
+ // Note that setting this._cursorid to 0 should be accompanied by
+ // this._cursorHandle.zeroCursorId().
+ this._cursorHandle =
+ this._db.getMongo().cursorHandleFromId(cmdResult.cursor.ns, cmdResult.cursor.id);
}
}
@@ -751,10 +745,7 @@ DBCommandCursor.prototype = {};
* Returns whether the cursor id is zero.
*/
DBCommandCursor.prototype.isClosed = function() {
- if (this._useReadCommands) {
- return bsonWoCompare({_: this._cursorid}, {_: NumberLong(0)}) === 0;
- }
- return this._cursor.isClosed();
+ return bsonWoCompare({_: this._cursorid}, {_: NumberLong(0)}) === 0;
};
/**
@@ -765,9 +756,7 @@ DBCommandCursor.prototype.isExhausted = function() {
};
DBCommandCursor.prototype.close = function() {
- if (!this._useReadCommands) {
- this._cursor.close();
- } else if (bsonWoCompare({_: this._cursorid}, {_: NumberLong(0)}) !== 0) {
+ if (bsonWoCompare({_: this._cursorid}, {_: NumberLong(0)}) !== 0) {
var killCursorCmd = {
killCursors: this._collName,
cursors: [this._cursorid],
@@ -848,9 +837,7 @@ DBCommandCursor.prototype._runGetMoreCommand = function() {
}
};
-DBCommandCursor.prototype._hasNextUsingCommands = function() {
- assert(this._useReadCommands);
-
+DBCommandCursor.prototype.hasNext = function() {
if (!this._batch.length) {
if (!this._cursorid.compare(NumberLong("0"))) {
return false;
@@ -862,14 +849,6 @@ DBCommandCursor.prototype._hasNextUsingCommands = function() {
return this._batch.length > 0;
};
-DBCommandCursor.prototype.hasNext = function() {
- if (this._useReadCommands) {
- return this._hasNextUsingCommands();
- }
-
- return this._batch.length || this._cursor.hasNext();
-};
-
DBCommandCursor.prototype.next = function() {
if (this._batch.length) {
// Pop the next result off the batch.
@@ -880,30 +859,16 @@ DBCommandCursor.prototype.next = function() {
this._resumeToken = (this._batch.length ? nextDoc._id : this._postBatchResumeToken);
}
return nextDoc;
- } else if (this._useReadCommands) {
+ } else {
// Have to call hasNext() here, as this is where we may issue a getMore in order to retrieve
// the next batch of results.
if (!this.hasNext())
throw Error("error hasNext: false");
return this._batch.pop();
- } else {
- if (!this._cursor.hasNext())
- throw Error("error hasNext: false");
-
- var ret = this._cursor.next();
- if (ret.$err)
- throw _getErrorWithCode(ret, "error: " + tojson(ret));
- return ret;
}
};
DBCommandCursor.prototype.objsLeftInBatch = function() {
- if (this._useReadCommands) {
- return this._batch.length;
- } else if (this._batch.length) {
- return this._batch.length;
- } else {
- return this._cursor.objsLeftInBatch();
- }
+ return this._batch.length;
};
DBCommandCursor.prototype.getId = function() {
return this._cursorid;
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index a6c8f766db8..ab52798788b 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -2112,16 +2112,13 @@ var ReplSetTest = function(opts) {
var secondary = secondariesToCheck[index];
var secondaryName = secondary.host;
- var secondaryConfigVersion =
- asCluster(secondary,
- () => secondary._runWithForcedReadMode(
- "commands",
- () => secondary.getDB("local")['system.replset']
- .find()
- .readConcern("local")
- .limit(1)
- .next()
- .version));
+ var secondaryConfigVersion = asCluster(secondary,
+ () => secondary.getDB("local")['system.replset']
+ .find()
+ .readConcern("local")
+ .limit(1)
+ .next()
+ .version);
if (primaryConfigVersion != secondaryConfigVersion) {
print("ReplSetTest awaitReplication: secondary #" + secondaryCount + ", " +
@@ -2130,14 +2127,12 @@ var ReplSetTest = function(opts) {
if (secondaryConfigVersion > primaryConfigVersion) {
primary = self.getPrimary();
- primaryConfigVersion = primary._runWithForcedReadMode(
- "commands",
- () => primary.getDB("local")['system.replset']
- .find()
- .readConcern("local")
- .limit(1)
- .next()
- .version);
+ primaryConfigVersion = primary.getDB("local")['system.replset']
+ .find()
+ .readConcern("local")
+ .limit(1)
+ .next()
+ .version;
primaryName = primary.host;
print("ReplSetTest awaitReplication: optime for primary, " + primaryName +
@@ -2524,8 +2519,7 @@ var ReplSetTest = function(opts) {
}
try {
- return this.mongo._runWithForcedReadMode("commands",
- () => operation(this.cursor));
+ return 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
@@ -2569,13 +2563,12 @@ var ReplSetTest = function(opts) {
};
this.getFirstDoc = function() {
- return this.mongo._runWithForcedReadMode("commands",
- () => this.getOplogColl()
- .find()
- .sort({$natural: 1})
- .readConcern("local")
- .limit(-1)
- .next());
+ return this.getOplogColl()
+ .find()
+ .sort({$natural: 1})
+ .readConcern("local")
+ .limit(-1)
+ .next();
};
this.getOplogColl = function() {
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index 76665f783e5..923365e1812 100644
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -1568,12 +1568,6 @@ runMongoProgram = function() {
'--authenticationDatabase=admin');
}
- if (progName == 'mongo' && !_useWriteCommandsDefault()) {
- progName = args[0];
- args = args.slice(1);
- args.unshift(progName, '--useLegacyWriteOps');
- }
-
return _runMongoProgram.apply(null, args);
};
@@ -1595,11 +1589,6 @@ startMongoProgramNoConnect = function() {
'--authenticationDatabase=admin');
}
- if (progName == 'mongo' && !_useWriteCommandsDefault()) {
- args = args.slice(1);
- args.unshift(progName, '--useLegacyWriteOps');
- }
-
return _startMongoProgram.apply(null, args);
};
diff --git a/src/mongo/shell/session.js b/src/mongo/shell/session.js
index 8fc0e98f617..44d82762dfb 100644
--- a/src/mongo/shell/session.js
+++ b/src/mongo/shell/session.js
@@ -257,11 +257,8 @@ var {
if (serverSupports(kWireVersionSupportingLogicalSession) &&
// Always attach sessionId from explicit sessions.
(driverSession._isExplicit ||
- // Check that implicit sessions are not disabled. The client must be using read
- // commands because aggregations always use runCommand() to establish cursors but
- // may use OP_GET_MORE (and therefore not have a session id attached) to retrieve
- // subsequent batches.
- (!jsTest.options().disableImplicitSessions && client.useReadCommands()))) {
+ // Check that implicit sessions are not disabled.
+ !jsTest.options().disableImplicitSessions)) {
cmdObj = driverSession._serverSession.injectSessionId(cmdObj);
}