diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2021-02-22 15:50:04 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-23 23:08:48 +0000 |
commit | 14bb3090ba26fe037cf796d406dcf0d23d959f55 (patch) | |
tree | 2fd5769dc457d2de834a04cb9ac37eb4623fcb8c /src/mongo/db/commands/user_management_commands.cpp | |
parent | 6abf5d917e5f5aac880c3201c17bf6749ddd2f55 (diff) | |
download | mongo-14bb3090ba26fe037cf796d406dcf0d23d959f55.tar.gz |
SERVER-54698 Retry UMC transaction on retryable op error
Diffstat (limited to 'src/mongo/db/commands/user_management_commands.cpp')
-rw-r--r-- | src/mongo/db/commands/user_management_commands.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 3336a1787b3..494789becc9 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -1764,6 +1764,11 @@ void CmdUMCTyped<RevokeRolesFromRoleCommand, void>::Invocation::typedRun(Operati */ using TxnOpsCallback = std::function<Status(UMCTransaction&)>; using TxnAuditCallback = std::function<void()>; + +bool shouldRetryTransaction(const Status& status) { + return (status == ErrorCodes::LockTimeout) || (status == ErrorCodes::SnapshotUnavailable); +} + Status retryTransactionOps(OperationContext* opCtx, StringData forCommand, TxnOpsCallback ops, @@ -1787,8 +1792,10 @@ Status retryTransactionOps(OperationContext* opCtx, UMCTransaction txn(opCtx, forCommand); status = ops(txn); if (!status.isOK()) { - // A failure in the setup ops is just a failure, abort without retry. - return status; + if (!shouldRetryTransaction(status)) { + return status; + } + continue; } if (tries == kMaxAttempts) { @@ -1805,8 +1812,7 @@ Status retryTransactionOps(OperationContext* opCtx, // Try to responsibly abort, but accept not being able to. txn.abort().ignore(); - if ((status != ErrorCodes::LockTimeout) && (status != ErrorCodes::SnapshotUnavailable)) { - // Something moved underneath us. Try again. + if (!shouldRetryTransaction(status)) { return status; } } |