From cbaa771d12c55fe99979ac89ecd6d78a58ae7685 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 26 Jul 2022 18:41:37 +1000 Subject: MDEV-29166: reduce locking of innodb trx_sys_t::history_* Acquire and release locks in trx_sys_t::history_* one by one so we reduce the risk of deadlock with a process that acquires a later segement and then aquires and earlier segment. While doing this means that the accuracy of the returned history length could be off by a factor, but by the time we release from these microfunctions, the rseg locks are released, so the history value is out of date by the time the calling function access it already. reasons why not are https://jira.mariadb.org/browse/MDEV-29141?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel Pushing for test purposes only at the momement. --- storage/innobase/trx/trx0sys.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/storage/innobase/trx/trx0sys.cc b/storage/innobase/trx/trx0sys.cc index 2479e5a4cc1..66b535c7188 100644 --- a/storage/innobase/trx/trx0sys.cc +++ b/storage/innobase/trx/trx0sys.cc @@ -196,9 +196,8 @@ size_t trx_sys_t::history_size() { rseg.latch.rd_lock(SRW_LOCK_CALL); size+= rseg.history_size; - } - for (auto &rseg : rseg_array) rseg.latch.rd_unlock(); + } return size; } @@ -207,20 +206,17 @@ bool trx_sys_t::history_exceeds(size_t threshold) ut_ad(is_initialised()); size_t size= 0; bool exceeds= false; - size_t i; - for (i= 0; i < array_elements(rseg_array); i++) + for (auto &rseg : rseg_array) { - rseg_array[i].latch.rd_lock(SRW_LOCK_CALL); - size+= rseg_array[i].history_size; + rseg.latch.rd_lock(SRW_LOCK_CALL); + size+= rseg.history_size; + rseg.latch.rd_unlock(); if (size > threshold) { exceeds= true; - i++; break; } } - while (i) - rseg_array[--i].latch.rd_unlock(); return exceeds; } -- cgit v1.2.1