MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trx_t Struct Reference

#include <trx0trx.h>

Collaboration diagram for trx_t:

Public Attributes

ulint magic_n
ib_mutex_t mutex
trx_state_t state
trx_lock_t lock
ulint is_recovered
const char * op_info
ulint isolation_level
ulint check_foreigns
unsigned is_registered:1
unsigned owns_prepare_mutex:1
ulint check_unique_secondary
ulint support_xa
ulint flush_log_later
ulint must_flush_log_later
ulint duplicates
ulint has_search_latch
ulint search_latch_timeout
trx_dict_op_t dict_operation
ulint declared_to_be_inside_innodb
ulint n_tickets_to_enter_innodb
ulint dict_operation_lock_mode
trx_id_t no
time_t start_time
trx_id_t id
XID xid
lsn_t commit_lsn
table_id_t table_id
THD * mysql_thd
const char * mysql_log_file_name
ib_int64_t mysql_log_offset
ulint n_mysql_tables_in_use
ulint mysql_n_tables_locked
 trx_list
 mysql_trx_list
dberr_t error_state
const dict_index_terror_info
ulint error_key_num
sess_tsess
que_tgraph
mem_heap_tglobal_read_view_heap
read_view_tglobal_read_view
read_view_tread_view
 trx_savepoints
ib_mutex_t undo_mutex
undo_no_t undo_no
trx_savept_t last_sql_stat_start
trx_rseg_trseg
trx_undo_tinsert_undo
trx_undo_tupdate_undo
undo_no_t roll_limit
ulint pages_undone
trx_undo_arr_tundo_no_arr
ulint n_autoinc_rows
ib_vector_tautoinc_locks
ibool read_only
ibool auto_commit
ulint will_lock
bool ddl
fts_trx_tfts_trx
doc_id_t fts_next_doc_id
ulint flush_tables
char detailed_error [256]

Detailed Description

The transaction handle

Normally, there is a 1:1 relationship between a transaction handle (trx) and a session (client connection). One session is associated with exactly one user transaction. There are some exceptions to this:

For DDL operations, a subtransaction is allocated that modifies the data dictionary tables. Lock waits and deadlocks are prevented by acquiring the dict_operation_lock before starting the subtransaction and releasing it after committing the subtransaction.

The purge system uses a special transaction that is not associated with any session.

If the system crashed or it was quickly shut down while there were transactions in the ACTIVE or PREPARED state, these transactions would no longer be associated with a session when the server is restarted.

A session may be served by at most one thread at a time. The serving thread of a session might change in some MySQL implementations. Therefore we do not have os_thread_get_curr_id() assertions in the code.

Normally, only the thread that is currently associated with a running transaction may access (read and modify) the trx object, and it may do so without holding any mutex. The following are exceptions to this:

trx_rollback_resurrected() may access resurrected (connectionless) transactions while the system is already processing new user transactions. The trx_sys->mutex prevents a race condition between it and lock_trx_release_locks() [invoked by trx_commit()].

trx_print_low() may access transactions not associated with the current thread. The caller must be holding trx_sys->mutex and lock_sys->mutex.

When a transaction handle is in the trx_sys->mysql_trx_list or trx_sys->trx_list, some of its fields must not be modified without holding trx_sys->mutex exclusively.

The locking code (in particular, lock_deadlock_recursive() and lock_rec_convert_impl_to_expl()) will access transactions associated to other connections. The locks of transactions are protected by lock_sys->mutex and sometimes by trx->mutex.

Definition at line 676 of file trx0trx.h.

Member Data Documentation

ibool trx_t::auto_commit

TRUE if it is an autocommit

Definition at line 980 of file trx0trx.h.

ulint trx_t::check_foreigns

normally TRUE, but if the user wants to suppress foreign key checks, (in table imports, for example) we set this FALSE

Definition at line 756 of file trx0trx.h.

ulint trx_t::check_unique_secondary

