mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Revert "SERVER-46686 Update explain() shell command to propagate "maxTimeMS" arg to top-level"
This reverts commit d7d3a0d782
.
This commit is contained in:
parent
0eebd4bdf5
commit
af62a3eeaf
@ -1,82 +0,0 @@
|
||||
/**
|
||||
* Tests the explain command with the maxTimeMS option.
|
||||
*/
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
const standalone = MongoRunner.runMongod();
|
||||
assert.neq(null, conn, "mongod was unable to start up");
|
||||
|
||||
const dbName = "test";
|
||||
const db = standalone.getDB(dbName);
|
||||
const collName = "explain_max_time_ms";
|
||||
const coll = db.getCollection(collName);
|
||||
|
||||
const destCollName = "explain_max_time_ms_dest";
|
||||
const mapFn = function() {
|
||||
emit(this.i, this.j);
|
||||
};
|
||||
const reduceFn = function(key, values) {
|
||||
return Array.sum(values);
|
||||
};
|
||||
|
||||
coll.drop();
|
||||
assert.commandWorked(db.createCollection(collName));
|
||||
|
||||
assert.commandWorked(coll.insert({i: 1, j: 1}));
|
||||
assert.commandWorked(coll.insert({i: 2, j: 1}));
|
||||
assert.commandWorked(coll.insert({i: 2, j: 2}));
|
||||
|
||||
// Set fail point to make sure operations with "maxTimeMS" set will time out.
|
||||
assert.commandWorked(
|
||||
db.adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "alwaysOn"}));
|
||||
|
||||
for (const verbosity of ["executionStats", "allPlansExecution"]) {
|
||||
// Expect explain to time out if "maxTimeMS" is set on the aggregate command.
|
||||
assert.commandFailedWithCode(assert.throws(function() {
|
||||
coll.explain(verbosity).aggregate(
|
||||
[{$match: {i: 1}}], {maxTimeMS: 1});
|
||||
}),
|
||||
ErrorCodes.MaxTimeMSExpired);
|
||||
// Expect explain to time out if "maxTimeMS" is set on the count command.
|
||||
assert.commandFailedWithCode(assert.throws(function() {
|
||||
coll.explain(verbosity).count({i: 1},
|
||||
{maxTimeMS: 1});
|
||||
}),
|
||||
ErrorCodes.MaxTimeMSExpired);
|
||||
// Expect explain to time out if "maxTimeMS" is set on the distinct command.
|
||||
assert.commandFailedWithCode(assert.throws(function() {
|
||||
coll.explain(verbosity).distinct(
|
||||
"i", {}, {maxTimeMS: 1});
|
||||
}),
|
||||
ErrorCodes.MaxTimeMSExpired);
|
||||
// Expect explain to time out if "maxTimeMS" is set on the find command.
|
||||
assert.commandFailedWithCode(assert.throws(function() {
|
||||
coll.find().maxTimeMS(1).explain(verbosity);
|
||||
}),
|
||||
ErrorCodes.MaxTimeMSExpired);
|
||||
assert.commandFailedWithCode(
|
||||
assert.throws(function() {
|
||||
coll.explain(verbosity).find().maxTimeMS(1).finish();
|
||||
}),
|
||||
ErrorCodes.MaxTimeMSExpired);
|
||||
// Expect explain to time out if "maxTimeMS" is set on the findAndModify command.
|
||||
assert.commandFailedWithCode(assert.throws(function() {
|
||||
coll.explain(verbosity).findAndModify(
|
||||
{update: {$inc: {j: 1}}, maxTimeMS: 1});
|
||||
}),
|
||||
ErrorCodes.MaxTimeMSExpired);
|
||||
// Expect explain to time out if "maxTimeMS" is set on the mapReduce command.
|
||||
assert.commandFailedWithCode(
|
||||
assert.throws(function() {
|
||||
coll.explain(verbosity).mapReduce(
|
||||
mapFn, reduceFn, {out: destCollName, maxTimeMS: 1});
|
||||
}),
|
||||
ErrorCodes.MaxTimeMSExpired);
|
||||
}
|
||||
|
||||
// Disable fail point.
|
||||
assert.commandWorked(db.adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}));
|
||||
|
||||
MongoRunner.stopMongod(standalone);
|
||||
})();
|
@ -151,11 +151,6 @@ var DBExplainQuery = (function() {
|
||||
|
||||
var explainCmd = {explain: innerCmd};
|
||||
explainCmd["verbosity"] = this._verbosity;
|
||||
// If "maxTimeMS" is set on innerCmd, it needs to be propagated to the top-level
|
||||
// of explainCmd so that it has the intended effect.
|
||||
if (innerCmd.hasOwnProperty("maxTimeMS")) {
|
||||
explainCmd.maxTimeMS = innerCmd.maxTimeMS;
|
||||
}
|
||||
|
||||
var explainDb = this._query._db;
|
||||
|
||||
|
@ -35,16 +35,6 @@ var Explainable = (function() {
|
||||
return explainResult;
|
||||
};
|
||||
|
||||
var buildExplainCmd = function(innerCmd, verbosity) {
|
||||
var explainCmd = {"explain": innerCmd, "verbosity": verbosity};
|
||||
// If "maxTimeMS" is set on innerCmd, it needs to be propagated to the top-level
|
||||
// of explainCmd so that it has the intended effect.
|
||||
if (innerCmd.hasOwnProperty("maxTimeMS")) {
|
||||
explainCmd.maxTimeMS = innerCmd.maxTimeMS;
|
||||
}
|
||||
return explainCmd;
|
||||
};
|
||||
|
||||
function constructor(collection, verbosity) {
|
||||
//
|
||||
// Private vars.
|
||||
@ -127,7 +117,7 @@ var Explainable = (function() {
|
||||
|
||||
let aggCmd = Object.extend(
|
||||
{"aggregate": this._collection.getName(), "pipeline": pipeline}, extraOptsCopy);
|
||||
let explainCmd = buildExplainCmd(aggCmd, this._verbosity);
|
||||
let explainCmd = {"explain": aggCmd, "verbosity": this._verbosity};
|
||||
let explainResult = this._collection.runReadCommand(explainCmd);
|
||||
return throwOrReturn(explainResult);
|
||||
}
|
||||
@ -150,7 +140,7 @@ var Explainable = (function() {
|
||||
|
||||
this.findAndModify = function(params) {
|
||||
var famCmd = Object.extend({"findAndModify": this._collection.getName()}, params);
|
||||
var explainCmd = buildExplainCmd(famCmd, this._verbosity);
|
||||
var explainCmd = {"explain": famCmd, "verbosity": this._verbosity};
|
||||
var explainResult = this._collection.runReadCommand(explainCmd);
|
||||
return throwOrReturn(explainResult);
|
||||
};
|
||||
@ -165,11 +155,8 @@ var Explainable = (function() {
|
||||
if (options && options.hasOwnProperty("collation")) {
|
||||
distinctCmd.collation = options.collation;
|
||||
}
|
||||
if (options && options.hasOwnProperty("maxTimeMS")) {
|
||||
distinctCmd.maxTimeMS = options.maxTimeMS;
|
||||
}
|
||||
|
||||
var explainCmd = buildExplainCmd(distinctCmd, this._verbosity);
|
||||
var explainCmd = {explain: distinctCmd, verbosity: this._verbosity};
|
||||
var explainResult = this._collection.runReadCommand(explainCmd);
|
||||
return throwOrReturn(explainResult);
|
||||
};
|
||||
@ -248,7 +235,7 @@ var Explainable = (function() {
|
||||
else
|
||||
Object.extend(mapReduceCmd, optionsObjOrOutString);
|
||||
|
||||
const explainCmd = buildExplainCmd(mapReduceCmd, this._verbosity);
|
||||
const explainCmd = {"explain": mapReduceCmd, "verbosity": this._verbosity};
|
||||
const explainResult = this._collection.runCommand(explainCmd);
|
||||
return throwOrReturn(explainResult);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user