Skip to content

Commit

Permalink
MDEV-14756 - Remove trx_sys_t::rw_trx_list
Browse files Browse the repository at this point in the history
Remove rw_trx_list.
  • Loading branch information
Sergey Vojtovich committed Jan 20, 2018
1 parent a447980 commit c6d2842
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 131 deletions.
58 changes: 40 additions & 18 deletions storage/innobase/include/trx0sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,37 @@ class rw_trx_hash_t
}


#ifdef UNIV_DEBUG
static void validate_element(trx_t *trx)
{
ut_ad(!trx->read_only || !trx->rsegs.m_redo.rseg);
ut_ad(!trx_is_autocommit_non_locking(trx));
mutex_enter(&trx->mutex);
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) ||
trx_state_eq(trx, TRX_STATE_PREPARED));
mutex_exit(&trx->mutex);
}


struct debug_iterator_arg
{
my_hash_walk_action action;
void *argument;
};


static my_bool debug_iterator(rw_trx_hash_element_t *element,
debug_iterator_arg *arg)
{
mutex_enter(&element->mutex);
if (element->trx)
validate_element(element->trx);
mutex_exit(&element->mutex);
return arg->action(element, arg->argument);
}
#endif


public:
void init()
{
Expand Down Expand Up @@ -675,12 +706,7 @@ class rw_trx_hash_t
{
if (do_ref_count)
trx->reference();
#ifdef UNIV_DEBUG
mutex_enter(&trx->mutex);
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) ||
trx_state_eq(trx, TRX_STATE_PREPARED));
mutex_exit(&trx->mutex);
#endif
ut_d(validate_element(trx));
}
mutex_exit(&element->mutex);
}
Expand All @@ -704,8 +730,7 @@ class rw_trx_hash_t

void insert(trx_t *trx)
{
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) ||
trx_state_eq(trx, TRX_STATE_PREPARED));
ut_d(validate_element(trx));
int res= lf_hash_insert(&hash, get_pins(trx),
reinterpret_cast<void*>(trx));
ut_a(res == 0);
Expand All @@ -722,8 +747,7 @@ class rw_trx_hash_t

