summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-09-21 13:20:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-21 14:06:27 +0000
commit5272f5854d1954820e859ebbbaf0b030e80dc32c (patch)
tree1403d11c4401e197acb6b17c080f6c6e49398909 /src/mongo
parent45c59ca2dbd0f2d316cc0a3d80ab787eb7e418f3 (diff)
downloadmongo-5272f5854d1954820e859ebbbaf0b030e80dc32c.tar.gz
SERVER-69727 Make ResourceLock acquisitions in the PersistentTaskQueue interruptible
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/concurrency/d_concurrency.h9
-rw-r--r--src/mongo/db/s/persistent_task_queue.h13
2 files changed, 13 insertions, 9 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h
index 2d4b5b6d6a8..11ac6e35b77 100644
--- a/src/mongo/db/concurrency/d_concurrency.h
+++ b/src/mongo/db/concurrency/d_concurrency.h
@@ -144,10 +144,15 @@ public:
ExclusiveLock(Locker* locker, ResourceMutex mutex)
: ResourceLock(locker, mutex.getRid(), MODE_X) {}
- // Lock/unlock overloads to allow ExclusiveLock to be used with with stdx::unique_lock and
- // stdx::condition_variable_any
+ // Lock/unlock overloads to allow ExclusiveLock to be used with condition_variable-like
+ // utilities such as stdx::condition_variable_any and waitForConditionOrInterrupt
void lock() {
+ // The contract of the condition_variable-like utilities is that that the lock is
+ // returned in the locked state so the acquisition below must be guaranteed to always
+ // succeed.
+ invariant(_opCtx);
+ UninterruptibleLockGuard ulg(_opCtx->lockState());
_lock(MODE_X);
}
diff --git a/src/mongo/db/s/persistent_task_queue.h b/src/mongo/db/s/persistent_task_queue.h
index c8d94b4bdf6..2bd70140bc6 100644
--- a/src/mongo/db/s/persistent_task_queue.h
+++ b/src/mongo/db/s/persistent_task_queue.h
@@ -124,7 +124,7 @@ TaskId PersistentTaskQueue<T>::push(OperationContext* opCtx, const T& t) {
BSONObjBuilder builder;
{
- Lock::ExclusiveLock lock(opCtx->lockState(), _mutex);
+ Lock::ExclusiveLock lock(opCtx, _mutex);
uassert(ErrorCodes::Interrupted, "Task queue was closed", !_closed);
@@ -148,7 +148,7 @@ TaskId PersistentTaskQueue<T>::pop(OperationContext* opCtx) {
DBDirectClient client(opCtx);
BSONObjBuilder builder;
- Lock::ExclusiveLock lock(opCtx->lockState(), _mutex);
+ Lock::ExclusiveLock lock(opCtx, _mutex);
uassert(ErrorCodes::Interrupted, "Task queue was closed", !_closed);
@@ -170,8 +170,7 @@ TaskId PersistentTaskQueue<T>::pop(OperationContext* opCtx) {
template <typename T>
const typename BlockingTaskQueue<T>::Record& PersistentTaskQueue<T>::peek(OperationContext* opCtx) {
- Lock::ExclusiveLock lock(opCtx->lockState(), _mutex);
-
+ Lock::ExclusiveLock lock(opCtx, _mutex);
opCtx->waitForConditionOrInterrupt(_cv, lock, [this] { return _count > 0 || _closed; });
uassert(ErrorCodes::Interrupted, "Task queue was closed", !_closed);
@@ -184,7 +183,7 @@ const typename BlockingTaskQueue<T>::Record& PersistentTaskQueue<T>::peek(Operat
template <typename T>
void PersistentTaskQueue<T>::close(OperationContext* opCtx) {
- Lock::ExclusiveLock lock(opCtx->lockState(), _mutex);
+ Lock::ExclusiveLock lock(opCtx, _mutex);
_closed = true;
_cv.notify_all();
@@ -192,14 +191,14 @@ void PersistentTaskQueue<T>::close(OperationContext* opCtx) {
template <typename T>
size_t PersistentTaskQueue<T>::size(OperationContext* opCtx) const {
- Lock::ExclusiveLock lock(opCtx->lockState(), _mutex);
+ Lock::ExclusiveLock lock(opCtx, _mutex);
return _count;
}
template <typename T>
bool PersistentTaskQueue<T>::empty(OperationContext* opCtx) const {
- Lock::ExclusiveLock lock(opCtx->lockState(), _mutex);
+ Lock::ExclusiveLock lock(opCtx, _mutex);
return _count == 0;
}