MySQL 9.1.0
Source Code Documentation
trx0trx.cc File Reference

The transaction. More...

#include <sys/types.h>
#include <time.h>
#include <algorithm>
#include <new>
#include <set>
#include <sql_thd_internal_api.h>
#include "btr0sea.h"
#include "clone0clone.h"
#include "current_thd.h"
#include "dict0dd.h"
#include "fsp0sysspace.h"
#include "ha_prototypes.h"
#include "lock0lock.h"
#include "log0chkp.h"
#include "log0write.h"
#include "os0proc.h"
#include "que0que.h"
#include "read0read.h"
#include "row0mysql.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "trx0purge.h"
#include "trx0rec.h"
#include "trx0roll.h"
#include "trx0rseg.h"
#include "trx0trx.h"
#include "trx0undo.h"
#include "trx0xa.h"
#include "usr0sess.h"
#include "ut0new.h"
#include "ut0pool.h"
#include "ut0vec.h"
#include "my_dbug.h"
#include "mysql/plugin.h"
#include "sql/clone_handler.h"

Classes

struct  TrxFactory
 For managing the life-cycle of the trx_t instance that we get from the pool. More...
 
struct  TrxPoolLock
 The lock strategy for TrxPool. More...
 
struct  TrxPoolManagerLock
 The lock strategy for the TrxPoolManager. More...
 

Typedefs

typedef std::set< table_id_t, std::less< table_id_t >, ut::allocator< table_id_t > > table_id_set
 Set of table_id. More...
 
typedef std::map< trx_t *, table_id_set, std::less< trx_t * >, ut::allocator< std::pair< trx_t *const, table_id_set > > > trx_table_map
 Map of transactions to affected table_id. More...
 
typedef Pool< trx_t, TrxFactory, TrxPoolLocktrx_pool_t
 Use explicit mutexes for the trx_t pool and its manager. More...
 
typedef PoolManager< trx_pool_t, TrxPoolManagerLocktrx_pools_t
 

Functions

static void trx_release_impl_and_expl_locks (trx_t *trx, bool serialised)
 
static void trx_flush_logs (trx_t *trx, lsn_t lsn)
 Tests the durability settings and flushes logs if needed. More...
 
void trx_set_flush_observer (trx_t *trx, Flush_observer *observer)
 Set flush observer for the transaction. More...
 
void trx_set_detailed_error (trx_t *trx, const char *msg)
 Set detailed error message for the transaction. More...
 
void trx_set_detailed_error_from_file (trx_t *trx, FILE *file)
 Set detailed error message for the transaction from a file. More...
 
static void trx_init (trx_t *trx)
 Initialize transaction object. More...
 
void trx_pool_init ()
 Create the trx_t pool. More...
 
void trx_pool_close ()
 Destroy the trx_t pool. More...
 
static trx_ttrx_create_low ()
 
static void trx_free (trx_t *&trx)
 Release a trx_t instance back to the pool. More...
 
trx_ttrx_allocate_for_background (void)
 Creates a transaction object for background operations by the master thread. More...
 
trx_ttrx_allocate_for_mysql (void)
 Creates a transaction object for MySQL. More...
 
static void trx_validate_state_before_free (trx_t *trx)
 Check state of transaction before freeing it. More...
 
void trx_free_resurrected (trx_t *trx)
 Free and initialize a transaction object instantiated during recovery. More...
 
void trx_free_for_background (trx_t *trx)
 Free a transaction that was allocated by background or user threads. More...
 
void trx_free_prepared_or_active_recovered (trx_t *trx)
 At shutdown, frees a transaction object that represents either: More...
 
void trx_disconnect_from_mysql (trx_t *trx, bool prepared)
 Disconnect a transaction from MySQL. More...
 
void trx_disconnect_plain (trx_t *trx)
 Disconnect a transaction from MySQL. More...
 
void trx_disconnect_prepared (trx_t *trx)
 Disconnect a prepared transaction from MySQL. More...
 
void trx_free_for_mysql (trx_t *trx)
 Free a transaction object for MySQL. More...
 
static void trx_resurrect_table_ids (trx_t *trx, const trx_undo_ptr_t *undo_ptr, const trx_undo_t *undo)
 Resurrect the table IDs for a resurrected transaction. More...
 
void trx_resurrect_locks (bool all)
 Resurrect table locks for resurrected transactions. More...
 
void trx_clear_resurrected_table_ids ()
 Clear all resurrected table IDs. More...
 
static trx_ttrx_resurrect_insert (trx_undo_t *undo, trx_rseg_t *rseg)
 Resurrect the transactions that were doing inserts at the time of the crash, they need to be undone. More...
 
static void trx_resurrect_update_in_prepared_state (trx_t *trx, const trx_undo_t *undo)
 Prepared transactions are left in the prepared state waiting for a commit or abort decision from MySQL. More...
 
static void trx_resurrect_update (trx_t *trx, trx_undo_t *undo, trx_rseg_t *rseg)
 Resurrect the transactions that were doing updates the time of the crash, they need to be undone. More...
 
static void trx_resurrect (trx_rseg_t *rseg)
 Resurrect the transactions that were doing inserts and updates at the time of a crash, they need to be undone. More...
 
