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