[SERVER-28039] Add full maxTimeMS support to the explain command Created: 17/Feb/17  Updated: 27/Oct/23  Resolved: 06/Jan/21

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: David Storch Assignee: David Storch
Resolution: Gone away Votes: 1
Labels: PM-265, maxTimeMS
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-46686 Explain does not respect maxTimeMS Closed
Sprint: Query 2021-01-11
Participants:

 Description   

The explain command does not fully support the maxTimeMS option due to the two following issues.

The first is that the explain shell helpers generate an explain command with the maxTimeMS parameter in the wrong location. The shell command

db.c.find().maxTimeMS(100).explain("executionStats");

generates the command:

{ explain: { find: "c", filter: {}, maxTimeMS: 100.0 }, verbosity: "executionStats" }

Instead it should place maxTimeMS as a top-level parameter:

{ explain: { find: "c", filter: {} }, verbosity: "executionStats", maxTimeMS: 100.0 }

The second issue is that mongos strips out the maxTimeMS before forwarding it to the shards. I can reproduce by starting a one-shard cluster and running the following against the mongos:

db.c.drop()
for (var i = 0; i < 10; i++) { db.c.insert({_id: i}); }
db.runCommand({explain: {find: "c", filter: {$where: "sleep(100)"}}, verbosity: "executionStats", maxTimeMS: 1});

When I run this directly against a mongod, it results in ErrorCodes::ExceededTimeLimit. But it does not time out when I run it against a mongos.



 Comments   
Comment by David Storch [ 06/Jan/21 ]

I have confirmed that both issues described here are now fixed. Running an explain with maxTimeMS against mongos using the shell helpers shows that the explain fails due to maxTimeMS expiration:

MongoDB Enterprise mongos> db.c.find({$where: "sleep(100)"}).maxTimeMS(1).explain("executionStats");
uncaught exception: Error: explain failed: {
	"ok" : 0,
	"errmsg" : "Explain command on shard __unknown_name__-rs0 failed :: caused by :: operation exceeded time limit",
	"code" : 50,
	"codeName" : "MaxTimeMSExpired",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1609975325, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1609975325, 1)
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
throwOrReturn@src/mongo/shell/explainable.js:25:19
constructor/this.finish@src/mongo/shell/explain_query.js:176:24
DBQuery.prototype.explain@src/mongo/shell/query.js:534:12
@(shell):1:1

Similarly, running the explain command directly against mongos fails as expected:

MongoDB Enterprise mongos> db.runCommand({
...     explain: {find: "c", filter: {$where: "sleep(100)"}},
...     verbosity: "executionStats",
...     maxTimeMS: 1
... });
{
	"ok" : 0,
	"errmsg" : "Explain command on shard __unknown_name__-rs0 failed :: caused by :: operation exceeded time limit",
	"code" : 50,
	"codeName" : "MaxTimeMSExpired",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1609975375, 3),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1609975307, 12)
}

The first issue was fixed by SERVER-46686 as discussed above. I'm not sure exactly which commit(s) fixed the second issue, so I am resolving this ticket as "Gone Away".

Comment by David Storch [ 08/Dec/20 ]

alex.bevilacqua I do believe that the shell issue is a duplicate of SERVER-46686. We should double-check whether the latter issue regarding propagation of the maxTimeMS from mongos to the shards is now fixed. I suspect it has been fixed by now, but adding to our triage queue so that we can investigate.

Comment by Alex Bevilacqua [ 26/Nov/20 ]

Is this now a duplicate of SERVER-46686?

Generated at Thu Feb 08 04:16:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.