Commit 868c77df authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-14756 - Remove trx_sys_t::rw_trx_list

Replaced UT_LIST_GET_LEN(trx_sys->rw_trx_list) with
trx_sys->rw_trx_hash.size().
Moved freeing of trx objects at shutdown to rw_trx_hash destructor.
Small clean-up in trx_rollback_recovered().
parent d09f1469
......@@ -244,13 +244,6 @@ trx_sys_close(void);
@return whether the creation succeeded */
bool
trx_sys_create_rsegs();
/*****************************************************************//**
Get the number of transaction in the system, independent of their state.
@return count of transactions in trx_sys_t::trx_list */
UNIV_INLINE
ulint
trx_sys_get_n_rw_trx(void);
/*======================*/
/*********************************************************************
Check if there are any active (non-prepared) transactions.
......@@ -506,6 +499,35 @@ class rw_trx_hash_t
}
/**
Destructor callback for lock-free allocator.
This destructor is used at shutdown. It frees remaining transaction
objects.
XA PREPARED transactions may remain if they haven't been committed or
rolled back. ACTIVE transactions may remain if startup was interrupted or
server is running in read-only mode or for certain srv_force_recovery
levels.
*/
static void rw_trx_hash_shutdown_destructor(uchar *arg)
{
rw_trx_hash_element_t *element=
reinterpret_cast<rw_trx_hash_element_t*>(arg + LF_HASH_OVERHEAD);
if (trx_t *trx= element->trx)
{
ut_ad(trx_state_eq(trx, TRX_STATE_PREPARED) ||
(trx_state_eq(trx, TRX_STATE_ACTIVE) &&
(!srv_was_started ||
srv_read_only_mode ||
srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO)));
trx_free_prepared(trx);
}
element->~rw_trx_hash_element_t();
}
/**
Initializer callback for lock-free hash.
......@@ -522,6 +544,7 @@ class rw_trx_hash_t
rw_trx_hash_element_t *element,
trx_t *trx)
{
ut_ad(element->trx == 0);
element->trx= trx;
element->id= trx->id;
trx->rw_trx_hash_element= element;
......@@ -562,6 +585,7 @@ class rw_trx_hash_t
void destroy()
{
hash.alloc.destructor= rw_trx_hash_shutdown_destructor;
lf_hash_destroy(&hash);
}
......
......@@ -293,22 +293,3 @@ trx_sys_get_max_trx_id(void)
return(trx_sys->max_trx_id);
#endif /* UNIV_WORD_SIZE < DATA_TRX_ID_LEN */
}
/*****************************************************************//**
Get the number of transaction in the system, independent of their state.
@return count of transactions in trx_sys_t::rw_trx_list */
UNIV_INLINE
ulint
trx_sys_get_n_rw_trx(void)
/*======================*/
{
ulint n_trx;
trx_sys_mutex_enter();
n_trx = UT_LIST_GET_LEN(trx_sys->rw_trx_list);
trx_sys_mutex_exit();
return(n_trx);
}
......@@ -852,16 +852,6 @@ trx_rollback_recovered(bool all)
ut_a(srv_force_recovery < SRV_FORCE_NO_TRX_UNDO);
if (trx_sys_get_n_rw_trx() == 0) {
return;
}
if (all) {
ib::info() << "Starting in background the rollback"
" of recovered transactions";
}
/* Note: For XA recovered transactions, we rely on MySQL to
do rollback. They will be in TRX_STATE_PREPARED state. If the server
is shutdown and they are still lingering in trx_sys_t::trx_list
......@@ -894,11 +884,6 @@ trx_rollback_recovered(bool all)
trx_sys_mutex_exit();
} while (trx != NULL);
if (all) {
ib::info() << "Rollback of non-prepared transactions"
" completed";
}
}
/*******************************************************************//**
......@@ -919,7 +904,13 @@ DECLARE_THREAD(trx_rollback_all_recovered)(void*)
pfs_register_thread(trx_rollback_clean_thread_key);
#endif /* UNIV_PFS_THREAD */
if (trx_sys->rw_trx_hash.size()) {
ib::info() << "Starting in background the rollback of"
" recovered transactions";
trx_rollback_recovered(true);
ib::info() << "Rollback of non-prepared transactions"
" completed";
}
trx_rollback_is_active = false;
......
......@@ -591,20 +591,7 @@ trx_sys_close(void)
trx_dummy_sess = NULL;
}
/* Only prepared transactions may be left in the system. Free them. */
ut_a(UT_LIST_GET_LEN(trx_sys->rw_trx_list) == trx_sys->n_prepared_trx
|| !srv_was_started
|| srv_read_only_mode
|| srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
for (trx_t* trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list);
trx != NULL;
trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list)) {
trx_free_prepared(trx);
UT_LIST_REMOVE(trx_sys->rw_trx_list, trx);
}
trx_sys->rw_trx_hash.destroy();
/* There can't be any active transactions. */
......@@ -629,7 +616,6 @@ trx_sys_close(void)
trx_sys->rw_trx_ids.~trx_ids_t();
trx_sys->rw_trx_hash.destroy();
ut_free(trx_sys);
trx_sys = NULL;
......@@ -643,12 +629,9 @@ ulint
trx_sys_any_active_transactions(void)
/*=================================*/
{
ulint total_trx = 0;
ulint total_trx = trx_sys->rw_trx_hash.size();
trx_sys_mutex_enter();
total_trx = UT_LIST_GET_LEN(trx_sys->rw_trx_list);
for (trx_t* trx = UT_LIST_GET_FIRST(trx_sys->mysql_trx_list);
trx != NULL;
trx = UT_LIST_GET_NEXT(mysql_trx_list, trx)) {
......
......@@ -645,6 +645,7 @@ trx_free_prepared(
trx_undo_free_prepared(trx);
assert_trx_in_rw_list(trx);
UT_LIST_REMOVE(trx_sys->rw_trx_list, trx);
ut_a(!trx->read_only);
......
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