diff options
author | Suganthi Mani <suganthi.mani@mongodb.com> | 2019-08-28 12:58:46 -0400 |
---|---|---|
committer | Suganthi Mani <suganthi.mani@mongodb.com> | 2019-08-28 17:27:43 -0400 |
commit | 8759a090f778608bdad1b0b1b158a7c2aed6bc27 (patch) | |
tree | 08eb4296f4fd995026c6c887f31fae42e764bda3 | |
parent | 490121d145eb5f22ed37c06469093e1f002f9007 (diff) | |
download | mongo-8759a090f778608bdad1b0b1b158a7c2aed6bc27.tar.gz |
SERVER-42398 On primary, abortTransaction and commitTransaction commands should not acquire ticket.
(cherry picked from commit 9dd11ed72971d6d5c00b9208e0200b6895658a87)
-rw-r--r-- | src/mongo/db/concurrency/d_concurrency_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/concurrency/locker.h | 12 | ||||
-rw-r--r-- | src/mongo/db/ftdc/collector.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/session.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/session.h | 4 |
5 files changed, 20 insertions, 9 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp index 191f74c219e..ab5ae795562 100644 --- a/src/mongo/db/concurrency/d_concurrency_test.cpp +++ b/src/mongo/db/concurrency/d_concurrency_test.cpp @@ -1196,7 +1196,7 @@ TEST_F(DConcurrencyTestFixture, NoThrottlingWhenNotAcquiringTickets) { UseGlobalThrottling throttle(opctx1, 1); // Prevent the enforcement of ticket throttling. - opctx1->lockState()->setShouldAcquireTicket(false); + opctx1->lockState()->skipAcquireTicket(); // Both locks should be acquired immediately because there is no throttling. Lock::GlobalRead R1(opctx1, Date_t::now(), Lock::InterruptBehavior::kThrow); diff --git a/src/mongo/db/concurrency/locker.h b/src/mongo/db/concurrency/locker.h index db90b3b6e76..9bd9864794a 100644 --- a/src/mongo/db/concurrency/locker.h +++ b/src/mongo/db/concurrency/locker.h @@ -433,13 +433,15 @@ public: } /** - * If set to false, this opts out of the ticket mechanism. This should be used sparingly - * for special purpose threads, such as FTDC. + * This will opt out of the ticket mechanism. This should be used sparingly for special purpose + * threads, such as FTDC and committing or aborting transactions. */ - void setShouldAcquireTicket(bool newValue) { - invariant(!isLocked() || isNoop()); - _shouldAcquireTicket = newValue; + void skipAcquireTicket() { + // Should not hold or wait for the ticket. + invariant(isNoop() || getClientState() == Locker::ClientState::kInactive); + _shouldAcquireTicket = false; } + bool shouldAcquireTicket() const { return _shouldAcquireTicket; } diff --git a/src/mongo/db/ftdc/collector.cpp b/src/mongo/db/ftdc/collector.cpp index 3f5696f95c8..3984c051083 100644 --- a/src/mongo/db/ftdc/collector.cpp +++ b/src/mongo/db/ftdc/collector.cpp @@ -69,7 +69,7 @@ std::tuple<BSONObj, Date_t> FTDCCollectorCollection::collect(Client* client) { // batches that are taking a long time. auto opCtx = client->makeOperationContext(); ShouldNotConflictWithSecondaryBatchApplicationBlock shouldNotConflictBlock(opCtx->lockState()); - opCtx->lockState()->setShouldAcquireTicket(false); + opCtx->lockState()->skipAcquireTicket(); // Explicitly start future read transactions without a timestamp. opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kNoTimestamp); diff --git a/src/mongo/db/session.cpp b/src/mongo/db/session.cpp index 337bd40baa5..7149b4fd085 100644 --- a/src/mongo/db/session.cpp +++ b/src/mongo/db/session.cpp @@ -779,6 +779,15 @@ void Session::unstashTransactionResources(OperationContext* opCtx, const std::st uassert(ErrorCodes::InvalidOptions, "Only the first command in a transaction may specify a readConcern", readConcernArgs.isEmpty()); + // On primary, 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. + if (opCtx->writesAreReplicated() && + (cmdName == "commitTransaction" || cmdName == "abortTransaction")) { + auto stashLocker = _txnResourceStash->locker(); + stashLocker->skipAcquireTicket(); + } + _txnResourceStash->release(opCtx); _txnResourceStash = boost::none; // Set the starting active time for this transaction. diff --git a/src/mongo/db/session.h b/src/mongo/db/session.h index 6070ddf109b..01d94721537 100644 --- a/src/mongo/db/session.h +++ b/src/mongo/db/session.h @@ -92,9 +92,9 @@ public: TxnResources& operator=(TxnResources&&) = default; /** - * Returns a const pointer to the stashed lock state, or nullptr if no stashed locks exist. + * Returns a pointer to the stashed lock state, or nullptr if no stashed locks exist. */ - const Locker* locker() const { + Locker* locker() const { return _locker.get(); } |