MySQL 9.1.0
Source Code Documentation
trx0trx.h File Reference

The transaction. More...

#include <atomic>
#include <set>
#include "ha_prototypes.h"
#include "dict0types.h"
#include "trx0types.h"
#include "ut0new.h"
#include "lock0types.h"
#include "mem0mem.h"
#include "que0types.h"
#include "trx0xa.h"
#include "usr0types.h"
#include "ut0vec.h"
#include "fts0fts.h"
#include "read0read.h"
#include "sql/handler.h"
#include "srv0srv.h"
#include "trx0trx.ic"

Go to the source code of this file.

Classes

struct  trx_lock_t
 Latching protocol for trx_lock_t::que_state. More...
 
struct  trx_undo_ptr_t
 The transaction handle. More...
 
struct  trx_rsegs_t
 Rollback segments assigned to a transaction for undo logging. More...
 
struct  trx_t
 
struct  commit_node_t
 Commit command node in a query graph. More...
 
class  TrxInInnoDB
 Track if a transaction is executing inside InnoDB code. More...
 

Macros

#define TRX_ISO_READ_UNCOMMITTED   trx_t::READ_UNCOMMITTED
 
#define TRX_ISO_READ_COMMITTED   trx_t::READ_COMMITTED
 
#define TRX_ISO_REPEATABLE_READ   trx_t::REPEATABLE_READ
 
#define TRX_ISO_SERIALIZABLE   trx_t::SERIALIZABLE
 
#define trx_mutex_enter_low(t, first_of_two)
 Please do not use this low-level macro. More...
 
#define trx_mutex_enter(t)   trx_mutex_enter_low(t, false)
 Acquire the trx->mutex (and promise not to request any more). More...
 
#define trx_mutex_enter_first_of_two(t)   trx_mutex_enter_low(t, true)
 Acquire the trx->mutex (and indicate we might request one more). More...
 
#define trx_mutex_exit(t)
 Release the trx->mutex. More...
 

Typedefs

typedef std::vector< ib_lock_t *, ut::allocator< ib_lock_t * > > lock_pool_t
 
typedef std::set< dict_table_t *, std::less< dict_table_t * >, ut::allocator< dict_table_t * > > trx_mod_tables_t
 Type used to store the list of tables that are modified by a given transaction. More...
 

Enumerations

enum  trx_rseg_type_t { TRX_RSEG_TYPE_NONE = 0 , TRX_RSEG_TYPE_REDO , TRX_RSEG_TYPE_NOREDO }
 
enum  commit_node_state { COMMIT_NODE_SEND = 1 , COMMIT_NODE_WAIT }
 Commit node states. More...
 

Functions

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 const dict_index_ttrx_get_error_index (const trx_t *trx)
 Retrieves the error_info field from a trx. More...
 
trx_ttrx_allocate_for_mysql (void)
 Creates a transaction object for MySQL. More...
 
trx_ttrx_allocate_for_background (void)
 Creates a transaction object for background operations by the master thread. 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...
 
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_free_for_mysql (trx_t *trx)
 Free a transaction object for 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_lists_init_at_db_start (void)
 Creates trx objects for transactions and initializes the trx list of trx_sys at database start. 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_commit (trx_t *trx)
 Commits a transaction. More...
 
void trx_commit_low (trx_t *trx, mtr_t *mtr)
 Commits a transaction and a mini-transaction. More...
 
void trx_cleanup_at_db_startup (trx_t *trx)
 Cleans up a transaction at database startup. More...
 
dberr_t trx_commit_for_mysql (trx_t *trx)
 Does the transaction commit for MySQL. More...
 
dberr_t trx_prepare_for_mysql (trx_t *trx)
 Does the transaction prepare for MySQL. 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...
 
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_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...
 
ReadViewtrx_assign_read_view (trx_t *trx)
 Assigns a read view for a consistent read query. More...
 
static ReadViewtrx_get_read_view (trx_t *trx)
 
static const ReadViewtrx_get_read_view (const trx_t *trx)
 
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...
 
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...
 
static enum trx_dict_op_t trx_get_dict_operation (const trx_t *trx)
 Determine if a transaction is a dictionary operation. More...
 
static void trx_set_dict_operation (trx_t *trx, enum trx_dict_op_t op)
 Flag a transaction a dictionary operation. More...
 
static bool trx_state_eq (const trx_t *trx, trx_state_t state)
 Determines if a transaction is in the given state. 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...
 
bool trx_is_interrupted (const trx_t *trx)
 Determines if the currently running transaction has been interrupted. More...
 
bool trx_is_strict (trx_t *trx)
 Determines if the currently running transaction is in strict mode. More...
 
bool trx_weight_ge (const trx_t *a, const trx_t *b)
 Compares the "weight" (or size) of two transactions. More...
 
static const char * trx_get_que_state_str (const trx_t *trx)
 Retrieves transaction's que state in a human readable string. More...
 
static trx_id_t trx_get_id_for_print (const trx_t *trx)
 Retreieves the transaction ID. More...
 
void trx_assign_rseg_temp (trx_t *trx)
 Assign a temp-tablespace bound rollback-segment to a transaction. More...
 
void trx_pool_init ()
 Create the trx_t pool. More...
 
void trx_pool_close ()
 Destroy the trx_t pool. 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...
 
static const trx_ttrx_arbitrate (const trx_t *requestor, const trx_t *holder)
 
static bool trx_is_high_priority (const trx_t *trx)
 
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...
 
static bool trx_is_rseg_updated (const trx_t *trx)
 Check if redo/noredo rseg is modified for insert/update. More...
 
static std::chrono::seconds trx_lock_wait_timeout_get (const trx_t *t)
 Transactions that aren't started by the MySQL server don't set the trx_t::mysql_thd field. More...
 
static bool trx_is_autocommit_non_locking (const trx_t *t)
 Determine if the transaction is a non-locking autocommit select (implied read-only). More...
 
static void check_trx_state (const trx_t *t)
 Check transaction state. More...
 
static void assert_trx_in_rw_list (const trx_t *t)
 Assert that the transaction is in the trx_sys_t::rw_trx_list. More...
 
static void assert_trx_is_free (const trx_t *t)
 Check if transaction is free so that it can be re-initialized. More...
 
static void assert_trx_is_inactive (const trx_t *t)
 Check if transaction is in-active so that it can be freed and put back to transaction pool. More...
 
static void assert_trx_nonlocking_or_in_list (const trx_t *t)
 Assert that an autocommit non-locking select cannot be in the rw_trx_list and that it is a read-only transaction. More...
 
static bool trx_is_ac_nl_ro (const trx_t *t)
 Determine if the transaction is a non-locking autocommit select with an explicit check for the read-only status. More...
 
static void trx_reference (trx_t *trx)
 Increase the reference count. More...
 
static void trx_release_reference (trx_t *trx)
 Release the transaction. More...
 
static bool trx_is_referenced (const trx_t *t)
 Check if the transaction is being referenced. More...
 
static uint64_t TRX_WEIGHT (const trx_t *t)
 Calculates the "weight" of a transaction. More...
 
static void trx_start_if_not_started_xa (trx_t *t, bool rw, ut::Location loc)
 
static void trx_start_if_not_started (trx_t *t, bool rw, ut::Location l)
 
static void trx_start_internal (trx_t *t, ut::Location loc)
 
static void trx_start_internal_read_only (trx_t *t, ut::Location loc)
 
bool trx_was_started (const trx_t *trx)
 Check if transaction was started. More...
 
bool trx_is_started (const trx_t *trx)
 Check if transaction is started. More...
 
bool trx_mutex_own (const trx_t *trx)
 Test if trx->mutex is owned by the current thread. More...
 
void trx_before_mutex_enter (const trx_t *trx, bool allow_another)
 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_is_mysql_xa (const trx_t *trx)
 Check if transaction is internal XA transaction. 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...
 
const char * trx_state_string (trx_state_t state)
 Human readable transaction state, for diagnostic purposes. More...
 

Variables

std::vector< std::pair< trx_id_t, table_id_t > > to_rollback_trx_tables
 
sess_ttrx_dummy_sess
 Dummy session used currently in MySQL interface. More...
 
constexpr uint32_t TRX_QUE_STATE_STR_MAX_LEN = 12
 

Detailed Description

The transaction.

Created 3/26/1996 Heikki Tuuri

Macro Definition Documentation

◆ TRX_ISO_READ_COMMITTED

#define TRX_ISO_READ_COMMITTED   trx_t::READ_COMMITTED

◆ TRX_ISO_READ_UNCOMMITTED

#define TRX_ISO_READ_UNCOMMITTED   trx_t::READ_UNCOMMITTED

◆ TRX_ISO_REPEATABLE_READ

#define TRX_ISO_REPEATABLE_READ   trx_t::REPEATABLE_READ

◆ TRX_ISO_SERIALIZABLE

#define TRX_ISO_SERIALIZABLE   trx_t::SERIALIZABLE

◆ trx_mutex_enter

#define trx_mutex_enter (   t)    trx_mutex_enter_low(t, false)

Acquire the trx->mutex (and promise not to request any more).

◆ trx_mutex_enter_first_of_two

#define trx_mutex_enter_first_of_two (   t)    trx_mutex_enter_low(t, true)

Acquire the trx->mutex (and indicate we might request one more).

◆ trx_mutex_enter_low

#define trx_mutex_enter_low (   t,
  first_of_two 
)
Value:
do { \
ut_ad(!trx_mutex_own(t)); \
ut_d(trx_before_mutex_enter(t, first_of_two)); \
mutex_enter(&t->mutex); \
} while (0)
void trx_before_mutex_enter(const trx_t *trx, bool allow_another)
Verifies the invariants and records debug state related to latching rules.
Definition: trx0trx.cc:2855
bool trx_mutex_own(const trx_t *trx)
Test if trx->mutex is owned by the current thread.
Definition: trx0trx.h:1345

Please do not use this low-level macro.

Use trx_mutex_enter(t) instead. In rare cases where you need to take two trx->mutex-es, take the first one using trx_mutex_enter_first_of_two(t1), and the second one with trx_mutex(2)

◆ trx_mutex_exit

#define trx_mutex_exit (   t)
Value:
do { \
ut_ad(trx_mutex_own(t)); \
mutex_exit(&t->mutex); \
} while (0)
void trx_before_mutex_exit(const trx_t *trx)
Verifies the invariants and records debug state related to latching rules.
Definition: trx0trx.cc:2882

Release the trx->mutex.

Typedef Documentation

◆ lock_pool_t

typedef std::vector<ib_lock_t *, ut::allocator<ib_lock_t *> > lock_pool_t

◆ trx_mod_tables_t

typedef std::set<dict_table_t *, std::less<dict_table_t *>, ut::allocator<dict_table_t *> > trx_mod_tables_t

Type used to store the list of tables that are modified by a given transaction.

We store pointers to the table objects in memory because we know that a table object will not be destroyed while a transaction that modified it is running.

Enumeration Type Documentation

◆ commit_node_state

Commit node states.

Enumerator
COMMIT_NODE_SEND 

about to send a commit signal to the transaction

COMMIT_NODE_WAIT 

commit signal sent to the transaction, waiting for completion

◆ trx_rseg_type_t

Enumerator
TRX_RSEG_TYPE_NONE 

void rollback segment type.

TRX_RSEG_TYPE_REDO 

redo rollback segment.

TRX_RSEG_TYPE_NOREDO 

non-redo rollback segment.

Function Documentation

◆ assert_trx_in_rw_list()

static void assert_trx_in_rw_list ( const trx_t t)
inlinestatic

Assert that the transaction is in the trx_sys_t::rw_trx_list.

◆ assert_trx_is_free()

static void assert_trx_is_free ( const trx_t t)
inlinestatic

Check if transaction is free so that it can be re-initialized.

Parameters
ttransaction handle

◆ assert_trx_is_inactive()

static void assert_trx_is_inactive ( const trx_t t)
inlinestatic