void erase(trx_t *trx)
{
ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) ||
trx_state_eq(trx, TRX_STATE_PREPARED));
ut_d(validate_element(trx));
mutex_enter(&trx->rw_trx_hash_element->mutex);
trx->rw_trx_hash_element->trx= 0;
mutex_exit(&trx->rw_trx_hash_element->mutex);
Expand Down Expand Up @@ -781,6 +805,11 @@ class rw_trx_hash_t
{
LF_PINS *pins= caller_trx ? get_pins(caller_trx) : lf_hash_get_pins(&hash);
ut_a(pins);
#ifdef UNIV_DEBUG
debug_iterator_arg debug_arg= { action, argument };
action= reinterpret_cast<my_hash_walk_action>(debug_iterator);
argument= &debug_arg;
#endif
int res= lf_hash_iterate(&hash, pins, action, argument);
if (!caller_trx)
lf_hash_put_pins(pins);
Expand Down Expand Up @@ -840,18 +869,11 @@ struct trx_sys_t {
transactions which exist or existed */
#endif /* UNIV_DEBUG */

/** Avoid false sharing */
const char pad1[CACHE_LINE_SIZE];
trx_ut_list_t rw_trx_list; /*!< List of active and committed in
memory read-write transactions, sorted
on trx id, biggest first. Recovered
transactions are always on this list. */

/** Avoid false sharing */
const char pad2[CACHE_LINE_SIZE];
trx_ut_list_t mysql_trx_list; /*!< List of transactions created
for MySQL. All user transactions are
on mysql_trx_list. The rw_trx_list
on mysql_trx_list. The rw_trx_hash
can contain system transactions and
recovered transactions that will not
be in the mysql_trx_list.
Expand Down
42 changes: 11 additions & 31 deletions storage/innobase/include/trx0trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ trx_set_dict_operation(
Determines if a transaction is in the given state.
The caller must hold trx_sys->mutex, or it must be the thread
that is serving a running transaction.
A running RW transaction must be in trx_sys->rw_trx_list.
A running RW transaction must be in trx_sys->rw_trx_hash.
@return TRUE if trx->state == state */
UNIV_INLINE
bool
Expand Down Expand Up @@ -556,15 +556,6 @@ with an explicit check for the read-only status.
#define trx_is_ac_nl_ro(t) \
((t)->read_only && trx_is_autocommit_non_locking((t)))

/**
Assert that the transaction is in the trx_sys_t::rw_trx_list */
#define assert_trx_in_rw_list(t) do { \
ut_ad(!(t)->read_only); \
ut_ad((t)->in_rw_trx_list \
== !((t)->read_only || !(t)->rsegs.m_redo.rseg)); \
check_trx_state(t); \
} while (0)

/**
Check transaction state */
#define check_trx_state(t) do { \
Expand Down Expand Up @@ -605,15 +596,14 @@ transaction pool.
#ifdef UNIV_DEBUG
/*******************************************************************//**
Assert that an autocommit non-locking select cannot be in the
rw_trx_list and that it is a read-only transaction.
rw_trx_hash and that it is a read-only transaction.
The tranasction must be in the mysql_trx_list. */
# define assert_trx_nonlocking_or_in_list(t) \
do { \
if (trx_is_autocommit_non_locking(t)) { \
trx_state_t t_state = (t)->state; \
ut_ad((t)->read_only); \
ut_ad(!(t)->is_recovered); \
ut_ad(!(t)->in_rw_trx_list); \
ut_ad((t)->in_mysql_trx_list); \
ut_ad(t_state == TRX_STATE_NOT_STARTED \
|| t_state == TRX_STATE_FORCED_ROLLBACK \
Expand All @@ -625,7 +615,7 @@ The tranasction must be in the mysql_trx_list. */
#else /* UNIV_DEBUG */
/*******************************************************************//**
Assert that an autocommit non-locking slect cannot be in the
rw_trx_list and that it is a read-only transaction.
rw_trx_hash and that it is a read-only transaction.
The tranasction must be in the mysql_trx_list. */
# define assert_trx_nonlocking_or_in_list(trx) ((void)0)
#endif /* UNIV_DEBUG */
Expand Down Expand Up @@ -946,7 +936,7 @@ struct trx_t {
transaction is moved to
COMMITTED_IN_MEMORY state.
Protected by trx_sys_t::mutex
when trx->in_rw_trx_list. Initially
when trx is in rw_trx_hash. Initially
set to TRX_ID_MAX. */

/** State of the trx from the point of view of concurrency control
Expand Down Expand Up @@ -987,11 +977,11 @@ struct trx_t {
XA (2PC) transactions are always treated as non-autocommit.
Transitions to ACTIVE or NOT_STARTED occur when
!in_rw_trx_list (no trx_sys->mutex needed).
Transitions to ACTIVE or NOT_STARTED occur when transaction
is not in rw_trx_hash (no trx_sys->mutex needed).
Autocommit non-locking read-only transactions move between states
without holding any mutex. They are !in_rw_trx_list.
without holding any mutex. They are not in rw_trx_hash.
All transactions, unless they are determined to be ac-nl-ro,
explicitly tagged as read-only or read-write, will first be put
Expand All @@ -1001,13 +991,13 @@ struct trx_t {
list. During this switch we assign it a rollback segment.
When a transaction is NOT_STARTED, it can be in_mysql_trx_list if
it is a user transaction. It cannot be in rw_trx_list.
it is a user transaction. It cannot be in rw_trx_hash.
ACTIVE->PREPARED->COMMITTED is only possible when trx->in_rw_trx_list.
ACTIVE->PREPARED->COMMITTED is only possible when trx is in rw_trx_hash.
The transition ACTIVE->PREPARED is protected by trx_sys->mutex.
ACTIVE->COMMITTED is possible when the transaction is in
rw_trx_list.
rw_trx_hash.
Transitions to COMMITTED are protected by both lock_sys->mutex
and trx->mutex.
Expand All @@ -1021,9 +1011,6 @@ struct trx_t {
ReadView* read_view; /*!< consistent read view used in the
transaction, or NULL if not yet set */

UT_LIST_NODE_T(trx_t)
trx_list; /*!< list of transactions;
protected by trx_sys->mutex. */
UT_LIST_NODE_T(trx_t)
no_list; /*!< Required during view creation
to check for the view limit for
Expand All @@ -1036,7 +1023,7 @@ struct trx_t {
bool is_recovered; /*!< 0=normal transaction,
1=recovered, must be rolled back,
protected by trx_sys->mutex when
trx->in_rw_trx_list holds */
trx is in rw_trx_hash */

hit_list_t hit_list; /*!< List of transactions to kill,
when a high priority transaction
Expand Down Expand Up @@ -1145,13 +1132,6 @@ struct trx_t {
statement uses, except those
in consistent read */
/*------------------------------*/
#ifdef UNIV_DEBUG
/** The following two fields are mutually exclusive. */
/* @{ */

bool in_rw_trx_list; /*!< true if in trx_sys->rw_trx_list */
/* @} */
#endif /* UNIV_DEBUG */
UT_LIST_NODE_T(trx_t)
mysql_trx_list; /*!< list of transactions created for
MySQL; protected by trx_sys->mutex */
Expand Down
4 changes: 1 addition & 3 deletions storage/innobase/include/trx0trx.ic
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Created 3/26/1996 Heikki Tuuri
Determines if a transaction is in the given state.
The caller must hold trx_sys->mutex, or it must be the thread
that is serving a running transaction.
A running RW transaction must be in trx_sys->rw_trx_list.
A running RW transaction must be in trx_sys->rw_trx_hash.
@return TRUE if trx->state == state */
UNIV_INLINE
bool
Expand Down Expand Up @@ -72,8 +72,6 @@ trx_state_eq(
|| (relaxed
&& thd_get_error_number(trx->mysql_thd)));

ut_ad(!trx->in_rw_trx_list);

return(true);
}
ut_error;
Expand Down
3 changes: 0 additions & 3 deletions storage/innobase/trx/trx0i_s.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,7 @@ static my_bool fetch_data_into_cache_callback(
{
mutex_enter(&element->mutex);
if (element->trx)
{
assert_trx_in_rw_list(element->trx);
fetch_data_into_cache_low(cache, element->trx);
}
mutex_exit(&element->mutex);
return cache->is_truncated;
}
Expand Down
2 changes: 0 additions & 2 deletions storage/innobase/trx/trx0roll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,6 @@ static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element,
mutex_enter(&element->mutex);
if (trx_t *trx= element->trx)
{
assert_trx_in_rw_list(trx);
if (trx->is_recovered && trx_state_eq(trx, TRX_STATE_ACTIVE))
{
arg->n_trx++;
Expand Down Expand Up @@ -796,7 +795,6 @@ static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element,
if (trx_t *trx= element->trx)
{
mutex_enter(&trx->mutex);
assert_trx_in_rw_list(trx);
if (trx->is_recovered && trx_state_eq(trx, TRX_STATE_ACTIVE))
UT_LIST_ADD_FIRST(*trx_list, trx);
mutex_exit(&trx->mutex);
Expand Down
2 changes: 0 additions & 2 deletions storage/innobase/trx/trx0sys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ trx_sys_create(void)
mutex_create(LATCH_ID_TRX_SYS, &trx_sys->mutex);

UT_LIST_INIT(trx_sys->serialisation_list, &trx_t::no_list);
UT_LIST_INIT(trx_sys->rw_trx_list, &trx_t::trx_list);
UT_LIST_INIT(trx_sys->mysql_trx_list, &trx_t::mysql_trx_list);

trx_sys->mvcc = UT_NEW_NOKEY(MVCC(1024));
Expand Down Expand Up @@ -607,7 +606,6 @@ trx_sys_close(void)

UT_DELETE(trx_sys->mvcc);

ut_a(UT_LIST_GET_LEN(trx_sys->rw_trx_list) == 0);
ut_a(UT_LIST_GET_LEN(trx_sys->mysql_trx_list) == 0);
ut_a(UT_LIST_GET_LEN(trx_sys->serialisation_list) == 0);

Expand Down
Loading

0 comments on commit c6d2842

Please sign in to comment.