summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency
diff options
context:
space:
mode:
authorLeonardo Menti <leonardo.menti@mongodb.com>2022-09-07 12:22:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-07 13:18:26 +0000
commitcd8f093c066e3a7a236857214eef50c61c8c47a5 (patch)
tree33f0f0eea085892abd1c53be4357435f43e73b02 /src/mongo/db/concurrency
parent30583a2c505c03e4d54bbb14cab170b225c071f2 (diff)
downloadmongo-cd8f093c066e3a7a236857214eef50c61c8c47a5.tar.gz
SERVER-68584 Generalize skipTicketAcquisitionForLock
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp2
-rw-r--r--src/mongo/db/concurrency/lock_state.h36
-rw-r--r--src/mongo/db/concurrency/lock_state_test.cpp10
-rw-r--r--src/mongo/db/concurrency/locker.h17
4 files changed, 32 insertions, 33 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index 22c638c811f..8e11fa7ef62 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -1469,7 +1469,7 @@ TEST_F(DConcurrencyTestFixture, NoThrottlingWhenNotAcquiringTickets) {
auto opctx2 = clientOpctxPairs[1].second.get();
// Prevent the enforcement of ticket throttling.
- opctx1->lockState()->skipAcquireTicket();
+ opctx1->lockState()->setAdmissionPriority(AdmissionContext::Priority::kImmediate);
// 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/lock_state.h b/src/mongo/db/concurrency/lock_state.h
index 392d0f7ef6d..8ff2b0bb5e0 100644
--- a/src/mongo/db/concurrency/lock_state.h
+++ b/src/mongo/db/concurrency/lock_state.h
@@ -420,32 +420,32 @@ public:
};
/**
- * RAII-style class to opt out of the ticket acquisition mechanism when acquiring a global lock.
- *
- * Operations that acquire the global lock but do not use any storage engine resources are eligible
- * to skip ticket acquisition. Otherwise, a ticket acquisition is required to prevent throughput
- * from suffering under high load.
+ * RAII-style class to set the priority for the ticket acquisition mechanism when acquiring a global
+ * lock.
*/
-class SkipTicketAcquisitionForLock {
+class SetTicketAquisitionPriorityForLock {
public:
- SkipTicketAcquisitionForLock(const SkipTicketAcquisitionForLock&) = delete;
- SkipTicketAcquisitionForLock& operator=(const SkipTicketAcquisitionForLock&) = delete;
- explicit SkipTicketAcquisitionForLock(OperationContext* opCtx)
- : _opCtx(opCtx), _shouldAcquireTicket(_opCtx->lockState()->shouldAcquireTicket()) {
- if (_shouldAcquireTicket) {
- _opCtx->lockState()->skipAcquireTicket();
- }
+ SetTicketAquisitionPriorityForLock(const SetTicketAquisitionPriorityForLock&) = delete;
+ SetTicketAquisitionPriorityForLock& operator=(const SetTicketAquisitionPriorityForLock&) =
+ delete;
+ explicit SetTicketAquisitionPriorityForLock(OperationContext* opCtx,
+ AdmissionContext::Priority priority)
+ : _opCtx(opCtx), _originalPriority(opCtx->lockState()->getAcquisitionPriority()) {
+ uassert(ErrorCodes::IllegalOperation,
+ "It is illegal for an operation to demote a high priority to a lower priority "
+ "operation",
+ _originalPriority != AdmissionContext::Priority::kImmediate ||
+ priority == AdmissionContext::Priority::kImmediate);
+ _opCtx->lockState()->setAdmissionPriority(priority);
}
- ~SkipTicketAcquisitionForLock() {
- if (_shouldAcquireTicket) {
- _opCtx->lockState()->setAcquireTicket();
- }
+ ~SetTicketAquisitionPriorityForLock() {
+ _opCtx->lockState()->setAdmissionPriority(_originalPriority);
}
private:
OperationContext* _opCtx;
- const bool _shouldAcquireTicket;
+ AdmissionContext::Priority _originalPriority;
};
/**
diff --git a/src/mongo/db/concurrency/lock_state_test.cpp b/src/mongo/db/concurrency/lock_state_test.cpp
index e5b03683058..d5750316327 100644
--- a/src/mongo/db/concurrency/lock_state_test.cpp
+++ b/src/mongo/db/concurrency/lock_state_test.cpp
@@ -1237,25 +1237,27 @@ TEST_F(LockerImplTest, ConvertLockPendingUnlockAndUnlock) {
locker.unlockGlobal();
}
-TEST_F(LockerImplTest, SkipTicketAcquisitionForLockRAIIType) {
+TEST_F(LockerImplTest, SetTicketAcquisitionForLockRAIIType) {
auto opCtx = makeOperationContext();
// By default, ticket acquisition is required.
ASSERT_TRUE(opCtx->lockState()->shouldAcquireTicket());
{
- SkipTicketAcquisitionForLock skipTicketAcquisition(opCtx.get());
+ SetTicketAquisitionPriorityForLock setTicketAquisition(
+ opCtx.get(), AdmissionContext::Priority::kImmediate);
ASSERT_FALSE(opCtx->lockState()->shouldAcquireTicket());
}
ASSERT_TRUE(opCtx->lockState()->shouldAcquireTicket());
// If ticket acquisitions are disabled on the lock state, the RAII type has no effect.
- opCtx->lockState()->skipAcquireTicket();
+ opCtx->lockState()->setAdmissionPriority(AdmissionContext::Priority::kImmediate);
ASSERT_FALSE(opCtx->lockState()->shouldAcquireTicket());
{
- SkipTicketAcquisitionForLock skipTicketAcquisition(opCtx.get());
+ SetTicketAquisitionPriorityForLock setTicketAquisition(
+ opCtx.get(), AdmissionContext::Priority::kImmediate);
ASSERT_FALSE(opCtx->lockState()->shouldAcquireTicket());
}
diff --git a/src/mongo/db/concurrency/locker.h b/src/mongo/db/concurrency/locker.h
index bd7a80fe19e..d29774e39a8 100644
--- a/src/mongo/db/concurrency/locker.h
+++ b/src/mongo/db/concurrency/locker.h
@@ -510,22 +510,19 @@ public:
}
/**
- * This will opt in or out of the ticket mechanism. This should be used sparingly for special
- * purpose threads, such as FTDC and committing or aborting prepared transactions.
+ * This will set the admission priority for the ticket mechanism.
*/
- void skipAcquireTicket() {
- // Should not hold or wait for the ticket.
+ void setAdmissionPriority(AdmissionContext::Priority priority) {
invariant(isNoop() || getClientState() == Locker::ClientState::kInactive);
- _admCtx.setPriority(AdmissionContext::AcquisitionPriority::kHigh);
+ _admCtx.setPriority(priority);
}
- void setAcquireTicket() {
- // Should hold or wait for the ticket.
- invariant(isNoop() || getClientState() == Locker::ClientState::kInactive);
- _admCtx.setPriority(AdmissionContext::AcquisitionPriority::kNormal);
+
+ AdmissionContext::Priority getAcquisitionPriority() {
+ return _admCtx.getPriority();
}
bool shouldAcquireTicket() const {
- return _admCtx.getPriority() != AdmissionContext::AcquisitionPriority::kHigh;
+ return _admCtx.getPriority() != AdmissionContext::Priority::kImmediate;
}
/**