summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2020-05-29 18:51:41 +0400
committerSergey Vojtovich <svoj@mariadb.org>2020-05-30 10:24:11 +0400
commitccdfcedf10610a32ce7d173e2936c29cb10df75c (patch)
treef156e195b597de9682b7f0e9302b7d1207d1c2c3
parent043828bdb321bc9ba3750fc50bba708db0279d1f (diff)
downloadmariadb-git-ccdfcedf10610a32ce7d173e2936c29cb10df75c.tar.gz
MDEV-22693 - InnoDB: get rid of casts for rw_trx_hash iterator
Less error prone, stricter type control.
-rw-r--r--storage/innobase/include/trx0sys.h61
-rw-r--r--storage/innobase/lock/lock0lock.cc12
-rw-r--r--storage/innobase/trx/trx0roll.cc6
-rw-r--r--storage/innobase/trx/trx0trx.cc9
4 files changed, 43 insertions, 45 deletions
diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h
index ea42d80088a..695a077e483 100644
--- a/storage/innobase/include/trx0sys.h
+++ b/storage/innobase/include/trx0sys.h
@@ -385,6 +385,10 @@ class rw_trx_hash_t
LF_HASH hash;
+ template <typename T>
+ using walk_action= my_bool(rw_trx_hash_element_t *element, T *action);
+
+
/**
Constructor callback for lock-free allocator.
@@ -487,18 +491,19 @@ class rw_trx_hash_t
}
- struct eliminate_duplicates_arg
+ template <typename T> struct eliminate_duplicates_arg
{
trx_ids_t ids;
- my_hash_walk_action action;
- void *argument;
- eliminate_duplicates_arg(size_t size, my_hash_walk_action act, void* arg):
+ walk_action<T> *action;
+ T *argument;
+ eliminate_duplicates_arg(size_t size, walk_action<T> *act, T *arg):
action(act), argument(arg) { ids.reserve(size); }
};
+ template <typename T>
static my_bool eliminate_duplicates(rw_trx_hash_element_t *element,
- eliminate_duplicates_arg *arg)
+ eliminate_duplicates_arg<T> *arg)
{
for (trx_ids_t::iterator it= arg->ids.begin(); it != arg->ids.end(); it++)
{
@@ -525,15 +530,16 @@ class rw_trx_hash_t
}
- struct debug_iterator_arg
+ template <typename T> struct debug_iterator_arg
{
- my_hash_walk_action action;
- void *argument;
+ walk_action<T> *action;
+ T *argument;
};
+ template <typename T>
static my_bool debug_iterator(rw_trx_hash_element_t *element,
- debug_iterator_arg *arg)
+ debug_iterator_arg<T> *arg)
{
mutex_enter(&element->mutex);
if (element->trx)
@@ -748,23 +754,28 @@ public:
@retval 1 iteration was interrupted (action returned 1)
*/
- int iterate(trx_t *caller_trx, my_hash_walk_action action, void *argument)
+ template <typename T>
+ int iterate(trx_t *caller_trx, walk_action<T> *action, T *argument= nullptr)
{
LF_PINS *pins= caller_trx ? get_pins(caller_trx) : lf_hash_get_pins(&hash);
ut_a(pins);
#ifdef UNIV_DEBUG
- debug_iterator_arg debug_arg= { action, argument };
- action= reinterpret_cast<my_hash_walk_action>(debug_iterator);
- argument= &debug_arg;
+ debug_iterator_arg<T> debug_arg= { action, argument };
+ action= reinterpret_cast<decltype(action)>(debug_iterator<T>);
+ argument= reinterpret_cast<T*>(&debug_arg);
#endif
- int res= lf_hash_iterate(&hash, pins, action, argument);
+ int res= lf_hash_iterate(&hash, pins,
+ reinterpret_cast<my_hash_walk_action>(action),
+ const_cast<void*>(static_cast<const void*>
+ (argument)));
if (!caller_trx)
lf_hash_put_pins(pins);
return res;
}
- int iterate(my_hash_walk_action action, void *argument)
+ template <typename T>
+ int iterate(walk_action<T> *action, T *argument= nullptr)
{
return iterate(current_trx(), action, argument);
}
@@ -776,16 +787,17 @@ public:
@sa iterate()
*/
- int iterate_no_dups(trx_t *caller_trx, my_hash_walk_action action,
- void *argument)
+ template <typename T>
+ int iterate_no_dups(trx_t *caller_trx, walk_action<T> *action,
+ T *argument= nullptr)
{
- eliminate_duplicates_arg arg(size() + 32, action, argument);
- return iterate(caller_trx, reinterpret_cast<my_hash_walk_action>
- (eliminate_duplicates), &arg);
+ eliminate_duplicates_arg<T> arg(size() + 32, action, argument);
+ return iterate(caller_trx, eliminate_duplicates<T>, &arg);
}
- int iterate_no_dups(my_hash_walk_action action, void *argument)
+ template <typename T>
+ int iterate_no_dups(walk_action<T> *action, T *argument= nullptr)
{
return iterate_no_dups(current_trx(), action, argument);
}
@@ -881,8 +893,7 @@ public:
trx_id_t get_min_trx_id()
{
trx_id_t id= get_max_trx_id();
- rw_trx_hash.iterate(reinterpret_cast<my_hash_walk_action>
- (get_min_trx_id_callback), &id);
+ rw_trx_hash.iterate(get_min_trx_id_callback, &id);
return id;
}
@@ -976,9 +987,7 @@ public:
ids->clear();
ids->reserve(rw_trx_hash.size() + 32);
- rw_trx_hash.iterate(caller_trx,
- reinterpret_cast<my_hash_walk_action>(copy_one_id),
- &arg);
+ rw_trx_hash.iterate(caller_trx, copy_one_id, &arg);
*max_trx_id= arg.m_id;
*min_trx_no= arg.m_no;
diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc
index 82bfdff3917..c24d1f12623 100644
--- a/storage/innobase/lock/lock0lock.cc
+++ b/storage/innobase/lock/lock0lock.cc
@@ -5157,8 +5157,7 @@ lock_validate()
lock_mutex_enter();
/* Validate table locks */
- trx_sys.rw_trx_hash.iterate(reinterpret_cast<my_hash_walk_action>
- (lock_validate_table_locks), 0);
+ trx_sys.rw_trx_hash.iterate(lock_validate_table_locks);
/* Iterate over all the record locks and validate the locks. We
don't want to hog the lock_sys_t::mutex. Release it during the
@@ -5452,9 +5451,7 @@ static void lock_rec_other_trx_holds_expl(trx_t *caller_trx, trx_t *trx,
lock_rec_other_trx_holds_expl_arg arg= { page_rec_get_heap_no(rec), block,
trx };
trx_sys.rw_trx_hash.iterate(caller_trx,
- reinterpret_cast<my_hash_walk_action>
- (lock_rec_other_trx_holds_expl_callback),
- &arg);
+ lock_rec_other_trx_holds_expl_callback, &arg);
lock_mutex_exit();
}
}
@@ -6233,10 +6230,7 @@ lock_table_has_locks(
#ifdef UNIV_DEBUG
if (!has_locks) {
- trx_sys.rw_trx_hash.iterate(
- reinterpret_cast<my_hash_walk_action>
- (lock_table_locks_lookup),
- const_cast<dict_table_t*>(table));
+ trx_sys.rw_trx_hash.iterate(lock_table_locks_lookup, table);
}
#endif /* UNIV_DEBUG */
diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc
index 79d4fa21b9b..3d89bea98e9 100644
--- a/storage/innobase/trx/trx0roll.cc
+++ b/storage/innobase/trx/trx0roll.cc
@@ -717,8 +717,7 @@ void trx_roll_report_progress()
rows they modified. Numbers must be accurate, because only this
thread is allowed to touch recovered transactions. */
trx_sys.rw_trx_hash.iterate_no_dups(
- reinterpret_cast<my_hash_walk_action>
- (trx_roll_count_callback), &arg);
+ trx_roll_count_callback, &arg);
if (arg.n_rows > 0) {
service_manager_extend_timeout(
@@ -776,8 +775,7 @@ void trx_rollback_recovered(bool all)
other thread is allowed to modify or remove these transactions from
rw_trx_hash.
*/
- trx_sys.rw_trx_hash.iterate_no_dups(reinterpret_cast<my_hash_walk_action>
- (trx_rollback_recovered_callback),
+ trx_sys.rw_trx_hash.iterate_no_dups(trx_rollback_recovered_callback,
&trx_list);
while (!trx_list.empty())
diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc
index 85e4ec54cf6..b48fed97872 100644
--- a/storage/innobase/trx/trx0trx.cc
+++ b/storage/innobase/trx/trx0trx.cc
@@ -2135,8 +2135,7 @@ int trx_recover_for_mysql(XID *xid_list, uint len)
ut_ad(len);
/* Fill xid_list with PREPARED transactions. */
- trx_sys.rw_trx_hash.iterate_no_dups(reinterpret_cast<my_hash_walk_action>
- (trx_recover_for_mysql_callback), &arg);
+ trx_sys.rw_trx_hash.iterate_no_dups(trx_recover_for_mysql_callback, &arg);
if (arg.count)
{
ib::info() << arg.count
@@ -2146,8 +2145,7 @@ int trx_recover_for_mysql(XID *xid_list, uint len)
transactions twice, by first calling tc_log->open() and then
ha_recover() directly. */
if (arg.count <= len)
- trx_sys.rw_trx_hash.iterate(reinterpret_cast<my_hash_walk_action>
- (trx_recover_reset_callback), NULL);
+ trx_sys.rw_trx_hash.iterate(trx_recover_reset_callback);
}
return int(std::min(arg.count, len));
}
@@ -2201,8 +2199,7 @@ trx_t* trx_get_trx_by_xid(const XID* xid)
trx_get_trx_by_xid_callback_arg arg= { xid, 0 };
if (xid)
- trx_sys.rw_trx_hash.iterate(reinterpret_cast<my_hash_walk_action>
- (trx_get_trx_by_xid_callback), &arg);
+ trx_sys.rw_trx_hash.iterate(trx_get_trx_by_xid_callback, &arg);
return arg.trx;
}