summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2020-02-10 14:23:37 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-19 02:23:41 +0000
commit48373e410074700117285938ab2b6d9baa6c06a5 (patch)
tree72f46660bcf2925156999c0616595a0f81de33d4 /src
parent2b80ad915ef25d9d5f4044fac0156f261d7f97a4 (diff)
downloadmongo-48373e410074700117285938ab2b6d9baa6c06a5.tar.gz
SERVER-45007 ResourceLock::lock() always requires OperationContext
(cherry picked from commit 25ffb326e1ecd57db0e1c309d0bcf6b8fd2e072c)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/sleep_command.cpp2
-rw-r--r--src/mongo/db/concurrency/d_concurrency.cpp4
-rw-r--r--src/mongo/db/concurrency/d_concurrency.h13
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp4
4 files changed, 13 insertions, 10 deletions
diff --git a/src/mongo/db/commands/sleep_command.cpp b/src/mongo/db/commands/sleep_command.cpp
index 4a6c7a2445e..e51412d5a5b 100644
--- a/src/mongo/db/commands/sleep_command.cpp
+++ b/src/mongo/db/commands/sleep_command.cpp
@@ -94,7 +94,7 @@ public:
void _sleepInPBWM(mongo::OperationContext* opCtx, long long millis) {
Lock::ResourceLock pbwm(opCtx->lockState(), resourceIdParallelBatchWriterMode);
- pbwm.lock(MODE_X);
+ pbwm.lock(nullptr, MODE_X);
opCtx->sleepFor(Milliseconds(millis));
pbwm.unlock();
}
diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp
index 4855b583347..03adab64190 100644
--- a/src/mongo/db/concurrency/d_concurrency.cpp
+++ b/src/mongo/db/concurrency/d_concurrency.cpp
@@ -307,10 +307,6 @@ Lock::ParallelBatchWriterMode::ParallelBatchWriterMode(Locker* lockState)
: _pbwm(lockState, resourceIdParallelBatchWriterMode, MODE_X),
_shouldNotConflictBlock(lockState) {}
-void Lock::ResourceLock::lock(LockMode mode) {
- lock(nullptr, mode);
-}
-
void Lock::ResourceLock::lock(OperationContext* opCtx, LockMode mode) {
invariant(_result == LOCK_INVALID);
_locker->lock(opCtx, _rid, mode);
diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h
index 9b31d35d164..c9e4b630d17 100644
--- a/src/mongo/db/concurrency/d_concurrency.h
+++ b/src/mongo/db/concurrency/d_concurrency.h
@@ -82,7 +82,7 @@ public:
ResourceLock(Locker* locker, ResourceId rid, LockMode mode)
: _rid(rid), _locker(locker), _result(LOCK_INVALID) {
- lock(mode);
+ lock(nullptr, mode);
}
ResourceLock(ResourceLock&& otherLock)
@@ -98,8 +98,15 @@ public:
}
}
- void lock(LockMode mode); // Uninterruptible
- void lock(OperationContext* opCtx, LockMode mode); // Interruptible
+ /**
+ * Acquires lock on this specified resource in the specified mode.
+ *
+ * If 'opCtx' is provided, it will be used to interrupt a LOCK_WAITING state.
+ *
+ * This function may throw an exception if it is interrupted.
+ */
+ void lock(OperationContext* opCtx, LockMode mode);
+
void unlock();
bool isLocked() const {
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index 28fad7bfe35..a8c6553fb03 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -235,7 +235,7 @@ TEST_F(DConcurrencyTestFixture, ResourceMutex) {
state.finish(3);
// Step 4: Try to regain the shared lock // transfers control to t1
- lk.lock(MODE_IS);
+ lk.lock(nullptr, MODE_IS);
// Step 6: CHeck we actually got back the shared lock
ASSERT(lk.isLocked());
@@ -2364,7 +2364,7 @@ TEST_F(DConcurrencyTestFixture, PBWMRespectsMaxTimeMS) {
auto opCtx2 = clientOpCtxPairs[1].second.get();
Lock::ResourceLock pbwm1(opCtx1->lockState(), resourceIdParallelBatchWriterMode);
- pbwm1.lock(MODE_X);
+ pbwm1.lock(nullptr, MODE_X);
opCtx2->setDeadlineAfterNowBy(Seconds{1}, ErrorCodes::ExceededTimeLimit);