Skip to content

Commit 0a67b15

Browse files
committed
Cleanup: Remove pointer indirection for trx_t::xid
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.
1 parent 8323471 commit 0a67b15

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

storage/innobase/handler/ha_innodb.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,7 +4357,7 @@ innobase_commit_ordered_2(
43574357
/* If the transaction is not run in 2pc, we must assign wsrep
43584358
XID here in order to get it written in rollback segment. */
43594359
if (trx->is_wsrep()) {
4360-
thd_get_xid(thd, (MYSQL_XID*)trx->xid);
4360+
thd_get_xid(thd, &reinterpret_cast<MYSQL_XID&>(trx->xid));
43614361
}
43624362
#endif /* WITH_WSREP */
43634363

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

1668416685
DBUG_ASSERT(hton == innodb_hton_ptr);
1668516686

16686-
thd_get_xid(thd, (MYSQL_XID*) trx->xid);
16687+
thd_get_xid(thd, &reinterpret_cast<MYSQL_XID&>(trx->xid));
1668716688

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

@@ -16815,8 +16816,8 @@ int innobase_rollback_by_xid(handlerton* hton, XID* xid)
1681516816
/* If a wsrep transaction is being rolled back during
1681616817
the recovery, we must clear the xid in order to avoid
1681716818
writing serialisation history for rolled back transaction. */
16818-
if (wsrep_is_wsrep_xid(trx->xid)) {
16819-
trx->xid->null();
16819+
if (wsrep_is_wsrep_xid(&trx->xid)) {
16820+
trx->xid.null();
1682016821
}
1682116822
#endif /* WITH_WSREP */
1682216823
int ret = innobase_rollback_trx(trx);
@@ -18312,7 +18313,7 @@ void lock_wait_wsrep_kill(trx_t *bf_trx, ulong thd_id, trx_id_t trx_id)
1831218313
default:
1831318314
break;
1831418315
case TRX_STATE_PREPARED:
18315-
if (!wsrep_is_wsrep_xid(vtrx->xid))
18316+
if (!wsrep_is_wsrep_xid(&vtrx->xid))
1831618317
break;
1831718318
/* fall through */
1831818319
case TRX_STATE_ACTIVE:

storage/innobase/include/trx0trx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ struct trx_t : ilist_node<>
859859
const char* start_file; /*!< Filename where it was started */
860860
#endif /* UNIV_DEBUG */
861861

862-
XID* xid; /*!< X/Open XA transaction
862+
XID xid; /*!< X/Open XA transaction
863863
identification to identify a
864864
transaction branch */
865865
trx_mod_tables_t mod_tables; /*!< List of tables that were modified

storage/innobase/trx/trx0purge.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ trx_purge_add_undo_to_history(const trx_t* trx, trx_undo_t*& undo, mtr_t* mtr)
284284
&& srv_fast_shutdown));
285285

286286
#ifdef WITH_WSREP
287-
if (wsrep_is_wsrep_xid(trx->xid)) {
288-
trx_rseg_update_wsrep_checkpoint(rseg_header, trx->xid, mtr);
287+
if (wsrep_is_wsrep_xid(&trx->xid)) {
288+
trx_rseg_update_wsrep_checkpoint(rseg_header, &trx->xid, mtr);
289289
}
290290
#endif
291291

storage/innobase/trx/trx0trx.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ struct TrxFactory {
178178

179179
trx->dict_operation_lock_mode = 0;
180180

181-
trx->xid = UT_NEW_NOKEY(xid_t());
182-
183181
trx->detailed_error = reinterpret_cast<char*>(
184182
ut_zalloc_nokey(MAX_DETAILED_ERROR_LEN));
185183

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

234-
UT_DELETE(trx->xid);
235232
ut_free(trx->detailed_error);
236233

237234
trx->mutex_destroy();
@@ -675,7 +672,7 @@ static void trx_resurrect(trx_undo_t *undo, trx_rseg_t *rseg,
675672
this trx_ref_count w/o mutex protection.
676673
*/
677674
trx->rsegs.m_redo.rseg->acquire();
678-
*trx->xid= undo->xid;
675+
trx->xid= undo->xid;
679676
trx->id= undo->trx_id;
680677
trx->is_recovered= true;
681678
trx->start_time= start_time;
@@ -913,7 +910,7 @@ trx_start_low(
913910
}
914911

915912
#ifdef WITH_WSREP
916-
trx->xid->null();
913+
trx->xid.null();
917914
#endif /* WITH_WSREP */
918915

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

1350-
commit_lsn= undo_no || !xid->is_null() ? mtr->commit_lsn() : 0;
1347+
commit_lsn= undo_no || !xid.is_null() ? mtr->commit_lsn() : 0;
13511348
if (!commit_lsn)
13521349
/* Nothing to be done. */;
13531350
else if (flush_log_later)
@@ -1922,7 +1919,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element,
19221919
<< " in prepared state after recovery";
19231920
ib::info() << "Transaction contains changes to " << trx->undo_no
19241921
<< " rows";
1925-
xid= *trx->xid;
1922+
xid= trx->xid;
19261923
}
19271924
}
19281925
}
@@ -1997,16 +1994,16 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element,
19971994
if (trx->is_recovered &&
19981995
(trx_state_eq(trx, TRX_STATE_PREPARED) ||
19991996
trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)) &&
2000-
arg->xid->eq(reinterpret_cast<XID*>(trx->xid)))
1997+
arg->xid->eq(&trx->xid))
20011998
{
20021999
#ifdef WITH_WSREP
20032000
/* The commit of a prepared recovered Galera
20042001
transaction needs a valid trx->xid for
20052002
invoking trx_sys_update_wsrep_checkpoint(). */
2006-
if (!wsrep_is_wsrep_xid(trx->xid))
2003+
if (!wsrep_is_wsrep_xid(&trx->xid))
20072004
#endif /* WITH_WSREP */
20082005
/* Invalidate the XID, so that subsequent calls will not find it. */
2009-
trx->xid->null();
2006+
trx->xid.null();
20102007
arg->trx= trx;
20112008
found= 1;
20122009
}

storage/innobase/trx/trx0undo.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ trx_undo_create(trx_t* trx, trx_rseg_t* rseg, trx_undo_t** undo,
10511051

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

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

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

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

11141114
if (rseg != trx->rsegs.m_redo.rseg) {
11151115
return block;
@@ -1277,7 +1277,7 @@ void trx_undo_set_state_at_prepare(trx_t *trx, trx_undo_t *undo, bool rollback,
12771277
/*------------------------------*/
12781278
ut_ad(undo->state == TRX_UNDO_ACTIVE);
12791279
undo->state = TRX_UNDO_PREPARED;
1280-
undo->xid = *trx->xid;
1280+
undo->xid = trx->xid;
12811281
/*------------------------------*/
12821282

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

0 commit comments

Comments
 (0)