mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
MDEV-15326 preparation: Remove trx_sys_t::n_prepared_trx
This is a backport of 900b07908b
from MariaDB Server 10.3.
This commit is contained in:
parent
154bd0950f
commit
7c79c12784
5 changed files with 47 additions and 59 deletions
|
@ -635,18 +635,6 @@ struct trx_sys_t {
|
|||
|
||||
TrxIdSet rw_trx_set; /*!< Mapping from transaction id
|
||||
to transaction instance */
|
||||
|
||||
ulint n_prepared_trx; /*!< Number of transactions currently
|
||||
in the XA PREPARED state */
|
||||
|
||||
ulint n_prepared_recovered_trx; /*!< Number of transactions
|
||||
currently in XA PREPARED state that are
|
||||
also recovered. Such transactions cannot
|
||||
be added during runtime. They can only
|
||||
occur after recovery if mysqld crashed
|
||||
while there were XA PREPARED
|
||||
transactions. We disable query cache
|
||||
if such transactions exist. */
|
||||
};
|
||||
|
||||
/** When a trx id which is zero modulo this number (which must be a power of
|
||||
|
|
|
@ -6552,26 +6552,12 @@ lock_trx_release_locks(
|
|||
{
|
||||
check_trx_state(trx);
|
||||
|
||||
if (trx_state_eq(trx, TRX_STATE_PREPARED)
|
||||
|| trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)) {
|
||||
|
||||
mutex_enter(&trx_sys->mutex);
|
||||
|
||||
ut_a(trx_sys->n_prepared_trx > 0);
|
||||
--trx_sys->n_prepared_trx;
|
||||
|
||||
if (trx->is_recovered) {
|
||||
ut_a(trx_sys->n_prepared_recovered_trx > 0);
|
||||
trx_sys->n_prepared_recovered_trx--;
|
||||
}
|
||||
|
||||
mutex_exit(&trx_sys->mutex);
|
||||
} else {
|
||||
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE)
|
||||
|| (trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY)
|
||||
&& trx->is_recovered
|
||||
&& !UT_LIST_GET_LEN(trx->lock.trx_locks)));
|
||||
}
|
||||
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE)
|
||||
|| trx_state_eq(trx, TRX_STATE_PREPARED)
|
||||
|| trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)
|
||||
|| (trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY)
|
||||
&& trx->is_recovered
|
||||
&& !UT_LIST_GET_LEN(trx->lock.trx_locks)));
|
||||
|
||||
bool release_lock;
|
||||
|
||||
|
|
|
@ -722,8 +722,6 @@ func_exit:
|
|||
&& !srv_undo_sources && srv_fast_shutdown) {
|
||||
fake_prepared:
|
||||
trx->state = TRX_STATE_PREPARED;
|
||||
trx_sys->n_prepared_trx++;
|
||||
trx_sys->n_prepared_recovered_trx++;
|
||||
*all = FALSE;
|
||||
goto func_exit;
|
||||
}
|
||||
|
|
|
@ -924,13 +924,7 @@ trx_sys_close(void)
|
|||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
while (trx_t* trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list)) {
|
||||
UT_LIST_REMOVE(trx_sys->rw_trx_list, trx);
|
||||
trx_free_prepared(trx);
|
||||
}
|
||||
|
||||
|
@ -976,17 +970,41 @@ trx_sys_any_active_transactions(void)
|
|||
|
||||
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->rw_trx_list);
|
||||
trx != NULL;
|
||||
trx = UT_LIST_GET_NEXT(trx_list, trx)) {
|
||||
ut_ad(trx->in_rw_trx_list);
|
||||
trx_mutex_enter(trx);
|
||||
switch (trx->state) {
|
||||
case TRX_STATE_NOT_STARTED:
|
||||
DBUG_ASSERT(!"invalid state");
|
||||
/* fall through */
|
||||
case TRX_STATE_PREPARED:
|
||||
case TRX_STATE_PREPARED_RECOVERED:
|
||||
break;
|
||||
case TRX_STATE_ACTIVE:
|
||||
case TRX_STATE_COMMITTED_IN_MEMORY:
|
||||
total_trx++;
|
||||
}
|
||||
trx_mutex_exit(trx);
|
||||
}
|
||||
|
||||
for (trx_t* trx = UT_LIST_GET_FIRST(trx_sys->mysql_trx_list);
|
||||
trx != NULL;
|
||||
trx = UT_LIST_GET_NEXT(mysql_trx_list, trx)) {
|
||||
total_trx += trx->state != TRX_STATE_NOT_STARTED;
|
||||
ut_ad(trx->in_mysql_trx_list);
|
||||
trx_mutex_enter(trx);
|
||||
/* This may count some ACTIVE transactions twice,
|
||||
both in rw_trx_list and mysql_trx_list. */
|
||||
total_trx += trx->state == TRX_STATE_ACTIVE;
|
||||
/* Any PREPARED or COMMITTED transactions must be
|
||||
in rw_trx_list, so it suffices to count them there. */
|
||||
ut_ad(trx->in_rw_trx_list
|
||||
|| trx->state == TRX_STATE_NOT_STARTED
|
||||
|| trx->state == TRX_STATE_ACTIVE);
|
||||
trx_mutex_exit(trx);
|
||||
}
|
||||
|
||||
ut_a(total_trx >= trx_sys->n_prepared_trx);
|
||||
total_trx -= trx_sys->n_prepared_trx;
|
||||
|
||||
trx_sys_mutex_exit();
|
||||
|
||||
return(total_trx);
|
||||
|
|
|
@ -526,6 +526,11 @@ trx_free_prepared(
|
|||
/*==============*/
|
||||
trx_t* trx) /*!< in, own: trx object */
|
||||
{
|
||||
ut_ad(trx->state == TRX_STATE_PREPARED
|
||||
|| trx->state == TRX_STATE_PREPARED_RECOVERED
|
||||
|| !srv_was_started
|
||||
|| srv_read_only_mode
|
||||
|| srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
|
||||
ut_a(trx_state_eq(trx, TRX_STATE_PREPARED)
|
||||
|| trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)
|
||||
|| (trx->is_recovered
|
||||
|
@ -545,7 +550,9 @@ trx_free_prepared(
|
|||
|
||||
ut_a(!trx->read_only);
|
||||
|
||||
ut_d(trx->in_rw_trx_list = FALSE);
|
||||
ut_ad(trx->in_rw_trx_list);
|
||||
UT_LIST_REMOVE(trx_sys->rw_trx_list, trx);
|
||||
ut_d(trx->in_rw_trx_list = false);
|
||||
|
||||
DBUG_LOG("trx", "Free prepared: " << trx);
|
||||
trx->state = TRX_STATE_NOT_STARTED;
|
||||
|
@ -594,7 +601,6 @@ trx_disconnect_from_mysql(
|
|||
ut_ad(trx_state_eq(trx, TRX_STATE_PREPARED));
|
||||
|
||||
trx->is_recovered = true;
|
||||
trx_sys->n_prepared_recovered_trx++;
|
||||
trx->mysql_thd = NULL;
|
||||
/* todo/fixme: suggest to do it at innodb prepare */
|
||||
trx->will_lock = 0;
|
||||
|
@ -756,8 +762,6 @@ trx_resurrect_insert(
|
|||
<< " was in the XA prepared state.";
|
||||
|
||||
trx->state = TRX_STATE_PREPARED;
|
||||
trx_sys->n_prepared_trx++;
|
||||
trx_sys->n_prepared_recovered_trx++;
|
||||
} else {
|
||||
trx->state = TRX_STATE_COMMITTED_IN_MEMORY;
|
||||
}
|
||||
|
@ -815,13 +819,8 @@ trx_resurrect_update_in_prepared_state(
|
|||
if (undo->state == TRX_UNDO_PREPARED) {
|
||||
ib::info() << "Transaction " << trx_get_id_for_print(trx)
|
||||
<< " was in the XA prepared state.";
|
||||
|
||||
if (trx_state_eq(trx, TRX_STATE_NOT_STARTED)) {
|
||||
trx_sys->n_prepared_trx++;
|
||||
trx_sys->n_prepared_recovered_trx++;
|
||||
} else {
|
||||
ut_ad(trx_state_eq(trx, TRX_STATE_PREPARED));
|
||||
}
|
||||
ut_ad(trx_state_eq(trx, TRX_STATE_NOT_STARTED)
|
||||
|| trx_state_eq(trx, TRX_STATE_PREPARED));
|
||||
|
||||
trx->state = TRX_STATE_PREPARED;
|
||||
} else {
|
||||
|
@ -2609,10 +2608,9 @@ trx_prepare(
|
|||
|
||||
/*--------------------------------------*/
|
||||
ut_a(trx->state == TRX_STATE_ACTIVE);
|
||||
trx_sys_mutex_enter();
|
||||
trx_mutex_enter(trx);
|
||||
trx->state = TRX_STATE_PREPARED;
|
||||
trx_sys->n_prepared_trx++;
|
||||
trx_sys_mutex_exit();
|
||||
trx_mutex_exit(trx);
|
||||
/*--------------------------------------*/
|
||||
|
||||
if (lsn) {
|
||||
|
|
Loading…
Reference in a new issue