![]() |
MySQL 8.0.29
Source Code Documentation
|
#include "sql/xa.h"
#include <memory>
#include <new>
#include <string>
#include <unordered_map>
#include <utility>
#include "m_ctype.h"
#include "m_string.h"
#include "map_helpers.h"
#include "my_dbug.h"
#include "my_loglevel.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/plugin.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_transaction.h"
#include "mysql/service_mysql_alloc.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_replica_commit_order_manager.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.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_string.h"
#include "template_utils.h"
#include "thr_mutex.h"
Classes | |
struct | transaction_free_hash |
struct | xarecover_st |
Functions | |
static std::string | to_string (const XID &xid) |
static void | attach_native_trx (THD *thd) |
The function restores previously saved storage engine transaction context. More... | |
static bool | transaction_cache_insert (XID *xid, Transaction_ctx *transaction) |
Insert information about XA transaction into a cache indexed by XID. More... | |
static bool | transaction_cache_insert_recovery (XID *xid) |
Insert information about XA transaction being recovered into a cache indexed by XID. More... | |
static bool | xacommit_handlerton (THD *, plugin_ref plugin, void *arg) |
static bool | xarollback_handlerton (THD *, plugin_ref plugin, void *arg) |
static bool | ha_commit_or_rollback_by_xid (XID *xid, bool commit) |
static bool | xarecover_create_mdl_backup (XA_recover_txn &txn, MEM_ROOT *mem_root) |
static bool | xarecover_handlerton (THD *, plugin_ref plugin, void *arg) |
int | ha_recover (const mem_root_unordered_set< my_xid > *commit_list) |
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... | |
static 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... | |
static bool | acquire_mandatory_metadata_locks (THD *thd, xid_t *external_xid) |
Acquire Commit metadata lock and all locks acquired by a prepared XA transaction before server was shutdown or terminated. More... | |
static void | init_transaction_cache_psi_keys (void) |
bool | transaction_cache_init () |
Initialize a cache to store Transaction_ctx and a mutex to protect access to the cache. More... | |
void | transaction_cache_free () |
Release resources occupied by transaction cache. More... | |
bool | create_and_insert_new_transaction (XID *xid, bool is_binlogged_arg, const Transaction_ctx *src) |
bool | transaction_cache_detach (Transaction_ctx *transaction) |
Transaction is marked in the cache as if it's recovered. More... | |
void | transaction_cache_delete (Transaction_ctx *transaction) |
Remove information about transaction from a cache. 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... | |
Variables | |
static const int | MIN_XID_LIST_SIZE = 128 |
static const int | MAX_XID_LIST_SIZE = 1024 * 128 |
static bool | inited = false |
static mysql_mutex_t | LOCK_transaction_cache |
static malloc_unordered_map< std::string, std::shared_ptr< Transaction_ctx > > | transaction_cache {key_memory_xa_transaction_contexts} |
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) |
static PSI_mutex_key | key_LOCK_transaction_cache |
static PSI_mutex_info | transaction_cache_mutexes [] |
Acquire Commit metadata lock and all locks acquired by a prepared XA transaction before server was shutdown or terminated.
thd | Thread context |
external_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 |
|
inline |
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.
|
static |
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 |
|
static |
int ha_recover | ( | const mem_root_unordered_set< my_xid > * | commit_list | ) |
|
static |
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 |
|
static |
void transaction_cache_delete | ( | Transaction_ctx * | transaction | ) |
Remove information about transaction from a cache.
transaction | Pointer to a Transaction_ctx that has to be removed from a cache. |
bool transaction_cache_detach | ( | Transaction_ctx * | transaction | ) |
Transaction is marked in the cache as if it's recovered.
The method allows to sustain prepared transaction disconnection.
transaction | Pointer to Transaction object that is replaced. |
false | success or a cache already contains XID_STATE for this XID value |
true | failure |
void transaction_cache_free | ( | ) |
Release resources occupied by transaction cache.
bool transaction_cache_init | ( | ) |
Initialize a cache to store Transaction_ctx and a mutex to protect access to the cache.
false | success |
true | failure |
|
static |
Insert information about XA transaction into a cache indexed by XID.
xid | Pointer to a XID structure that identifies a XA transaction. |
transaction | Pointer to Transaction object that is inserted. |
false | success or a cache already contains XID_STATE for this XID value |
true | failure |
|
static |
Insert information about XA transaction being recovered into a cache indexed by XID.
xid | Pointer to a XID structure that identifies a XA transaction. |
false | success or a cache already contains Transaction_ctx for this XID value |
true | failure |
bool xa_trans_force_rollback | ( | THD * | thd | ) |
Rollback the active XA transaction.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |