MySQL  8.0.27
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 
43 class Protocol;
44 class THD;
45 struct xid_t;
46 
47 typedef int64 query_id_t;
48 
56 };
57 
58 static const int TC_HEURISTIC_NOT_USED = 0;
59 static const int TC_HEURISTIC_RECOVER_COMMIT = 1;
60 static 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 
67 class 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 
72  enum_sql_command sql_command_code() const override { return SQLCOM_XA_START; }
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 
87 class 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 
108 class Sql_cmd_xa_prepare : public Sql_cmd {
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 
129 class Sql_cmd_xa_recover : public Sql_cmd {
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 
147 class XID_STATE;
148 /**
149  This class represents SQL statement which commits
150  and terminates an XA transaction with the given xid value.
151 */
152 
153 class Sql_cmd_xa_commit : public Sql_cmd {
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, XID_STATE *xid_state);
169  bool process_internal_xa_commit(THD *thd, XID_STATE *xid_state);
170 
173 };
174 
175 /**
176  This class represents SQL statement which rollbacks and
177  terminates an XA transaction with the given xid value.
178 */
179 
180 class Sql_cmd_xa_rollback : public Sql_cmd {
181  public:
182  explicit Sql_cmd_xa_rollback(xid_t *xid_arg) : m_xid(xid_arg) {}
183 
185  return SQLCOM_XA_ROLLBACK;
186  }
187 
188  bool execute(THD *thd) override;
189 
190  private:
191  bool trans_xa_rollback(THD *thd);
192  bool process_external_xa_rollback(THD *thd, xid_t *xid, XID_STATE *xid_state);
193  bool process_internal_xa_rollback(THD *thd, XID_STATE *xid_state);
194 
196 };
197 
198 typedef ulonglong my_xid; // this line is the same as in log_event.h
199 #define MYSQL_XID_PREFIX "MySQLXid"
200 
201 /*
202  Same as MYSQL_XIDDATASIZE but we do not want to include plugin.h here
203  See static_assert in .cc file.
204 */
205 #define XIDDATASIZE 128
206 
207 /**
208  struct xid_t is binary compatible with the XID structure as
209  in the X/Open CAE Specification, Distributed Transaction Processing:
210  The XA Specification, X/Open Company Ltd., 1991.
211  http://www.opengroup.org/bookstore/catalog/c193.htm
212 
213  @see MYSQL_XID in mysql/plugin.h
214 */
215 typedef struct xid_t {
216  private:
217  /**
218  -1 means that the XID is null
219  */
220  long formatID;
221 
222  /**
223  value from 1 through 64
224  */
226 
227  /**
228  value from 1 through 64
229  */
231 
232  /**
233  distributed trx identifier. not \0-terminated.
234  */
236 
237  public:
239  memset(data, 0, XIDDATASIZE);
240  }
241 
242  long get_format_id() const { return formatID; }
243 
244  void set_format_id(long v) {
245  DBUG_TRACE;
246  DBUG_PRINT("debug", ("SETTING XID_STATE formatID: %ld", v));
247  formatID = v;
248  return;
249  }
250 
251  long get_gtrid_length() const { return gtrid_length; }
252 
253  void set_gtrid_length(long v) { gtrid_length = v; }
254 
255  long get_bqual_length() const { return bqual_length; }
256 
257  void set_bqual_length(long v) { bqual_length = v; }
258 
259  const char *get_data() const { return data; }
260 
261  void set_data(const void *v, long l) {
262  assert(l <= XIDDATASIZE);
263  memcpy(data, v, l);
264  }
265 
266  void reset() {
267  formatID = -1;
268  gtrid_length = 0;
269  bqual_length = 0;
270  memset(data, 0, XIDDATASIZE);
271  }
272 
273  void set(long f, const char *g, long gl, const char *b, long bl) {
274  DBUG_TRACE;
275  DBUG_PRINT("debug", ("SETTING XID_STATE formatID: %ld", f));
276  formatID = f;
277  memcpy(data, g, gtrid_length = gl);
278  bqual_length = bl;
279  if (bl > 0) memcpy(data + gl, b, bl);
280  return;
281  }
282 
283  my_xid get_my_xid() const;
284 
285  uchar *key() { return reinterpret_cast<uchar *>(&gtrid_length); }
286 
287  const uchar *key() const {
288  return reinterpret_cast<const uchar *>(&gtrid_length);
289  }
290 
291  uint key_length() const {
292  return sizeof(gtrid_length) + sizeof(bqual_length) + gtrid_length +
293  bqual_length;
294  }
295 
296  /*
297  The size of the string containing serialized Xid representation
298  is computed as a sum of
299  eight as the number of formatting symbols (X'',X'',)
300  plus 2 x XIDDATASIZE (2 due to hex format),
301  plus space for decimal digits of XID::formatID,
302  plus one for 0x0.
303  */
304  static const uint ser_buf_size = 8 + 2 * XIDDATASIZE + 4 * sizeof(long) + 1;
305 
306  /**
307  The method fills XID in a buffer in format of GTRID,BQUAL,FORMATID
308  where GTRID, BQUAL are represented as hex strings.
309 
310  @param buf a pointer to buffer
311  @return the value of the first argument
312  */
313 
314  char *serialize(char *buf) const {
316  }
317 
318 #ifndef NDEBUG
319  /**
320  Get printable XID value.
321 
322  @param buf pointer to the buffer where printable XID value has to be
323  stored
324 
325  @return pointer to the buffer passed in the first argument
326  */
327  char *xid_to_str(char *buf) const;
328 #endif
329  /**
330  Check if equal to another xid.
331 
332  @param[in] xid the id of another X/Open XA transaction
333 
334  @return true iff formats, gtrid_length, bqual_length and the content of
335  gtrid_length+bqual_length bytes is exactly the same
336  */
337  bool eq(const xid_t *xid) const {
338  return xid->formatID == formatID && xid->gtrid_length == gtrid_length &&
339  xid->bqual_length == bqual_length &&
340  !memcmp(xid->data, data, gtrid_length + bqual_length);
341  }
342 
343  bool is_null() const { return formatID == -1; }
344 
345  private:
346  void set(const xid_t *xid) {
347  memcpy(this, xid, sizeof(xid->formatID) + xid->key_length());
348  }
349 
350  void set(my_xid xid);
351 
352  void null() { formatID = -1; }
353 
354  friend class XID_STATE;
355 } XID;
356 
357 struct st_handler_tablename;
358 
359 /**
360  Plain structure to store information about XA transaction id
361  and a list of table names involved into XA transaction with
362  specified id.
363 */
364 typedef struct st_xarecover_txn {
368 
369 class XID_STATE {
370  public:
371  enum xa_states {
372  XA_NOTR = 0,
377  };
378 
379  /**
380  Transaction identifier.
381  For now, this is only used to catch duplicated external xids.
382  */
383  private:
384  static const char *xa_state_names[];
385 
387  /**
388  This mutex used for eliminating a possibility to run two
389  XA COMMIT/XA ROLLBACK statements concurrently against the same xid value.
390  m_xa_lock is used on handling XA COMMIT/XA ROLLBACK and acquired only for
391  external XA branches.
392  */
393  std::mutex m_xa_lock;
394 
395  /// Used by external XA only
398  /// Error reported by the Resource Manager (RM) to the Transaction Manager.
400  /*
401  XA-prepare binary logging status. The flag serves as a facility
402  to conduct XA transaction two round binary logging.
403  It is set to @c false at XA-start.
404  It is set to @c true by binlogging routine of XA-prepare handler as well
405  as recovered to @c true at the server recovery upon restart.
406  Checked and reset at XA-commit/rollback.
407  */
409 
410  public:
412  : xa_state(XA_NOTR),
413  in_recovery(false),
414  rm_error(0),
415  m_is_binlogged(false) {
416  m_xid.null();
417  }
418 
419  std::mutex &get_xa_lock() { return m_xa_lock; }
420 
421  void set_state(xa_states state) { xa_state = state; }
422 
423  enum xa_states get_state() { return xa_state; }
424 
425  bool has_state(xa_states state) const { return xa_state == state; }
426 
427  const char *state_name() const { return xa_state_names[xa_state]; }
428 
429  const XID *get_xid() const { return &m_xid; }
430 
431  XID *get_xid() { return &m_xid; }
432 
433  bool has_same_xid(const XID *xid) const { return m_xid.eq(xid); }
434 
435  void set_query_id(query_id_t query_id) {
436  if (m_xid.is_null()) m_xid.set(query_id);
437  }
438 
439  void set_error(THD *thd);
440 
441  void reset_error() { rm_error = 0; }
442 
443  void cleanup() {
444  /*
445  If rm_error is raised, it means that this piece of a distributed
446  transaction has failed and must be rolled back. But the user must
447  rollback it explicitly, so don't start a new distributed XA until
448  then.
449  */
450  if (!rm_error) m_xid.null();
451  }
452 
453  void reset() {
454  xa_state = XA_NOTR;
455  m_xid.null();
456  in_recovery = false;
457  m_is_binlogged = false;
458  }
459 
460  void start_normal_xa(const XID *xid) {
461  assert(m_xid.is_null());
463  m_xid.set(xid);
464  in_recovery = false;
465  rm_error = 0;
466  }
467 
468  void start_recovery_xa(const XID *xid, bool binlogged_arg = false) {
470  m_xid.set(xid);
471  in_recovery = true;
472  rm_error = 0;
473  m_is_binlogged = binlogged_arg;
474  }
475 
476  bool is_in_recovery() const { return in_recovery; }
477 
478  bool is_binlogged() const { return m_is_binlogged; }
479 
480  void set_binlogged() { m_is_binlogged = true; }
481 
482  void unset_binlogged() { m_is_binlogged = false; }
483 
484  void store_xid_info(Protocol *protocol, bool print_xid_as_hex) const;
485 
486  /**
487  Mark a XA transaction as rollback-only if the RM unilaterally
488  rolled back the transaction branch.
489 
490  @note If a rollback was requested by the RM, this function sets
491  the appropriate rollback error code and transits the state
492  to XA_ROLLBACK_ONLY.
493 
494  @return true if transaction was rolled back or if the transaction
495  state is XA_ROLLBACK_ONLY. false otherwise.
496  */
497 
498  bool xa_trans_rolled_back();
499 
500  /**
501  Check that XA transaction is in state IDLE or PREPARED.
502 
503  @param report_error true if state IDLE or PREPARED has to be interpreted
504  as an error, else false
505 
506  @return result of check
507  @retval false XA transaction is NOT in state IDLE or PREPARED
508  @retval true XA transaction is in state IDLE or PREPARED
509  */
510 
511  bool check_xa_idle_or_prepared(bool report_error) const;
512 
513  /**
514  Check that XA transaction has an uncommitted work. Report an error
515  to a mysql user in case when there is an uncommitted work for XA
516  transaction.
517 
518  @return result of check
519  @retval false XA transaction is NOT in state IDLE, PREPARED
520  or ROLLBACK_ONLY.
521  @retval true XA transaction is in state IDLE or PREPARED
522  or ROLLBACK_ONLY.
523  */
524 
525  bool check_has_uncommitted_xa() const;
526 
527  /**
528  Check if an XA transaction has been started.
529 
530  @param report_error true if report an error in case when
531  XA transaction has been stared, else false.
532 
533  @return result of check
534  @retval false XA transaction hasn't been started (XA_NOTR)
535  @retval true XA transaction has been started (!XA_NOTR)
536  */
537 
538  bool check_in_xa(bool report_error) const;
539 };
540 
541 /**
542  This class servers as a registry for prepared XA transactions existed before
543  server was shutdown and being resurrected during the server restart.
544  The class is singleton. To collect a list of XA transaction identifiers and
545  a list of tables for that MDL locks have be acquired the method
546  add_prepared_xa_transaction() must be called. This method is invoked by
547  the function trx_recover_for_mysql() called by innobase_xa_recover during
548  running of X/Open XA distributed transaction recovery procedure. After a list
549  of XA transaction identifiers and a list of table names to be locked in MDL
550  have been collected and the function ha_recover() has returned control flow
551  the method recover_prepared_xa_transactions() must be called to resurrect
552  prepared XA transactions. Separation of collecting information about prepared
553  XA transactions from restoring XA transactions is done in order to exclude
554  possible suspending on MDL locks inside the function
555  dd::reset_tables_and_tablespaces() that is called right after the function
556  ha_recover() returns control flow.
557  */
558 
560  public:
561  /**
562  Initialize singleton.
563  */
564  static bool init();
565 
566  /**
567  Cleanup and delete singleton object
568  */
569  static void destroy();
570 
571  /**
572  Get instance of the class Recovered_xa_transactions
573  */
575 
576  /**
577  Add information about prepared XA transaction into a list of
578  XA transactions to resurrect.
579 
580  @param prepared_xa_trn information about prepared XA transaction
581 
582  @return false on success, else true
583  */
584  bool add_prepared_xa_transaction(XA_recover_txn *prepared_xa_trn);
585 
586  /**
587  Iterate along a list of prepared XA transactions, register every XA
588  transaction in a cache and acquire MDL locks for every table taking part in
589  XA transaction being resurrected.
590 
591  @return false on success, else true
592  */
594 
595  /**
596  Get initialized MEM_ROOT.
597 
598  @return Pointer to a initialized MEM_ROOT.
599  */
601 
602  private:
603  // Disable direct instantiation. Use the method init() instead.
605 
607  std::list<XA_recover_txn *, Malloc_allocator<XA_recover_txn *>>
611 };
612 
613 class Transaction_ctx;
614 
615 /**
616  Initialize a cache to store Transaction_ctx and a mutex to protect access
617  to the cache
618 
619  @return result of initialization
620  @retval false success
621  @retval true failure
622 */
623 
625 
626 /**
627  Transaction is marked in the cache as if it's recovered.
628  The method allows to sustain prepared transaction disconnection.
629 
630  @param transaction
631  Pointer to Transaction object that is replaced.
632 
633  @return operation result
634  @retval false success or a cache already contains XID_STATE
635  for this XID value
636  @retval true failure
637 */
638 
639 bool transaction_cache_detach(Transaction_ctx *transaction);
640 
641 /**
642  Remove information about transaction from a cache.
643 
644  @param transaction Pointer to a Transaction_ctx that has to be removed
645  from a cache.
646 */
647 
648 void transaction_cache_delete(Transaction_ctx *transaction);
649 
650 /**
651  Release resources occupied by transaction cache.
652 */
653 
655 
656 /**
657  This is a specific to "slave" applier collection of standard cleanup
658  actions to reset XA transaction state at the end of XA prepare rather than
659  to do it at the transaction commit, see @c ha_commit_one_phase.
660  THD of the slave applier is dissociated from a transaction object in engine
661  that continues to exist there.
662 
663  @param thd current thread
664  @return the value of is_error()
665 */
666 
667 bool applier_reset_xa_trans(THD *thd);
668 
669 /* interface to randomly access plugin data */
671 
672 /**
673  The function detaches existing storage engines transaction
674  context from thd. Backup area to save it is provided to low level
675  storage engine function.
676 
677  is invoked by plugin_foreach() after
678  trans_xa_start() for each storage engine.
679 
680  @param[in,out] thd Thread context
681  @param plugin Reference to handlerton
682 
683  @return false on success, true otherwise.
684 */
685 
686 bool detach_native_trx(THD *thd, plugin_ref plugin, void *);
687 
688 /**
689  The function reattaches existing storage engines transaction
690  context to thd. Backup area to save it is provided to low level
691  storage engine function.
692 
693  is invoked by plugin_foreach() after
694  trans_xa_prepare() for each storage engine.
695 
696  @param[in,out] thd Thread context
697  @param plugin Reference to handlerton
698 
699  @return false on success,
700  true otherwise.
701 */
702 
703 bool reattach_native_trx(THD *thd, plugin_ref plugin, void *);
704 
705 /**
706  Reset some transaction state information and delete corresponding
707  Transaction_ctx object from cache.
708 
709  @param thd Current thread
710 */
711 
712 void cleanup_trans_state(THD *thd);
713 
714 /**
715  Rollback the active XA transaction.
716 
717  @note Resets rm_error before calling ha_rollback(), so
718  the thd->transaction.xid structure gets reset
719  by ha_rollback() / THD::transaction::cleanup().
720 
721  @return true if the rollback failed, false otherwise.
722 */
723 
724 bool xa_trans_force_rollback(THD *thd);
725 #endif
int64 query_id_t
Definition: binlog.h:70
Definition: protocol.h:32
This class servers as a registry for prepared XA transactions existed before server was shutdown and ...
Definition: xa.h:559
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:292
MEM_ROOT * get_allocated_memroot()
Get initialized MEM_ROOT.
Definition: xa.cc:240
std::list< XA_recover_txn *, Malloc_allocator< XA_recover_txn * > > m_prepared_xa_trans
Definition: xa.h:608
MEM_ROOT m_mem_root
Definition: xa.h:610
static Recovered_xa_transactions * m_instance
Definition: xa.h:606
Recovered_xa_transactions()
Definition: xa.cc:203
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:222
static Recovered_xa_transactions & instance()
Get instance of the class Recovered_xa_transactions.
Definition: xa.cc:208
static bool init()
Initialize singleton.
Definition: xa.cc:212
static void destroy()
Cleanup and delete singleton object.
Definition: xa.cc:217
bool m_mem_root_inited
Definition: xa.h:609
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:529
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
enum xa_option_words get_xa_opt() const
Definition: xa.h:164
enum xa_option_words m_xa_opt
Definition: xa.h:172
bool process_external_xa_commit(THD *thd, xid_t *xid, XID_STATE *xid_state)
Handle the statement XA COMMIT for the case when xid corresponds to an external XA transaction,...
Definition: xa.cc:604
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:742
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:837
xid_t * m_xid
Definition: xa.h:171
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:1171
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:1147
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:1247
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:1188
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:1321
bool trans_xa_recover(THD *thd)
Return the list of XID's to a client, the same way SHOW commands do.
Definition: xa.cc:1273
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:1339
This class represents SQL statement which rollbacks and terminates an XA transaction with the given x...
Definition: xa.h:180
xid_t * m_xid
Definition: xa.h:195
Sql_cmd_xa_rollback(xid_t *xid_arg)
Definition: xa.h:182
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:1010
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:894
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: xa.h:184
bool trans_xa_rollback(THD *thd)
Roll back and terminate a XA transaction.
Definition: xa.cc:862
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:1062
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:1089
bool execute(THD *thd) override
Execute this SQL statement.
Definition: xa.cc:1127
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:821
Definition: transaction_info.h:51
Definition: xa.h:369
void store_xid_info(Protocol *protocol, bool print_xid_as_hex) const
Definition: xa.cc:1401
std::mutex & get_xa_lock()
Definition: xa.h:419
xa_states
Definition: xa.h:371
@ XA_ACTIVE
Definition: xa.h:373
@ XA_ROLLBACK_ONLY
Definition: xa.h:376
@ XA_IDLE
Definition: xa.h:374
@ XA_PREPARED
Definition: xa.h:375
@ XA_NOTR
Definition: xa.h:372
XID * get_xid()
Definition: xa.h:431
uint rm_error
Error reported by the Resource Manager (RM) to the Transaction Manager.
Definition: xa.h:399
void set_query_id(query_id_t query_id)
Definition: xa.h:435
const char * state_name() const
Definition: xa.h:427
void cleanup()
Definition: xa.h:443
void reset_error()
Definition: xa.h:441
bool is_binlogged() const
Definition: xa.h:478
bool has_state(xa_states state) const
Definition: xa.h:425
bool xa_trans_rolled_back()
Mark a XA transaction as rollback-only if the RM unilaterally rolled back the transaction branch.
Definition: xa.cc:1347
void set_state(xa_states state)
Definition: xa.h:421
void unset_binlogged()
Definition: xa.h:482
bool check_xa_idle_or_prepared(bool report_error) const
Check that XA transaction is in state IDLE or PREPARED.
Definition: xa.cc:1366
XID m_xid
Definition: xa.h:386
bool m_is_binlogged
Definition: xa.h:408
void start_recovery_xa(const XID *xid, bool binlogged_arg=false)
Definition: xa.h:468
enum xa_states get_state()
Definition: xa.h:423
XID_STATE()
Definition: xa.h:411
xa_states xa_state
Used by external XA only.
Definition: xa.h:396
bool check_has_uncommitted_xa() const
Check that XA transaction has an uncommitted work.
Definition: xa.cc:1377
bool has_same_xid(const XID *xid) const
Definition: xa.h:433
std::mutex m_xa_lock
This mutex used for eliminating a possibility to run two XA COMMIT/XA ROLLBACK statements concurrentl...
Definition: xa.h:393
void start_normal_xa(const XID *xid)
Definition: xa.h:460
void set_binlogged()
Definition: xa.h:480
void reset()
Definition: xa.h:453
static const char * xa_state_names[]
Transaction identifier.
Definition: xa.h:384
void set_error(THD *thd)
Definition: xa.cc:1397
bool in_recovery
Definition: xa.h:397
bool check_in_xa(bool report_error) const
Check if an XA transaction has been started.
Definition: xa.cc:1387
bool is_in_recovery() const
Definition: xa.h:476
const XID * get_xid() const
Definition: xa.h:429
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:168
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:6931
Representation of an SQL command.
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
Definition: mysql_lex_string.h:39
Definition: handler.h:805
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:364
List< st_handler_tablename > * mod_tables
Definition: xa.h:366
XID id
Definition: xa.h:365
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification,...
Definition: xa.h:215
long get_gtrid_length() const
Definition: xa.h:251
void null()
Definition: xa.h:352
void set_gtrid_length(long v)
Definition: xa.h:253
long bqual_length
value from 1 through 64
Definition: xa.h:230
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:337
uint key_length() const
Definition: xa.h:291
long formatID
-1 means that the XID is null
Definition: xa.h:220
char data[XIDDATASIZE]
distributed trx identifier.
Definition: xa.h:235
xid_t()
Definition: xa.h:238
long gtrid_length
value from 1 through 64
Definition: xa.h:225
void set(long f, const char *g, long gl, const char *b, long bl)
Definition: xa.h:273
void set_data(const void *v, long l)
Definition: xa.h:261
void reset()
Definition: xa.h:266
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:314
static const uint ser_buf_size
Definition: xa.h:304
void set(const xid_t *xid)
Definition: xa.h:346
uchar * key()
Definition: xa.h:285
long get_bqual_length() const
Definition: xa.h:255
void set_format_id(long v)
Definition: xa.h:244
bool is_null() const
Definition: xa.h:343
void set_bqual_length(long v)
Definition: xa.h:257
const uchar * key() const
Definition: xa.h:287
long get_format_id() const
Definition: xa.h:242
char * xid_to_str(char *buf) const
Get printable XID value.
Definition: xa.cc:1429
const char * get_data() const
Definition: xa.h:259
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:1608
bool xa_trans_force_rollback(THD *thd)
Rollback the active XA transaction.
Definition: xa.cc:436
int64 query_id_t
Definition: xa.h:45
bool detach_native_trx(THD *thd, plugin_ref plugin, void *)
The function detaches existing storage engines transaction context from thd.
Definition: xa.cc:1704
bool transaction_cache_init()
Initialize a cache to store Transaction_ctx and a mutex to protect access to the cache.
Definition: xa.cc:1496
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:1556
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:1719
void cleanup_trans_state(THD *thd)
Reset some transaction state information and delete corresponding Transaction_ctx object from cache.
Definition: xa.cc:450
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:3697
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:1636
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:198
void transaction_cache_free()
Release resources occupied by transaction cache.
Definition: xa.cc:1507
#define XIDDATASIZE
Definition: xa.h:205
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