Skip to content

Commit 900b079

Browse files
committed
MDEV-14756 - Remove trx_sys_t::rw_trx_list
Removed trx_sys_t::n_prepared_recovered_trx: never used. Removed trx_sys_t::n_prepared_trx: used only at shutdown, we can perfectly get this value from rw_trx_hash.
1 parent a0b385e commit 900b079

File tree

5 files changed

+72
-36
lines changed

5 files changed

+72
-36
lines changed

storage/innobase/include/trx0sys.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,29 @@ class rw_trx_hash_t
561561
}
562562

563563

564+
struct eliminate_duplicates_arg
565+
{
566+
trx_ids_t ids;
567+
my_hash_walk_action action;
568+
void *argument;
569+
eliminate_duplicates_arg(size_t size, my_hash_walk_action act, void* arg):
570+
action(act), argument(arg) { ids.reserve(size); }
571+
};
572+
573+
574+
static my_bool eliminate_duplicates(rw_trx_hash_element_t *element,
575+
eliminate_duplicates_arg *arg)
576+
{
577+
for (trx_ids_t::iterator it= arg->ids.begin(); it != arg->ids.end(); it++)
578+
{
579+
if (*it == element->id)
580+
return 0;
581+
}
582+
arg->ids.push_back(element->id);
583+
return arg->action(element, arg->argument);
584+
}
585+
586+
564587
public:
565588
void init()
566589
{
@@ -765,6 +788,27 @@ class rw_trx_hash_t
765788
{
766789
return iterate(current_trx(), action, argument);
767790
}
791+
792+
793+
/**
794+
Iterates the hash and eliminates duplicate elements.
795+
796+
@sa iterate()
797+
*/
798+
799+
int iterate_no_dups(trx_t *caller_trx, my_hash_walk_action action,
800+
void *argument)
801+
{
802+
eliminate_duplicates_arg arg(size() + 32, action, argument);
803+
return iterate(caller_trx, reinterpret_cast<my_hash_walk_action>
804+
(eliminate_duplicates), &arg);
805+
}
806+
807+
808+
int iterate_no_dups(my_hash_walk_action action, void *argument)
809+
{
810+
return iterate_no_dups(current_trx(), action, argument);
811+
}
768812
};
769813

770814

storage/innobase/lock/lock0lock.cc

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7601,27 +7601,10 @@ lock_trx_release_locks(
76017601
trx_t* trx)/*!< in/out: transaction */
76027602
{
76037603
check_trx_state(trx);
7604+
ut_ad(trx_state_eq(trx, TRX_STATE_PREPARED)
7605+
|| trx_state_eq(trx, TRX_STATE_ACTIVE));
76047606

7605-
if (trx_state_eq(trx, TRX_STATE_PREPARED)) {
7606-
7607-
mutex_enter(&trx_sys->mutex);
7608-
7609-
ut_a(trx_sys->n_prepared_trx > 0);
7610-
--trx_sys->n_prepared_trx;
7611-
7612-
if (trx->is_recovered) {
7613-
ut_a(trx_sys->n_prepared_recovered_trx > 0);
7614-
trx_sys->n_prepared_recovered_trx--;
7615-
}
7616-
7617-
mutex_exit(&trx_sys->mutex);
7618-
} else {
7619-
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE));
7620-
}
7621-
7622-
boolrelease_lock;
7623-
7624-
release_lock = (UT_LIST_GET_LEN(trx->lock.trx_locks) > 0);
7607+
bool release_lock = UT_LIST_GET_LEN(trx->lock.trx_locks) > 0;
76257608

76267609
/* Don't take lock_sys mutex if trx didn't acquire any lock. */
76277610
if (release_lock) {

storage/innobase/trx/trx0roll.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,6 @@ trx_rollback_resurrected(
757757
&& !srv_undo_sources && srv_fast_shutdown) {
758758
fake_prepared:
759759
trx->state = TRX_STATE_PREPARED;
760-
trx_sys->n_prepared_trx++;
761-
trx_sys->n_prepared_recovered_trx++;
762760
*all = false;
763761
goto func_exit;
764762
}

storage/innobase/trx/trx0sys.cc

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,23 @@ trx_sys_close(void)
621621
trx_sys = NULL;
622622
}
623623