static void trx_add_to_rw_trx_list (trx_t *trx)
 Adds the transaction to trx_sys->rw_trx_list Requires trx_sys->mutex, unless called in the single threaded startup code. More...
 
static void trx_remove_from_rw_trx_list (trx_t *trx)
 Removes the transaction from trx_sys->rw_trx_list. More...
 
void trx_lists_init_at_db_start (void)
 Creates trx objects for transactions and initializes the trx list of trx_sys at database start. More...
 
static trx_rseg_tget_next_redo_rseg_from_undo_spaces ()
 Get next redo rollback segment in round-robin fashion. More...
 
static trx_rseg_tget_next_redo_rseg_from_trx_sys ()
 Get the next redo rollback segment in round-robin fashion. More...
 
static trx_rseg_tget_next_redo_rseg ()
 Get next redo rollback segment in round-robin fashion. More...
 
static trx_rseg_tget_next_temp_rseg ()
 Get the next noredo rollback segment. More...
 
void trx_assign_rseg_durable (trx_t *trx)
 Assign a durable rollback segment to a transaction in a round-robin fashion. More...
 
void trx_assign_rseg_temp (trx_t *trx)
 Assign a temp-tablespace bound rollback-segment to a transaction. More...
 
static void trx_start_low (trx_t *trx, bool read_write)
 Starts a transaction. More...
 
static bool trx_add_to_serialisation_list (trx_t *trx)
 Assigns the trx->no and add the transaction to the serialisation_list. More...
 
static void trx_erase_from_serialisation_list_low (trx_t *trx)
 Erases transaction from the serialisation_list. More...
 
static bool trx_serialisation_number_get (trx_t *trx, trx_undo_ptr_t *redo_rseg_undo_ptr, trx_undo_ptr_t *temp_rseg_undo_ptr)
 Set the transaction serialisation number. More...
 
static bool trx_write_serialisation_history (trx_t *trx, mtr_t *mtr)
 Assign the transaction its history serialisation number and write the update UNDO log record to the assigned rollback segment. More...
 
static void trx_finalize_for_fts_table (fts_trx_table_t *ftt)
 
static void trx_finalize_for_fts (trx_t *trx, bool is_commit)
 Finalize a transaction containing updates to FTS tables. More...
 
static void trx_flush_log_if_needed_low (lsn_t lsn)
 If required, flushes the log to disk based on the value of innodb_flush_log_at_trx_commit. More...
 
static void trx_flush_log_if_needed (lsn_t lsn, trx_t *trx)
 If required, flushes the log to disk based on the value of innodb_flush_log_at_trx_commit. More...
 
static void trx_update_mod_tables_timestamp (trx_t *trx)
 For each table that has been modified by the given transaction: update its dict_table_t::update_time with the current timestamp. More...
 
static void trx_erase_lists (trx_t *trx)
 Erase the transaction from running transaction lists and serialization list. More...
 
static void trx_commit_in_memory (trx_t *trx, const mtr_t *mtr, bool serialised)
 Commits a transaction in memory. More...
 
void trx_commit_low (trx_t *trx, mtr_t *mtr)
 Commits a transaction and a mini-transaction. More...
 
void trx_commit (trx_t *trx)
 Commits a transaction. More...
 
void trx_cleanup_at_db_startup (trx_t *trx)
 Cleans up a transaction at database startup. More...
 
ReadViewtrx_assign_read_view (trx_t *trx)
 Assigns a read view for a consistent read query. More...
 
void trx_commit_or_rollback_prepare (trx_t *trx)
 Prepares a transaction for commit/rollback. More...
 
commit_node_ttrx_commit_node_create (mem_heap_t *heap)
 Creates a commit command node struct. More...
 
que_thr_ttrx_commit_step (que_thr_t *thr)
 Performs an execution step for a commit type node in a query graph. More...
 
dberr_t trx_commit_for_mysql (trx_t *trx)
 Does the transaction commit for MySQL. More...
 
void trx_commit_complete_for_mysql (trx_t *trx)
 If required, flushes the log to disk if we called trx_commit_for_mysql() with trx->flush_log_later == true. More...
 
void trx_mark_sql_stat_end (trx_t *trx)
 Marks the latest SQL statement ended. More...
 
void trx_print_low (FILE *f, const trx_t *trx, ulint max_query_len, ulint n_rec_locks, ulint n_trx_locks, ulint heap_size)
 Prints info about a transaction. More...
 
void trx_print_latched (FILE *f, const trx_t *trx, ulint max_query_len)
 Prints info about a transaction. More...
 
void trx_print (FILE *f, const trx_t *trx, ulint max_query_len)
 Prints info about a transaction. More...
 
bool trx_can_be_handled_by_current_thread (const trx_t *trx)
 Determines if trx can be handled by current thread, which is when trx->mysql_thd is nullptr (a "background" trx) or equals current_thd. More...
 
bool trx_can_be_handled_by_current_thread_or_is_hp_victim (const trx_t *trx)
 Determines if trx can be handled by current thread, which is when trx->mysql_thd is nullptr (a "background" trx) or equals current_thd, or is a victim being killed by HP transaction run by the current thread. More...
 
