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;
mysql_pfs_key_t srv_threads_mutex_key;
mysql_pfs_key_t thread_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;
/* all_innodb_mutexes array contains mutexes that are
......
......@@ -40,7 +40,6 @@ Created 3/26/1996 Heikki Tuuri
#ifdef UNIV_PFS_MUTEX
extern mysql_pfs_key_t trx_sys_mutex_key;
extern mysql_pfs_key_t rw_trx_hash_element_mutex_key;
#endif
/** Checks if a page address is the trx sys header page.
......@@ -335,16 +334,14 @@ trx_t* current_trx();
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()
{
mysql_mutex_destroy(&mutex);
}
~rw_trx_hash_element_t() { mutex.destroy(); }
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
*/
Atomic_counter<trx_id_t> no;
trx_t *trx;
mysql_mutex_t mutex;
srw_mutex mutex;
};
......@@ -526,10 +523,10 @@ class rw_trx_hash_t
static my_bool debug_iterator(rw_trx_hash_element_t *element,
debug_iterator_arg<T> *arg)
{
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (element->trx)
validate_element(element->trx);
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
return arg->action(element, arg->argument);
}
#endif
......@@ -631,7 +628,7 @@ class rw_trx_hash_t
sizeof(trx_id_t)));
if (element)
{
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
lf_hash_search_unpin(pins);
if ((trx= element->trx)) {
DBUG_ASSERT(trx_id == trx->id);
......@@ -652,7 +649,7 @@ class rw_trx_hash_t
trx->reference();
}
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
}
if (!caller_trx)
lf_hash_put_pins(pins);
......@@ -686,9 +683,9 @@ class rw_trx_hash_t
void erase(trx_t *trx)
{
ut_d(validate_element(trx));
mysql_mutex_lock(&trx->rw_trx_hash_element->mutex);
trx->rw_trx_hash_element->trx= 0;
mysql_mutex_unlock(&trx->rw_trx_hash_element->mutex);
trx->rw_trx_hash_element->mutex.wr_lock();
trx->rw_trx_hash_element->trx= nullptr;
trx->rw_trx_hash_element->mutex.wr_unlock();
int res= lf_hash_delete(&hash, get_pins(trx),
reinterpret_cast<const void*>(&trx->id),
sizeof(trx_id_t));
......@@ -722,12 +719,12 @@ class rw_trx_hash_t
May return element with committed transaction. If caller doesn't like to
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)
{
// trx is protected against commit in this branch
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
May miss concurrently inserted transactions.
......@@ -1180,11 +1177,11 @@ class trx_sys_t
{
if (element->id < *id)
{
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
/* We don't care about read-only transactions here. */
if (element->trx && element->trx->rsegs.m_redo.rseg)
*id= element->id;
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
}
return 0;
}
......
......@@ -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*)
{
lock_sys.assert_locked();
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (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*)
if (lock->is_table())
lock_table_queue_validate(lock->un_member.tab_lock.table);
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
return 0;
}
......@@ -5075,7 +5075,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback(
rw_trx_hash_element_t *element,
lock_rec_other_trx_holds_expl_arg *arg)
{
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (element->trx)
{
element->trx->mutex_lock();
......@@ -5091,7 +5091,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback(
ut_ad(!expl_lock || expl_lock->trx == &arg->impl_trx);
element->trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
return 0;
}
......@@ -5835,7 +5835,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element,
const dict_table_t *table)
{
lock_sys.assert_locked();
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (element->trx)
{
element->trx->mutex_lock();
......@@ -5859,7 +5859,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element,
}
element->trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
return 0;
}
#endif /* UNIV_DEBUG */
......
/*****************************************************************************
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
the terms of the GNU General Public License as published by the Free Software
......@@ -631,7 +631,7 @@ struct trx_roll_count_callback_arg
static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element,
trx_roll_count_callback_arg *arg)
{
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (trx_t *trx= element->trx)
{
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,
arg->n_rows+= trx->undo_no;
}
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
return 0;
}
......@@ -678,7 +678,7 @@ void trx_roll_report_progress()
static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element,
std::vector<trx_t*> *trx_list)
{
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (trx_t *trx= element->trx)
{
trx->mutex_lock();
......@@ -686,7 +686,7 @@ static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element,
trx_list->push_back(trx);
trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
return 0;
}
......
/*****************************************************************************
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
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,
trx_recover_for_mysql_callback_arg *arg)
{
DBUG_ASSERT(arg->len > 0);
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (trx_t *trx= element->trx)
{
/*
......@@ -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 */
return false;
}
......@@ -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,
void*)
{
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (trx_t *trx= element->trx)
{
if (trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED))
trx->state= TRX_STATE_PREPARED;
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
return false;
}
......@@ -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)
{
my_bool found= 0;
mysql_mutex_lock(&element->mutex);
element->mutex.wr_lock();
if (trx_t *trx= element->trx)
{
trx->mutex_lock();
......@@ -2026,7 +2026,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element,
}
trx->mutex_unlock();
}
mysql_mutex_unlock(&element->mutex);
element->mutex.wr_unlock();
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