summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Witten <andrew.witten@mongodb.com>2022-03-21 17:23:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-21 18:57:54 +0000
commite2f27369cdfb8c417b026afb323c810226417206 (patch)
tree2f441d4a92198fcd949c940859f6a3fad617aec6
parentd39e7190321588f593eb2bceb2fbe4208631866f (diff)
downloadmongo-e2f27369cdfb8c417b026afb323c810226417206.tar.gz
SERVER-64642 handle CallbackCanceled error code in batch_write_exec.cpp
-rw-r--r--jstests/sharding/retryable_mongos_write_errors.js9
-rw-r--r--src/mongo/s/write_ops/batch_write_exec.cpp13
2 files changed, 17 insertions, 5 deletions
diff --git a/jstests/sharding/retryable_mongos_write_errors.js b/jstests/sharding/retryable_mongos_write_errors.js
index efa6963f226..bb5d5c54f96 100644
--- a/jstests/sharding/retryable_mongos_write_errors.js
+++ b/jstests/sharding/retryable_mongos_write_errors.js
@@ -1,5 +1,10 @@
/**
* Tests that retryable write errors in MongoS return a top level error message.
+ * Does the following:
+ * 1. Set failpoint hangAfterCollectionInserts so that inserts never complete.
+ * 2. Initiate a batch insert (which won't complete).
+ * 3. Stop the mongos.
+ * 4. Assert that the returned error code is InterruptedAtShutdown (which is retryable).
*/
(function() {
@@ -22,10 +27,8 @@ function insertHandler(host, dbName, collName, testData) {
const conn = new Mongo(host);
const database = conn.getDB(dbName);
// creates an array with 10 documents
- const docs = Array.from(Array(10).keys()).map((i) => ({a: i, b: "retryable"}));
+ const docs = Array.from(Array(10).keys()).map((i) => ({a: i}));
const commandResponse = database.runCommand({insert: collName, documents: docs});
- // assert that retryableInsertRes failed with the HostUnreachableError or
- // InterruptedAtShutdown error code
assert.commandFailedWithCode(commandResponse, ErrorCodes.InterruptedAtShutdown);
jsTest.log("Command Response: " + tojson(commandResponse) + "." + commandResponse.code);
return {ok: 1};
diff --git a/src/mongo/s/write_ops/batch_write_exec.cpp b/src/mongo/s/write_ops/batch_write_exec.cpp
index 9a91c80c50a..ef1ce3f66d7 100644
--- a/src/mongo/s/write_ops/batch_write_exec.cpp
+++ b/src/mongo/s/write_ops/batch_write_exec.cpp
@@ -363,11 +363,20 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
: OID());
} else {
// Error occurred dispatching, note it
- if (ErrorCodes::isShutdownError(responseStatus.code()) &&
+ if ((ErrorCodes::isShutdownError(responseStatus.code()) ||
+ responseStatus.code() == ErrorCodes::CallbackCanceled) &&
globalInShutdownDeprecated()) {
// Throw an error since the mongos itself is shutting down so this should
// be a top level error instead of a write error.
- uassertStatusOK(responseStatus);
+ if (responseStatus.code() == ErrorCodes::CallbackCanceled) {
+ // CallbackCanceled indicates the TaskExecutor got shut down as part of
+ // mongos shutting down. Drivers won't automatically retry on a
+ // CallbackCanceled error so we replace it with an InterruptedAtShutdown
+ // error which drivers do support automatically retrying on.
+ uasserted(ErrorCodes::InterruptedAtShutdown, responseStatus.reason());
+ } else {
+ uassertStatusOK(responseStatus);
+ }
}
const Status status = responseStatus.withContext(