diff options
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r-- | src/mongo/db/concurrency/SConscript | 25 | ||||
-rw-r--r-- | src/mongo/db/concurrency/d_concurrency.cpp | 23 | ||||
-rw-r--r-- | src/mongo/db/concurrency/d_concurrency.h | 21 | ||||
-rw-r--r-- | src/mongo/db/concurrency/lock_manager.h | 2 | ||||
-rw-r--r-- | src/mongo/db/concurrency/lock_manager_defs.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/concurrency/lock_manager_test_help.h | 2 | ||||
-rw-r--r-- | src/mongo/db/concurrency/lock_state.cpp (renamed from src/mongo/db/concurrency/locker_impl.cpp) | 18 | ||||
-rw-r--r-- | src/mongo/db/concurrency/lock_state.h (renamed from src/mongo/db/concurrency/locker_impl.h) | 10 | ||||
-rw-r--r-- | src/mongo/db/concurrency/lock_state_test.cpp (renamed from src/mongo/db/concurrency/locker_impl_test.cpp) | 0 | ||||
-rw-r--r-- | src/mongo/db/concurrency/locker.cpp | 38 | ||||
-rw-r--r-- | src/mongo/db/concurrency/locker.h | 4 |
11 files changed, 66 insertions, 79 deletions
diff --git a/src/mongo/db/concurrency/SConscript b/src/mongo/db/concurrency/SConscript index 872b28b8047..efd2d335cf2 100644 --- a/src/mongo/db/concurrency/SConscript +++ b/src/mongo/db/concurrency/SConscript @@ -37,29 +37,39 @@ env.Library( ) env.Library( + target='lock_manager_defs', + source=[ + 'lock_manager_defs.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/util/namespace_string_database_name_util', + ], +) + +env.Library( target='lock_manager', source=[ 'd_concurrency.cpp', 'lock_manager.cpp', - 'lock_manager_defs.cpp', + 'lock_state.cpp', 'lock_stats.cpp', - 'locker.cpp', - 'locker_impl.cpp', 'replication_state_transition_lock_guard.cpp', 'resource_catalog.cpp', ], LIBDEPS=[ + '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/storage/concurrency_adjustment_parameters', '$BUILD_DIR/mongo/db/storage/storage_engine_parameters', + '$BUILD_DIR/mongo/util/background_job', '$BUILD_DIR/mongo/util/concurrency/spin_lock', '$BUILD_DIR/mongo/util/concurrency/ticketholder', + '$BUILD_DIR/third_party/shim_boost', + 'lock_manager_defs', ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/concurrency/flow_control_ticketholder', '$BUILD_DIR/mongo/db/server_base', - '$BUILD_DIR/mongo/db/service_context', - '$BUILD_DIR/mongo/util/background_job', - '$BUILD_DIR/mongo/util/namespace_string_database_name_util', ], ) @@ -79,7 +89,6 @@ env.Benchmark( 'd_concurrency_bm.cpp', ], LIBDEPS=[ - '$BUILD_DIR/mongo/db/service_context', 'lock_manager', ], ) @@ -90,8 +99,8 @@ env.CppUnitTest( 'd_concurrency_test.cpp', 'fast_map_noalloc_test.cpp', 'lock_manager_test.cpp', + 'lock_state_test.cpp', 'lock_stats_test.cpp', - 'locker_impl_test.cpp', 'resource_catalog_test.cpp', ], LIBDEPS=[ diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp index 9fe447c15f0..fe7daed7201 100644 --- a/src/mongo/db/concurrency/d_concurrency.cpp +++ b/src/mongo/db/concurrency/d_concurrency.cpp @@ -29,9 +29,11 @@ #include "mongo/db/concurrency/d_concurrency.h" +#include <memory> #include <string> #include <vector> +#include "mongo/db/concurrency/flow_control_ticketholder.h" #include "mongo/db/namespace_string.h" #include "mongo/db/service_context.h" #include "mongo/logv2/log.h" @@ -176,27 +178,6 @@ Lock::GlobalLock::GlobalLock(GlobalLock&& otherLock) otherLock._result = LOCK_INVALID; } -Lock::GlobalLock::~GlobalLock() { - // Preserve the original lock result which will be overridden by unlock(). - auto lockResult = _result; - auto* locker = _opCtx->lockState(); - - if (isLocked()) { - // Abandon our snapshot if destruction of the GlobalLock object results in actually - // unlocking the global lock. Recursive locking and the two-phase locking protocol may - // prevent lock release. - const bool willReleaseLock = _isOutermostLock && !locker->inAWriteUnitOfWork(); - if (willReleaseLock) { - _opCtx->recoveryUnit()->abandonSnapshot(); - } - _unlock(); - } - - if (!_skipRSTLLock && (lockResult == LOCK_OK || lockResult == LOCK_WAITING)) { - locker->unlock(resourceIdReplicationStateTransitionLock); - } -} - void Lock::GlobalLock::_unlock() { _opCtx->lockState()->unlockGlobal(); _result = LOCK_INVALID; diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h index 9cf4aef7c7e..aacd3b6d724 100644 --- a/src/mongo/db/concurrency/d_concurrency.h +++ b/src/mongo/db/concurrency/d_concurrency.h @@ -29,6 +29,8 @@ #pragma once +#include <climits> // For UINT_MAX + #include "mongo/db/concurrency/locker.h" #include "mongo/db/operation_context.h" #include "mongo/util/timer.h" @@ -244,7 +246,24 @@ public: GlobalLock(GlobalLock&&); - ~GlobalLock(); + ~GlobalLock() { + // Preserve the original lock result which will be overridden by unlock(). + auto lockResult = _result; + if (isLocked()) { + // Abandon our snapshot if destruction of the GlobalLock object results in actually + // unlocking the global lock. Recursive locking and the two-phase locking protocol + // may prevent lock release. + const bool willReleaseLock = _isOutermostLock && + !(_opCtx->lockState() && _opCtx->lockState()->inAWriteUnitOfWork()); + if (willReleaseLock) { + _opCtx->recoveryUnit()->abandonSnapshot(); + } + _unlock(); + } + if (!_skipRSTLLock && (lockResult == LOCK_OK || lockResult == LOCK_WAITING)) { + _opCtx->lockState()->unlock(resourceIdReplicationStateTransitionLock); + } + } bool isLocked() const { return _result == LOCK_OK; diff --git a/src/mongo/db/concurrency/lock_manager.h b/src/mongo/db/concurrency/lock_manager.h index 18a20900332..4b82349432c 100644 --- a/src/mongo/db/concurrency/lock_manager.h +++ b/src/mongo/db/concurrency/lock_manager.h @@ -63,6 +63,8 @@ public: * Retrieves the lock manager instance attached to this ServiceContext. * The lock manager is now a decoration on the service context and this is the accessor that * most callers should prefer outside of startup, lock internals, and debugger scripts. + * Using the ServiceContext and OperationContext versions where possible is preferable to + * getGlobalLockManager(). */ static LockManager* get(ServiceContext* service); static LockManager* get(ServiceContext& service); diff --git a/src/mongo/db/concurrency/lock_manager_defs.cpp b/src/mongo/db/concurrency/lock_manager_defs.cpp index 655340a355d..38f3976c0ea 100644 --- a/src/mongo/db/concurrency/lock_manager_defs.cpp +++ b/src/mongo/db/concurrency/lock_manager_defs.cpp @@ -27,7 +27,7 @@ * it in the license file. */ -#include "mongo/db/concurrency/lock_manager_defs.h" +#include "lock_manager_defs.h" namespace mongo { diff --git a/src/mongo/db/concurrency/lock_manager_test_help.h b/src/mongo/db/concurrency/lock_manager_test_help.h index c7b9212dc03..5eba9d33dbd 100644 --- a/src/mongo/db/concurrency/lock_manager_test_help.h +++ b/src/mongo/db/concurrency/lock_manager_test_help.h @@ -30,7 +30,7 @@ #pragma once #include "mongo/db/concurrency/lock_manager.h" -#include "mongo/db/concurrency/locker_impl.h" +#include "mongo/db/concurrency/lock_state.h" namespace mongo { diff --git a/src/mongo/db/concurrency/locker_impl.cpp b/src/mongo/db/concurrency/lock_state.cpp index a45cb05679d..e53a2e955b7 100644 --- a/src/mongo/db/concurrency/locker_impl.cpp +++ b/src/mongo/db/concurrency/lock_state.cpp @@ -27,12 +27,16 @@ * it in the license file. */ -#include "mongo/db/concurrency/locker_impl.h" + +#include "mongo/platform/basic.h" + +#include "mongo/db/concurrency/lock_state.h" #include <vector> #include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/json.h" +#include "mongo/db/concurrency/flow_control_ticketholder.h" #include "mongo/db/namespace_string.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/flow_control.h" @@ -137,12 +141,6 @@ PartitionedInstanceWideLockStats globalStats; } // namespace -LockManager* getGlobalLockManager() { - auto serviceContext = getGlobalServiceContext(); - invariant(serviceContext); - return LockManager::get(serviceContext); -} - bool LockerImpl::_shouldDelayUnlock(ResourceId resId, LockMode mode) const { switch (resId.getType()) { case RESOURCE_MUTEX: @@ -1230,6 +1228,12 @@ public: // Standalone functions // +LockManager* getGlobalLockManager() { + auto serviceContext = getGlobalServiceContext(); + invariant(serviceContext); + return LockManager::get(serviceContext); +} + void reportGlobalLockingStats(SingleThreadedLockStats* outStats) { globalStats.report(outStats); } diff --git a/src/mongo/db/concurrency/locker_impl.h b/src/mongo/db/concurrency/lock_state.h index 2f83580de83..0d19a10cac8 100644 --- a/src/mongo/db/concurrency/locker_impl.h +++ b/src/mongo/db/concurrency/lock_state.h @@ -436,4 +436,14 @@ public: } }; +/** + * Retrieves the global lock manager instance. + * Legacy global lock manager accessor for internal lock implementation * and debugger scripts + * such as gdb/mongo_lock.py. + * The lock manager is now a decoration on the service context and this accessor is retained for + * startup, lock internals, and debugger scripts. + * Using LockManager::get(ServiceContext*) where possible is preferable. + */ +LockManager* getGlobalLockManager(); + } // namespace mongo diff --git a/src/mongo/db/concurrency/locker_impl_test.cpp b/src/mongo/db/concurrency/lock_state_test.cpp index 6e67f7c31ea..6e67f7c31ea 100644 --- a/src/mongo/db/concurrency/locker_impl_test.cpp +++ b/src/mongo/db/concurrency/lock_state_test.cpp diff --git a/src/mongo/db/concurrency/locker.cpp b/src/mongo/db/concurrency/locker.cpp deleted file mode 100644 index 296ed9f9e63..00000000000 --- a/src/mongo/db/concurrency/locker.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2023-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/db/concurrency/locker.h" - -namespace mongo { - -Locker::Locker() = default; - -Locker::~Locker() = default; - -} // namespace mongo diff --git a/src/mongo/db/concurrency/locker.h b/src/mongo/db/concurrency/locker.h index 26f12adbd0b..59a4c92d9c5 100644 --- a/src/mongo/db/concurrency/locker.h +++ b/src/mongo/db/concurrency/locker.h @@ -57,7 +57,7 @@ class Locker { public: using LockTimeoutCallback = std::function<void()>; - virtual ~Locker(); + virtual ~Locker() {} /** * Returns true if this is an instance of LockerNoop. Because LockerNoop doesn't implement many @@ -570,7 +570,7 @@ public: } protected: - Locker(); + Locker() {} /** * The number of callers that are guarding from lock interruptions. |