Commit b7fd7ce2 authored by Sergey Vojtovich's avatar Sergey Vojtovich

Moved normal transaction xid to implicit_xid

Part of MDEV-7974 - backport fix for mysql bug#12161 (XA and binlog)
parent 228514e5
......@@ -1199,8 +1199,11 @@ void trans_register_ha(THD *thd, bool all, handlerton *ht_arg)
ha_info->register_ha(trans, ht_arg);
trans->no_2pc|=(ht_arg->prepare==0);
if (thd->transaction.xid_state.xid.is_null())
thd->transaction.xid_state.xid.set(thd->query_id);
/* Set implicit xid even if there's explicit XA, it will be ignored anyway. */
if (thd->transaction.implicit_xid.is_null())
thd->transaction.implicit_xid.set(thd->query_id);
DBUG_VOID_RETURN;
}
......@@ -1541,7 +1544,10 @@ int ha_commit_trans(THD *thd, bool all)
need_prepare_ordered= FALSE;
need_commit_ordered= FALSE;
xid= thd->transaction.xid_state.xid.get_my_xid();
DBUG_ASSERT(thd->transaction.implicit_xid.get_my_xid() ==
thd->transaction.implicit_xid.quick_get_my_xid());
xid= thd->transaction.xid_state.is_explicit_XA() ? 0 :
thd->transaction.implicit_xid.quick_get_my_xid();
for (Ha_trx_info *hi= ha_info; hi; hi= hi->next())
{
......
......@@ -1285,7 +1285,7 @@ bool Transaction_state_tracker::store(THD *thd, String *buf)
if ((tx_curr_state & TX_EXPLICIT) && is_xa)
{
XID *xid= &thd->transaction.xid_state.xid;
XID *xid= thd->transaction.xid_state.get_xid();
long glen, blen;
buf->append(STRING_WITH_LEN("XA START"));
......
......@@ -1159,10 +1159,12 @@ void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid)
if (!thd->wsrep_xid.is_null())
{
*xid = *(MYSQL_XID *) &thd->wsrep_xid;
return;
}
else
#endif /* WITH_WSREP */
*xid = *(MYSQL_XID *) &thd->transaction.xid_state.xid;
*xid= thd->transaction.xid_state.is_explicit_XA() ?
*(MYSQL_XID *) thd->transaction.xid_state.get_xid() :
*(MYSQL_XID *) &thd->transaction.implicit_xid;
}
......@@ -1386,7 +1388,7 @@ void THD::init_for_queries()
variables.trans_alloc_block_size,
variables.trans_prealloc_size);
DBUG_ASSERT(!transaction.xid_state.is_explicit_XA());
DBUG_ASSERT(transaction.xid_state.xid.is_null());
DBUG_ASSERT(transaction.implicit_xid.is_null());
}
......
......@@ -2582,6 +2582,7 @@ class THD: public THD_count, /* this must be first */
THD_TRANS stmt; // Trans for current statement
bool on; // see ha_enable_transaction()
XID_STATE xid_state;
XID implicit_xid;
WT_THD wt; ///< for deadlock detection
Rows_log_event *m_pending_rows_event;
......@@ -2606,9 +2607,7 @@ class THD: public THD_count, /* this must be first */
DBUG_ENTER("THD::st_transactions::cleanup");
changed_tables= 0;
savepoints= 0;
/* xid_cache_delete() resets xid of explicitly started XA transaction */
if (!xid_state.is_explicit_XA())
xid_state.xid.null();
implicit_xid.null();
free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
DBUG_VOID_RETURN;
}
......@@ -2620,6 +2619,7 @@ class THD: public THD_count, /* this must be first */
{
bzero((char*)this, sizeof(*this));
xid_state.xid.null();
implicit_xid.null();
init_sql_alloc(&mem_root, "THD::transactions",
ALLOC_ROOT_MIN_BLOCK_SIZE, 0,
MYF(MY_THREAD_SPECIFIC));
......
......@@ -184,12 +184,6 @@ int wsrep_apply_events(THD* thd,
thd->set_server_id(ev->server_id);
thd->set_time(); // time the query
thd->transaction.start_time.reset(thd);
//#define mariadb_10_4_0
#ifdef mariadb_10_4_0
wsrep_xid_init(&thd->transaction.xid_state.xid,
thd->wsrep_trx_meta.gtid.uuid,
thd->wsrep_trx_meta.gtid.seqno);
#endif
thd->lex->current_select= 0;
if (!ev->when)
{
......
......@@ -188,6 +188,13 @@ bool XID_STATE::check_has_uncommitted_xa() const
}
XID *XID_STATE::get_xid() const
{
DBUG_ASSERT(is_explicit_XA());
return const_cast<XID*>(&xid);
}
void xid_cache_init()
{
xid_cache_inited= true;
......
......@@ -28,6 +28,7 @@ struct XID_STATE {
bool is_explicit_XA() const { return xid_cache_element != 0; }
void set_error(uint error);
void er_xaer_rmfail() const;
XID *get_xid() const;
};
void xid_cache_init(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment