summaryrefslogtreecommitdiff
path: root/jstests/libs/override_methods/mongos_manual_intervention_actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/libs/override_methods/mongos_manual_intervention_actions.js')
-rw-r--r--jstests/libs/override_methods/mongos_manual_intervention_actions.js103
1 files changed, 51 insertions, 52 deletions
diff --git a/jstests/libs/override_methods/mongos_manual_intervention_actions.js b/jstests/libs/override_methods/mongos_manual_intervention_actions.js
index 802778b6ec1..fb0a7080585 100644
--- a/jstests/libs/override_methods/mongos_manual_intervention_actions.js
+++ b/jstests/libs/override_methods/mongos_manual_intervention_actions.js
@@ -41,7 +41,7 @@ var ManualInterventionActions = (function() {
", dropping the collection, and retrying the command.");
removeChunks(mongosConn, ns);
- const[dbName, collName] = ns.split(".");
+ const [dbName, collName] = ns.split(".");
assert.commandWorked(
mongosConn.getDB(dbName).runCommand({"drop": collName, writeConcern: {w: "majority"}}));
};
@@ -51,64 +51,63 @@ var ManualInterventionActions = (function() {
(function() {
- const mongoRunCommandOriginal = Mongo.prototype.runCommand;
+const mongoRunCommandOriginal = Mongo.prototype.runCommand;
- Mongo.prototype.runCommand = function runCommand(dbName, cmdObj, options) {
- const cmdName = Object.keys(cmdObj)[0];
- const commandsToRetry =
- new Set(["mapReduce", "mapreduce", "shardCollection", "shardcollection"]);
+Mongo.prototype.runCommand = function runCommand(dbName, cmdObj, options) {
+ const cmdName = Object.keys(cmdObj)[0];
+ const commandsToRetry =
+ new Set(["mapReduce", "mapreduce", "shardCollection", "shardcollection"]);
- if (!commandsToRetry.has(cmdName)) {
- return mongoRunCommandOriginal.apply(this, arguments);
- }
+ if (!commandsToRetry.has(cmdName)) {
+ return mongoRunCommandOriginal.apply(this, arguments);
+ }
+
+ const maxAttempts = 10;
+ let numAttempts = 0;
+ let res;
- const maxAttempts = 10;
- let numAttempts = 0;
- let res;
+ while (numAttempts < maxAttempts) {
+ res = mongoRunCommandOriginal.apply(this, arguments);
+ ++numAttempts;
- while (numAttempts < maxAttempts) {
- res = mongoRunCommandOriginal.apply(this, arguments);
- ++numAttempts;
+ if (res.ok === 1 || res.code !== ErrorCodes.ManualInterventionRequired ||
+ numAttempts === maxAttempts) {
+ break;
+ }
- if (res.ok === 1 || res.code !== ErrorCodes.ManualInterventionRequired ||
- numAttempts === maxAttempts) {
+ print("Manual intervention retry attempt# " + numAttempts +
+ " because of error: " + tojson(res));
+
+ if (cmdName === "shardCollection" || cmdName === "shardcollection") {
+ const ns = cmdObj[cmdName];
+ ManualInterventionActions.removePartiallyWrittenChunks(this, ns, cmdObj, numAttempts);
+ } else if (cmdName === "mapReduce" || cmdName === "mapreduce") {
+ const out = cmdObj.out;
+
+ // The output collection can be specified as a string argument to the mapReduce
+ // command's 'out' option, or nested under 'out.replace', 'out.merge', or
+ // 'out.reduce'.
+ let outCollName;
+ if (typeof out === "string") {
+ outCollName = out;
+ } else if (typeof out === "object") {
+ outCollName = out.replace || out.merge || out.reduce;
+ } else {
+ print("Could not parse the output collection's name from 'out' option in " +
+ tojson(cmdObj) + "; not retrying on ManualInterventionRequired error " +
+ tojson(res));
break;
}
- print("Manual intervention retry attempt# " + numAttempts + " because of error: " +
- tojson(res));
-
- if (cmdName === "shardCollection" || cmdName === "shardcollection") {
- const ns = cmdObj[cmdName];
- ManualInterventionActions.removePartiallyWrittenChunks(
- this, ns, cmdObj, numAttempts);
- } else if (cmdName === "mapReduce" || cmdName === "mapreduce") {
- const out = cmdObj.out;
-
- // The output collection can be specified as a string argument to the mapReduce
- // command's 'out' option, or nested under 'out.replace', 'out.merge', or
- // 'out.reduce'.
- let outCollName;
- if (typeof out === "string") {
- outCollName = out;
- } else if (typeof out === "object") {
- outCollName = out.replace || out.merge || out.reduce;
- } else {
- print("Could not parse the output collection's name from 'out' option in " +
- tojson(cmdObj) + "; not retrying on ManualInterventionRequired error " +
- tojson(res));
- break;
- }
-
- // The output collection's database can optionally be specified under 'out.db',
- // else it defaults to the input collection's database.
- const outDbName = out.db || dbName;
-
- const ns = outDbName + "." + outCollName;
- ManualInterventionActions.removePartiallyWrittenChunksAndDropCollection(
- this, ns, cmdObj, numAttempts);
- }
+ // The output collection's database can optionally be specified under 'out.db',
+ // else it defaults to the input collection's database.
+ const outDbName = out.db || dbName;
+
+ const ns = outDbName + "." + outCollName;
+ ManualInterventionActions.removePartiallyWrittenChunksAndDropCollection(
+ this, ns, cmdObj, numAttempts);
}
- return res;
- };
+ }
+ return res;
+};
})();