From dec5c321915bfa33fd6b47fefc8b4e461e559ccb Mon Sep 17 00:00:00 2001 From: Allison Easton Date: Mon, 18 May 2026 08:10:15 +0200 Subject: [PATCH] SERVER-126193 Handle ShardNotFound errors with killOp in implicitly_retry_on_shard_transition_errors (#53410) GitOrigin-RevId: 19e06ab65372ffab208286c3a8e8a3040daf66fd --- jstests/core/query/map_reduce/mr_killop.js | 13 ++++++++++++- .../implicitly_retry_on_shard_transition_errors.js | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/jstests/core/query/map_reduce/mr_killop.js b/jstests/core/query/map_reduce/mr_killop.js index 0d633d3e7ad..24f27c67d96 100644 --- a/jstests/core/query/map_reduce/mr_killop.js +++ b/jstests/core/query/map_reduce/mr_killop.js @@ -25,7 +25,18 @@ assert.commandWorked(db.adminCommand({configureFailPoint: "mr_killop_test_fp", m /** @return op code for map reduce op created by spawned shell. */ function getOpCode() { - const inProg = db.currentOp().inprog; + let inProg; + // In add/remove shard suites, we use localOps to get the opId on the mongoS rather than the + // shard. This ensures that we don't end up with an opId for shard local operation on a shard + // that no longer exists. + if (TestData.hasRandomShardsAddedRemoved) { + inProg = db + .getSiblingDB("admin") + .aggregate([{$currentOp: {localOps: true}}]) + .toArray(); + } else { + inProg = db.currentOp().inprog; + } function isMapReduce(op) { if (!op.command) { diff --git a/jstests/libs/override_methods/implicitly_retry_on_shard_transition_errors.js b/jstests/libs/override_methods/implicitly_retry_on_shard_transition_errors.js index 7c2699e5e20..5f976c085ff 100644 --- a/jstests/libs/override_methods/implicitly_retry_on_shard_transition_errors.js +++ b/jstests/libs/override_methods/implicitly_retry_on_shard_transition_errors.js @@ -83,6 +83,15 @@ const kCommandRetryableOnShardNotFoundError = { // will show up again) return command.shardDistribution[0].shard == "config"; }, + "killOp": (command) => { + // if the opId is not in the format "shardid:opid", then we can retry + if (command.op.indexOf(":") == -1) { + return true; + } + // only retryable if the target is the config shard (as eventually it will show up again) + const shardId = command.op.split(":")[0]; + return shardId == "config"; + }, }; function matchesRetryableError(error, retryableError) {