bool trx_assert_started (const trx_t *trx)
 Asserts that a transaction has been started. More...
 
void trx_before_mutex_enter (const trx_t *trx, bool first_of_two)
 Verifies the invariants and records debug state related to latching rules. More...
 
void trx_before_mutex_exit (const trx_t *trx)
 Verifies the invariants and records debug state related to latching rules. More...
 
bool trx_weight_ge (const trx_t *a, const trx_t *b)
 Compares the "weight" (or size) of two transactions. More...
 
static lsn_t trx_prepare_low (trx_t *trx, trx_undo_ptr_t *undo_ptr, bool noredo_logging)
 Prepares a transaction for given rollback segment. More...
 
bool trx_is_mysql_xa (const trx_t *trx)
 Check if transaction is internal XA transaction. More...
 
static void trx_prepare (trx_t *trx)
 Prepares a transaction. More...
 
static lsn_t trx_set_prepared_in_tc_low (trx_t *trx, trx_undo_ptr_t *undo_ptr)
 Sets the transaction as prepared in the transaction coordinator for the given rollback segment. More...
 
static void trx_set_prepared_in_tc (trx_t *trx)
 Marks a transaction as prepared in the transaction coordinator. More...
 
dberr_t trx_prepare_for_mysql (trx_t *trx)
 Does the transaction prepare for MySQL. More...
 
static bool get_table_name_info (st_handler_tablename *table, const dict_table_t *dd_table, MEM_ROOT *mem_root)
 Get the table name and database name for the given dd_table object. More...
 
static bool get_info_about_prepared_transaction (XA_recover_txn *txn_list, const trx_t *trx, MEM_ROOT *mem_root)
 Get prepared transaction info from InnoDB data structure. More...
 
int trx_recover_for_mysql (XA_recover_txn *txn_list, ulint len, MEM_ROOT *mem_root)
 This function is used to find number of prepared transactions and their transaction objects for a recovery. More...
 
int trx_recover_tc_for_mysql (Xa_state_list &xa_list)
 Find prepared transactions that are marked as prepared in TC, for recovery purposes. More...
 
static trx_ttrx_get_trx_by_xid_low (const XID *xid)
 This function is used to find one X/Open XA distributed transaction which is in the prepared state. More...
 
trx_ttrx_get_trx_by_xid (const XID *xid)
 This function is used to find one X/Open XA distributed transaction which is in the prepared state. More...
 
void trx_start_if_not_started_xa_low (trx_t *trx, bool read_write)
 Starts the transaction if it is not yet started. More...
 
void trx_start_if_not_started_low (trx_t *trx, bool read_write)
 Starts the transaction if it is not yet started. More...
 
void trx_start_internal_low (trx_t *trx)
 Starts a transaction for internal processing. More...
 
void trx_start_internal_read_only_low (trx_t *trx)
 Starts a read-only transaction for internal processing. More...
 
void trx_set_rw_mode (trx_t *trx)
 Set the transaction as a read-write transaction if it is not already tagged as such. More...
 
void trx_kill_blocking (trx_t *trx)
 If this is a high priority transaction, kill all transactions that are blocking this transaction from acquiring locks. More...
 
THDthd_get_current_thd ()
 Get current THD object from thread local data. More...
 
void trx_sys_update_binlog_position (trx_t *trx)
 Update transaction binlog file name and position from session THD. More...
 
bool trx_is_prepared_in_tc (trx_t const *trx)
 Checks whether or not the transaction has been marked as prepared in TC. More...
 
dberr_t trx_set_prepared_in_tc_for_mysql (trx_t *trx)
 Does the 2nd phase of an XA transaction prepare for MySQL. More...
 

Variables

static const ulint MAX_DETAILED_ERROR_LEN = 256
 
static trx_table_map resurrected_trx_tables
 Map of resurrected transactions to affected table_id. More...
 
std::vector< std::pair< trx_id_t, table_id_t > > to_rollback_trx_tables
 
sess_ttrx_dummy_sess = nullptr
 Dummy session used currently in MySQL interface. More...
 
static trx_pools_ttrx_pools
 The trx_t pool manager. More...
 
static const ulint MAX_TRX_BLOCK_SIZE = 1024 * 1024 * 4
 Size of on trx_t pool in bytes. More...
 
static thread_local const trx_ttrx_first_latched_trx = nullptr
 
static thread_local int32_t trx_latched_count = 0
 
static thread_local bool trx_allowed_two_latches = false
 

Detailed Description

The transaction.

Created 3/26/1996 Heikki Tuuri

Typedef Documentation

◆ table_id_set

typedef std::set<table_id_t, std::less<table_id_t>, ut::allocator<table_id_t> > table_id_set

Set of table_id.

◆ trx_pool_t

Use explicit mutexes for the trx_t pool and its manager.

◆ trx_pools_t

◆ trx_table_map

typedef std::map<trx_t *, table_id_set, std::less<trx_t *>, ut::allocator<std::pair<trx_t *const, table_id_set> > > trx_table_map

Map of transactions to affected table_id.

Function Documentation

