Skip to content

Commit

Permalink
MDEV-15326/MDEV-16136 dead code removal
Browse files Browse the repository at this point in the history
Revert part of fa2a74e.

trx_reference(): Remove, and merge the relevant part to the only caller
trx_rw_is_active(). If the statements trx = NULL; were ever executed,
the function would have dereferenced a NULL pointer and crashed in
trx_mutex_exit(trx). Hence, those statements must have been unreachable,
and they can be replaced with debug assertions.

trx_rw_is_active(): Avoid unnecessary acquisition and release of trx->mutex
when do_ref_count=false.

lock_trx_release_locks(): Do not reset trx->id=0. Had the statement been
necessary, we would have experienced crashes in trx_reference().
  • Loading branch information
dr-m committed Aug 27, 2019
1 parent e7b71e0 commit 25af2a1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
9 changes: 7 additions & 2 deletions storage/innobase/include/trx0sys.ic
Expand Up @@ -364,8 +364,13 @@ trx_rw_is_active(

trx_t* trx = trx_rw_is_active_low(trx_id, corrupt);

if (trx) {
trx = trx_reference(do_ref_count ? trx_id : 0, trx);
if (trx && do_ref_count) {
trx_mutex_enter(trx);
ut_ad(!trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY));
ut_ad(trx->id == trx_id);
ut_ad(trx->n_ref >= 0);
++trx->n_ref;
trx_mutex_exit(trx);
}

trx_sys_mutex_exit();
Expand Down
26 changes: 0 additions & 26 deletions storage/innobase/include/trx0trx.h
Expand Up @@ -1270,32 +1270,6 @@ struct commit_node_t{
mutex_exit(&t->mutex); \
} while (0)

/**
Increase the reference count. If the transaction is in state
TRX_STATE_COMMITTED_IN_MEMORY then the transaction is considered
committed and the reference count is not incremented.
@param id the transaction ID; 0 if not to increment the reference count
@param trx Transaction that is being referenced
@return trx
@retval NULL if the transaction is no longer active */
inline trx_t* trx_reference(trx_id_t id, trx_t* trx)
{
trx_mutex_enter(trx);

if (trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY)) {
trx = NULL;
} else if (!id) {
} else if (trx->id != id) {
trx = NULL;
} else {
ut_ad(trx->n_ref >= 0);
++trx->n_ref;
}

trx_mutex_exit(trx);
return(trx);
}

#include "trx0trx.ic"

#endif
2 changes: 0 additions & 2 deletions storage/innobase/lock/lock0lock.cc
Expand Up @@ -6647,8 +6647,6 @@ lock_trx_release_locks(
the is_recovered flag. */

trx->is_recovered = false;
/* Ensure that trx_reference() will not find this transaction. */
trx->id = 0;

trx_mutex_exit(trx);

Expand Down
7 changes: 4 additions & 3 deletions storage/innobase/trx/trx0trx.cc
Expand Up @@ -557,6 +557,7 @@ trx_free_prepared(
transaction was never committed and therefore lock_trx_release()
was not called. */
trx->lock.table_locks.clear();
trx->id = 0;

trx_free(trx);
}
Expand Down Expand Up @@ -1660,10 +1661,8 @@ trx_commit_in_memory(
trx_erase_lists(trx, serialised);
}

/* trx->id will be cleared in lock_trx_release_locks(trx). */
ut_ad(trx->read_only || !trx->rsegs.m_redo.rseg || trx->id);
lock_trx_release_locks(trx);
ut_ad(trx->id == 0);
ut_ad(trx->read_only || !trx->rsegs.m_redo.rseg || trx->id);

/* Remove the transaction from the list of active
transactions now that it no longer holds any user locks. */
Expand All @@ -1682,6 +1681,8 @@ trx_commit_in_memory(
} else {
MONITOR_INC(MONITOR_TRX_RW_COMMIT);
}

trx->id = 0;
}

ut_ad(!trx->rsegs.m_redo.update_undo);
Expand Down

0 comments on commit 25af2a1

Please sign in to comment.