Skip to content

Commit

Permalink
Cleanup: Remove pointer indirection for trx_t::xid
Browse files Browse the repository at this point in the history
The trx_t::xid is always allocated, so we might as well allocate it
directly in the trx_t object to improve the locality of reference.
  • Loading branch information
dr-m committed Jul 1, 2021
1 parent 8323471 commit 0a67b15
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
15 changes: 8 additions & 7 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4357,7 +4357,7 @@ innobase_commit_ordered_2(
/* If the transaction is not run in 2pc, we must assign wsrep
XID here in order to get it written in rollback segment. */
if (trx->is_wsrep()) {
thd_get_xid(thd, (MYSQL_XID*)trx->xid);
thd_get_xid(thd, &reinterpret_cast<MYSQL_XID&>(trx->xid));
}
#endif /* WITH_WSREP */

Expand Down Expand Up @@ -4552,8 +4552,9 @@ innobase_rollback(
trx is being rolled back due to BF abort, clear XID in order
to avoid writing it to rollback segment out of order. The XID
will be reassigned when the transaction is replayed. */
if (trx->state != TRX_STATE_NOT_STARTED && wsrep_is_wsrep_xid(trx->xid)) {
trx->xid->null();
if (trx->state != TRX_STATE_NOT_STARTED
&& wsrep_is_wsrep_xid(&trx->xid)) {
trx->xid.null();
}
#endif /* WITH_WSREP */
if (rollback_trx
Expand Down Expand Up @@ -16683,7 +16684,7 @@ innobase_xa_prepare(

DBUG_ASSERT(hton == innodb_hton_ptr);

thd_get_xid(thd, (MYSQL_XID*) trx->xid);
thd_get_xid(thd, &reinterpret_cast<MYSQL_XID&>(trx->xid));

if (!trx_is_registered_for_2pc(trx) && trx_is_started(trx)) {

Expand Down Expand Up @@ -16815,8 +16816,8 @@ int innobase_rollback_by_xid(handlerton* hton, XID* xid)
/* If a wsrep transaction is being rolled back during
the recovery, we must clear the xid in order to avoid
writing serialisation history for rolled back transaction. */
if (wsrep_is_wsrep_xid(trx->xid)) {
trx->xid->null();
if (wsrep_is_wsrep_xid(&trx->xid)) {
trx->xid.null();
}
#endif /* WITH_WSREP */
int ret = innobase_rollback_trx(trx);
Expand Down Expand Up @@ -18312,7 +18313,7 @@ void lock_wait_wsrep_kill(trx_t *bf_trx, ulong thd_id, trx_id_t trx_id)
default:
break;
case TRX_STATE_PREPARED:
if (!wsrep_is_wsrep_xid(vtrx->xid))
if (!wsrep_is_wsrep_xid(&vtrx->xid))
break;
/* fall through */
case TRX_STATE_ACTIVE:
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/trx0trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ struct trx_t : ilist_node<>
const char* start_file; /*!< Filename where it was started */
#endif /* UNIV_DEBUG */

XID* xid; /*!< X/Open XA transaction
XID xid; /*!< X/Open XA transaction
identification to identify a
transaction branch */
trx_mod_tables_t mod_tables; /*!< List of tables that were modified
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/trx/trx0purge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ trx_purge_add_undo_to_history(const trx_t* trx, trx_undo_t*& undo, mtr_t* mtr)
&& srv_fast_shutdown));

#ifdef WITH_WSREP
if (wsrep_is_wsrep_xid(trx->xid)) {
trx_rseg_update_wsrep_checkpoint(rseg_header, trx->xid, mtr);
if (wsrep_is_wsrep_xid(&trx->xid)) {
trx_rseg_update_wsrep_checkpoint(rseg_header, &trx->xid, mtr);
}
#endif

Expand Down
17 changes: 7 additions & 10 deletions storage/innobase/trx/trx0trx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ struct TrxFactory {

trx->dict_operation_lock_mode = 0;

trx->xid = UT_NEW_NOKEY(xid_t());

trx->detailed_error = reinterpret_cast<char*>(
ut_zalloc_nokey(MAX_DETAILED_ERROR_LEN));

Expand Down Expand Up @@ -231,7 +229,6 @@ struct TrxFactory {
ut_a(UT_LIST_GET_LEN(trx->lock.trx_locks) == 0);
ut_ad(UT_LIST_GET_LEN(trx->lock.evicted_tables) == 0);

UT_DELETE(trx->xid);
ut_free(trx->detailed_error);

trx->mutex_destroy();
Expand Down Expand Up @@ -675,7 +672,7 @@ static void trx_resurrect(trx_undo_t *undo, trx_rseg_t *rseg,
this trx_ref_count w/o mutex protection.
*/
trx->rsegs.m_redo.rseg->acquire();
*trx->xid= undo->xid;
trx->xid= undo->xid;
trx->id= undo->trx_id;
trx->is_recovered= true;
trx->start_time= start_time;
Expand Down Expand Up @@ -913,7 +910,7 @@ trx_start_low(
}

#ifdef WITH_WSREP
trx->xid->null();
trx->xid.null();
#endif /* WITH_WSREP */

ut_a(ib_vector_is_empty(trx->autoinc_locks));
Expand Down Expand Up @@ -1347,7 +1344,7 @@ inline void trx_t::commit_in_memory(const mtr_t *mtr)
serialize all commits and prevent a group of transactions from
gathering. */

commit_lsn= undo_no || !xid->is_null() ? mtr->commit_lsn() : 0;
commit_lsn= undo_no || !xid.is_null() ? mtr->commit_lsn() : 0;
if (!commit_lsn)
/* Nothing to be done. */;
else if (flush_log_later)
Expand Down Expand Up @@ -1922,7 +1919,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element,
<< " in prepared state after recovery";
ib::info() << "Transaction contains changes to " << trx->undo_no
<< " rows";
xid= *trx->xid;
xid= trx->xid;
}
}
}
Expand Down Expand Up @@ -1997,16 +1994,16 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element,
if (trx->is_recovered &&
(trx_state_eq(trx, TRX_STATE_PREPARED) ||
trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)) &&
arg->xid->eq(reinterpret_cast<XID*>(trx->xid)))
arg->xid->eq(&trx->xid))
{
#ifdef WITH_WSREP
/* The commit of a prepared recovered Galera
transaction needs a valid trx->xid for
invoking trx_sys_update_wsrep_checkpoint(). */
if (!wsrep_is_wsrep_xid(trx->xid))
if (!wsrep_is_wsrep_xid(&trx->xid))
#endif /* WITH_WSREP */
/* Invalidate the XID, so that subsequent calls will not find it. */
trx->xid->null();
trx->xid.null();
arg->trx= trx;
found= 1;
}
Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/trx/trx0undo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ trx_undo_create(trx_t* trx, trx_rseg_t* rseg, trx_undo_t** undo,

uint16_t offset = trx_undo_header_create(block, trx->id, mtr);

*undo = trx_undo_mem_create(rseg, id, trx->id, trx->xid,
*undo = trx_undo_mem_create(rseg, id, trx->id, &trx->xid,
block->page.id().page_no(), offset);
if (*undo == NULL) {
*err = DB_OUT_OF_MEMORY;
Expand Down Expand Up @@ -1109,7 +1109,7 @@ trx_undo_reuse_cached(trx_t* trx, trx_rseg_t* rseg, trx_undo_t** pundo,

uint16_t offset = trx_undo_header_create(block, trx->id, mtr);

trx_undo_mem_init_for_reuse(undo, trx->id, trx->xid, offset);
trx_undo_mem_init_for_reuse(undo, trx->id, &trx->xid, offset);

if (rseg != trx->rsegs.m_redo.rseg) {
return block;
Expand Down Expand Up @@ -1277,7 +1277,7 @@ void trx_undo_set_state_at_prepare(trx_t *trx, trx_undo_t *undo, bool rollback,
/*------------------------------*/
ut_ad(undo->state == TRX_UNDO_ACTIVE);
undo->state = TRX_UNDO_PREPARED;
undo->xid = *trx->xid;
undo->xid = trx->xid;
/*------------------------------*/

mtr->write<2>(*block, TRX_UNDO_SEG_HDR + TRX_UNDO_STATE + block->frame,
Expand Down

0 comments on commit 0a67b15

Please sign in to comment.