◆ get_info_about_prepared_transaction()

static bool get_info_about_prepared_transaction ( XA_recover_txn txn_list,
const trx_t trx,
MEM_ROOT mem_root 
)
static

Get prepared transaction info from InnoDB data structure.

Parameters
[in,out]txn_listHandler layer transaction list.
[in]trxInnodb transaction info.
[in]mem_rootMem_root for space allocation.
Return values
trueError, e.g. Memory allocation failure.
falseSuccess

◆ get_next_redo_rseg()

static trx_rseg_t * get_next_redo_rseg ( )
static

Get next redo rollback segment in round-robin fashion.

We assume that the assigned slots are not contiguous and have gaps.

Returns
assigned rollback segment instance

◆ get_next_redo_rseg_from_trx_sys()

static trx_rseg_t * get_next_redo_rseg_from_trx_sys ( )
static

Get the next redo rollback segment in round-robin fashion.

The assigned slots may have gaps but the vector does not.

Returns
assigned rollback segment instance

◆ get_next_redo_rseg_from_undo_spaces()

static trx_rseg_t * get_next_redo_rseg_from_undo_spaces ( )
static

Get next redo rollback segment in round-robin fashion.

While InnoDB is running in multi-threaded mode, the vectors of undo tablespaces and rsegs do not shrink. So they do not need protection to get a pointer to an rseg. If an rseg is not marked for undo tablespace truncation, we assign it to a transaction. We increment trx_ref_count to keep the purge thread from truncating the undo tablespace that contains this rseg until the transaction is done with it.

Returns
assigned rollback segment instance

◆ get_next_temp_rseg()

static trx_rseg_t * get_next_temp_rseg ( )
static

Get the next noredo rollback segment.

Returns
assigned rollback segment instance

◆ get_table_name_info()

static bool get_table_name_info ( st_handler_tablename table,
const dict_table_t dd_table,
MEM_ROOT mem_root 
)
static

Get the table name and database name for the given dd_table object.

Parameters
[in,out]tableHandler table name object pointer.
[in]dd_tablePointer table name DD object.
[in]mem_rootMem_root for space allocation.
Return values
trueError, e.g. Memory allocation failure.
falseSuccess

◆ thd_get_current_thd()

THD * thd_get_current_thd ( )

Get current THD object from thread local data.

Return values
TheTHD object for the thread, NULL if not connection thread

◆ trx_add_to_rw_trx_list()

static void trx_add_to_rw_trx_list ( trx_t trx)
inlinestatic

Adds the transaction to trx_sys->rw_trx_list Requires trx_sys->mutex, unless called in the single threaded startup code.

Parameters
[in]trxThe transaction assumed to not be in the rw_trx_list yet

◆ trx_add_to_serialisation_list()

static bool trx_add_to_serialisation_list ( trx_t trx)
inlinestatic

Assigns the trx->no and add the transaction to the serialisation_list.

Skips adding to the serialisation_list if the transaction is read-only, in which case still the trx->no is assigned.

Parameters
[in,out]trxthe modified transaction
Returns
true if added to the serialisation_list (non read-only trx)

◆ trx_allocate_for_background()

trx_t * trx_allocate_for_background ( void  )

Creates a transaction object for background operations by the master thread.

Returns
own: transaction object

◆ trx_allocate_for_mysql()

trx_t * trx_allocate_for_mysql ( void  )

Creates a transaction object for MySQL.

Returns
own: transaction object

◆ trx_assert_started()

bool trx_assert_started ( const trx_t trx)

Asserts that a transaction has been started.

The caller must hold trx_sys->mutex.

Returns
true if started
Parameters
trxin: transaction

◆ trx_assign_read_view()

ReadView * trx_assign_read_view ( trx_t trx)

Assigns a read view for a consistent read query.

All the consistent reads within the same transaction will get the same read view, which is created when this function is first called for a new started transaction.

Returns
consistent read view
Parameters
trxin/out: active transaction

◆ trx_assign_rseg_durable()

void trx_assign_rseg_durable ( trx_t trx)

Assign a durable rollback segment to a transaction in a round-robin fashion.

Parameters
[in,out]trxtransaction that involves a durable write.

◆ trx_assign_rseg_temp()

void trx_assign_rseg_temp ( trx_t trx)

Assign a temp-tablespace bound rollback-segment to a transaction.

Parameters
[in,out]trxtransaction that involves write to temp-table.

◆ trx_before_mutex_enter()

void trx_before_mutex_enter ( const trx_t trx,
bool  allow_another 
)

Verifies the invariants and records debug state related to latching rules.

Called during trx_mutex_enter before the actual mutex acquisition.

Parameters
[in]trxThe transaction for which trx_mutex_enter(trx) is called
[in]allow_anotherIf false, then no further calls to trx_mutex_enter are allowed, until trx_mutex_exit(). If true, then this must be the first trx acquisition and we will allow one more.

◆ trx_before_mutex_exit()

void trx_before_mutex_exit ( const trx_t trx)

Verifies the invariants and records debug state related to latching rules.

Called during trx_mutex_exit before the actual mutex release.

Parameters
[in]trxThe transaction for which trx_mutex_exit(trx) is called

◆ trx_can_be_handled_by_current_thread()

bool trx_can_be_handled_by_current_thread ( const trx_t trx)

Determines if trx can be handled by current thread, which is when trx->mysql_thd is nullptr (a "background" trx) or equals current_thd.

Parameters
[in]trxThe transaction to check
Returns
true iff current thread can handle the transaction

◆ trx_can_be_handled_by_current_thread_or_is_hp_victim()

bool trx_can_be_handled_by_current_thread_or_is_hp_victim ( const trx_t trx)

Determines if trx can be handled by current thread, which is when trx->mysql_thd is nullptr (a "background" trx) or equals current_thd, or is a victim being killed by HP transaction run by the current thread.

Parameters
[in]trxThe transaction to check
Returns
true iff current thread can handle the transaction

◆ trx_cleanup_at_db_startup()

void trx_cleanup_at_db_startup ( trx_t trx)

Cleans up a transaction at database startup.

The cleanup is needed if the transaction already got to the middle of a commit when the database crashed, and we cannot roll it back.

Parameters
trxin: transaction

◆ trx_clear_resurrected_table_ids()

void trx_clear_resurrected_table_ids ( )

Clear all resurrected table IDs.

Needs to be called after all tables locks are resurrected.

◆ trx_commit()

void trx_commit ( trx_t trx)

Commits a transaction.

in/out: transaction

Parameters
trxin/out: transaction

◆ trx_commit_complete_for_mysql()

void trx_commit_complete_for_mysql ( trx_t trx)

If required, flushes the log to disk if we called trx_commit_for_mysql() with trx->flush_log_later == true.

in/out: transaction

Parameters
trxin/out: transaction

◆ trx_commit_for_mysql()

dberr_t trx_commit_for_mysql ( trx_t trx)

Does the transaction commit for MySQL.

Returns
DB_SUCCESS or error number
Parameters
trxin/out: transaction

◆ trx_commit_in_memory()

static void trx_commit_in_memory ( trx_t trx,
const mtr_t mtr,
bool  serialised 
)
static

Commits a transaction in memory.

Parameters
trxin/out: transaction
mtrin: mini-transaction of trx_write_serialisation_history(), or NULL if the transaction did not modify anything
serialisedin: true if serialisation log was written

◆ trx_commit_low()

void trx_commit_low ( trx_t trx,
mtr_t mtr 
)

Commits a transaction and a mini-transaction.

Parameters
[in,out]trxTransaction
[in,out]mtrMini-transaction (will be committed), or null if trx made no modifications

◆ trx_commit_node_create()

commit_node_t * trx_commit_node_create ( mem_heap_t heap)

Creates a commit command node struct.

Returns
own: commit node struct
Parameters
heapin: mem heap where created

◆ trx_commit_or_rollback_prepare()

void trx_commit_or_rollback_prepare ( trx_t trx)

Prepares a transaction for commit/rollback.

in/out: transaction

Parameters
trxin/out: transaction

◆ trx_commit_step()

que_thr_t * trx_commit_step ( que_thr_t thr)

Performs an execution step for a commit type node in a query graph.

Returns
query thread to run next, or NULL
Parameters
thrin: query thread

◆ trx_create_low()

static trx_t * trx_create_low ( )
static
Returns
a trx_t instance from trx_pools.

◆ trx_disconnect_from_mysql()

void trx_disconnect_from_mysql ( trx_t trx,
bool  prepared 
)
inline

Disconnect a transaction from MySQL.

Parameters
[in,out]trxtransaction
[in]preparedboolean value to specify whether trx is in TRX_STATE_PREPARED state (such as after XA PREPARE) and we want to unlink it from the mysql_thd object, so it can potentially be linked to another session in future.

◆ trx_disconnect_plain()

void trx_disconnect_plain ( trx_t trx)
inline

Disconnect a transaction from MySQL.

Parameters
[in,out]trxtransaction

◆ trx_disconnect_prepared()

void trx_disconnect_prepared ( trx_t trx)

Disconnect a prepared transaction from MySQL.

Parameters
[in,out]trxtransaction

◆ trx_erase_from_serialisation_list_low()

static void trx_erase_from_serialisation_list_low ( trx_t trx)
inlinestatic

Erases transaction from the serialisation_list.

Caller must have acquired trx_sys->serialisation_mutex prior to calling this function.

Parameters
[in,out]trxthe transaction to erase

◆ trx_erase_lists()

static void trx_erase_lists ( trx_t trx)
static

Erase the transaction from running transaction lists and serialization list.

Active RW transaction list of a MVCC snapshot(ReadView::prepare) won't include this transaction after this call. All implicit locks are also released by this call as trx is removed from rw_trx_list.

Parameters
[in]trxTransaction to erase, must have an ID > 0

◆ trx_finalize_for_fts()

static void trx_finalize_for_fts ( trx_t trx,
bool  is_commit 
)
static

Finalize a transaction containing updates to FTS tables.

Parameters
trxin/out: transaction
is_commitin: true if the transaction was committed, false if it was rolled back.

◆ trx_finalize_for_fts_table()

