MySQL 9.0.0
Source Code Documentation
|
#include <trx0trx.h>
Public Types | |
enum | isolation_level_t { READ_UNCOMMITTED , READ_COMMITTED , REPEATABLE_READ , SERIALIZABLE } |
Public Member Functions | |
trx_t ()=default | |
Default constructor. More... | |
bool | is_read_uncommitted () const |
bool | releases_gap_locks_at_prepare () const |
bool | skip_gap_locks () const |
bool | allow_semi_consistent () const |
bool | releases_non_matching_rows () const |
Checks if this transaction releases locks on non matching records due to low isolation level. More... | |
Public Attributes | |
TrxMutex | mutex |
Mutex protecting the fields state and lock (except some fields of lock , which are protected by lock_sys latches) More... | |
uint32_t | in_depth |
Track nested TrxInInnoDB count. More... | |
uint32_t | in_innodb |
if the thread is executing in the InnoDB context count > 0. More... | |
bool | abort |
if this flag is set then this transaction must abort when it can More... | |
trx_id_t | id |
transaction id More... | |
trx_id_t | no |
transaction serialization number: max trx id shortly before the transaction is moved to COMMITTED_IN_MEMORY state. More... | |
std::atomic< trx_state_t > | state |
State of the trx from the point of view of concurrency control and the valid state transitions. More... | |
bool | skip_lock_inheritance |
ReadView * | read_view |
consistent read view used in the transaction, or NULL if not yet set More... | |
trx_list | |
list of transactions; protected by trx_sys->mutex. More... | |
no_list | |
Required during view creation to check for the view limit for transactions that are committing. More... | |
trx_lock_t | lock |
Information about the transaction locks and state. More... | |
bool | is_recovered |
false: a normal transaction true: a recovered transaction More... | |
std::atomic< std::thread::id > | killed_by |
The thread ID that wants to kill this transaction asynchronously. More... | |
const char * | op_info |
English text describing the current operation, or an empty string. More... | |
isolation_level_t | isolation_level |
Current isolation level. More... | |
bool | check_foreigns |
normally true, but if the user wants to suppress foreign key checks, (in table imports, for example) we set this false More... | |
bool | is_registered |
bool | 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 More... | |
bool | flush_log_later |
bool | 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() More... | |
bool | has_search_latch |
true if this trx has latched the search system latch in S-mode. More... | |
trx_dict_op_t | dict_operation |
bool | ddl_operation |
True if this trx involves dd table change. More... | |
bool | ddl_must_flush |
True if this trx involves dd table change, and must flush. More... | |
bool | in_truncate |
bool | 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 More... | |
uint32_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 More... | |
uint32_t | dict_operation_lock_mode |
0, RW_S_LATCH, or RW_X_LATCH: the latch mode trx currently holds on dict_operation_lock. More... | |
std::atomic< std::chrono::system_clock::time_point > | start_time |
Time the state last time became TRX_STATE_ACTIVE. More... | |
lsn_t | commit_lsn |
lsn at the time of the commit More... | |
THD * | mysql_thd |
MySQL thread handle corresponding to this trx, or NULL. More... | |
const char * | 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 More... | |
uint64_t | mysql_log_offset |
if MySQL binlog is used, this field contains the end offset of the binlog entry More... | |
uint32_t | n_mysql_tables_in_use |
number of Innobase tables used in the processing of the current SQL statement in MySQL More... | |
uint32_t | mysql_n_tables_locked |
how many tables the current SQL statement uses, except those in consistent read More... | |
bool | in_rw_trx_list |
True iff in trx_sys->rw_trx_list. More... | |
mysql_trx_list | |
list of transactions created for MySQL; protected by trx_sys->mutex More... | |
bool | in_mysql_trx_list |
true if in trx_sys->mysql_trx_list More... | |
dberr_t | error_state |
DB_SUCCESS if no error, otherwise error number. More... | |
const dict_index_t * | error_index |
if the error number indicates a duplicate key error, a pointer to the problematic index is stored here More... | |
ulint | error_key_num |
if the index creation fails to a duplicate key error, a mysql key number of that index is stored here More... | |
sess_t * | sess |
session of the trx, NULL if none More... | |
que_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 More... | |
trx_savepoints {} | |
savepoints set with SAVEPOINT ..., oldest first More... | |
UndoMutex | 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! More... | |
undo_no_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 More... | |
space_id_t | undo_rseg_space |
space id where last undo record was written More... | |
trx_savept_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! More... | |
trx_rsegs_t | rsegs |
undo_no_t | roll_limit |
least undo number to undo during a partial rollback; 0 otherwise More... | |
bool | in_rollback |
true when the transaction is executing a partial or full rollback More... | |
ulint | pages_undone |
number of undo log pages undone since the last undo log truncation More... | |
ulint | n_autoinc_rows |
no. More... | |
bool | read_only |
true if transaction is flagged as a READ-ONLY transaction. More... | |
bool | auto_commit |
true if it is an autocommit More... | |
uint32_t | will_lock |
Will acquire some locks. More... | |
fts_trx_t * | fts_trx |
FTS information, or NULL if transaction hasn't modified tables with FTS indexes (yet). More... | |
doc_id_t | fts_next_doc_id |
uint32_t | flush_tables |
if "covering" the FLUSH TABLES", count of tables being flushed. More... | |
bool | internal |
true if it is a system/internal transaction background task. More... | |
bool | persists_gtid |
Transaction persists GTID. More... | |
ulint | start_line |
Track where it was started from. More... | |
const char * | start_file |
Filename where it was started. More... | |
lint | n_ref |
Count of references, protected by trx_t::mutex. More... | |
std::atomic_uint64_t | version |
Version of this instance. More... | |
XID * | xid |
X/Open XA transaction identification to identify a transaction branch. More... | |
trx_mod_tables_t | mod_tables |
List of tables that were modified by this transaction. More... | |
bool | api_trx |
trx started by InnoDB API More... | |
bool | api_auto_commit |
automatic commit More... | |
bool | read_write |
if read and write operation More... | |
bool | purge_sys_trx |
This flag is set for trx_t objects used by the purge sys. More... | |
char * | detailed_error |
detailed error message for last error, or empty. More... | |
Flush_observer * | flush_observer |
flush observer More... | |
bool | is_dd_trx |
True if the transaction is used for doing Non-locking Read-only Read Committed on DD tables. More... | |
ulint | magic_n |
|
default |
Default constructor.
|
inline |
|
inline |
|
inline |
|
inline |
Checks if this transaction releases locks on non matching records due to low isolation level.
|
inline |
bool trx_t::abort |
if this flag is set then this transaction must abort when it can
bool trx_t::api_auto_commit |
automatic commit
bool trx_t::api_trx |
trx started by InnoDB API
bool trx_t::auto_commit |
true if it is an autocommit
bool 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
bool 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
lsn_t trx_t::commit_lsn |
lsn at the time of the commit
bool trx_t::ddl_must_flush |
True if this trx involves dd table change, and must flush.
bool trx_t::ddl_operation |
True if this trx involves dd table change.
bool 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
char* trx_t::detailed_error |
detailed error message for last error, or empty.
trx_dict_op_t trx_t::dict_operation |
uint32_t 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.
const dict_index_t* trx_t::error_index |
if the error number indicates a duplicate key error, a pointer to the problematic index is stored here
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
dberr_t trx_t::error_state |
DB_SUCCESS if no error, otherwise error number.
Accessed without any mutex only by the thread doing the transaction or, if it is suspended (waiting for a lock), by the thread holding this->mutex which has changed trx->lock.wait_lock to nullptr and will wake up the transaction.
bool trx_t::flush_log_later |
Flush_observer* trx_t::flush_observer |
flush observer
uint32_t trx_t::flush_tables |
if "covering" the FLUSH TABLES", count of tables being flushed.
doc_id_t trx_t::fts_next_doc_id |
fts_trx_t* trx_t::fts_trx |
FTS information, or NULL if transaction hasn't modified tables with FTS indexes (yet).
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
bool trx_t::has_search_latch |
true if this trx has latched the search system latch in S-mode.
This now can only be true in row_search_mvcc, the btr search latch must has been released before exiting, and this flag would be set to false
trx_id_t trx_t::id |
transaction id
uint32_t trx_t::in_depth |
Track nested TrxInInnoDB count.
uint32_t trx_t::in_innodb |
if the thread is executing in the InnoDB context count > 0.
bool trx_t::in_mysql_trx_list |
true if in trx_sys->mysql_trx_list
bool trx_t::in_rollback |
true when the transaction is executing a partial or full rollback
bool trx_t::in_rw_trx_list |
True iff in trx_sys->rw_trx_list.
bool trx_t::in_truncate |
bool trx_t::internal |
true if it is a system/internal transaction background task.
Such transactions are always treated as read-write.
bool trx_t::is_dd_trx |
True if the transaction is used for doing Non-locking Read-only Read Committed on DD tables.
bool trx_t::is_recovered |
false: a normal transaction true: a recovered transaction
Set to true when srv_is_being_started for recovered transactions. Set to false without any protection in trx_init (where no other thread should access this object anyway). Can be read safely when holding trx_sys->mutex and trx belongs to rw_trx_list, as trx_init can not be called until trx leaves rw_trx_list which requires the trx_sys->mutex.
bool trx_t::is_registered |
isolation_level_t trx_t::isolation_level |
Current isolation level.
std::atomic<std::thread::id> trx_t::killed_by |
The thread ID that wants to kill this transaction asynchronously.
This is required because we recursively enter the handlerton methods and need to distinguish between the kill thread and the transaction thread.
Note: We need to be careful w.r.t the Thread Pool. The thread doing the kill should not leave InnoDB between the mark and the actual async kill because the running thread can change.
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!
trx_lock_t trx_t::lock |
Information about the transaction locks and state.
Protected by trx->mutex or lock_sys latches or both
ulint trx_t::magic_n |
trx_mod_tables_t trx_t::mod_tables |
List of tables that were modified by this transaction.
bool 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()
|
mutable |
Mutex protecting the fields state
and lock
(except some fields of lock
, which are protected by lock_sys latches)
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
uint64_t trx_t::mysql_log_offset |
if MySQL binlog is used, this field contains the end offset of the binlog entry
uint32_t trx_t::mysql_n_tables_locked |
how many tables the current SQL statement uses, except those in consistent read
THD* trx_t::mysql_thd |
MySQL thread handle corresponding to this trx, or NULL.
trx_t::mysql_trx_list |
list of transactions created for MySQL; protected by trx_sys->mutex
ulint trx_t::n_autoinc_rows |
no.
of AUTO-INC rows required for an SQL statement. This is useful for multi-row INSERTs
uint32_t trx_t::n_mysql_tables_in_use |
number of Innobase tables used in the processing of the current SQL statement in MySQL
lint trx_t::n_ref |
Count of references, protected by trx_t::mutex.
We can't release the locks nor commit the transaction until this reference is 0. We can change the state to COMMITTED_IN_MEMORY to signify that it is no longer "active".
uint32_t 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
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.
trx_t::no_list |
Required during view creation to check for the view limit for transactions that are committing.
const char* trx_t::op_info |
English text describing the current operation, or an empty string.
ulint trx_t::pages_undone |
number of undo log pages undone since the last undo log truncation
bool trx_t::persists_gtid |
Transaction persists GTID.
bool trx_t::purge_sys_trx |
This flag is set for trx_t objects used by the purge sys.
We use the flag when validating mysql_trx_list in trx_sys_before_pre_dd_shutdown_validate. Purge threads can have allocated trx_t objects visible in the mysql_trx_list at this point during shutdown, this is acceptable so we need a way to signal this fact.
bool trx_t::read_only |
true if transaction is flagged as a READ-ONLY transaction.
if auto_commit && will_lock == 0 then it will be handled as a AC-NL-RO-SELECT (Auto Commit Non-Locking Read Only Select). A read only transaction will not be assigned an UNDO log.
ReadView* trx_t::read_view |
consistent read view used in the transaction, or NULL if not yet set
bool trx_t::read_write |
if read and write operation
undo_no_t trx_t::roll_limit |
least undo number to undo during a partial rollback; 0 otherwise
trx_rsegs_t trx_t::rsegs |
sess_t* trx_t::sess |
session of the trx, NULL if none
bool trx_t::skip_lock_inheritance |
const char* trx_t::start_file |
Filename where it was started.
ulint trx_t::start_line |
Track where it was started from.
std::atomic<std::chrono::system_clock::time_point> trx_t::start_time |
Time the state last time became TRX_STATE_ACTIVE.
std::atomic<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_FORCED_ROLLBACK 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 or disconnect before ROLLBACK or COMMIT): NOT_STARTED -> PREPARED -> (freed)
Disconnected XA can become recovered: ... -> ACTIVE -> PREPARED (connected) -> PREPARED (disconnected) Disconnected means from mysql e.g due to the mysql client disconnection. 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 (no trx_sys->mutex needed).
Autocommit non-locking read-only transactions move between states without holding any mutex. They are !in_rw_trx_list.
All transactions, unless they are determined to be ac-nl-ro, explicitly tagged as read-only or read-write, will first be put on the read-only transaction list. Only when a !read-only transaction in the read-only list tries to acquire an X or IX lock on a table do we remove it from the read-only list and put it on the read-write list. During this switch we assign it a rollback segment.
When a transaction is NOT_STARTED, it can be in_mysql_trx_list if it is a user transaction. It cannot be in 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 rw_trx_list.
Transitions to COMMITTED are protected by 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.
trx_t::trx_list |
list of transactions; protected by trx_sys->mutex.
trx_t::trx_savepoints {} |
savepoints set with SAVEPOINT ..., oldest first
UndoMutex 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!
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
space_id_t trx_t::undo_rseg_space |
space id where last undo record was written
std::atomic_uint64_t trx_t::version |
Version of this instance.
It is incremented each time the instance is re-used in trx_start_low(). It is used to track whether a transaction has been restarted since it was tagged for asynchronous rollback.
uint32_t trx_t::will_lock |
Will acquire some locks.
Increment each time we determine that a lock will be acquired by the MySQL layer.
XID* trx_t::xid |
X/Open XA transaction identification to identify a transaction branch.