diff options
-rw-r--r-- | src/mongo/db/transaction_participant.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/transaction_participant.h | 24 |
2 files changed, 17 insertions, 15 deletions
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp index 840448371c9..5d9b45eeda0 100644 --- a/src/mongo/db/transaction_participant.cpp +++ b/src/mongo/db/transaction_participant.cpp @@ -916,8 +916,6 @@ void TransactionParticipant::Participant::_releaseTransactionResourcesToOpCtx( tempTxnResourceStash->release(opCtx); releaseOnError.dismiss(); - - invariant(opCtx->lockState()->shouldAcquireTicket() || o().txnState.isPrepared()); } void TransactionParticipant::Participant::unstashTransactionResources(OperationContext* opCtx, @@ -941,10 +939,14 @@ void TransactionParticipant::Participant::unstashTransactionResources(OperationC // Primaries should respect the transaction lock timeout, since it can prevent // the transaction from making progress. maxLockTimeout = MaxLockTimeout::kAllowed; + // commitTransaction and abortTransaction commands can skip ticketing mechanism as they + // don't acquire any new storage resources (except writing to oplog) but they release + // any claimed storage resources. // Prepared transactions should not acquire ticket. Else, it can deadlock with other // non-transactional operations that have exhausted the write tickets and are blocked on // them due to prepare or lock conflict. - if (o().txnState.isPrepared()) { + if (o().txnState.isPrepared() || cmdName == "commitTransaction" || + cmdName == "abortTransaction") { acquireTicket = AcquireTicket::kSkip; } } else { diff --git a/src/mongo/db/transaction_participant.h b/src/mongo/db/transaction_participant.h index 92c5f5e3e13..dc62783d028 100644 --- a/src/mongo/db/transaction_participant.h +++ b/src/mongo/db/transaction_participant.h @@ -789,18 +789,18 @@ public: * - AcquireTicket::kNoSkip will retain the default behavior which is to acquire ticket. * * Below is the expected behavior. - * ---------------------------------------------------------------------------- - * | | | | | - * | | PRIMARY | SECONDARY | STATE TRANSITION | - * | | | | | - * |----------------|----------------------|---------------|------------------| - * | |Unprepared | Prepared | | | - * | | Txn | Txn | | | - * | |----------------------| | | - * |acquireTicket | kNoSkip | kSkip | kNoSkip | kNoSkip | - * |----------------|----------------------|---------------|------------------| - * |maxLockTimeout | kAllowed | kNotAllowed | kNotAllowed | - * ---------------------------------------------------------------------------- + * ----------------------------------------------------------------------------- + * | | | | | + * | | PRIMARY | SECONDARY | STATE TRANSITION | + * | | | | | + * |----------------|-----------------------|---------------|------------------| + * | | Commit/ | Other Txn | | | + * | | Abort Cmd | Cmds | | | + * | |-----------------------| | | + * |acquireTicket | kSkip | kNoSkip | kNoSkip | kNoSkip | + * |----------------|-----------------------|---------------|------------------| + * |maxLockTimeout | kAllowed | kNotAllowed | kNotAllowed | + * ----------------------------------------------------------------------------- */ void _releaseTransactionResourcesToOpCtx(OperationContext* opCtx, MaxLockTimeout maxLockTimeout, |