Commit 8074ab57 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-28313: Shrink rw_trx_hash_element_t::mutex

The element mutex is unnecessarily large. The PERFORMANCE_SCHEMA
instrumentation was not even enabled.
parent 0cd2e6c6
...@@ -546,7 +546,6 @@ mysql_pfs_key_t trx_sys_mutex_key; ...@@ -546,7 +546,6 @@ mysql_pfs_key_t trx_sys_mutex_key;
mysql_pfs_key_t srv_threads_mutex_key; mysql_pfs_key_t srv_threads_mutex_key;
mysql_pfs_key_t thread_mutex_key; mysql_pfs_key_t thread_mutex_key;
mysql_pfs_key_t row_drop_list_mutex_key; mysql_pfs_key_t row_drop_list_mutex_key;
mysql_pfs_key_t rw_trx_hash_element_mutex_key;
mysql_pfs_key_t read_view_mutex_key; mysql_pfs_key_t read_view_mutex_key;
/* all_innodb_mutexes array contains mutexes that are /* all_innodb_mutexes array contains mutexes that are
......
...@@ -40,7 +40,6 @@ Created 3/26/1996 Heikki Tuuri ...@@ -40,7 +40,6 @@ Created 3/26/1996 Heikki Tuuri
#ifdef UNIV_PFS_MUTEX #ifdef UNIV_PFS_MUTEX
extern mysql_pfs_key_t trx_sys_mutex_key; extern mysql_pfs_key_t trx_sys_mutex_key;
extern mysql_pfs_key_t rw_trx_hash_element_mutex_key;
#endif #endif
/** Checks if a page address is the trx sys header page. /** Checks if a page address is the trx sys header page.
...@@ -335,16 +334,14 @@ trx_t* current_trx(); ...@@ -335,16 +334,14 @@ trx_t* current_trx();
struct rw_trx_hash_element_t struct rw_trx_hash_element_t
{ {
rw_trx_hash_element_t(): trx(0) rw_trx_hash_element_t()
{ {
mysql_mutex_init(rw_trx_hash_element_mutex_key, &mutex, nullptr); memset(reinterpret_cast<void*>(this), 0, sizeof *this);
mutex.init();
} }
~rw_trx_hash_element_t() ~rw_trx_hash_element_t() { mutex.destroy(); }
{
mysql_mutex_destroy(&mutex);
}
trx_id_t id; /* lf_hash_init() relies on this to be first in the struct */ trx_id_t id; /* lf_hash_init() relies on this to be first in the struct */
...@@ -357,7 +354,7 @@ struct rw_trx_hash_element_t ...@@ -357,7 +354,7 @@ struct rw_trx_hash_element_t
*/ */
Atomic_counter<trx_id_t> no; Atomic_counter<trx_id_t> no;
trx_t *trx; trx_t *trx;
mysql_mutex_t mutex; srw_mutex mutex;
}; };
...@@ -526,10 +523,10 @@ class rw_trx_hash_t ...@@ -526,10 +523,10 @@ class rw_trx_hash_t
static my_bool debug_iterator(rw_trx_hash_element_t *element, static my_bool debug_iterator(rw_trx_hash_element_t *element,
debug_iterator_arg<T> *arg) debug_iterator_arg<T> *arg)
{ {
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (element->trx) if (element->trx)
validate_element(element->trx); validate_element(element->trx);
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return arg->action(element, arg->argument); return arg->action(element, arg->argument);
} }
#endif #endif
...@@ -631,7 +628,7 @@ class rw_trx_hash_t ...@@ -631,7 +628,7 @@ class rw_trx_hash_t
sizeof(trx_id_t))); sizeof(trx_id_t)));
if (element) if (element)
{ {
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
lf_hash_search_unpin(pins); lf_hash_search_unpin(pins);
if ((trx= element->trx)) { if ((trx= element->trx)) {
DBUG_ASSERT(trx_id == trx->id); DBUG_ASSERT(trx_id == trx->id);
...@@ -652,7 +649,7 @@ class rw_trx_hash_t ...@@ -652,7 +649,7 @@ class rw_trx_hash_t
trx->reference(); trx->reference();
} }
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
} }
if (!caller_trx) if (!caller_trx)
lf_hash_put_pins(pins); lf_hash_put_pins(pins);
...@@ -686,9 +683,9 @@ class rw_trx_hash_t ...@@ -686,9 +683,9 @@ class rw_trx_hash_t
void erase(trx_t *trx) void erase(trx_t *trx)
{ {
ut_d(validate_element(trx)); ut_d(validate_element(trx));
mysql_mutex_lock(&trx->rw_trx_hash_element->mutex); trx->rw_trx_hash_element->mutex.wr_lock();
trx->rw_trx_hash_element->trx= 0; trx->rw_trx_hash_element->trx= nullptr;
mysql_mutex_unlock(&trx->rw_trx_hash_element->mutex); trx->rw_trx_hash_element->mutex.wr_unlock();
int res= lf_hash_delete(&hash, get_pins(trx), int res= lf_hash_delete(&hash, get_pins(trx),
reinterpret_cast<const void*>(&trx->id), reinterpret_cast<const void*>(&trx->id),
sizeof(trx_id_t)); sizeof(trx_id_t));
...@@ -722,12 +719,12 @@ class rw_trx_hash_t ...@@ -722,12 +719,12 @@ class rw_trx_hash_t
May return element with committed transaction. If caller doesn't like to May return element with committed transaction. If caller doesn't like to
see committed transactions, it has to skip those under element mutex: see committed transactions, it has to skip those under element mutex:
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (trx_t trx= element->trx) if (trx_t trx= element->trx)
{ {
// trx is protected against commit in this branch // trx is protected against commit in this branch
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
May miss concurrently inserted transactions. May miss concurrently inserted transactions.
...@@ -1180,11 +1177,11 @@ class trx_sys_t ...@@ -1180,11 +1177,11 @@ class trx_sys_t
{ {
if (element->id < *id) if (element->id < *id)
{ {
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
/* We don't care about read-only transactions here. */ /* We don't care about read-only transactions here. */
if (element->trx && element->trx->rsegs.m_redo.rseg) if (element->trx && element->trx->rsegs.m_redo.rseg)
*id= element->id; *id= element->id;
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
} }
return 0; return 0;
} }
......
...@@ -4868,7 +4868,7 @@ static void lock_rec_block_validate(const page_id_t page_id) ...@@ -4868,7 +4868,7 @@ static void lock_rec_block_validate(const page_id_t page_id)
static my_bool lock_validate_table_locks(rw_trx_hash_element_t *element, void*) static my_bool lock_validate_table_locks(rw_trx_hash_element_t *element, void*)
{ {
lock_sys.assert_locked(); lock_sys.assert_locked();
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (element->trx) if (element->trx)
{ {
check_trx_state(element->trx); check_trx_state(element->trx);
...@@ -4878,7 +4878,7 @@ static my_bool lock_validate_table_locks(rw_trx_hash_element_t *element, void*) ...@@ -4878,7 +4878,7 @@ static my_bool lock_validate_table_locks(rw_trx_hash_element_t *element, void*)
if (lock->is_table()) if (lock->is_table())
lock_table_queue_validate(lock->un_member.tab_lock.table); lock_table_queue_validate(lock->un_member.tab_lock.table);
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return 0; return 0;
} }
...@@ -5075,7 +5075,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback( ...@@ -5075,7 +5075,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback(
rw_trx_hash_element_t *element, rw_trx_hash_element_t *element,
lock_rec_other_trx_holds_expl_arg *arg) lock_rec_other_trx_holds_expl_arg *arg)
{ {
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (element->trx) if (element->trx)
{ {
element->trx->mutex_lock(); element->trx->mutex_lock();
...@@ -5091,7 +5091,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback( ...@@ -5091,7 +5091,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback(
ut_ad(!expl_lock || expl_lock->trx == &arg->impl_trx); ut_ad(!expl_lock || expl_lock->trx == &arg->impl_trx);
element->trx->mutex_unlock(); element->trx->mutex_unlock();
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return 0; return 0;
} }
...@@ -5835,7 +5835,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element, ...@@ -5835,7 +5835,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element,
const dict_table_t *table) const dict_table_t *table)
{ {
lock_sys.assert_locked(); lock_sys.assert_locked();
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (element->trx) if (element->trx)
{ {
element->trx->mutex_lock(); element->trx->mutex_lock();
...@@ -5859,7 +5859,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element, ...@@ -5859,7 +5859,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element,
} }
element->trx->mutex_unlock(); element->trx->mutex_unlock();
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return 0; return 0;
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2016, 2021, MariaDB Corporation. Copyright (c) 2016, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -631,7 +631,7 @@ struct trx_roll_count_callback_arg ...@@ -631,7 +631,7 @@ struct trx_roll_count_callback_arg
static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element, static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element,
trx_roll_count_callback_arg *arg) trx_roll_count_callback_arg *arg)
{ {
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (trx_t *trx= element->trx) if (trx_t *trx= element->trx)
{ {
if (trx->is_recovered && trx_state_eq(trx, TRX_STATE_ACTIVE)) if (trx->is_recovered && trx_state_eq(trx, TRX_STATE_ACTIVE))
...@@ -640,7 +640,7 @@ static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element, ...@@ -640,7 +640,7 @@ static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element,
arg->n_rows+= trx->undo_no; arg->n_rows+= trx->undo_no;
} }
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return 0; return 0;
} }
...@@ -678,7 +678,7 @@ void trx_roll_report_progress() ...@@ -678,7 +678,7 @@ void trx_roll_report_progress()
static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element, static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element,
std::vector<trx_t*> *trx_list) std::vector<trx_t*> *trx_list)
{ {
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (trx_t *trx= element->trx) if (trx_t *trx= element->trx)
{ {
trx->mutex_lock(); trx->mutex_lock();
...@@ -686,7 +686,7 @@ static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element, ...@@ -686,7 +686,7 @@ static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element,
trx_list->push_back(trx); trx_list->push_back(trx);
trx->mutex_unlock(); trx->mutex_unlock();
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return 0; return 0;
} }
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2015, 2021, MariaDB Corporation. Copyright (c) 2015, 2022, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -1914,7 +1914,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element, ...@@ -1914,7 +1914,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element,
trx_recover_for_mysql_callback_arg *arg) trx_recover_for_mysql_callback_arg *arg)
{ {
DBUG_ASSERT(arg->len > 0); DBUG_ASSERT(arg->len > 0);
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (trx_t *trx= element->trx) if (trx_t *trx= element->trx)
{ {
/* /*
...@@ -1940,7 +1940,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element, ...@@ -1940,7 +1940,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element,
} }
} }
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
/* Do not terminate upon reaching arg->len; count all transactions */ /* Do not terminate upon reaching arg->len; count all transactions */
return false; return false;
} }
...@@ -1949,13 +1949,13 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element, ...@@ -1949,13 +1949,13 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element,
static my_bool trx_recover_reset_callback(rw_trx_hash_element_t *element, static my_bool trx_recover_reset_callback(rw_trx_hash_element_t *element,
void*) void*)
{ {
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (trx_t *trx= element->trx) if (trx_t *trx= element->trx)
{ {
if (trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)) if (trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED))
trx->state= TRX_STATE_PREPARED; trx->state= TRX_STATE_PREPARED;
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return false; return false;
} }
...@@ -2004,7 +2004,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element, ...@@ -2004,7 +2004,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element,
trx_get_trx_by_xid_callback_arg *arg) trx_get_trx_by_xid_callback_arg *arg)
{ {
my_bool found= 0; my_bool found= 0;
mysql_mutex_lock(&element->mutex); element->mutex.wr_lock();
if (trx_t *trx= element->trx) if (trx_t *trx= element->trx)
{ {
trx->mutex_lock(); trx->mutex_lock();
...@@ -2026,7 +2026,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element, ...@@ -2026,7 +2026,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element,
} }
trx->mutex_unlock(); trx->mutex_unlock();
} }
mysql_mutex_unlock(&element->mutex); element->mutex.wr_unlock();
return found; return found;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment