MySQL 8.0.29
Source Code Documentation
xa.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2013, 2021, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef XA_H_INCLUDED
25#define XA_H_INCLUDED
26
27#include <string.h>
28#include <sys/types.h>
29#include <list>
30#include <mutex>
31
32#include "lex_string.h"
33#include "my_dbug.h"
34#include "my_inttypes.h"
35#include "my_sqlcommand.h"
36#include "sql/malloc_allocator.h" // Malloc_allocator
37#include "sql/psi_memory_key.h" // key_memory_xa_recovered_transactions
38#include "sql/sql_cmd.h" // Sql_cmd
39#include "sql/sql_list.h" // List
40#include "sql/sql_plugin_ref.h" // plugin_ref
41#include "sql/xa_aux.h" // serialize_xid
42
43class Protocol;
44class THD;
45struct xid_t;
46
48
56};
57
58static const int TC_HEURISTIC_NOT_USED = 0;
59static const int TC_HEURISTIC_RECOVER_COMMIT = 1;
60static const int TC_HEURISTIC_RECOVER_ROLLBACK = 2;
61
62/**
63 This class represents SQL statement which starts an XA transaction
64 with the given xid value.
65*/
66
67class Sql_cmd_xa_start : public Sql_cmd {
68 public:
69 Sql_cmd_xa_start(xid_t *xid_arg, enum xa_option_words xa_option)
70 : m_xid(xid_arg), m_xa_opt(xa_option) {}
71
73
74 bool execute(THD *thd) override;
75
76 private:
77 bool trans_xa_start(THD *thd);
80};
81
82/**
83 This class represents SQL statement which puts in the IDLE state
84 an XA transaction with the given xid value.
85*/
86
87class Sql_cmd_xa_end : public Sql_cmd {
88 public:
89 Sql_cmd_xa_end(xid_t *xid_arg, enum xa_option_words xa_option)
90 : m_xid(xid_arg), m_xa_opt(xa_option) {}
91
92 enum_sql_command sql_command_code() const override { return SQLCOM_XA_END; }
93
94 bool execute(THD *thd) override;
95
96 private:
97 bool trans_xa_end(THD *thd);
98
101};
102
103/**
104 This class represents SQL statement which puts in the PREPARED state
105 an XA transaction with the given xid value.
106*/
107
109 public:
110 explicit Sql_cmd_xa_prepare(xid_t *xid_arg) : m_xid(xid_arg) {}
111
113 return SQLCOM_XA_PREPARE;
114 }
115
116 bool execute(THD *thd) override;
117
118 private:
119 bool trans_xa_prepare(THD *thd);
120
122};
123
124/**
125 This class represents SQL statement which returns to a client
126 a list of XID's prepared to a XA commit/rollback.
127*/
128
130 public:
131 explicit Sql_cmd_xa_recover(bool print_xid_as_hex)
132 : m_print_xid_as_hex(print_xid_as_hex) {}
133
135 return SQLCOM_XA_RECOVER;
136 }
137
138 bool execute(THD *thd) override;
139
140 private:
141 bool check_xa_recover_privilege(THD *thd) const;
142 bool trans_xa_recover(THD *thd);
143
145};
146
147class XID_STATE;
148/**
149 This class represents SQL statement which commits
150 and terminates an XA transaction with the given xid value.
151*/
152
154 public:
155 Sql_cmd_xa_commit(xid_t *xid_arg, enum xa_option_words xa_option)
156 : m_xid(xid_arg), m_xa_opt(xa_option) {}
157
159 return SQLCOM_XA_COMMIT;
160 }
161
162 bool execute(THD *thd) override;
163
164 enum xa_option_words get_xa_opt() const { return m_xa_opt; }
165
166 private:
167 bool trans_xa_commit(THD *thd);
168 bool process_external_xa_commit(THD *thd, xid_t *xid,
169 XID_STATE *thd_xid_state);
170 bool process_internal_xa_commit(THD *thd, XID_STATE *xid_state);
171
174};
175
176/**
177 This class represents SQL statement which rollbacks and
178 terminates an XA transaction with the given xid value.
179*/
180
182 public:
183 explicit Sql_cmd_xa_rollback(xid_t *xid_arg) : m_xid(xid_arg) {}
184
186 return SQLCOM_XA_ROLLBACK;
187 }
188
189 bool execute(THD *thd) override;
190
191 private:
192 bool trans_xa_rollback(THD *thd);
193 bool process_external_xa_rollback(THD *thd, xid_t *xid, XID_STATE *xid_state);
194 bool process_internal_xa_rollback(THD *thd, XID_STATE *xid_state);
195
197};
198
199typedef ulonglong my_xid; // this line is the same as in log_event.h
200#define MYSQL_XID_PREFIX "MySQLXid"
201
202/*
203 Same as MYSQL_XIDDATASIZE but we do not want to include plugin.h here
204 See static_assert in .cc file.
205*/
206#define XIDDATASIZE 128
207
208/**
209 struct xid_t is binary compatible with the XID structure as
210 in the X/Open CAE Specification, Distributed Transaction Processing:
211 The XA Specification, X/Open Company Ltd., 1991.
212 http://www.opengroup.org/bookstore/catalog/c193.htm
213
214 @see MYSQL_XID in mysql/plugin.h
215*/
216typedef struct xid_t {
217 private:
218 /**
219 -1 means that the XID is null
220 */
222
223 /**
224 value from 1 through 64
225 */
227
228 /**
229 value from 1 through 64
230 */
232
233 /**
234 distributed trx identifier. not \0-terminated.
235 */
237
238 public:
240 memset(data, 0, XIDDATASIZE);
241 }
242
243 long get_format_id() const { return formatID; }
244
245 void set_format_id(long v) {
247 DBUG_PRINT("debug", ("SETTING XID_STATE formatID: %ld", v));
248 formatID = v;
249 return;
250 }
251
252 long get_gtrid_length() const { return gtrid_length; }
253
254 void set_gtrid_length(long v) { gtrid_length = v; }
255
256 long get_bqual_length() const { return bqual_length; }
257
258 void set_bqual_length(long v) { bqual_length = v; }
259
260 const char *get_data() const { return data; }
261
262 void set_data(const void *v, long l) {
263 assert(l <= XIDDATASIZE);
264 memcpy(data, v, l);
265 }
266
267 void reset() {
268 formatID = -1;
269 gtrid_length = 0;
270 bqual_length = 0;
271 memset(data, 0, XIDDATASIZE);
272 }
273
274 void set(long f, const char *g, long gl, const char *b, long bl) {
276 DBUG_PRINT("debug", ("SETTING XID_STATE formatID: %ld", f));
277 formatID = f;
278 memcpy(data, g, gtrid_length = gl);
279 bqual_length = bl;
280 if (bl > 0) memcpy(data + gl, b, bl);
281 return;
282 }
283
284 my_xid get_my_xid() const;
285
286 uchar *key() { return reinterpret_cast<uchar *>(&gtrid_length); }
287
288 const uchar *key() const {
289 return reinterpret_cast<const uchar *>(&gtrid_length);
290 }
291
292 uint key_length() const {
293 return sizeof(gtrid_length) + sizeof(bqual_length) + gtrid_length +
295 }
296
297 /*
298 The size of the string containing serialized Xid representation
299 is computed as a sum of
300 eight as the number of formatting symbols (X'',X'',)
301 plus 2 x XIDDATASIZE (2 due to hex format),
302 plus space for decimal digits of XID::formatID,
303 plus one for 0x0.
304 */
305 static const uint ser_buf_size = 8 + 2 * XIDDATASIZE + 4 * sizeof(long) + 1;
306
307 /**
308 The method fills XID in a buffer in format of GTRID,BQUAL,FORMATID
309 where GTRID, BQUAL are represented as hex strings.
310
311 @param buf a pointer to buffer
312 @return the value of the first argument
313 */
314
315 char *serialize(char *buf) const {
317 }
318
319#ifndef NDEBUG
320 /**
321 Get printable XID value.
322
323 @param buf pointer to the buffer where printable XID value has to be
324 stored
325
326 @return pointer to the buffer passed in the first argument
327 */
328 char *xid_to_str(char *buf) const;
329#endif
330 /**
331 Check if equal to another xid.
332
333 @param[in] xid the id of another X/Open XA transaction
334
335 @return true iff formats, gtrid_length, bqual_length and the content of
336 gtrid_length+bqual_length bytes is exactly the same
337 */
338 bool eq(const xid_t *xid) const {
339 return xid->formatID == formatID && xid->gtrid_length == gtrid_length &&
340 xid->bqual_length == bqual_length &&
341 !memcmp(xid->data, data, gtrid_length + bqual_length);
342 }
343
344 bool is_null() const { return formatID == -1; }
345
346 private:
347 void set(const xid_t *xid) {
348 memcpy(this, xid, sizeof(xid->formatID) + xid->key_length());
349 }
350
351 void set(my_xid xid);
352
353 void null() { formatID = -1; }
354
355 friend class XID_STATE;
357
359
360/**
361 Plain structure to store information about XA transaction id
362 and a list of table names involved into XA transaction with
363 specified id.
364*/
365typedef struct st_xarecover_txn {
369
371 public:
378 };
379
380 /**
381 Transaction identifier.
382 For now, this is only used to catch duplicated external xids.
383 */
384 private:
385 static const char *xa_state_names[];
386
388 /**
389 This mutex used for eliminating a possibility to run two
390 XA COMMIT/XA ROLLBACK statements concurrently against the same xid value.
391 m_xa_lock is used on handling XA COMMIT/XA ROLLBACK and acquired only for
392 external XA branches.
393 */
394 std::mutex m_xa_lock;
395
396 /// Used by external XA only
398 bool m_is_detached = false;
399 /// Error reported by the Resource Manager (RM) to the Transaction Manager.
401 /*
402 XA-prepare binary logging status. The flag serves as a facility
403 to conduct XA transaction two round binary logging.
404 It is set to @c false at XA-start.
405 It is set to @c true by binlogging routine of XA-prepare handler as well
406 as recovered to @c true at the server recovery upon restart.
407 Checked and reset at XA-commit/rollback.
408 */
410
411 public:
413 m_xid.null();
414 }
415
416 std::mutex &get_xa_lock() { return m_xa_lock; }
417
418 void set_state(xa_states state) { xa_state = state; }
419
420 enum xa_states get_state() { return xa_state; }
421
422 bool has_state(xa_states state) const { return xa_state == state; }
423
424 const char *state_name() const { return xa_state_names[xa_state]; }
425
426 const XID *get_xid() const { return &m_xid; }
427
428 XID *get_xid() { return &m_xid; }
429
430 bool has_same_xid(const XID *xid) const { return m_xid.eq(xid); }
431
432 void set_query_id(query_id_t query_id) {
433 if (m_xid.is_null()) m_xid.set(query_id);
434 }
435
436 void set_error(THD *thd);
437
438 void reset_error() { rm_error = 0; }
439
440 void cleanup() {
441 /*
442 If rm_error is raised, it means that this piece of a distributed
443 transaction has failed and must be rolled back. But the user must
444 rollback it explicitly, so don't start a new distributed XA until
445 then.
446 */
447 if (!rm_error) m_xid.null();
448 }
449
450 void reset() {
452 m_xid.null();
453 m_is_detached = false;
454 m_is_binlogged = false;
455 }
456
457 void start_normal_xa(const XID *xid) {
458 assert(m_xid.is_null());
460 m_xid.set(xid);
461 m_is_detached = false;
462 rm_error = 0;
463 }
464
465 void start_detached_xa(const XID *xid, bool binlogged_arg = false) {
467 m_xid.set(xid);
468 m_is_detached = true;
469 rm_error = 0;
470 m_is_binlogged = binlogged_arg;
471 }
472
473 bool is_detached() const { return m_is_detached; }
474
475 bool is_binlogged() const { return m_is_binlogged; }
476
477 void set_binlogged() { m_is_binlogged = true; }
478
479 void unset_binlogged() { m_is_binlogged = false; }
480
481 void store_xid_info(Protocol *protocol, bool print_xid_as_hex) const;
482
483 /**
484 Mark a XA transaction as rollback-only if the RM unilaterally
485 rolled back the transaction branch.
486
487 @note If a rollback was requested by the RM, this function sets
488 the appropriate rollback error code and transits the state
489 to XA_ROLLBACK_ONLY.
490
491 @return true if transaction was rolled back or if the transaction
492 state is XA_ROLLBACK_ONLY. false otherwise.
493 */
494
496
497 /**
498 Check that XA transaction is in state IDLE or PREPARED.
499
500 @param report_error true if state IDLE or PREPARED has to be interpreted
501 as an error, else false
502
503 @return result of check
504 @retval false XA transaction is NOT in state IDLE or PREPARED
505 @retval true XA transaction is in state IDLE or PREPARED
506 */
507
509
510 /**
511 Check that XA transaction has an uncommitted work. Report an error
512 to a mysql user in case when there is an uncommitted work for XA
513 transaction.
514
515 @return result of check
516 @retval false XA transaction is NOT in state IDLE, PREPARED
517 or ROLLBACK_ONLY.
518 @retval true XA transaction is in state IDLE or PREPARED
519 or ROLLBACK_ONLY.
520 */
521
522 bool check_has_uncommitted_xa() const;
523
524 /**
525 Check if an XA transaction has been started.
526
527 @param report_error true if report an error in case when
528 XA transaction has been stared, else false.
529
530 @return result of check
531 @retval false XA transaction hasn't been started (XA_NOTR)
532 @retval true XA transaction has been started (!XA_NOTR)
533 */
534
535 bool check_in_xa(bool report_error) const;
536};
537
538/**
539 This class servers as a registry for prepared XA transactions existed before
540 server was shutdown and being resurrected during the server restart.
541 The class is singleton. To collect a list of XA transaction identifiers and
542 a list of tables for that MDL locks have be acquired the method
543 add_prepared_xa_transaction() must be called. This method is invoked by
544 the function trx_recover_for_mysql() called by innobase_xa_recover during
545 running of X/Open XA distributed transaction recovery procedure. After a list
546 of XA transaction identifiers and a list of table names to be locked in MDL
547 have been collected and the function ha_recover() has returned control flow
548 the method recover_prepared_xa_transactions() must be called to resurrect
549 prepared XA transactions. Separation of collecting information about prepared
550 XA transactions from restoring XA transactions is done in order to exclude
551 possible suspending on MDL locks inside the function
552 dd::reset_tables_and_tablespaces() that is called right after the function
553 ha_recover() returns control flow.
554 */
555
557 public:
558 /**
559 Initialize singleton.
560 */
561 static bool init();
562
563 /**
564 Cleanup and delete singleton object
565 */
566 static void destroy();
567
568 /**
569 Get instance of the class Recovered_xa_transactions
570 */
572
573 /**
574 Add information about prepared XA transaction into a list of
575 XA transactions to resurrect.
576
577 @param prepared_xa_trn information about prepared XA transaction
578
579 @return false on success, else true
580 */
581 bool add_prepared_xa_transaction(XA_recover_txn *prepared_xa_trn);
582
583 /**
584 Iterate along a list of prepared XA transactions, register every XA
585 transaction in a cache and acquire MDL locks for every table taking part in
586 XA transaction being resurrected.
587
588 @return false on success, else true
589 */
591
592 /**
593 Get initialized MEM_ROOT.
594
595 @return Pointer to a initialized MEM_ROOT.
596 */
598
599 private:
600 // Disable direct instantiation. Use the method init() instead.
602
604 std::list<XA_recover_txn *, Malloc_allocator<XA_recover_txn *>>
608};
609
610class Transaction_ctx;
611
612/**
613 Initialize a cache to store Transaction_ctx and a mutex to protect access
614 to the cache
615
616 @return result of initialization
617 @retval false success
618 @retval true failure
619*/
620
622
623/**
624 Transaction is marked in the cache as if it's recovered.
625 The method allows to sustain prepared transaction disconnection.
626
627 @param transaction
628 Pointer to Transaction object that is replaced.
629
630 @return operation result
631 @retval false success or a cache already contains XID_STATE
632 for this XID value
633 @retval true failure
634*/
635
637
638/**
639 Remove information about transaction from a cache.
640
641 @param transaction Pointer to a Transaction_ctx that has to be removed
642 from a cache.
643*/
644
646
647/**
648 Release resources occupied by transaction cache.
649*/
650
652
653/**
654 This is a specific to "slave" applier collection of standard cleanup
655 actions to reset XA transaction state at the end of XA prepare rather than
656 to do it at the transaction commit, see @c ha_commit_one_phase.
657 THD of the slave applier is dissociated from a transaction object in engine
658 that continues to exist there.
659
660 @param thd current thread
661 @return the value of is_error()
662*/
663
664bool applier_reset_xa_trans(THD *thd);
665
666/* interface to randomly access plugin data */
668
669/**
670 The function detaches existing storage engines transaction
671 context from thd. Backup area to save it is provided to low level
672 storage engine function.
673
674 is invoked by plugin_foreach() after
675 trans_xa_start() for each storage engine.
676
677 @param[in,out] thd Thread context
678 @param plugin Reference to handlerton
679
680 @return false on success, true otherwise.
681*/
682
683bool detach_native_trx(THD *thd, plugin_ref plugin, void *);
684
685/**
686 The function reattaches existing storage engines transaction
687 context to thd. Backup area to save it is provided to low level
688 storage engine function.
689
690 is invoked by plugin_foreach() after
691 trans_xa_prepare() for each storage engine.
692
693 @param[in,out] thd Thread context
694 @param plugin Reference to handlerton
695
696 @return false on success,
697 true otherwise.
698*/
699
700bool reattach_native_trx(THD *thd, plugin_ref plugin, void *);
701
702/**
703 Reset some transaction state information and delete corresponding
704 Transaction_ctx object from cache.
705
706 @param thd Current thread
707*/
708
709void cleanup_trans_state(THD *thd);
710
711/**
712 Rollback the active XA transaction.
713
714 @note Resets rm_error before calling ha_rollback(), so
715 the thd->transaction.xid structure gets reset
716 by ha_rollback() / THD::transaction::cleanup().
717
718 @return true if the rollback failed, false otherwise.
719*/
720
722
723bool disconnect_native_trx(THD *, plugin_ref, void *);
724#endif
int64 query_id_t
Definition: binlog.h:70
Definition: sql_list.h:433
Definition: protocol.h:32
This class servers as a registry for prepared XA transactions existed before server was shutdown and ...
Definition: xa.h:556
bool recover_prepared_xa_transactions()
Iterate along a list of prepared XA transactions, register every XA transaction in a cache and acquir...
Definition: xa.cc:310
MEM_ROOT * get_allocated_memroot()
Get initialized MEM_ROOT.
Definition: xa.cc:258
std::list< XA_recover_txn *, Malloc_allocator< XA_recover_txn * > > m_prepared_xa_trans
Definition: xa.h:605
MEM_ROOT m_mem_root
Definition: xa.h:607
static Recovered_xa_transactions * m_instance
Definition: xa.h:603
Recovered_xa_transactions()
Definition: xa.cc:221
bool add_prepared_xa_transaction(XA_recover_txn *prepared_xa_trn)
Add information about prepared XA transaction into a list of XA transactions to resurrect.
Definition: xa.cc:240
static Recovered_xa_transactions & instance()
Get instance of the class Recovered_xa_transactions.
Definition: xa.cc:226
static bool init()
Initialize singleton.
Definition: xa.cc:230
static void destroy()
Cleanup and delete singleton object.
Definition: xa.cc:235
bool m_mem_root_inited
Definition: xa.h:606
This class represents SQL statement which commits and terminates an XA transaction with the given xid...
Definition: xa.h:153
bool trans_xa_commit(THD *thd)
Commit and terminate a XA transaction.
Definition: xa.cc:564
Sql_cmd_xa_commit(xid_t *xid_arg, enum xa_option_words xa_option)
Definition: xa.h:155
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: xa.h:158
bool process_external_xa_commit(THD *thd, xid_t *xid, XID_STATE *thd_xid_state)
Handle the statement XA COMMIT for the case when xid corresponds to an external XA transaction,...
Definition: xa.cc:643
enum xa_option_words get_xa_opt() const
Definition: xa.h:164
enum xa_option_words m_xa_opt
Definition: xa.h:173
bool process_internal_xa_commit(THD *thd, XID_STATE *xid_state)
Handle the statement XA COMMIT for the case when xid corresponds to an internal XA transaction,...
Definition: xa.cc:790
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:885
xid_t * m_xid
Definition: xa.h:172
This class represents SQL statement which puts in the IDLE state an XA transaction with the given xid...
Definition: xa.h:87
Sql_cmd_xa_end(xid_t *xid_arg, enum xa_option_words xa_option)
Definition: xa.h:89
xid_t * m_xid
Definition: xa.h:99
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:1224
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: xa.h:92
bool trans_xa_end(THD *thd)
Put a XA transaction in the IDLE state.
Definition: xa.cc:1200
enum xa_option_words m_xa_opt
Definition: xa.h:100
This class represents SQL statement which puts in the PREPARED state an XA transaction with the given...
Definition: xa.h:108
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:1376
Sql_cmd_xa_prepare(xid_t *xid_arg)
Definition: xa.h:110
xid_t * m_xid
Definition: xa.h:121
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: xa.h:112
bool trans_xa_prepare(THD *thd)
Put a XA transaction in the PREPARED state.
Definition: xa.cc:1241
This class represents SQL statement which returns to a client a list of XID's prepared to a XA commit...
Definition: xa.h:129
bool m_print_xid_as_hex
Definition: xa.h:144
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: xa.h:134
bool check_xa_recover_privilege(THD *thd) const
Check if the current user has a privilege to perform XA RECOVER.
Definition: xa.cc:1449
bool trans_xa_recover(THD *thd)
Return the list of XID's to a client, the same way SHOW commands do.
Definition: xa.cc:1401
Sql_cmd_xa_recover(bool print_xid_as_hex)
Definition: xa.h:131
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:1467
This class represents SQL statement which rollbacks and terminates an XA transaction with the given x...
Definition: xa.h:181
xid_t * m_xid
Definition: xa.h:196
Sql_cmd_xa_rollback(xid_t *xid_arg)
Definition: xa.h:183
bool process_internal_xa_rollback(THD *thd, XID_STATE *xid_state)
Handle the statement XA ROLLBACK for the case when xid corresponds to an internal XA transaction,...
Definition: xa.cc:1063
bool process_external_xa_rollback(THD *thd, xid_t *xid, XID_STATE *xid_state)
Handle the statement XA ROLLBACK for the case when xid corresponds to an external XA transaction,...
Definition: xa.cc:942
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: xa.h:185
bool trans_xa_rollback(THD *thd)
Roll back and terminate a XA transaction.
Definition: xa.cc:910
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:1115
This class represents SQL statement which starts an XA transaction with the given xid value.
Definition: xa.h:67
enum xa_option_words m_xa_opt
Definition: xa.h:79
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: xa.h:72
Sql_cmd_xa_start(xid_t *xid_arg, enum xa_option_words xa_option)
Definition: xa.h:69
bool trans_xa_start(THD *thd)
Start a XA transaction with the given xid value.
Definition: xa.cc:1142
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:1180
xid_t * m_xid
Definition: xa.h:78
Representation of an SQL command.
Definition: sql_cmd.h:64
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:945
Definition: transaction_info.h:51
Definition: xa.h:370
void store_xid_info(Protocol *protocol, bool print_xid_as_hex) const
Definition: xa.cc:1529
xa_states
Definition: xa.h:372
@ XA_ACTIVE
Definition: xa.h:374
@ XA_ROLLBACK_ONLY
Definition: xa.h:377
@ XA_IDLE
Definition: xa.h:375
@ XA_PREPARED
Definition: xa.h:376
@ XA_NOTR
Definition: xa.h:373
uint rm_error
Error reported by the Resource Manager (RM) to the Transaction Manager.
Definition: xa.h:400
bool m_is_detached
Definition: xa.h:398
void set_query_id(query_id_t query_id)
Definition: xa.h:432
void cleanup()
Definition: xa.h:440
void reset_error()
Definition: xa.h:438
bool is_binlogged() const
Definition: xa.h:475
bool has_state(xa_states state) const
Definition: xa.h:422
bool is_detached() const
Definition: xa.h:473
bool xa_trans_rolled_back()
Mark a XA transaction as rollback-only if the RM unilaterally rolled back the transaction branch.
Definition: xa.cc:1475
void set_state(xa_states state)
Definition: xa.h:418
void unset_binlogged()
Definition: xa.h:479
bool check_xa_idle_or_prepared(bool report_error) const
Check that XA transaction is in state IDLE or PREPARED.
Definition: xa.cc:1494
XID m_xid
Definition: xa.h:387
void start_detached_xa(const XID *xid, bool binlogged_arg=false)
Definition: xa.h:465
bool m_is_binlogged
Definition: xa.h:409
XID * get_xid()
Definition: xa.h:428
const XID * get_xid() const
Definition: xa.h:426
enum xa_states get_state()
Definition: xa.h:420
const char * state_name() const
Definition: xa.h:424
XID_STATE()
Definition: xa.h:412
xa_states xa_state
Used by external XA only.
Definition: xa.h:397
bool check_has_uncommitted_xa() const
Check that XA transaction has an uncommitted work.
Definition: xa.cc:1505
bool has_same_xid(const XID *xid) const
Definition: xa.h:430
std::mutex m_xa_lock
This mutex used for eliminating a possibility to run two XA COMMIT/XA ROLLBACK statements concurrentl...
Definition: xa.h:394
void start_normal_xa(const XID *xid)
Definition: xa.h:457
void set_binlogged()
Definition: xa.h:477
void reset()
Definition: xa.h:450
static const char * xa_state_names[]
Transaction identifier.
Definition: xa.h:385
void set_error(THD *thd)
Definition: xa.cc:1525
bool check_in_xa(bool report_error) const
Check if an XA transaction has been started.
Definition: xa.cc:1515
std::mutex & get_xa_lock()
Definition: xa.h:416
DBUG_TRACE
Definition: do_ctype.cc:46
static bool report_error(THD *thd, int error_code, Sql_condition::enum_severity_level level, Args... args)
Definition: error_handler.cc:290
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:180
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
int64_t int64
Definition: my_inttypes.h:67
enum_sql_command
Definition: my_sqlcommand.h:45
@ SQLCOM_XA_PREPARE
Definition: my_sqlcommand.h:154
@ SQLCOM_XA_COMMIT
Definition: my_sqlcommand.h:155
@ SQLCOM_XA_ROLLBACK
Definition: my_sqlcommand.h:156
@ SQLCOM_XA_RECOVER
Definition: my_sqlcommand.h:157
@ SQLCOM_XA_END
Definition: my_sqlcommand.h:153
@ SQLCOM_XA_START
Definition: my_sqlcommand.h:152
Definition: buf0block_hint.cc:29
required string type
Definition: replication_group_member_actions.proto:33
ulonglong my_xid
recover() step of xa.
Definition: handler.h:6995
Representation of an SQL command.
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_lex_string.h:39
Definition: handler.h:811
Definition: sql_plugin_ref.h:44
st_mysql_plugin * plugin
Definition: sql_plugin_ref.h:46
Plain structure to store information about XA transaction id and a list of table names involved into ...
Definition: xa.h:365
List< st_handler_tablename > * mod_tables
Definition: xa.h:367
XID id
Definition: xa.h:366
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification,...
Definition: xa.h:216
long get_gtrid_length() const
Definition: xa.h:252
void null()
Definition: xa.h:353
void set_gtrid_length(long v)
Definition: xa.h:254
long bqual_length
value from 1 through 64
Definition: xa.h:231
my_xid get_my_xid() const
Definition: xa.cc:109
bool eq(const xid_t *xid) const
Check if equal to another xid.
Definition: xa.h:338
uint key_length() const
Definition: xa.h:292
long formatID
-1 means that the XID is null
Definition: xa.h:221
char data[XIDDATASIZE]
distributed trx identifier.
Definition: xa.h:236
const char * get_data() const
Definition: xa.h:260
xid_t()
Definition: xa.h:239
long gtrid_length
value from 1 through 64
Definition: xa.h:226
void set(long f, const char *g, long gl, const char *b, long bl)
Definition: xa.h:274
char * serialize(char *buf) const
The method fills XID in a buffer in format of GTRID,BQUAL,FORMATID where GTRID, BQUAL are represented...
Definition: xa.h:315
void set_data(const void *v, long l)
Definition: xa.h:262
void reset()
Definition: xa.h:267
static const uint ser_buf_size
Definition: xa.h:305
void set(const xid_t *xid)
Definition: xa.h:347
const uchar * key() const
Definition: xa.h:288
uchar * key()
Definition: xa.h:286
long get_bqual_length() const
Definition: xa.h:256
void set_format_id(long v)
Definition: xa.h:245
bool is_null() const
Definition: xa.h:344
void set_bqual_length(long v)
Definition: xa.h:258
long get_format_id() const
Definition: xa.h:243
char * xid_to_str(char *buf) const
Get printable XID value.
Definition: xa.cc:1557
unsigned int uint
Definition: uca-dump.cc:29
void transaction_cache_delete(Transaction_ctx *transaction)
Remove information about transaction from a cache.
Definition: xa.cc:1748
bool xa_trans_force_rollback(THD *thd)
Rollback the active XA transaction.
Definition: xa.cc:454
int64 query_id_t
Definition: xa.h:45
struct st_plugin_int * plugin_find_by_type(const LEX_CSTRING &plugin, int type)
Searches for a correctly loaded plugin of a particular type by name.
Definition: sql_plugin.cc:3658
bool detach_native_trx(THD *thd, plugin_ref plugin, void *)
The function detaches existing storage engines transaction context from thd.
Definition: xa.cc:1844
bool transaction_cache_init()
Initialize a cache to store Transaction_ctx and a mutex to protect access to the cache.
Definition: xa.cc:1624
static const int TC_HEURISTIC_RECOVER_ROLLBACK
Definition: xa.h:60
bool transaction_cache_detach(Transaction_ctx *transaction)
Transaction is marked in the cache as if it's recovered.
Definition: xa.cc:1694
struct st_xarecover_txn XA_recover_txn
Plain structure to store information about XA transaction id and a list of table names involved into ...
bool reattach_native_trx(THD *thd, plugin_ref plugin, void *)
The function reattaches existing storage engines transaction context to thd.
Definition: xa.cc:1859
void cleanup_trans_state(THD *thd)
Reset some transaction state information and delete corresponding Transaction_ctx object from cache.
Definition: xa.cc:468
bool applier_reset_xa_trans(THD *thd)
This is a specific to "slave" applier collection of standard cleanup actions to reset XA transaction ...
Definition: xa.cc:1776
bool disconnect_native_trx(THD *, plugin_ref, void *)
Disconnect transaction in SE.
Definition: xa.cc:1879
struct xid_t XID
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification,...
static const int TC_HEURISTIC_NOT_USED
Definition: xa.h:58
static const int TC_HEURISTIC_RECOVER_COMMIT
Definition: xa.h:59
xa_option_words
Definition: xa.h:49
@ XA_JOIN
Definition: xa.h:51
@ XA_RESUME
Definition: xa.h:52
@ XA_NONE
Definition: xa.h:50
@ XA_FOR_MIGRATE
Definition: xa.h:55
@ XA_ONE_PHASE
Definition: xa.h:53
@ XA_SUSPEND
Definition: xa.h:54
ulonglong my_xid
Definition: xa.h:199
void transaction_cache_free()
Release resources occupied by transaction cache.
Definition: xa.cc:1635
#define XIDDATASIZE
Definition: xa.h:206
char * serialize_xid(char *buf, long fmt, long gln, long bln, const char *dat)
Function serializes XID which is characterized by by four last arguments of the function.
Definition: xa_aux.h:45