normally TRUE, but if the user wants to speed up inserts by suppressing unique key checks for secondary indexes when we decide if we can use the insert buffer for them, we set this FALSE

Definition at line 775 of file trx0trx.h.

lsn_t trx_t::commit_lsn

lsn at the time of the commit

Definition at line 846 of file trx0trx.h.

bool trx_t::ddl

true if it is a transaction that is being started for a DDL operation

Definition at line 984 of file trx0trx.h.

ulint trx_t::declared_to_be_inside_innodb

this is TRUE if we have declared this transaction in srv_conc_enter_innodb to be inside the InnoDB engine

Definition at line 816 of file trx0trx.h.

char trx_t::detailed_error[256]

detailed error message for last error, or empty.

Definition at line 1002 of file trx0trx.h.

trx_dict_op_t trx_t::dict_operation
See Also
enum trx_dict_op

Definition at line 812 of file trx0trx.h.

ulint trx_t::dict_operation_lock_mode

0, RW_S_LATCH, or RW_X_LATCH: the latch mode trx currently holds on dict_operation_lock. Protected by dict_operation_lock.

Definition at line 826 of file trx0trx.h.

ulint trx_t::duplicates

TRX_DUP_IGNORE | TRX_DUP_REPLACE

Definition at line 798 of file trx0trx.h.

const dict_index_t* trx_t::error_info

if the error number indicates a duplicate key error, a pointer to the problematic index is stored here

Definition at line 898 of file trx0trx.h.

ulint trx_t::error_key_num

if the index creation fails to a duplicate key error, a mysql key number of that index is stored here

Definition at line 901 of file trx0trx.h.

dberr_t trx_t::error_state

0 if no error, otherwise error number; NOTE That ONLY the thread doing the transaction is allowed to set this field: this is NOT protected by any mutex

Definition at line 893 of file trx0trx.h.

ulint trx_t::flush_tables

if "covering" the FLUSH TABLES", count of tables being flushed.

Definition at line 992 of file trx0trx.h.

fts_trx_t* trx_t::fts_trx

FTS information, or NULL if transaction hasn't modified tables with FTS indexes (yet).

Definition at line 987 of file trx0trx.h.

read_view_t* trx_t::global_read_view

consistent read view associated to a transaction or NULL

Definition at line 915 of file trx0trx.h.

mem_heap_t* trx_t::global_read_view_heap

memory heap for the global read view

Definition at line 912 of file trx0trx.h.

que_t* trx_t::graph

query currently run in the session, or NULL if none; NOTE that the query belongs to the session, and it can survive over a transaction commit, if it is a stored procedure with a COMMIT WORK statement, for instance

Definition at line 905 of file trx0trx.h.

ulint trx_t::has_search_latch

TRUE if this trx has latched the search system latch in S-mode

Definition at line 800 of file trx0trx.h.

trx_id_t trx_t::id

transaction id

Definition at line 842 of file trx0trx.h.

trx_undo_t* trx_t::insert_undo

pointer to the insert undo log, or NULL if no inserts performed yet

Definition at line 949 of file trx0trx.h.

ulint trx_t::is_recovered

0=normal transaction, 1=recovered, must be rolled back, protected by trx_sys->mutex when trx->in_rw_trx_list holds

Definition at line 746 of file trx0trx.h.

ulint trx_t::isolation_level

TRX_ISO_REPEATABLE_READ, ...

Definition at line 755 of file trx0trx.h.

trx_savept_t trx_t::last_sql_stat_start

undo_no when the last sql statement was started: in case of an error, trx is rolled back down to this undo number; see note at undo_mutex!

Definition at line 942 of file trx0trx.h.

trx_lock_t trx_t::lock

Information about the transaction locks and state. Protected by trx->mutex or lock_sys->mutex or both

Definition at line 742 of file trx0trx.h.

ulint trx_t::must_flush_log_later

this flag is set to TRUE in trx_commit() if flush_log_later was TRUE, and there were modifications by the transaction; in that case we must flush the log in trx_commit_complete_for_mysql()

Definition at line 792 of file trx0trx.h.

ib_mutex_t trx_t::mutex

Mutex protecting the fields state and lock (except some fields of lock, which are protected by lock_sys->mutex)

Definition at line 679 of file trx0trx.h.

const char* trx_t::mysql_log_file_name

if MySQL binlog is used, this field contains a pointer to the latest file name; this is NULL if binlog is not used

Definition at line 853 of file trx0trx.h.

ib_int64_t trx_t::mysql_log_offset

if MySQL binlog is used, this field contains the end offset of the binlog entry

Definition at line 858 of file trx0trx.h.

ulint trx_t::mysql_n_tables_locked

how many tables the current SQL statement uses, except those in consistent read

Definition at line 866 of file trx0trx.h.

THD* trx_t::mysql_thd

MySQL thread handle corresponding to this trx, or NULL

Definition at line 850 of file trx0trx.h.

trx_t::mysql_trx_list

list of transactions created for MySQL; protected by trx_sys->mutex

Definition at line 885 of file trx0trx.h.

ulint trx_t::n_autoinc_rows

no. of AUTO-INC rows required for an SQL statement. This is useful for multi-row INSERTs

Definition at line 961 of file trx0trx.h.

ulint trx_t::n_mysql_tables_in_use

number of Innobase tables used in the processing of the current SQL statement in MySQL

Definition at line 862 of file trx0trx.h.

ulint trx_t::n_tickets_to_enter_innodb

this can be > 0 only when declared_to_... is TRUE; when we come to srv_conc_innodb_enter, if the value here is > 0, we decrement this by 1

Definition at line 821 of file trx0trx.h.

trx_id_t trx_t::no

transaction serialization number: max trx id shortly before the transaction is moved to COMMITTED_IN_MEMORY state. Protected by trx_sys_t::mutex when trx->in_rw_trx_list. Initially set to TRX_ID_MAX.

Definition at line 831 of file trx0trx.h.

const char* trx_t::op_info

English text describing the current operation, or an empty string

Definition at line 752 of file trx0trx.h.

ulint trx_t::pages_undone

number of undo log pages undone since the last undo log truncation

Definition at line 955 of file trx0trx.h.

ibool trx_t::read_only

TRUE if transaction is flagged as a READ-ONLY transaction. if !auto_commit || will_lock > 0 then it will added to the list trx_sys_t::ro_trx_list. A read only transaction will not be assigned an UNDO log. Non-locking auto-commit read-only transaction will not be on either list.

Definition at line 971 of file trx0trx.h.

read_view_t* trx_t::read_view

consistent read view used in the transaction or NULL, this read view if defined can be normal read view associated to a transaction (i.e. same as global_read_view) or read view associated to a cursor

Definition at line 917 of file trx0trx.h.

undo_no_t trx_t::roll_limit

least undo number to undo during a rollback

Definition at line 953 of file trx0trx.h.

trx_rseg_t* trx_t::rseg

rollback segment assigned to the transaction, or NULL if not assigned yet

Definition at line 946 of file trx0trx.h.

ulint trx_t::search_latch_timeout

If we notice that someone is waiting for our S-lock on the search latch to be released, we wait in row0sel.cc for BTR_SEA_TIMEOUT new searches until we try to keep the search latch again over calls from MySQL; this is intended to reduce contention on the search latch

Definition at line 803 of file trx0trx.h.

sess_t* trx_t::sess

session of the trx, NULL if none

Definition at line 904 of file trx0trx.h.

time_t trx_t::start_time

time the trx object was created or the state last time became TRX_STATE_ACTIVE

Definition at line 839 of file trx0trx.h.

trx_state_t trx_t::state
State of the trx from the point of view of concurrency control

and the valid state transitions.

Possible states:

