diff options
-rw-r--r-- | sql/handler.cc | 12 | ||||
-rw-r--r-- | sql/session_tracker.cc | 2 | ||||
-rw-r--r-- | sql/sql_class.cc | 8 | ||||
-rw-r--r-- | sql/sql_class.h | 6 | ||||
-rw-r--r-- | sql/wsrep_applier.cc | 6 | ||||
-rw-r--r-- | sql/xa.cc | 7 | ||||
-rw-r--r-- | sql/xa.h | 1 |
7 files changed, 26 insertions, 16 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index e46dcf98052..ee881d92337 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -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()) { diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index d6cc0552df6..0088f1b20de 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -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")); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 8243c7377e6..a32d4bad5d2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -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()); } diff --git a/sql/sql_class.h b/sql/sql_class.h index 9a63ba60865..32165aed223 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2582,6 +2582,7 @@ public: 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 @@ public: 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 @@ public: { 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)); diff --git a/sql/wsrep_applier.cc b/sql/wsrep_applier.cc index 2c4dab3bd20..39cdef77be2 100644 --- a/sql/wsrep_applier.cc +++ b/sql/wsrep_applier.cc @@ -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) { diff --git a/sql/xa.cc b/sql/xa.cc index 5accd01d600..0214059b401 100644 --- a/sql/xa.cc +++ b/sql/xa.cc @@ -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); |