Check if transaction is in-active so that it can be freed and put back to transaction pool.

Parameters
ttransaction handle

◆ assert_trx_nonlocking_or_in_list()

static void assert_trx_nonlocking_or_in_list ( const trx_t t)
inlinestatic

Assert that an autocommit non-locking select cannot be in the rw_trx_list and that it is a read-only transaction.

The transaction must be in the mysql_trx_list.

◆ check_trx_state()

static void check_trx_state ( const trx_t t)
inlinestatic

Check transaction state.

◆ 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_arbitrate()

static const trx_t * trx_arbitrate ( const trx_t requestor,
const trx_t holder 
)
inlinestatic
Parameters
[in]requestorTransaction requesting the lock
[in]holderTransaction holding the lock
Returns
the transaction that will be rolled back, null don't care

◆ 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 in: transaction

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. in: active transaction

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_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. in: transaction

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 in/out: transaction
DB_SUCCESS or error number
Parameters
trxin/out: transaction

◆ 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 in: mem heap where created
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 in: query thread
query thread to run next, or NULL
Parameters
thrin: query thread

◆ 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_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_dict_operation()

static enum trx_dict_op_t trx_get_dict_operation ( const trx_t trx)
inlinestatic

Determine if a transaction is a dictionary operation.

Returns
dictionary operation mode in: transaction

◆ trx_get_error_index()

static const dict_index_t * trx_get_error_index ( const trx_t trx)
inlinestatic

Retrieves the error_info field from a trx.

Returns
the error index in: trx object

◆ trx_get_id_for_print()

static trx_id_t trx_get_id_for_print ( const trx_t trx)
inlinestatic

Retreieves the transaction ID.

In a given point in time it is guaranteed that IDs of the running transactions are unique. The values returned by this function for readonly transactions may be reused, so a subsequent RO transaction may get the same ID as a RO transaction that existed in the past. The values returned by this function should be used for printing purposes only.

Parameters
[in]trxtransaction whose id to retrieve
Returns
transaction id

◆ trx_get_que_state_str()

static const char * trx_get_que_state_str ( const trx_t trx)
inlinestatic

Retrieves transaction's que state in a human readable string.

The string should not be free()'d or modified.

Returns
string in the data segment in: transaction

◆ trx_get_read_view() [1/2]

static const ReadView * trx_get_read_view ( const trx_t trx)
inlinestatic
Returns
the transaction's read view or NULL if one not assigned.

◆ trx_get_read_view() [2/2]

static ReadView * trx_get_read_view ( trx_t trx)
inlinestatic
Returns
the transaction's read view or NULL if one not assigned.

◆ 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_is_ac_nl_ro()

static bool trx_is_ac_nl_ro ( const trx_t t)
inlinestatic

Determine if the transaction is a non-locking autocommit select with an explicit check for the read-only status.

Parameters
ttransaction
Returns
true if non-locking autocommit read-only transaction.

◆ trx_is_autocommit_non_locking()

static bool trx_is_autocommit_non_locking ( const trx_t t)
inlinestatic

Determine if the transaction is a non-locking autocommit select (implied read-only).

Parameters
ttransaction
Returns
true if non-locking autocommit select transaction.

◆ trx_is_high_priority()

static bool trx_is_high_priority ( const trx_t trx)
inlinestatic
Parameters
[in]trxTransaction to check
Returns
true if the transaction is a high priority transaction.

◆ trx_is_interrupted()

bool trx_is_interrupted ( const trx_t trx)

Determines if the currently running transaction has been interrupted.

Returns
true if interrupted in: transaction
true if interrupted
Parameters
trxin: transaction

◆ 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_is_referenced()

static bool trx_is_referenced ( const trx_t t)
inlinestatic

Check if the transaction is being referenced.

◆ trx_is_rseg_updated()

static bool trx_is_rseg_updated ( const trx_t trx)
inlinestatic

Check if redo/noredo rseg is modified for insert/update.

Parameters
[in]trxTransaction to check

◆ trx_is_started()

bool trx_is_started ( const trx_t trx)
inline

Check if transaction is started.