TRX_STATE_NOT_STARTED TRX_STATE_ACTIVE TRX_STATE_PREPARED TRX_STATE_COMMITTED_IN_MEMORY (alias below COMMITTED)

Valid state transitions are:

Regular transactions: NOT_STARTED -> ACTIVE -> COMMITTED -> NOT_STARTED

Auto-commit non-locking read-only: NOT_STARTED -> ACTIVE -> NOT_STARTED

XA (2PC): NOT_STARTED -> ACTIVE -> PREPARED -> COMMITTED -> NOT_STARTED

Recovered XA: NOT_STARTED -> PREPARED -> COMMITTED -> (freed)

XA (2PC) (shutdown before ROLLBACK or COMMIT): NOT_STARTED -> PREPARED -> (freed)

Latching and various transaction lists membership rules:

XA (2PC) transactions are always treated as non-autocommit.

Transitions to ACTIVE or NOT_STARTED occur when !in_rw_trx_list and !in_ro_trx_list (no trx_sys->mutex needed).

Autocommit non-locking read-only transactions move between states without holding any mutex. They are !in_rw_trx_list, !in_ro_trx_list.

When a transaction is NOT_STARTED, it can be in_mysql_trx_list if it is a user transaction. It cannot be in ro_trx_list or rw_trx_list.

ACTIVE->PREPARED->COMMITTED is only possible when trx->in_rw_trx_list. The transition ACTIVE->PREPARED is protected by trx_sys->mutex.

ACTIVE->COMMITTED is possible when the transaction is in ro_trx_list or rw_trx_list.

Transitions to COMMITTED are protected by both lock_sys->mutex and trx->mutex.

NOTE: Some of these state change constraints are an overkill, currently only required for a consistent view for printing stats. This unnecessarily adds a huge cost for the general case.

NOTE: In the future we should add read only transactions to the ro_trx_list the first time they try to acquire a lock ie. by default we treat all read-only transactions as non-locking.

Definition at line 740 of file trx0trx.h.

ulint trx_t::support_xa

normally we do the XA two-phase commit steps, but by setting this to FALSE, one can save CPU time and about 150 bytes in the undo log size as then we skip XA steps

Definition at line 781 of file trx0trx.h.

table_id_t trx_t::table_id

Table to drop iff dict_operation == TRX_DICT_OP_TABLE, or 0.

Definition at line 847 of file trx0trx.h.

trx_t::trx_list

list of transactions; protected by trx_sys->mutex. The same node is used for both trx_sys_t::ro_trx_list and trx_sys_t::rw_trx_list

Definition at line 871 of file trx0trx.h.

trx_t::trx_savepoints

savepoints set with SAVEPOINT ..., oldest first

Definition at line 925 of file trx0trx.h.

ib_mutex_t trx_t::undo_mutex

mutex protecting the fields in this section (down to undo_no_arr), EXCEPT last_sql_stat_start, which can be accessed only when we know that there cannot be any activity in the undo logs!

Definition at line 928 of file trx0trx.h.

undo_no_t trx_t::undo_no

next undo log record number to assign; since the undo log is private for a transaction, this is a simple ascending sequence with no gaps; thus it represents the number of modified/inserted rows in a transaction

Definition at line 934 of file trx0trx.h.

trx_undo_arr_t* trx_t::undo_no_arr

array of undo numbers of undo log records which are currently processed by a rollback operation

Definition at line 957 of file trx0trx.h.

trx_undo_t* trx_t::update_undo

pointer to the update undo log, or NULL if no update performed yet

Definition at line 951 of file trx0trx.h.

ulint trx_t::will_lock

Will acquire some locks. Increment each time we determine that a lock will be acquired by the MySQL layer.

Definition at line 981 of file trx0trx.h.

XID trx_t::xid

X/Open XA transaction identification to identify a transaction branch

Definition at line 843 of file trx0trx.h.


The documentation for this struct was generated from the following file: