summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-09-02 14:00:53 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2019-09-04 09:42:38 +0300
commit7c79c127842133d1f85ac2273a229d84007075c9 (patch)
tree7582110bd167be0ca4a8db8b8282f366a4293296 /storage
parent154bd0950f6691dff22a5e01d4aa68e281ea6092 (diff)
downloadmariadb-git-7c79c127842133d1f85ac2273a229d84007075c9.tar.gz
MDEV-15326 preparation: Remove trx_sys_t::n_prepared_trx
This is a backport of 900b07908bf9dbd2c79c3a66fc471e6be4cf0d13 from MariaDB Server 10.3.
Diffstat (limited to 'storage')
-rw-r--r--storage/innobase/include/trx0sys.h12
-rw-r--r--storage/innobase/lock/lock0lock.cc26
-rw-r--r--storage/innobase/trx/trx0roll.cc2
-rw-r--r--storage/innobase/trx/trx0sys.cc40
-rw-r--r--storage/innobase/trx/trx0trx.cc26
5 files changed, 47 insertions, 59 deletions
diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h
index 1f24dabe3ac..37ac8975783 100644
--- a/storage/innobase/include/trx0sys.h
+++ b/storage/innobase/include/trx0sys.h
@@ -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
diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc
index 8cb9f19d93d..8634f7e73c5 100644
--- a/storage/innobase/lock/lock0lock.cc
+++ b/storage/innobase/lock/lock0lock.cc
@@ -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;
diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc
index f1a19d91d0b..e827cda46eb 100644
--- a/storage/innobase/trx/trx0roll.cc
+++ b/storage/innobase/trx/trx0roll.cc
@@ -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;
}
diff --git a/storage/innobase/trx/trx0sys.cc b/storage/innobase/trx/trx0sys.cc
index 6529de31fb5..415afc4a90b 100644
--- a/storage/innobase/trx/trx0sys.cc
+++ b/storage/innobase/trx/trx0sys.cc
@@ -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);
diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc
index 1f6ed7a48d4..d6fbc65ea55 100644
--- a/storage/innobase/trx/trx0trx.cc
+++ b/storage/innobase/trx/trx0trx.cc
@@ -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) {