summaryrefslogtreecommitdiff
path: root/src/mongo/s/client/shard.cpp
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2016-08-26 18:11:44 -0400
committerSpencer T Brody <spencer@mongodb.com>2016-08-29 18:13:12 -0400
commitde66470b9e14717c829e07010759a89437946f5b (patch)
treec4666a897ded5757c88fdc9d66a2e60535239b92 /src/mongo/s/client/shard.cpp
parent973a02dac92d3d192fd5e98011c4c4704356c3e2 (diff)
downloadmongo-de66470b9e14717c829e07010759a89437946f5b.tar.gz
SERVER-25832 Add version of Shard::runCommand that retries indefinitely, and use it for moveChunkr3.3.12
Diffstat (limited to 'src/mongo/s/client/shard.cpp')
-rw-r--r--src/mongo/s/client/shard.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp
index 622c6ea7c50..bc1e791e3db 100644
--- a/src/mongo/s/client/shard.cpp
+++ b/src/mongo/s/client/shard.cpp
@@ -30,6 +30,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/operation_context.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/write_ops/batched_command_request.h"
@@ -106,7 +107,7 @@ StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* txn,
const std::string& dbName,
const BSONObj& cmdObj,
RetryPolicy retryPolicy) {
- MONGO_UNREACHABLE;
+ return runCommand(txn, readPref, dbName, cmdObj, Milliseconds::max(), retryPolicy);
}
StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* txn,
@@ -115,6 +116,25 @@ StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* txn,
const BSONObj& cmdObj,
Milliseconds maxTimeMSOverride,
RetryPolicy retryPolicy) {
+ while (true) {
+ auto interruptStatus = txn->checkForInterruptNoAssert();
+ if (!interruptStatus.isOK()) {
+ return interruptStatus;
+ }
+
+ auto hostWithResponse = _runCommand(txn, readPref, dbName, maxTimeMSOverride, cmdObj);
+ auto swCmdResponse = std::move(hostWithResponse.commandResponse);
+ auto commandStatus = _getEffectiveCommandStatus(swCmdResponse);
+
+ if (isRetriableError(commandStatus.code(), retryPolicy)) {
+ LOG(2) << "Command " << redact(cmdObj)
+ << " failed with retriable error and will be retried"
+ << causedBy(redact(commandStatus));
+ continue;
+ }
+
+ return swCmdResponse;
+ }
MONGO_UNREACHABLE;
}
@@ -136,6 +156,11 @@ StatusWith<Shard::CommandResponse> Shard::runCommandWithFixedRetryAttempts(
Milliseconds maxTimeMSOverride,
RetryPolicy retryPolicy) {
for (int retry = 1; retry <= kOnErrorNumRetries; ++retry) {
+ auto interruptStatus = txn->checkForInterruptNoAssert();
+ if (!interruptStatus.isOK()) {
+ return interruptStatus;
+ }
+
auto hostWithResponse = _runCommand(txn, readPref, dbName, maxTimeMSOverride, cmdObj);
auto swCmdResponse = std::move(hostWithResponse.commandResponse);
auto commandStatus = _getEffectiveCommandStatus(swCmdResponse);