624+
625+
static my_bool active_count_callback(rw_trx_hash_element_t *element,
626+
uint32_t *count)
627+
{
628+
mutex_enter(&element->mutex);
629+
if (trx_t *trx= element->trx)
630+
{
631+
mutex_enter(&trx->mutex);
632+
if (trx_state_eq(trx, TRX_STATE_ACTIVE))
633+
++*count;
634+
mutex_exit(&trx->mutex);
635+
}
636+
mutex_exit(&element->mutex);
637+
return 0;
638+
}
639+
640+
624641
/*********************************************************************
625642
Check if there are any active (non-prepared) transactions.
626643
This is only used to check if it's safe to shutdown.
@@ -629,18 +646,20 @@ ulint
629646
trx_sys_any_active_transactions(void)
630647
/*=================================*/
631648
{
632-
ulint total_trx = trx_sys->rw_trx_hash.size();
649+
uint32_t total_trx = 0;
650+
651+
trx_sys->rw_trx_hash.iterate_no_dups(
652+
reinterpret_cast<my_hash_walk_action>
653+
(active_count_callback), &total_trx);
633654

634655
trx_sys_mutex_enter();
635656
for (trx_t* trx = UT_LIST_GET_FIRST(trx_sys->mysql_trx_list);
636657
trx != NULL;
637658
trx = UT_LIST_GET_NEXT(mysql_trx_list, trx)) {
638-
total_trx += trx->state != TRX_STATE_NOT_STARTED;
659+
if (trx->state != TRX_STATE_NOT_STARTED && !trx->id) {
660+
total_trx++;
661+
}
639662
}
640-
641-
ut_a(total_trx >= trx_sys->n_prepared_trx);
642-
total_trx -= trx_sys->n_prepared_trx;
643-
644663
trx_sys_mutex_exit();
645664

646665
return(total_trx);

storage/innobase/trx/trx0trx.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ trx_disconnect_from_mysql(
697697
ut_ad(trx_state_eq(trx, TRX_STATE_PREPARED));
698698

699699
trx->is_recovered = true;
700-
trx_sys->n_prepared_recovered_trx++;
701700
trx->mysql_thd = NULL;
702701
/* todo/fixme: suggest to do it at innodb prepare */
703702
trx->will_lock = 0;
@@ -873,8 +872,6 @@ static void trx_resurrect(trx_undo_t *undo, trx_rseg_t *rseg,
873872
<< " was in the XA prepared state.";
874873

875874
state= TRX_STATE_PREPARED;
876-
trx_sys->n_prepared_trx++;
877-
trx_sys->n_prepared_recovered_trx++;
878875
break;
879876
default:
880877
if (is_old_insert && srv_force_recovery < SRV_FORCE_NO_TRX_UNDO)
@@ -1003,10 +1000,6 @@ trx_lists_init_at_db_start()
10031000
undo->rseg->space;
10041001
}
10051002
trx_resurrect_table_locks(trx, undo);
1006-
if (trx_state_eq(trx, TRX_STATE_PREPARED)) {
1007-
trx_sys->n_prepared_trx++;
1008-
trx_sys->n_prepared_recovered_trx++;
1009-
}
10101003
}
10111004
}
10121005
}
@@ -2631,7 +2624,6 @@ trx_prepare(
26312624
ut_a(trx->state == TRX_STATE_ACTIVE);
26322625
trx_sys_mutex_enter();
26332626
trx->state = TRX_STATE_PREPARED;
2634-
trx_sys->n_prepared_trx++;
26352627
trx_sys_mutex_exit();
26362628
/*--------------------------------------*/
26372629

0 commit comments

Comments
 (0)