static void trx_finalize_for_fts_table ( fts_trx_table_t ftt)
static

◆ trx_flush_log_if_needed()

static void trx_flush_log_if_needed ( lsn_t  lsn,
trx_t trx 
)
static

If required, flushes the log to disk based on the value of innodb_flush_log_at_trx_commit.

Parameters
lsnin: lsn up to which logs are to be flushed.
trxin/out: transaction

◆ trx_flush_log_if_needed_low()

static void trx_flush_log_if_needed_low ( lsn_t  lsn)
static

If required, flushes the log to disk based on the value of innodb_flush_log_at_trx_commit.

Parameters
lsnin: lsn up to which logs are to be flushed.

◆ trx_flush_logs()

static void trx_flush_logs ( trx_t trx,
lsn_t  lsn 
)
static

Tests the durability settings and flushes logs if needed.

Parameters
[in,out]trxthe transaction to flush the logs for.
[in]lsnthe identifier of the transaction to flush.

◆ trx_free()

static void trx_free ( trx_t *&  trx)
static

Release a trx_t instance back to the pool.

Parameters
trxthe instance to release.

◆ trx_free_for_background()

void trx_free_for_background ( trx_t trx)

Free a transaction that was allocated by background or user threads.

Parameters
[in,out]trxtransaction object to free

◆ trx_free_for_mysql()

void trx_free_for_mysql ( trx_t trx)

Free a transaction object for MySQL.

Parameters
[in,out]trxtransaction

◆ trx_free_prepared_or_active_recovered()

void trx_free_prepared_or_active_recovered ( trx_t trx)

At shutdown, frees a transaction object that represents either:

  • a PREPARED transaction,
  • or a recovered ACTIVE transaction.
    Parameters
    [in,out]trxtransaction object to free

◆ trx_free_resurrected()

void trx_free_resurrected ( trx_t trx)

Free and initialize a transaction object instantiated during recovery.

Parameters
[in,out]trxtransaction object to free and initialize

◆ trx_get_trx_by_xid()

trx_t * trx_get_trx_by_xid ( const XID xid)

This function is used to find one X/Open XA distributed transaction which is in the prepared state.

Parameters
[in]xidX/Open XA transaction identifier
Returns
trx or NULL; on match, the trx->xid will be invalidated; note that the trx may have been committed

◆ trx_get_trx_by_xid_low()

static trx_t * trx_get_trx_by_xid_low ( const XID xid)
static

This function is used to find one X/Open XA distributed transaction which is in the prepared state.

Returns
trx on match, the trx->xid will be invalidated;
Parameters
xidin: X/Open XA transaction identifier

◆ trx_init()

static void trx_init ( trx_t trx)
static

Initialize transaction object.

Parameters
trxtrx to initialize

◆ trx_is_mysql_xa()

bool trx_is_mysql_xa ( const trx_t trx)

Check if transaction is internal XA transaction.

Parameters
[in]trxtransaction
Returns
true, iff internal XA transaction.

◆ trx_is_prepared_in_tc()

bool trx_is_prepared_in_tc ( trx_t const *  trx)

Checks whether or not the transaction has been marked as prepared in TC.

Parameters
[in]trxthe transaction
Returns
true if the transaction is marked as prepared in TC, false otherwise.

◆ trx_kill_blocking()

void trx_kill_blocking ( trx_t trx)

If this is a high priority transaction, kill all transactions that are blocking this transaction from acquiring locks.

Parameters
[in,out]trxHigh priority transaction

Kill the transactions in the lock acquisition order old -> new.

◆ trx_lists_init_at_db_start()

void trx_lists_init_at_db_start ( void  )

Creates trx objects for transactions and initializes the trx list of trx_sys at database start.

Rollback segments and undo log lists must already exist when this function is called, because the lists of transactions to be rolled back or cleaned up are built based on the undo log lists.

◆ trx_mark_sql_stat_end()

void trx_mark_sql_stat_end ( trx_t trx)

Marks the latest SQL statement ended.

in: trx handle

Parameters
trxin: trx handle

◆ trx_pool_close()

void trx_pool_close ( )

Destroy the trx_t pool.

◆ trx_pool_init()

void trx_pool_init ( )

Create the trx_t pool.

◆ trx_prepare()

static void trx_prepare ( trx_t trx)
static

Prepares a transaction.

Parameters
[in]trxthe transction to prepare.

◆ trx_prepare_for_mysql()

dberr_t trx_prepare_for_mysql ( trx_t trx)

Does the transaction prepare for MySQL.

Parameters
[in,out]trxTransaction instance to prepare

◆ trx_prepare_low()

static lsn_t trx_prepare_low ( trx_t trx,
trx_undo_ptr_t undo_ptr,
bool  noredo_logging 
)
static

Prepares a transaction for given rollback segment.

Returns
lsn_t: lsn assigned for commit of scheduled rollback segment
Parameters
trxin/out: transaction
undo_ptrin/out: pointer to rollback segment scheduled for prepare.
noredo_loggingin: turn-off redo logging.

◆ trx_print()

void trx_print ( FILE *  f,
const trx_t trx,
ulint  max_query_len 
)

Prints info about a transaction.

