MySQL  8.0.12
Source Code Documentation
trx_lock_t Struct Reference

Latching protocol for trx_lock_t::que_state. More...

#include <trx0trx.h>

Public Attributes

ulint n_active_thrs
 number of active query threads More...
 
trx_que_t que_state
 valid when trx->state == TRX_STATE_ACTIVE: TRX_QUE_RUNNING, TRX_QUE_LOCK_WAIT, ... More...
 
lock_twait_lock
 if trx execution state is TRX_QUE_LOCK_WAIT, this points to the lock request, otherwise this is NULL; set to non-NULL when holding both trx->mutex and lock_sys->mutex; set to NULL when holding lock_sys->mutex; readers should hold lock_sys->mutex, except when they are holding trx->mutex and wait_lock==NULL More...
 
ib_uint64_t deadlock_mark
 A mark field that is initialized to and checked against lock_mark_counter by lock_deadlock_recursive(). More...
 
bool was_chosen_as_deadlock_victim
 when the transaction decides to wait for a lock, it sets this to false; if another transaction chooses this transaction as a victim in deadlock resolution, it sets this to true. More...
 
time_t wait_started
 lock wait started at this time, protected only by lock_sys->mutex More...
 
que_thr_twait_thr
 query thread belonging to this trx that is in QUE_THR_LOCK_WAIT state. More...
 
lock_pool_t rec_pool
 Pre-allocated record locks. More...
 
lock_pool_t table_pool
 Pre-allocated table locks. More...
 
ulint rec_cached
 Next free rec lock in pool. More...
 
ulint table_cached
 Next free table lock in pool. More...
 
mem_heap_tlock_heap
 memory heap for trx_locks; protected by lock_sys->mutex More...
 
trx_lock_list_t trx_locks
 locks requested by the transaction; insertions are protected by trx->mutex and lock_sys->mutex; removals are protected by lock_sys->mutex More...
 
lock_pool_t table_locks
 All table locks requested by this transaction, including AUTOINC locks. More...
 
bool cancel
 true if the transaction is being rolled back either via deadlock detection or due to lock timeout. More...
 
ulint n_rec_locks
 number of rec locks in this trx More...
 
bool in_rollback
 When a transaction is forced to rollback due to a deadlock check or by another high priority transaction this is true. More...
 
bool start_stmt
 The transaction called ha_innobase::start_stmt() to lock a table. More...
 

Detailed Description

Latching protocol for trx_lock_t::que_state.

trx_lock_t::que_state captures the state of the query thread during the execution of a query. This is different from a transaction state. The query state of a transaction can be updated asynchronously by other threads. The other threads can be system threads, like the timeout monitor thread or user threads executing other queries. Another thing to be mindful of is that there is a delay between when a query thread is put into LOCK_WAIT state and before it actually starts waiting. Between these two events it is possible that the query thread is granted the lock it was waiting for, which implies that the state can be changed asynchronously.

All these operations take place within the context of locking. Therefore state changes within the locking code must acquire both the lock mutex and the trx->mutex when changing trx->lock.que_state to TRX_QUE_LOCK_WAIT or trx->lock.wait_lock to non-NULL but when the lock wait ends it is sufficient to only acquire the trx->mutex. To query the state either of the mutexes is sufficient within the locking code and no mutex is required when the query thread is no longer waiting. The locks and state of an active transaction. Protected by lock_sys->mutex, trx->mutex or both.

Member Data Documentation

◆ cancel

bool trx_lock_t::cancel

true if the transaction is being rolled back either via deadlock detection or due to lock timeout.

The caller has to acquire the trx_t::mutex in order to cancel the locks. In lock_trx_table_locks_remove() we check for this cancel of a transaction's locks and avoid reacquiring the trx mutex to prevent recursive deadlocks. Protected by both the lock sys mutex and the trx_t::mutex.

◆ deadlock_mark

ib_uint64_t trx_lock_t::deadlock_mark

A mark field that is initialized to and checked against lock_mark_counter by lock_deadlock_recursive().

◆ in_rollback

bool trx_lock_t::in_rollback

When a transaction is forced to rollback due to a deadlock check or by another high priority transaction this is true.

Used by debug checks in lock0lock.cc

◆ lock_heap

mem_heap_t* trx_lock_t::lock_heap

memory heap for trx_locks; protected by lock_sys->mutex

◆ n_active_thrs

ulint trx_lock_t::n_active_thrs

number of active query threads

◆ n_rec_locks

ulint trx_lock_t::n_rec_locks

number of rec locks in this trx

◆ que_state

trx_que_t trx_lock_t::que_state

valid when trx->state == TRX_STATE_ACTIVE: TRX_QUE_RUNNING, TRX_QUE_LOCK_WAIT, ...

◆ rec_cached

ulint trx_lock_t::rec_cached

Next free rec lock in pool.

◆ rec_pool

lock_pool_t trx_lock_t::rec_pool

Pre-allocated record locks.

◆ start_stmt

bool trx_lock_t::start_stmt

The transaction called ha_innobase::start_stmt() to lock a table.

Most likely a temporary table.

◆ table_cached

ulint trx_lock_t::table_cached

Next free table lock in pool.

◆ table_locks

lock_pool_t trx_lock_t::table_locks

All table locks requested by this transaction, including AUTOINC locks.

◆ table_pool

lock_pool_t trx_lock_t::table_pool

Pre-allocated table locks.

◆ trx_locks

trx_lock_list_t trx_lock_t::trx_locks

locks requested by the transaction; insertions are protected by trx->mutex and lock_sys->mutex; removals are protected by lock_sys->mutex

◆ wait_lock

lock_t* trx_lock_t::wait_lock

if trx execution state is TRX_QUE_LOCK_WAIT, this points to the lock request, otherwise this is NULL; set to non-NULL when holding both trx->mutex and lock_sys->mutex; set to NULL when holding lock_sys->mutex; readers should hold lock_sys->mutex, except when they are holding trx->mutex and wait_lock==NULL

◆ wait_started

time_t trx_lock_t::wait_started

lock wait started at this time, protected only by lock_sys->mutex

◆ wait_thr

que_thr_t* trx_lock_t::wait_thr

query thread belonging to this trx that is in QUE_THR_LOCK_WAIT state.

For threads suspended in a lock wait, this is protected by lock_sys->mutex. Otherwise, this may only be modified by the thread that is serving the running transaction.

◆ was_chosen_as_deadlock_victim

bool trx_lock_t::was_chosen_as_deadlock_victim

when the transaction decides to wait for a lock, it sets this to false; if another transaction chooses this transaction as a victim in deadlock resolution, it sets this to true.

Protected by trx->mutex.


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