From 7c524d4414e1608a54a8affbcce35d08c1ceaa59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 8 Apr 2021 13:32:16 +0300 Subject: [PATCH] MDEV-25371 Potential hang in wsrep_is_BF_lock_timeout() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In commit e71e6133535da8d5eab86e504f0b116a03680780 (MDEV-24671), lock_sys.wait_mutex was moved above lock_sys.mutex (which was later replaced with lock_sys.latch) in the latching order. In commit 7cf4419fc4874a31d6242699dadbfe470ce5626c (MDEV-24789), a potential hang was introduced to Galera. The function lock_wait() would hold lock_sys.wait_mutex while invoking wsrep_is_BF_lock_timeout(), which in turn could acquire LockMutexGuard for some diagnostic printout. wsrep_is_BF_lock_timeout(): Do not invoke trx_print_latched() or LockMutexGuard. lock_sys_t::wr_lock(), lock_sys_t::rd_lock(): Assert that the current thread is not holding lock_sys.wait_mutex. Unfortunately, RW-locks are not covered by SAFE_MUTEX. Reviewed by: Jan Lindström --- storage/innobase/include/lock0lock.h | 2 ++ storage/innobase/lock/lock0lock.cc | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h index c3b802f4284..8e38b99c121 100644 --- a/storage/innobase/include/lock0lock.h +++ b/storage/innobase/include/lock0lock.h @@ -703,6 +703,7 @@ public: /** Acquire exclusive lock_sys.latch */ void wr_lock() { + mysql_mutex_assert_not_owner(&wait_mutex); ut_ad(!is_writer()); latch.wr_lock(); ut_ad(!writer.exchange(os_thread_get_curr_id(), @@ -718,6 +719,7 @@ public: /** Acquire shared lock_sys.latch */ void rd_lock() { + mysql_mutex_assert_not_owner(&wait_mutex); ut_ad(!is_writer()); latch.rd_lock(); ut_ad(!writer.load(std::memory_order_relaxed)); diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 7c266eccb3c..756902690c2 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -391,6 +391,7 @@ void lock_sys_t::create(ulint n_cells) /** Acquire exclusive lock_sys.latch */ void lock_sys_t::wr_lock(const char *file, unsigned line) { + mysql_mutex_assert_not_owner(&wait_mutex); latch.wr_lock(file, line); ut_ad(!writer.exchange(os_thread_get_curr_id(), std::memory_order_relaxed)); } @@ -405,6 +406,7 @@ void lock_sys_t::wr_unlock() /** Acquire shared lock_sys.latch */ void lock_sys_t::rd_lock(const char *file, unsigned line) { + mysql_mutex_assert_not_owner(&wait_mutex); latch.rd_lock(file, line); ut_ad(!writer.load(std::memory_order_relaxed)); ut_d(readers.fetch_add(1, std::memory_order_relaxed)); @@ -549,10 +551,6 @@ ATTRIBUTE_NOINLINE static bool wsrep_is_BF_lock_timeout(const trx_t &trx) ib::info() << "WSREP: BF lock wait long for trx:" << ib::hex(trx.id) << " query: " << wsrep_thd_query(trx.mysql_thd); - { - LockMutexGuard g{SRW_LOCK_CALL}; - trx_print_latched(stderr, &trx, 3000); - } srv_print_innodb_monitor= true; srv_print_innodb_lock_monitor= true;