Acquires and releases lock_sys exclusive global latch and trx_sys->mutex.

Parameters
[in]foutput stream
[in]trxtransaction
[in]max_query_lenmax query length to print, must be positive

◆ trx_print_latched()

void trx_print_latched ( FILE *  f,
const trx_t trx,
ulint  max_query_len 
)

Prints info about a transaction.

The caller must hold lock_sys exclusive global latch and trx_sys->mutex.

Parameters
[in]foutput stream
[in]trxtransaction
[in]max_query_lenmax query length to print, must be positive

◆ trx_print_low()

void trx_print_low ( FILE *  f,
const trx_t trx,
ulint  max_query_len,
ulint  n_rec_locks,
ulint  n_trx_locks,
ulint  heap_size 
)

Prints info about a transaction.

Caller must hold trx_sys->mutex.

Parameters
fin: output stream
trxin: transaction
max_query_lenin: max query length to print, must be positive
n_rec_locksin: lock_number_of_rows_locked(&trx->lock)
n_trx_locksin: length of trx->lock.trx_locks
heap_sizein: mem_heap_get_size(trx->lock.lock_heap)

◆ trx_recover_for_mysql()

int trx_recover_for_mysql ( XA_recover_txn txn_list,
ulint  len,
MEM_ROOT mem_root 
)

This function is used to find number of prepared transactions and their transaction objects for a recovery.

Returns
number of prepared transactions stored in xid_list
Parameters
txn_listin/out: prepared transactions
lenin: number of slots in xid_list
mem_rootin: memory for table names

◆ trx_recover_tc_for_mysql()

int trx_recover_tc_for_mysql ( Xa_state_list xa_list)

Find prepared transactions that are marked as prepared in TC, for recovery purposes.

Parameters
[in,out]xa_listprepared transactions state
Returns
0 if successful or error number

◆ trx_release_impl_and_expl_locks()

static void trx_release_impl_and_expl_locks ( trx_t trx,
bool  serialised 
)
static

◆ trx_remove_from_rw_trx_list()

static void trx_remove_from_rw_trx_list ( trx_t trx)
inlinestatic

Removes the transaction from trx_sys->rw_trx_list.

Requires trx_sys->mutex, unless called in the single threaded startup code.

Parameters
[in]trxThe transaction assumed to be in the rw_trx_list

◆ trx_resurrect()

static void trx_resurrect ( trx_rseg_t rseg)
static

Resurrect the transactions that were doing inserts and updates at the time of a crash, they need to be undone.

Parameters
[in]rsegrollback segment

◆ trx_resurrect_insert()

static trx_t * trx_resurrect_insert ( trx_undo_t undo,
trx_rseg_t rseg 
)
static

Resurrect the transactions that were doing inserts at the time of the crash, they need to be undone.

Returns
trx_t instance
Parameters
undoin: entry to UNDO
rsegin: rollback segment

◆ trx_resurrect_locks()

void trx_resurrect_locks ( bool  all)

Resurrect table locks for resurrected transactions.

Parameters
[in]allfalse: resurrect locks for dictionary transactions, true : resurrect locks for all transactions.

◆ trx_resurrect_table_ids()

static void trx_resurrect_table_ids ( trx_t trx,
const trx_undo_ptr_t undo_ptr,
const trx_undo_t undo 
)
static

Resurrect the table IDs for a resurrected transaction.

Parameters
[in]trxresurrected transaction
[in]undo_ptrpointer to undo segment
[in]undoundo log

◆ trx_resurrect_update()

static void trx_resurrect_update ( trx_t trx,
trx_undo_t undo,
trx_rseg_t rseg 
)
static

Resurrect the transactions that were doing updates the time of the crash, they need to be undone.

Parameters
trxin/out: transaction
undoin/out: update UNDO record
rsegin/out: rollback segment

◆ trx_resurrect_update_in_prepared_state()

static void trx_resurrect_update_in_prepared_state ( trx_t trx,
const trx_undo_t undo 
)
static

Prepared transactions are left in the prepared state waiting for a commit or abort decision from MySQL.

Parameters
trxin,out: transaction
undoin: update UNDO record

◆ trx_serialisation_number_get()

static bool trx_serialisation_number_get ( trx_t trx,
trx_undo_ptr_t redo_rseg_undo_ptr,
trx_undo_ptr_t temp_rseg_undo_ptr 
)
static

Set the transaction serialisation number.

Returns
true if the transaction number was added to the serialisation_list.
Parameters
trxin/out: transaction
redo_rseg_undo_ptrin/out: Set trx serialisation number in referred undo rseg.
temp_rseg_undo_ptrin/out: Set trx serialisation number in referred undo rseg.

◆ trx_set_detailed_error()

void trx_set_detailed_error ( trx_t trx,
const char *  msg 
)

Set detailed error message for the transaction.

Parameters
[in]trxTransaction struct
[in]msgDetailed error message

◆ trx_set_detailed_error_from_file()

void trx_set_detailed_error_from_file ( trx_t trx,
FILE *  file 
)

Set detailed error message for the transaction from a file.

Note that the file is rewinded before reading from it.

Parameters
trxin: transaction struct
filein: file to read message from

