MySQL 9.1.0
Source Code Documentation
|
#include "sql/xa.h"
#include <memory>
#include <new>
#include <string>
#include <unordered_map>
#include <utility>
#include "dig_vec.h"
#include "map_helpers.h"
#include "my_dbug.h"
#include "my_macros.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "mysql/components/services/bits/mysql_mutex_bits.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/bits/psi_mutex_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/my_loglevel.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_transaction.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "scope_guard.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/binlog.h"
#include "sql/clone_handler.h"
#include "sql/debug_sync.h"
#include "sql/handler.h"
#include "sql/item.h"
#include "sql/log.h"
#include "sql/mdl.h"
#include "sql/mdl_context_backup.h"
#include "sql/mysqld.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h"
#include "sql/query_options.h"
#include "sql/rpl_context.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_handler.h"
#include "sql/rpl_replica_commit_order_manager.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_plugin.h"
#include "sql/sql_table.h"
#include "sql/system_variables.h"
#include "sql/tc_log.h"
#include "sql/transaction.h"
#include "sql/transaction_info.h"
#include "sql/xa/recovery.h"
#include "sql/xa/sql_xa_commit.h"
#include "sql/xa/transaction_cache.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "template_utils.h"
#include "thr_mutex.h"
Functions | |
static void | attach_native_trx (THD *thd) |
The function restores previously saved storage engine transaction context. More... | |
std::ostream & | operator<< (std::ostream &out, struct xid_t const &in) |
static bool | xarecover_create_mdl_backup (XA_recover_txn &txn, MEM_ROOT *mem_root) |
int | ha_recover (Xid_commit_list *commit_list, Xa_state_list *xa_list) |
Stage of the recovery process where information is collected from the storage engines (SE), merged with information from the transaction coordinator (TC) and transactions states are determined and enforced. More... | |
bool | xa_trans_force_rollback (THD *thd) |
Rollback the active XA transaction. More... | |
void | cleanup_trans_state (THD *thd) |
Reset some transaction state information and delete corresponding Transaction_ctx object from cache. More... | |
std::shared_ptr< Transaction_ctx > | find_trn_for_recover_and_check_its_state (THD *thd, xid_t *xid_for_trn_in_recover, XID_STATE *xid_state) |
Find XA transaction in cache by its xid value. More... | |
bool | acquire_mandatory_metadata_locks (THD *thd, xid_t *detached_xid) |
Acquire Commit metadata lock and all locks acquired by a prepared XA transaction before server was shutdown or terminated. More... | |
bool | applier_reset_xa_trans (THD *thd) |
This is a specific to "slave" applier collection of standard cleanup actions to reset XA transaction state at the end of XA prepare rather than to do it at the transaction commit, see ha_commit_one_phase . More... | |
bool | detach_native_trx (THD *thd, plugin_ref plugin, void *) |
The function detaches existing storage engines transaction context from thd. More... | |
bool | reattach_native_trx (THD *thd, plugin_ref plugin, void *) |
The function reattaches existing storage engines transaction context to thd. More... | |
bool | disconnect_native_trx (THD *thd, plugin_ref plugin, void *) |
Disconnect transaction in SE. More... | |
bool | thd_holds_xa_transaction (THD *thd) |
Test if the THD session underlying transaction is an externally coordinated (XA) transaction. More... | |
bool | is_xa_prepare (THD *thd) |
Checks whether or not the underlying statement is an XA PREPARE . More... | |
bool | is_xa_rollback (THD *thd) |
Checks whether or not the underlying statement is an XA ROLLBACK . More... | |
Variables | |
static const int | MIN_XID_LIST_SIZE = 128 |
static const int | MAX_XID_LIST_SIZE = 1024 * 128 |
static const uint | MYSQL_XID_PREFIX_LEN = 8 |
static const uint | MYSQL_XID_OFFSET = MYSQL_XID_PREFIX_LEN + sizeof(server_id) |
static const uint | MYSQL_XID_GTRID_LEN = MYSQL_XID_OFFSET + sizeof(my_xid) |
Acquire Commit metadata lock and all locks acquired by a prepared XA transaction before server was shutdown or terminated.
thd | Thread context |
detached_xid | XID value specified by XA COMMIT or XA ROLLBACK that corresponds to a XA transaction generated outside current session context. |
false | Success |
true | Failure |
bool applier_reset_xa_trans | ( | THD * | thd | ) |
This is a specific to "slave" applier collection of standard cleanup actions to reset XA transaction state at the end of XA prepare rather than to do it at the transaction commit, see ha_commit_one_phase
.
THD of the slave applier is dissociated from a transaction object in engine that continues to exist there.
thd | current thread |
|
static |
The function restores previously saved storage engine transaction context.
thd | Thread context |
void cleanup_trans_state | ( | THD * | thd | ) |
Reset some transaction state information and delete corresponding Transaction_ctx object from cache.
thd | Current thread |
bool detach_native_trx | ( | THD * | thd, |
plugin_ref | plugin, | ||
void * | |||
) |
The function detaches existing storage engines transaction context from thd.
Backup area to save it is provided to low level storage engine function.
is invoked by plugin_foreach() after trans_xa_start() for each storage engine.
[in,out] | thd | Thread context |
plugin | Reference to handlerton |
bool disconnect_native_trx | ( | THD * | thd, |
plugin_ref | plugin, | ||
void * | |||
) |
Disconnect transaction in SE.
This the same action which is performed by SE when disconnecting a connection which has a prepared XA transaction, when xa_detach_on_prepare is OFF. Signature matches that required by plugin_foreach.
std::shared_ptr< Transaction_ctx > find_trn_for_recover_and_check_its_state | ( | THD * | thd, |
xid_t * | xid_for_trn_in_recover, | ||
XID_STATE * | xid_state | ||
) |
Find XA transaction in cache by its xid value.
thd | Thread context |
xid_for_trn_in_recover | xid value to look for in transaction cache |
xid_state | State of XA transaction in current session |
int ha_recover | ( | Xid_commit_list * | commit_list = nullptr , |
Xa_state_list * | xa_state_list = nullptr |
||
) |
Stage of the recovery process where information is collected from the storage engines (SE), merged with information from the transaction coordinator (TC) and transactions states are determined and enforced.
Implemented heuristics is as follows:
commit_list
parameter contains the set of internally coordinated transactions that the TC ensures were marked as committed.xa_state_list
parameter contains the list of externally coordinated transactions and their states, as recorded by the TC.For each SE: a. Collect list of transactions found in PREPARED_IN_TC
state in the SE and merge it with the information collected from the TC, in xa_state_list
. b. Retrieve the list of transactions found in prepared state in the SE.
c. For each internally coordinated transactions found in prepared state:
commit_list
, commit it.commit_list
but tc_heuristic_recover = TC_HEURISTIC_RECOVER_COMMIT
, commit it.d. For each externally coordinated transactions found in prepared state:
xa_state_list
, roll it back.xa_state_list
in COMMITTED
state, commit it.xa_state_list
in ROLLEDBACK
state, roll it back.xa_state_list
in PREPARED
state, ensure that the transaction state in the SE is PREPARED_IN_TC
.commit_list | Set of XIDs of internally coordinated transactions found as been committed in the transaction coordinator state. |
xa_state_list | Map between XIDs and states of externally coordinated transactions as found in the internal transaction coordinator state. |
bool is_xa_prepare | ( | THD * | thd | ) |
Checks whether or not the underlying statement is an XA PREPARE
.
thd | THD session object. |
XA PREPARE
, false if not bool is_xa_rollback | ( | THD * | thd | ) |
Checks whether or not the underlying statement is an XA ROLLBACK
.
thd | THD session object. |
XA ROLLBACK
, false if not std::ostream & operator<< | ( | std::ostream & | out, |
struct xid_t const & | in | ||
) |
out | The stream to write the XID representation to |
in | The XID for which the string representation should be written |
bool reattach_native_trx | ( | THD * | thd, |
plugin_ref | plugin, | ||
void * | |||
) |
The function reattaches existing storage engines transaction context to thd.
Backup area to save it is provided to low level storage engine function.
is invoked by plugin_foreach() after trans_xa_prepare() for each storage engine.
[in,out] | thd | Thread context |
plugin | Reference to handlerton |
bool thd_holds_xa_transaction | ( | THD * | thd | ) |
Test if the THD session underlying transaction is an externally coordinated (XA) transaction.
thd | The session THD object holding the transaction to be tested. |
bool xa_trans_force_rollback | ( | THD * | thd | ) |
Rollback the active XA transaction.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |