Skip to content

Commit 868c77d

Browse files
committed
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().
1 parent d09f146 commit 868c77d

File tree

5 files changed

+41
-61
lines changed

5 files changed

+41
-61
lines changed

storage/innobase/include/trx0sys.h

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,6 @@ trx_sys_close(void);
244244
@return whether the creation succeeded */
245245
bool
246246
trx_sys_create_rsegs();
247-
/*****************************************************************//**
248-
Get the number of transaction in the system, independent of their state.
249-
@return count of transactions in trx_sys_t::trx_list */
250-
UNIV_INLINE
251-
ulint
252-
trx_sys_get_n_rw_trx(void);
253-
/*======================*/
254247

255248
/*********************************************************************
256249
Check if there are any active (non-prepared) transactions.
@@ -506,6 +499,35 @@ class rw_trx_hash_t
506499
}
507500

508501

502+
/**
503+
Destructor callback for lock-free allocator.
504+
505+
This destructor is used at shutdown. It frees remaining transaction
506+
objects.
507+
508+
XA PREPARED transactions may remain if they haven't been committed or
509+
rolled back. ACTIVE transactions may remain if startup was interrupted or
510+
server is running in read-only mode or for certain srv_force_recovery
511+
levels.
512+
*/
513+
514+
static void rw_trx_hash_shutdown_destructor(uchar *arg)
515+
{
516+
rw_trx_hash_element_t *element=
517+
reinterpret_cast<rw_trx_hash_element_t*>(arg + LF_HASH_OVERHEAD);
518+
if (trx_t *trx= element->trx)
519+
{
520+
ut_ad(trx_state_eq(trx, TRX_STATE_PREPARED) ||
521+
(trx_state_eq(trx, TRX_STATE_ACTIVE) &&
522+
(!srv_was_started ||
523+
srv_read_only_mode ||
524+
srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO)));
525+
trx_free_prepared(trx);
526+
}
527+
element->~rw_trx_hash_element_t();
528+
}
529+
530+
509531
/**
510532
Initializer callback for lock-free hash.
511533
@@ -522,6 +544,7 @@ class rw_trx_hash_t
522544
rw_trx_hash_element_t *element,
523545
trx_t *trx)
524546
{
547+
ut_ad(element->trx == 0);
525548
element->trx= trx;
526549
element->id= trx->id;
527550
trx->rw_trx_hash_element= element;
@@ -562,6 +585,7 @@ class rw_trx_hash_t
562585

563586
void destroy()
564587
{
588+
hash.alloc.destructor= rw_trx_hash_shutdown_destructor;
565589
lf_hash_destroy(&hash);
566590
}
567591

storage/innobase/include/trx0sys.ic

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,3 @@ trx_sys_get_max_trx_id(void)
293293
return(trx_sys->max_trx_id);
294294
#endif /* UNIV_WORD_SIZE < DATA_TRX_ID_LEN */
295295
}
296-
297-
/*****************************************************************//**
298-
Get the number of transaction in the system, independent of their state.
299-
@return count of transactions in trx_sys_t::rw_trx_list */
300-
UNIV_INLINE
301-
ulint
302-
trx_sys_get_n_rw_trx(void)
303-
/*======================*/
304-
{
305-
ulint n_trx;
306-
307-
trx_sys_mutex_enter();
308-
309-
n_trx = UT_LIST_GET_LEN(trx_sys->rw_trx_list);
310-
311-
trx_sys_mutex_exit();
312-
313-
return(n_trx);
314-
}

storage/innobase/trx/trx0roll.cc

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -852,16 +852,6 @@ trx_rollback_recovered(bool all)
852852

853853
ut_a(srv_force_recovery < SRV_FORCE_NO_TRX_UNDO);
854854

855-
if (trx_sys_get_n_rw_trx() == 0) {
856-
857-
return;
858-
}
859-
860-
if (all) {
861-
ib::info() << "Starting in background the rollback"
862-
" of recovered transactions";
863-
}
864-
865855
/* Note: For XA recovered transactions, we rely on MySQL to
866856
do rollback. They will be in TRX_STATE_PREPARED state. If the server
867857
is shutdown and they are still lingering in trx_sys_t::trx_list
@@ -894,11 +884,6 @@ trx_rollback_recovered(bool all)
894884
trx_sys_mutex_exit();
895885

896886
} while (trx != NULL);
897-
898-
if (all) {
899-
ib::info() << "Rollback of non-prepared transactions"
900-
" completed";
901-
}
902887
}
903888

904889
/*******************************************************************//**
@@ -919,7 +904,13 @@ DECLARE_THREAD(trx_rollback_all_recovered)(void*)
919904
pfs_register_thread(trx_rollback_clean_thread_key);
920905
#endif /* UNIV_PFS_THREAD */
921906

922-
trx_rollback_recovered(true);
907+
if (trx_sys->rw_trx_hash.size()) {
908+
ib::info() << "Starting in background the rollback of"
909+
" recovered transactions";
910+
trx_rollback_recovered(true);
911+
ib::info() << "Rollback of non-prepared transactions"
912+
" completed";
913+
}
923914

924915
trx_rollback_is_active = false;
925916

storage/innobase/trx/trx0sys.cc

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -591,20 +591,7 @@ trx_sys_close(void)
591591
trx_dummy_sess = NULL;
592592
}
593593

594-
/* Only prepared transactions may be left in the system. Free them. */
595-
ut_a(UT_LIST_GET_LEN(trx_sys->rw_trx_list) == trx_sys->n_prepared_trx
596-
|| !srv_was_started
597-
|| srv_read_only_mode
598-
|| srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
599-
600-
for (trx_t* trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list);
601-
trx != NULL;
602-
trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list)) {
603-
604-
trx_free_prepared(trx);
605-
606-
UT_LIST_REMOVE(trx_sys->rw_trx_list, trx);
607-
}
594+
trx_sys->rw_trx_hash.destroy();
608595

609596
/* There can't be any active transactions. */
610597

@@ -629,7 +616,6 @@ trx_sys_close(void)
629616

630617
trx_sys->rw_trx_ids.~trx_ids_t();
631618

632-
trx_sys->rw_trx_hash.destroy();
633619
ut_free(trx_sys);
634620

635621
trx_sys = NULL;
@@ -643,12 +629,9 @@ ulint
643629
trx_sys_any_active_transactions(void)
644630
/*=================================*/
645631
{
646-
ulint total_trx = 0;
632+
ulint total_trx = trx_sys->rw_trx_hash.size();
647633

648634
trx_sys_mutex_enter();
649-
650-
total_trx = UT_LIST_GET_LEN(trx_sys->rw_trx_list);
651-
652635
for (trx_t* trx = UT_LIST_GET_FIRST(trx_sys->mysql_trx_list);
653636
trx != NULL;
654637
trx = UT_LIST_GET_NEXT(mysql_trx_list, trx)) {

storage/innobase/trx/trx0trx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ trx_free_prepared(
645645
trx_undo_free_prepared(trx);
646646

647647
assert_trx_in_rw_list(trx);
648+
UT_LIST_REMOVE(trx_sys->rw_trx_list, trx);
648649

649650
ut_a(!trx->read_only);
650651

0 commit comments

Comments
 (0)