From 14bb3090ba26fe037cf796d406dcf0d23d959f55 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Mon, 22 Feb 2021 15:50:04 +0000 Subject: SERVER-54698 Retry UMC transaction on retryable op error --- src/mongo/db/commands/user_management_commands.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/mongo/db/commands/user_management_commands.cpp') 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::Invocation::typedRun(Operati */ using TxnOpsCallback = std::function; using TxnAuditCallback = std::function; + +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; } } -- cgit v1.2.1