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