summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp23
-rw-r--r--src/mongo/db/concurrency/lock_state.cpp4
-rw-r--r--src/mongo/db/concurrency/locker.h14
3 files changed, 37 insertions, 4 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index e2e881ef866..67b903c51af 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -62,12 +62,13 @@ const int kMinPerfMillis = 30; // min duration for reliable timing
class UseGlobalThrottling {
public:
explicit UseGlobalThrottling(OperationContext* opCtx, int numTickets)
- : _opCtx(opCtx), _holder(1) {
+ : _opCtx(opCtx), _holder(numTickets) {
_opCtx->lockState()->setGlobalThrottling(&_holder, &_holder);
}
- ~UseGlobalThrottling() {
+ ~UseGlobalThrottling() noexcept(false) {
// Reset the global setting as we're about to destroy the ticket holder.
_opCtx->lockState()->setGlobalThrottling(nullptr, nullptr);
+ ASSERT_EQ(_holder.used(), 0);
}
private:
@@ -1008,6 +1009,24 @@ TEST_F(DConcurrencyTestFixture, Throttling) {
ASSERT(!overlongWait);
}
+TEST_F(DConcurrencyTestFixture, NoThrottlingWhenNotAcquiringTickets) {
+ auto clientOpctxPairs = makeKClientsWithLockers<DefaultLockerImpl>(2);
+ auto opctx1 = clientOpctxPairs[0].second.get();
+ auto opctx2 = clientOpctxPairs[1].second.get();
+ // Limit the locker to 1 ticket at a time.
+ UseGlobalThrottling throttle(opctx1, 1);
+
+ // Prevent the enforcement of ticket throttling.
+ opctx1->lockState()->setShouldAcquireTicket(false);
+
+ // Both locks should be acquired immediately because there is no throttling.
+ Lock::GlobalRead R1(opctx1, Date_t::now());
+ ASSERT(R1.isLocked());
+
+ Lock::GlobalRead R2(opctx2, Date_t::now());
+ ASSERT(R2.isLocked());
+}
+
TEST_F(DConcurrencyTestFixture, DBLockTimeout) {
auto clientOpctxPairs = makeKClientsWithLockers<DefaultLockerImpl>(2);
auto opctx1 = clientOpctxPairs[0].second.get();
diff --git a/src/mongo/db/concurrency/lock_state.cpp b/src/mongo/db/concurrency/lock_state.cpp
index 34645189977..4efdb1c49b6 100644
--- a/src/mongo/db/concurrency/lock_state.cpp
+++ b/src/mongo/db/concurrency/lock_state.cpp
@@ -301,7 +301,7 @@ LockResult LockerImpl<IsForMMAPV1>::_lockGlobalBegin(LockMode mode, Date_t deadl
dassert(isLocked() == (_modeForTicket != MODE_NONE));
if (_modeForTicket == MODE_NONE) {
const bool reader = isSharedLockMode(mode);
- auto holder = ticketHolders[mode];
+ auto holder = shouldAcquireTicket() ? ticketHolders[mode] : nullptr;
if (holder) {
_clientState.store(reader ? kQueuedReader : kQueuedWriter);
if (deadline == Date_t::max()) {
@@ -810,7 +810,7 @@ bool LockerImpl<IsForMMAPV1>::_unlockImpl(LockRequestsMap::Iterator* it) {
if (globalLockManager.unlock(it->objAddr())) {
if (it->key() == resourceIdGlobal) {
invariant(_modeForTicket != MODE_NONE);
- auto holder = ticketHolders[_modeForTicket];
+ auto holder = shouldAcquireTicket() ? ticketHolders[_modeForTicket] : nullptr;
_modeForTicket = MODE_NONE;
if (holder) {
holder->release();
diff --git a/src/mongo/db/concurrency/locker.h b/src/mongo/db/concurrency/locker.h
index 3e70d000fe8..ff133800115 100644
--- a/src/mongo/db/concurrency/locker.h
+++ b/src/mongo/db/concurrency/locker.h
@@ -334,11 +334,25 @@ public:
return _shouldConflictWithSecondaryBatchApplication;
}
+ /**
+ * If set to false, this opts out of the ticket mechanism. This should be used sparingly
+ * for special purpose threads, such as FTDC.
+ */
+ void setShouldAcquireTicket(bool newValue) {
+ invariant(!isLocked());
+ _shouldAcquireTicket = newValue;
+ }
+ bool shouldAcquireTicket() const {
+ return _shouldAcquireTicket;
+ }
+
+
protected:
Locker() {}
private:
bool _shouldConflictWithSecondaryBatchApplication = true;
+ bool _shouldAcquireTicket = true;
};
} // namespace mongo