◆ trx_set_flush_observer()

void trx_set_flush_observer ( trx_t trx,
Flush_observer observer 
)

Set flush observer for the transaction.

Parameters
[in,out]trxtransaction struct
[in]observerflush observer

◆ trx_set_prepared_in_tc()

static void trx_set_prepared_in_tc ( trx_t trx)
static

Marks a transaction as prepared in the transaction coordinator.

Parameters
[in]trxthe transction to mark.

◆ trx_set_prepared_in_tc_for_mysql()

dberr_t trx_set_prepared_in_tc_for_mysql ( trx_t trx)

Does the 2nd phase of an XA transaction prepare for MySQL.

Parameters
[in,out]trxTransaction instance to finish prepare
Returns
DB_SUCCESS or error number

◆ trx_set_prepared_in_tc_low()

static lsn_t trx_set_prepared_in_tc_low ( trx_t trx,
trx_undo_ptr_t undo_ptr 
)
static

Sets the transaction as prepared in the transaction coordinator for the given rollback segment.

Parameters
[in,out]trxThe rollback segment parent transaction.
[in]undo_ptrThe rollback segment.
Returns
lsn assigned for commit of scheduled rollback segment

◆ trx_set_rw_mode()

void trx_set_rw_mode ( trx_t trx)

Set the transaction as a read-write transaction if it is not already tagged as such.

Read-only transactions that are writing to temporary tables are assigned an ID and a rollback segment but are not added to the trx read-write list because their updates should not be visible to other transactions and therefore their changes can be ignored by by MVCC.

Parameters
trxin/out: transaction that is RW

◆ trx_start_if_not_started_low()

void trx_start_if_not_started_low ( trx_t trx,
bool  read_write 
)

Starts the transaction if it is not yet started.

Parameters
[in]trxTransaction
[in]read_writeTrue if read write transaction

◆ trx_start_if_not_started_xa_low()

void trx_start_if_not_started_xa_low ( trx_t trx,
bool  read_write 
)

Starts the transaction if it is not yet started.

Parameters
[in,out]trxTransaction
[in]read_writeTrue if read write transaction

◆ trx_start_internal_low()

void trx_start_internal_low ( trx_t trx)

Starts a transaction for internal processing.

in/out: transaction

Parameters
trxin/out: transaction

◆ trx_start_internal_read_only_low()

void trx_start_internal_read_only_low ( trx_t trx)

Starts a read-only transaction for internal processing.

Parameters
[in,out]trxtransaction to be started

◆ trx_start_low()

static void trx_start_low ( trx_t trx,
bool  read_write 
)
static

Starts a transaction.

Parameters
trxin: transaction
read_writein: true if read-write transaction

◆ trx_sys_update_binlog_position()

void trx_sys_update_binlog_position ( trx_t trx)

Update transaction binlog file name and position from session THD.

Parameters
[in,out]trxcurrent transaction.

◆ trx_update_mod_tables_timestamp()

static void trx_update_mod_tables_timestamp ( trx_t trx)
static

For each table that has been modified by the given transaction: update its dict_table_t::update_time with the current timestamp.

Clear the list of the modified tables at the end.

Parameters
trxin: transaction

◆ trx_validate_state_before_free()

static void trx_validate_state_before_free ( trx_t trx)
static

Check state of transaction before freeing it.

Parameters
[in,out]trxtransaction object to validate

◆ trx_weight_ge()

bool trx_weight_ge ( const trx_t a,
const trx_t b 
)

Compares the "weight" (or size) of two transactions.

Transactions that have edited non-transactional tables are considered heavier than ones that have not.

Returns
true if weight(a) >= weight(b)
Parameters
ain: transaction to be compared
bin: transaction to be compared

◆ trx_write_serialisation_history()

static bool trx_write_serialisation_history ( trx_t trx,
mtr_t mtr 
)
static

Assign the transaction its history serialisation number and write the update UNDO log record to the assigned rollback segment.

Returns
true if a serialisation log was written
Parameters
trxin/out: transaction
mtrin/out: mini-transaction

Variable Documentation

◆ MAX_DETAILED_ERROR_LEN

const ulint MAX_DETAILED_ERROR_LEN = 256
static

◆ MAX_TRX_BLOCK_SIZE

const ulint MAX_TRX_BLOCK_SIZE = 1024 * 1024 * 4
static

Size of on trx_t pool in bytes.

◆ resurrected_trx_tables

trx_table_map resurrected_trx_tables
static

Map of resurrected transactions to affected table_id.

◆ to_rollback_trx_tables

std::vector<std::pair<trx_id_t, table_id_t> > to_rollback_trx_tables

◆ trx_allowed_two_latches

thread_local bool trx_allowed_two_latches = false
static

◆ trx_dummy_sess

sess_t* trx_dummy_sess = nullptr

Dummy session used currently in MySQL interface.

◆ trx_first_latched_trx

thread_local const trx_t* trx_first_latched_trx = nullptr
static

◆ trx_latched_count

thread_local int32_t trx_latched_count = 0
static

◆ trx_pools

trx_pools_t* trx_pools
static

The trx_t pool manager.