Parameters
[in]trxTransaction whose state we need to check
Returns
true if transaction is in state started

◆ trx_is_strict()

bool trx_is_strict ( trx_t trx)

Determines if the currently running transaction is in strict mode.

Returns
true if strict in: transaction
true if strict
Parameters
trxin: transaction

◆ 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 segment 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.

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_lock_wait_timeout_get()

static std::chrono::seconds trx_lock_wait_timeout_get ( const trx_t t)
inlinestatic

Transactions that aren't started by the MySQL server don't set the trx_t::mysql_thd field.

For such transactions we set the lock wait timeout to 0 instead of the user configured value that comes from innodb_lock_wait_timeout via trx_t::mysql_thd.

Parameters
ttransaction
Returns
lock wait timeout in seconds

◆ 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_mutex_own()

bool trx_mutex_own ( const trx_t trx)
inline

Test if trx->mutex is owned by the current thread.

◆ 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_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_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. in: mem_heap_get_size(trx->lock.lock_heap)

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 in: memory for table names
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_reference()

static void trx_reference ( trx_t trx)
inlinestatic

Increase the reference count.

If the transaction is in state TRX_STATE_COMMITTED_IN_MEMORY then the transaction is considered committed and the reference count is not incremented.

Parameters
trxTransaction that is being referenced

◆ trx_release_reference()

static void trx_release_reference ( trx_t trx)
inlinestatic

Release the transaction.

Decrease the reference count.

Parameters
trxTransaction that is being released

◆ 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_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. in: file to read message from

Note that the file is rewinded before reading from it.

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

◆ trx_set_dict_operation()

static void trx_set_dict_operation ( trx_t trx,
enum trx_dict_op_t  op 
)
inlinestatic

Flag a transaction a dictionary operation.

Parameters
[in,out]trxtransaction
[in]opoperation, not TRX_DICT_OP_NONE

◆ 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_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_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.

Parameters
[in,out]trxTransaction that needs to be "upgraded" to RW from RO

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()

static void trx_start_if_not_started ( trx_t t,
bool  rw,
ut::Location  l 
)
inlinestatic

◆ 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()

static void trx_start_if_not_started_xa ( trx_t t,
bool  rw,
ut::Location  loc 
)
inlinestatic

◆ 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()

static void trx_start_internal ( trx_t t,
ut::Location  loc 
)
inlinestatic

◆ 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()

static void trx_start_internal_read_only ( trx_t t,
ut::Location  loc 
)
inlinestatic

◆ 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_state_eq()

static bool trx_state_eq ( const trx_t trx,
trx_state_t  state 
)
inlinestatic

Determines if a transaction is in the given state.

The caller must hold trx_sys->mutex, or it must be the thread that is serving a running transaction. A running RW transaction must be in trx_sys->rw_trx_list.

Parameters
[in]trxTransaction.
[in]stateState.
Returns
true if trx->state == state

◆ trx_state_string()

const char * trx_state_string ( trx_state_t  state)
inline

Human readable transaction state, for diagnostic purposes.

Returns
pointer to static string, nullptr if state is not valid

◆ 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_was_started()

bool trx_was_started ( const trx_t trx)
inline

Check if transaction was started.

Note, that after the check situation might have already been changed (and note that holding the trx_sys->mutex does not prevent state transitions for read-only transactions).

Parameters
[in]trxTransaction whose state we need to check
Returns
true if transaction is in state started

◆ TRX_WEIGHT()

static uint64_t TRX_WEIGHT ( const trx_t t)
inlinestatic

Calculates the "weight" of a transaction.

The weight of one transaction is estimated as the number of altered rows + the number of locked rows.

Parameters
ttransaction
Returns
transaction weight

◆ 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) in: the transaction to be compared

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

Variable Documentation

◆ to_rollback_trx_tables

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

◆ trx_dummy_sess

sess_t* trx_dummy_sess
extern

Dummy session used currently in MySQL interface.

◆ TRX_QUE_STATE_STR_MAX_LEN

constexpr uint32_t TRX_QUE_STATE_STR_MAX_LEN = 12
constexpr