diff options
author | Ben Caimano <ben.caimano@mongodb.com> | 2019-09-09 18:45:01 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-09 18:45:01 +0000 |
commit | 0f16c5fc452d16c5a92e43e9fdd96f3822f05271 (patch) | |
tree | 890ff8a80ae78d7831452aedb30feb9e76be1567 /src/mongo/s | |
parent | f4e387fa1b7e369ce067650bdda9c8676683b929 (diff) | |
download | mongo-0f16c5fc452d16c5a92e43e9fdd96f3822f05271.tar.gz |
SERVER-42908 Add ErrorCodes to retryable errors to match drivers
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/client/shard.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/client/shard_remote.cpp | 19 | ||||
-rw-r--r-- | src/mongo/s/query/establish_cursors.cpp | 8 | ||||
-rw-r--r-- | src/mongo/s/transaction_router.cpp | 11 |
4 files changed, 19 insertions, 25 deletions
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp index e2c751529e2..d2b007a501a 100644 --- a/src/mongo/s/client/shard.cpp +++ b/src/mongo/s/client/shard.cpp @@ -93,10 +93,8 @@ Status Shard::CommandResponse::processBatchWriteResponse( const Milliseconds Shard::kDefaultConfigCommandTimeout = Seconds{30}; bool Shard::shouldErrorBePropagated(ErrorCodes::Error code) { - return std::find(RemoteCommandRetryScheduler::kAllRetriableErrors.begin(), - RemoteCommandRetryScheduler::kAllRetriableErrors.end(), - code) == RemoteCommandRetryScheduler::kAllRetriableErrors.end() && - code != ErrorCodes::NetworkInterfaceExceededTimeLimit; + return !ErrorCodes::isRetriableError(code) && + (code != ErrorCodes::NetworkInterfaceExceededTimeLimit); } Shard::Shard(const ShardId& id) : _id(id) {} diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp index 7d306e998f9..25f2e1959c0 100644 --- a/src/mongo/s/client/shard_remote.cpp +++ b/src/mongo/s/client/shard_remote.cpp @@ -106,14 +106,21 @@ bool ShardRemote::isRetriableError(ErrorCodes::Error code, RetryPolicy options) return false; } - if (options == RetryPolicy::kNoRetry) { - return false; + switch (options) { + case RetryPolicy::kNoRetry: { + return false; + } break; + + case RetryPolicy::kIdempotent: { + return ErrorCodes::isRetriableError(code); + } break; + + case RetryPolicy::kNotIdempotent: { + return ErrorCodes::isNotMasterError(code); + } break; } - const auto& retriableErrors = options == RetryPolicy::kIdempotent - ? RemoteCommandRetryScheduler::kAllRetriableErrors - : RemoteCommandRetryScheduler::kNotMasterErrors; - return std::find(retriableErrors.begin(), retriableErrors.end(), code) != retriableErrors.end(); + MONGO_UNREACHABLE; } const ConnectionString ShardRemote::getConnString() const { diff --git a/src/mongo/s/query/establish_cursors.cpp b/src/mongo/s/query/establish_cursors.cpp index b97f9026d03..a0ff0f6cb07 100644 --- a/src/mongo/s/query/establish_cursors.cpp +++ b/src/mongo/s/query/establish_cursors.cpp @@ -95,13 +95,9 @@ std::vector<RemoteCursor> establishCursors(OperationContext* opCtx, uassertStatusOK(cursor.getStatus()); } - } catch (const DBException& ex) { + } catch (const ExceptionForCat<ErrorCategory::RetriableError>&) { // Retriable errors are swallowed if 'allowPartialResults' is true. - if (allowPartialResults && - std::find(RemoteCommandRetryScheduler::kAllRetriableErrors.begin(), - RemoteCommandRetryScheduler::kAllRetriableErrors.end(), - ex.code()) != - RemoteCommandRetryScheduler::kAllRetriableErrors.end()) { + if (allowPartialResults) { continue; } throw; // Fail this loop. diff --git a/src/mongo/s/transaction_router.cpp b/src/mongo/s/transaction_router.cpp index 5b791ab0270..81cd77fcab0 100644 --- a/src/mongo/s/transaction_router.cpp +++ b/src/mongo/s/transaction_router.cpp @@ -158,13 +158,6 @@ bool isReadConcernLevelAllowedInTransaction(repl::ReadConcernLevel readConcernLe readConcernLevel == repl::ReadConcernLevel::kLocalReadConcern; } -// Returns if the error code would be considered a retryable error for a retryable write. -bool isRetryableWritesError(ErrorCodes::Error code) { - return std::find(RemoteCommandRetryScheduler::kAllRetriableErrors.begin(), - RemoteCommandRetryScheduler::kAllRetriableErrors.end(), - code) != RemoteCommandRetryScheduler::kAllRetriableErrors.end(); -} - // Returns if a transaction's commit result is unknown based on the given statuses. A result is // considered unknown if it would be given the "UnknownTransactionCommitResult" as defined by the // driver transactions specification or fails with one of the errors for invalid write concern that @@ -176,8 +169,8 @@ bool isRetryableWritesError(ErrorCodes::Error code) { // https://github.com/mongodb/specifications/blob/master/source/transactions/transactions.rst#unknowntransactioncommitresult. bool isCommitResultUnknown(const Status& commitStatus, const Status& commitWCStatus) { if (!commitStatus.isOK()) { - return isRetryableWritesError(commitStatus.code()) || - ErrorCodes::isExceededTimeLimitError(commitStatus.code()) || + return ErrorCodes::isRetriableError(commitStatus) || + ErrorCodes::isExceededTimeLimitError(commitStatus) || commitStatus.code() == ErrorCodes::TransactionTooOld; } |