diff options
-rw-r--r-- | SConstruct | 10 | ||||
-rw-r--r-- | etc/evergreen.yml | 12 | ||||
-rw-r--r-- | src/mongo/SConscript | 5 | ||||
-rw-r--r-- | src/mongo/config.h.in | 3 | ||||
-rw-r--r-- | src/mongo/db/SConscript | 3 | ||||
-rw-r--r-- | src/mongo/db/curop.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/curop.h | 6 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/pipeline/process_interface/common_process_interface.cpp | 8 | ||||
-rw-r--r-- | src/mongo/embedded/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/platform/mutex.cpp | 14 | ||||
-rw-r--r-- | src/mongo/platform/mutex.h | 25 | ||||
-rw-r--r-- | src/mongo/platform/mutex_test.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 2 | ||||
-rw-r--r-- | src/mongo/util/SConscript | 57 | ||||
-rw-r--r-- | src/mongo/util/concurrency/spin_lock.h | 6 | ||||
-rw-r--r-- | src/mongo/util/interruptible.h | 2 |
17 files changed, 113 insertions, 51 deletions
diff --git a/SConstruct b/SConstruct index b51e87f1a1e..398f278e2f4 100644 --- a/SConstruct +++ b/SConstruct @@ -320,6 +320,13 @@ add_option('use-sasl-client', nargs=0, ) +add_option('use-diagnostic-latches', + choices=['on', 'off'], + default='on', + help='Enable annotated Mutex types', + type='choice', +) + # Most of the "use-system-*" options follow a simple form. for pack in [ ('abseil-cpp',), @@ -3478,6 +3485,9 @@ def doConfigure(myenv): if posix_monotonic_clock: conf.env.SetConfigHeaderDefine("MONGO_CONFIG_HAVE_POSIX_MONOTONIC_CLOCK") + if get_option('use-diagnostic-latches') == 'off': + conf.env.SetConfigHeaderDefine("MONGO_CONFIG_USE_RAW_LATCHES") + if (conf.CheckCXXHeader( "execinfo.h" ) and conf.CheckDeclaration('backtrace', includes='#include <execinfo.h>') and conf.CheckDeclaration('backtrace_symbols', includes='#include <execinfo.h>') and diff --git a/etc/evergreen.yml b/etc/evergreen.yml index 3e0098819ed..cdf06347acb 100644 --- a/etc/evergreen.yml +++ b/etc/evergreen.yml @@ -12026,6 +12026,18 @@ buildvariants: distros: - ubuntu1604-build +- name: enterprise-ubuntu-no-latch-1604-64-bit + display_name: "~ Enterprise Ubuntu 16.04 (without Diagnostic Latches)" + batchtime: 1440 # 1 day + modules: + - enterprise + expansions: + compile_flags: MONGO_DISTMOD=ubuntu1604 -j$(grep -c ^processor /proc/cpuinfo) --variables-files=etc/scons/mongodbtoolchain_v3_gcc.vars --use-diagnostic-latches=off + tasks: + - name: compile_all_run_unittests_TG + distros: + - ubuntu1604-build + - name: shared-scons-cache-pruning display_name: "Shared SCons Cache Pruning" run_on: diff --git a/src/mongo/SConscript b/src/mongo/SConscript index c57724f3566..f0ef13a95e7 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -310,6 +310,7 @@ config_header_substs = ( ('@mongo_config_usdt_enabled@', 'MONGO_CONFIG_USDT_ENABLED'), ('@mongo_config_usdt_provider@', 'MONGO_CONFIG_USDT_PROVIDER'), ('@mongo_config_use_libunwind@', 'MONGO_CONFIG_USE_LIBUNWIND'), + ('@mongo_config_use_raw_latches@', 'MONGO_CONFIG_USE_RAW_LATCHES'), ('@mongo_config_wiredtiger_enabled@', 'MONGO_CONFIG_WIREDTIGER_ENABLED'), ) @@ -469,7 +470,7 @@ mongod = env.Program( 'util/clock_sources', 'util/elapsed_tracker', 'util/fail_point', - 'util/latch_analyzer', + 'util/latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [], 'util/net/network', 'util/ntservice', 'util/options_parser/options_parser_init', @@ -579,7 +580,7 @@ mongos = env.Program( 'transport/transport_layer_manager', 'util/clock_sources', 'util/fail_point', - 'util/latch_analyzer', + 'util/latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [], 'util/net/ssl_options_server' if get_option('ssl') == 'on' else '', 'util/ntservice', 'util/version_impl', diff --git a/src/mongo/config.h.in b/src/mongo/config.h.in index 54e7a14787d..91e87b5a9b9 100644 --- a/src/mongo/config.h.in +++ b/src/mongo/config.h.in @@ -92,5 +92,8 @@ // Defined if using libunwind. @mongo_config_use_libunwind@ +// Defined if raw latches are enabled +@mongo_config_use_raw_latches@ + // Defined if WiredTiger storage engine is enabled @mongo_config_wiredtiger_enabled@ diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 350e3057526..193a759b5a5 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -2,6 +2,7 @@ Import("env") Import("has_option") +Import("get_option") env = env.Clone() @@ -122,7 +123,7 @@ env.Library( '$BUILD_DIR/mongo/db/query/command_request_response', '$BUILD_DIR/mongo/db/stats/timer_stats', '$BUILD_DIR/mongo/rpc/client_metadata', - '$BUILD_DIR/mongo/util/diagnostic_info', + '$BUILD_DIR/mongo/util/diagnostic_info' if get_option('use-diagnostic-latches') == 'on' else [], '$BUILD_DIR/mongo/util/fail_point', '$BUILD_DIR/mongo/util/net/network', '$BUILD_DIR/mongo/util/progress_meter', diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index 7b12045121b..9824e70a766 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -38,6 +38,7 @@ #include <iomanip> #include "mongo/bson/mutable/document.h" +#include "mongo/config.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" @@ -317,6 +318,7 @@ void CurOp::reportCurrentOpForClient(OperationContext* opCtx, CurOp::get(clientOpCtx)->reportState(clientOpCtx, infoBuilder, truncateOps); } +#ifndef MONGO_CONFIG_USE_RAW_LATCHES if (auto diagnostic = DiagnosticInfo::get(*client)) { BSONObjBuilder waitingForLatchBuilder(infoBuilder->subobjStart("waitingForLatch")); waitingForLatchBuilder.append("timestamp", diagnostic->getTimestamp()); @@ -332,6 +334,7 @@ void CurOp::reportCurrentOpForClient(OperationContext* opCtx, */ } } +#endif } void CurOp::setGenericCursor_inlock(GenericCursor gc) { diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h index 41a5e5da50a..076bc119d75 100644 --- a/src/mongo/db/curop.h +++ b/src/mongo/db/curop.h @@ -30,6 +30,7 @@ #pragma once +#include "mongo/config.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" #include "mongo/db/cursor_id.h" @@ -39,10 +40,13 @@ #include "mongo/logv2/attribute_storage.h" #include "mongo/logv2/log_component.h" #include "mongo/platform/atomic_word.h" -#include "mongo/util/diagnostic_info.h" #include "mongo/util/progress_meter.h" #include "mongo/util/time_support.h" +#ifndef MONGO_CONFIG_USE_RAW_LATCHES +#include "mongo/util/diagnostic_info.h" +#endif + namespace mongo { class Client; diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 011fb782d7d..3559b42b7ea 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -1219,7 +1219,9 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { audit::logShutdown(client); +#ifndef MONGO_CONFIG_USE_RAW_LATCHES LatchAnalyzer::get(serviceContext).dump(); +#endif } int mongoDbMain(int argc, char* argv[], char** envp) { diff --git a/src/mongo/db/pipeline/process_interface/common_process_interface.cpp b/src/mongo/db/pipeline/process_interface/common_process_interface.cpp index 14c48822f13..376fb3c9af7 100644 --- a/src/mongo/db/pipeline/process_interface/common_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/common_process_interface.cpp @@ -34,6 +34,7 @@ #include "mongo/db/pipeline/process_interface/common_process_interface.h" #include "mongo/bson/mutable/document.h" +#include "mongo/config.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/client.h" @@ -45,9 +46,12 @@ #include "mongo/platform/mutex.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/grid.h" -#include "mongo/util/diagnostic_info.h" #include "mongo/util/net/socket_utils.h" +#ifndef MONGO_CONFIG_USE_RAW_LATCHES +#include "mongo/util/diagnostic_info.h" +#endif + namespace mongo { std::vector<BSONObj> CommonProcessInterface::getCurrentOps( @@ -63,7 +67,9 @@ std::vector<BSONObj> CommonProcessInterface::getCurrentOps( std::vector<BSONObj> ops; +#ifndef MONGO_CONFIG_USE_RAW_LATCHES auto blockedOpGuard = DiagnosticInfo::maybeMakeBlockedOpForTest(opCtx->getClient()); +#endif for (ServiceContext::LockedClientsCursor cursor(opCtx->getClient()->getServiceContext()); Client* client = cursor.next();) { diff --git a/src/mongo/embedded/SConscript b/src/mongo/embedded/SConscript index 8d943c53720..63ccc64fa10 100644 --- a/src/mongo/embedded/SConscript +++ b/src/mongo/embedded/SConscript @@ -122,7 +122,7 @@ env.Library( '$BUILD_DIR/mongo/db/storage/storage_options', '$BUILD_DIR/mongo/db/wire_version', '$BUILD_DIR/mongo/rpc/client_metadata', - '$BUILD_DIR/mongo/util/latch_analyzer', + '$BUILD_DIR/mongo/util/latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [], '$BUILD_DIR/mongo/util/options_parser/options_parser', '$BUILD_DIR/mongo/util/version_impl', ] diff --git a/src/mongo/platform/mutex.cpp b/src/mongo/platform/mutex.cpp index fd5a5dd212f..8bab12737fc 100644 --- a/src/mongo/platform/mutex.cpp +++ b/src/mongo/platform/mutex.cpp @@ -31,9 +31,9 @@ #include "mongo/base/init.h" -namespace mongo { +namespace mongo::latch_detail { -Mutex::Mutex(std::shared_ptr<latch_detail::Data> data) : _data{std::move(data)} { +Mutex::Mutex(std::shared_ptr<Data> data) : _data{std::move(data)} { invariant(_data); _data->counts().created.fetchAndAdd(1); @@ -80,7 +80,7 @@ StringData Mutex::getName() const { void Mutex::_onContendedLock() noexcept { _data->counts().contended.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -93,7 +93,7 @@ void Mutex::_onContendedLock() noexcept { void Mutex::_onQuickLock() noexcept { _data->counts().acquired.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -106,7 +106,7 @@ void Mutex::_onQuickLock() noexcept { void Mutex::_onSlowLock() noexcept { _data->counts().acquired.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -119,7 +119,7 @@ void Mutex::_onSlowLock() noexcept { void Mutex::_onUnlock() noexcept { _data->counts().released.fetchAndAdd(1); - auto& state = latch_detail::getDiagnosticListenerState(); + auto& state = getDiagnosticListenerState(); if (!state.isFinalized.load()) { return; } @@ -141,4 +141,4 @@ MONGO_INITIALIZER(FinalizeDiagnosticListeners)(InitializerContext* context) { return Status::OK(); } -} // namespace mongo +} // namespace mongo::latch_detail diff --git a/src/mongo/platform/mutex.h b/src/mongo/platform/mutex.h index 833a33560cf..8f09f8a2463 100644 --- a/src/mongo/platform/mutex.h +++ b/src/mongo/platform/mutex.h @@ -37,6 +37,7 @@ #include "mongo/base/error_codes.h" #include "mongo/base/string_data.h" +#include "mongo/config.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/source_location.h" #include "mongo/stdx/mutex.h" @@ -49,10 +50,10 @@ namespace mongo { -class Mutex; - namespace latch_detail { +class Mutex; + using Level = hierarchical_acquisition_detail::Level; static constexpr auto kAnonymousName = "AnonymousLatch"_sd; @@ -290,7 +291,6 @@ auto getOrMakeLatchData(Tag&&, Identity identity, const SourceLocationHolder& so inline auto defaultData() { return getOrMakeLatchData([] {}, Identity(kAnonymousName), MONGO_SOURCE_LOCATION()); } -} // namespace latch_detail /** * Latch is an abstract base class that implements the Lockable concept @@ -334,8 +334,8 @@ public: bool try_lock() override; StringData getName() const override; - Mutex() : Mutex(latch_detail::defaultData()) {} - explicit Mutex(std::shared_ptr<latch_detail::Data> data); + Mutex() : Mutex(defaultData()) {} + explicit Mutex(std::shared_ptr<Data> data); ~Mutex(); @@ -345,11 +345,20 @@ private: void _onSlowLock() noexcept; void _onUnlock() noexcept; - const std::shared_ptr<latch_detail::Data> _data; + const std::shared_ptr<Data> _data; stdx::mutex _mutex; // NOLINT bool _isLocked = false; }; +} // namespace latch_detail + +#ifndef MONGO_CONFIG_USE_RAW_LATCHES +using Latch = latch_detail::Latch; +using Mutex = latch_detail::Mutex; +#else +using Latch = stdx::mutex; // NOLINT +using Mutex = stdx::mutex; // NOLINT +#endif } // namespace mongo @@ -363,4 +372,8 @@ private: /** * Construct a mongo::Mutex using the result of MONGO_GET_LATCH_DATA with all arguments forwarded */ +#ifndef MONGO_CONFIG_USE_RAW_LATCHES #define MONGO_MAKE_LATCH(...) ::mongo::Mutex(MONGO_GET_LATCH_DATA(__VA_ARGS__)); +#else +#define MONGO_MAKE_LATCH(...) ::mongo::stdx::mutex(); // NOLINT +#endif diff --git a/src/mongo/platform/mutex_test.cpp b/src/mongo/platform/mutex_test.cpp index e85f8290466..122dd58b299 100644 --- a/src/mongo/platform/mutex_test.cpp +++ b/src/mongo/platform/mutex_test.cpp @@ -29,6 +29,7 @@ #include "mongo/unittest/unittest.h" +#include "mongo/config.h" #include "mongo/platform/mutex.h" namespace mongo { @@ -41,6 +42,7 @@ TEST(MutexTest, BasicSingleThread) { m.unlock(); } +#ifndef MONGO_CONFIG_USE_RAW_LATCHES namespace { // Since this MONGO_MAKE_LATCH has no arguments, the mutex is anonymous auto gMutex = MONGO_MAKE_LATCH(); @@ -65,4 +67,6 @@ TEST(MutexTest, Macros) { static_assert(std::is_same_v<decltype(gMutex), Mutex>); ASSERT_EQ(gMutex.getName(), latch_detail::kAnonymousName); } +#endif + } // namespace mongo diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 8ce848998a7..34bb98f4d93 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -364,7 +364,9 @@ void cleanupTask(ServiceContext* serviceContext) { audit::logShutdown(Client::getCurrent()); +#ifndef MONGO_CONFIG_USE_RAW_LATCHES LatchAnalyzer::get(serviceContext).dump(); +#endif } Status initializeSharding(OperationContext* opCtx) { diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript index b2793e906c9..50b413173dd 100644 --- a/src/mongo/util/SConscript +++ b/src/mongo/util/SConscript @@ -286,31 +286,32 @@ env.Library( ], ) -env.Library( - target='diagnostic_info', - source= [ - 'diagnostic_info.cpp', - ], - LIBDEPS=[ - '$BUILD_DIR/mongo/base', - "$BUILD_DIR/mongo/db/service_context", - ], -) +if get_option('use-diagnostic-latches') == 'on': + env.Library( + target='diagnostic_info', + source= [ + 'diagnostic_info.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + "$BUILD_DIR/mongo/db/service_context", + ], + ) -env.Library( - target='latch_analyzer', - source= [ - 'latch_analyzer.cpp', - ], - LIBDEPS=[ - '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/commands/test_commands_enabled', - '$BUILD_DIR/mongo/db/service_context', - ], - LIBDEPS_PRIVATE=[ - '$BUILD_DIR/mongo/db/commands/server_status', - ], -) + env.Library( + target='latch_analyzer', + source= [ + 'latch_analyzer.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/db/commands/test_commands_enabled', + '$BUILD_DIR/mongo/db/service_context', + ], + LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/commands/server_status', + ], + ) env.Benchmark( target='clock_source_bm', @@ -554,7 +555,7 @@ icuEnv.CppUnitTest( 'container_size_helper_test.cpp', 'decimal_counter_test.cpp', 'decorable_test.cpp', - 'diagnostic_info_test.cpp', + 'diagnostic_info_test.cpp' if get_option('use-diagnostic-latches') == 'on' else [], 'dns_name_test.cpp', 'dns_query_test.cpp', 'duration_test.cpp', @@ -574,7 +575,7 @@ icuEnv.CppUnitTest( 'invalidating_lru_cache_test.cpp', 'interruptible_test.cpp', 'itoa_test.cpp', - 'latch_analyzer_test.cpp', + 'latch_analyzer_test.cpp' if get_option('use-diagnostic-latches') == 'on' else [], 'lockable_adapter_test.cpp', 'log_with_sampling_test.cpp', 'lru_cache_test.cpp', @@ -611,11 +612,11 @@ icuEnv.CppUnitTest( 'clock_source_mock', 'clock_sources', 'concurrency/thread_pool', - 'diagnostic_info', + 'diagnostic_info' if get_option('use-diagnostic-latches') == 'on' else [], 'dns_query', 'fail_point', 'icu', - 'latch_analyzer', + 'latch_analyzer' if get_option('use-diagnostic-latches') == 'on' else [], 'md5', 'periodic_runner_impl', 'processinfo', diff --git a/src/mongo/util/concurrency/spin_lock.h b/src/mongo/util/concurrency/spin_lock.h index 380ad9f7c4e..30e88488654 100644 --- a/src/mongo/util/concurrency/spin_lock.h +++ b/src/mongo/util/concurrency/spin_lock.h @@ -42,7 +42,7 @@ namespace mongo { #if defined(_WIN32) -class SpinLock : public Latch { +class SpinLock : public latch_detail::Latch { SpinLock(const SpinLock&) = delete; SpinLock& operator=(const SpinLock&) = delete; @@ -74,7 +74,7 @@ private: #else #if MONGO_CONFIG_DEBUG_BUILD -class SpinLock : public Latch { +class SpinLock : public latch_detail::Latch { SpinLock(const SpinLock&) = delete; SpinLock& operator=(const SpinLock&) = delete; @@ -99,7 +99,7 @@ private: #else -class SpinLock : public Latch { +class SpinLock : public latch_detail::Latch { SpinLock(const SpinLock&) = delete; SpinLock& operator=(const SpinLock&) = delete; diff --git a/src/mongo/util/interruptible.h b/src/mongo/util/interruptible.h index 14236877b8b..92c48cc0a8a 100644 --- a/src/mongo/util/interruptible.h +++ b/src/mongo/util/interruptible.h @@ -323,7 +323,7 @@ public: * Get the name for a Latch */ TEMPLATE(typename LatchT) - REQUIRES(std::is_base_of_v<Latch, LatchT>) // + REQUIRES(std::is_base_of_v<latch_detail::Latch, LatchT>) // static StringData getLatchName(const stdx::unique_lock<LatchT>& lk) { return lk.mutex()->getName(); } |