InnoDB Plugin  1.0
Data Structures | Macros | Enumerations | Functions | Variables
trx0trx.h File Reference
#include "univ.i"
#include "trx0types.h"
#include "dict0types.h"
#include "lock0types.h"
#include "log0log.h"
#include "usr0types.h"
#include "que0types.h"
#include "mem0mem.h"
#include "read0types.h"
#include "trx0xa.h"
#include "ut0vec.h"
#include "fts0fts.h"
#include "trx0trx.ic"
Include dependency graph for trx0trx.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  trx_lock_t
struct  trx_t
struct  commit_node_t

Macros

#define trx_start_if_not_started_xa(t)
#define trx_start_if_not_started(t)
#define trx_start_for_ddl(t, o)
#define TRX_WEIGHT(t)   ((t)->undo_no + UT_LIST_GET_LEN((t)->lock.trx_locks))
#define TRX_QUE_STATE_STR_MAX_LEN   12 /* "ROLLING BACK" */
#define trx_lock_wait_timeout_get(trx)
#define trx_is_autocommit_non_locking(t)   ((t)->auto_commit && (t)->will_lock == 0)
#define trx_is_ac_nl_ro(t)   ((t)->read_only && trx_is_autocommit_non_locking((t)))
#define assert_trx_in_rw_list(t)
#define assert_trx_in_list(t)
#define assert_trx_nonlocking_or_in_list(t)
#define TRX_MAGIC_N   91118598
#define TRX_ISO_READ_UNCOMMITTED
#define TRX_ISO_READ_COMMITTED
#define TRX_ISO_REPEATABLE_READ
#define TRX_ISO_SERIALIZABLE
#define TRX_DUP_IGNORE   1 /* duplicate rows are to be updated */
#define TRX_DUP_REPLACE   2 /* duplicate rows are to be replaced */
#define TRX_SIG_NO_SIGNAL   0
#define TRX_SIG_TOTAL_ROLLBACK   1
#define TRX_SIG_ROLLBACK_TO_SAVEPT   2
#define TRX_SIG_COMMIT   3
#define TRX_SIG_BREAK_EXECUTION   5
#define TRX_SIG_SELF
#define TRX_SIG_OTHER_SESS
#define trx_mutex_own(t)   mutex_own(&t->mutex)
#define trx_mutex_enter(t)
#define trx_mutex_exit(t)
#define btr_search_latch   (*btr_search_latch_temp)

Enumerations

enum  commit_node_state { COMMIT_NODE_SEND = 1, COMMIT_NODE_WAIT }

Functions

UNIV_INLINE void trx_search_latch_release_if_reserved (trx_t *trx)
UNIV_INTERN void trx_set_detailed_error (trx_t *trx, const char *msg)
UNIV_INTERN void trx_set_detailed_error_from_file (trx_t *trx, FILE *file)
UNIV_INLINE const dict_index_ttrx_get_error_info (const trx_t *trx)
UNIV_INTERN trx_ttrx_allocate_for_mysql (void)
UNIV_INTERN trx_ttrx_allocate_for_background (void)
UNIV_INTERN void trx_free_for_background (trx_t *trx)
UNIV_INTERN void trx_free_prepared (trx_t *trx) UNIV_COLD)
UNIV_INTERN void trx_free_for_mysql (trx_t *trx)
UNIV_INTERN void trx_lists_init_at_db_start (void)
UNIV_INTERN void trx_start_if_not_started_xa_low (trx_t *trx)
UNIV_INTERN void trx_start_if_not_started_low (trx_t *trx)
UNIV_INTERN void trx_start_for_ddl_low (trx_t *trx, trx_dict_op_t op))
UNIV_INTERN void trx_commit (trx_t *trx))
UNIV_INTERN void trx_commit_low (trx_t *trx, mtr_t *mtr)))
UNIV_INTERN void trx_cleanup_at_db_startup (trx_t *trx)
UNIV_INTERN dberr_t trx_commit_for_mysql (trx_t *trx)
UNIV_INTERN void trx_prepare_for_mysql (trx_t *trx)
UNIV_INTERN int trx_recover_for_mysql (XID *xid_list, ulint len)
UNIV_INTERN trx_ttrx_get_trx_by_xid (const XID *xid)
UNIV_INTERN void trx_commit_complete_for_mysql (trx_t *trx))
UNIV_INTERN void trx_mark_sql_stat_end (trx_t *trx)
UNIV_INTERN read_view_ttrx_assign_read_view (trx_t *trx)
UNIV_INTERN void trx_commit_or_rollback_prepare (trx_t *trx)
UNIV_INTERN commit_node_ttrx_commit_node_create (mem_heap_t *heap)
UNIV_INTERN que_thr_ttrx_commit_step (que_thr_t *thr)
UNIV_INTERN 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))
UNIV_INTERN void trx_print_latched (FILE *f, const trx_t *trx, ulint max_query_len))
UNIV_INTERN void trx_print (FILE *f, const trx_t *trx, ulint max_query_len))
UNIV_INLINE enum trx_dict_op_t trx_get_dict_operation (const trx_t *trx))
UNIV_INLINE void trx_set_dict_operation (trx_t *trx, enum trx_dict_op_t op)
UNIV_INLINE ibool trx_state_eq (const trx_t *trx, trx_state_t state))
UNIV_INTERN ibool trx_assert_started (const trx_t *trx))
UNIV_INTERN ibool trx_is_interrupted (const trx_t *trx)
UNIV_INTERN ibool trx_is_strict (trx_t *trx)
UNIV_INTERN ibool trx_weight_ge (const trx_t *a, const trx_t *b)
UNIV_INLINE const char * trx_get_que_state_str (const trx_t *trx)
UNIV_INTERN void trx_assign_rseg (trx_t *trx)

Variables

sess_ttrx_dummy_sess
rw_lock_tbtr_search_latch_temp
 The latch protecting the adaptive search system.

Detailed Description

The transaction

Created 3/26/1996 Heikki Tuuri

Macro Definition Documentation

#define assert_trx_in_list (   t)
Value:
do { \
ut_ad((t)->in_ro_trx_list == (t)->read_only); \
ut_ad((t)->in_rw_trx_list == !(t)->read_only); \
switch ((t)->state) { \
case TRX_STATE_PREPARED: \
/* fall through */ \
case TRX_STATE_ACTIVE: \
case TRX_STATE_COMMITTED_IN_MEMORY: \
continue; \
case TRX_STATE_NOT_STARTED: \
break; \
} \
ut_error; \
} while (0)

Assert that the transaction is either in trx_sys->ro_trx_list or trx_sys->rw_trx_list but not both and it cannot be an autocommit non-locking select

#define assert_trx_in_rw_list (   t)
Value:
do { \
ut_ad(!(t)->read_only); \
assert_trx_in_list(t); \
} while (0)

Assert that the transaction is in the trx_sys_t::rw_trx_list

#define assert_trx_nonlocking_or_in_list (   t)
Value:
do { \
trx_state_t t_state = (t)->state; \
ut_ad((t)->read_only); \
ut_ad(!(t)->is_recovered); \
ut_ad(!(t)->in_ro_trx_list); \
ut_ad(!(t)->in_rw_trx_list); \
ut_ad((t)->in_mysql_trx_list); \
ut_ad(t_state == TRX_STATE_NOT_STARTED \
|| t_state == TRX_STATE_ACTIVE); \
} else { \
assert_trx_in_list(t); \
} \
} while (0)

Assert that an autocommit non-locking select cannot be in the ro_trx_list nor the rw_trx_list and that it is a read-only transaction. The tranasction must be in the mysql_trx_list.

#define btr_search_latch   (*btr_search_latch_temp)

The latch protecting the adaptive search system

#define trx_is_ac_nl_ro (   t)    ((t)->read_only && trx_is_autocommit_non_locking((t)))

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.
#define trx_is_autocommit_non_locking (   t)    ((t)->auto_commit && (t)->will_lock == 0)

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

Parameters
ttransaction
Returns
true if non-locking autocommit select transaction.
#define TRX_ISO_READ_COMMITTED
Value:
1 /* somewhat Oracle-like
isolation, except that in
range UPDATE and DELETE we
must block phantom rows
with next-key locks;
SELECT ... FOR UPDATE and ...
LOCK IN SHARE MODE only lock
the index records, NOT the
gaps before them, and thus
allow free inserting;
each consistent read reads its
own snapshot */
#define TRX_ISO_READ_UNCOMMITTED
Value:
0 /* dirty read: non-locking
SELECTs are performed so that
we do not look at a possible
earlier version of a record;
thus they are not 'consistent'
reads under this isolation
level; otherwise like level
2 */
#define TRX_ISO_REPEATABLE_READ
Value:
2 /* this is the default;
all consistent reads in the
same trx read the same
snapshot;
full next-key locking used
in locking reads to block
insertions into gaps */
#define TRX_ISO_SERIALIZABLE
Value:
3 /* all plain SELECTs are
converted to LOCK IN SHARE
MODE reads */
#define trx_lock_wait_timeout_get (   trx)
Value:
((trx)->mysql_thd != NULL \
? thd_lock_wait_timeout((trx)->mysql_thd) \
: 0)

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
trxtransaction
Returns
lock wait timeout in seconds
#define trx_mutex_enter (   t)
Value:
do { \
mutex_enter(&t->mutex); \
} while (0)

Acquire the trx->mutex.

#define trx_mutex_exit (   t)
Value:
do { \
mutex_exit(&t->mutex); \
} while (0)

Release the trx->mutex.

#define trx_mutex_own (   t)    mutex_own(&t->mutex)

Test if trx->mutex is owned.

#define TRX_SIG_OTHER_SESS
Value:
1 /* sent by another session (which
must hold rights to this) */
#define TRX_SIG_SELF
Value:
0 /* sent by the session itself, or
by an error occurring within this
session */
#define trx_start_for_ddl (   t,
 
)
Value:
{ \
ut_ad((t)->start_file == 0); \
(t)->start_line = __LINE__; \
(t)->start_file = __FILE__; \
trx_start_for_ddl_low((t), (o)); \
}
#define trx_start_if_not_started (   t)
Value:
{ \
(t)->start_line = __LINE__; \
(t)->start_file = __FILE__; \
trx_start_if_not_started_low((t)); \
}
#define trx_start_if_not_started_xa (   t)
Value:
{ \
(t)->start_line = __LINE__; \
(t)->start_file = __FILE__; \
trx_start_if_not_started_xa_low((t)); \
}
#define TRX_WEIGHT (   t)    ((t)->undo_no + UT_LIST_GET_LEN((t)->lock.trx_locks))

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

Enumeration Type Documentation

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

Function Documentation

UNIV_INTERN trx_t* trx_allocate_for_background ( void  )

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

Returns
own: transaction object
UNIV_INTERN trx_t* trx_allocate_for_mysql ( void  )

Creates a transaction object for MySQL.

Returns
own: transaction object
UNIV_INTERN ibool 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
UNIV_INTERN read_view_t* 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 in: active transaction
UNIV_INTERN void trx_assign_rseg ( trx_t trx)

Assign a read-only transaction a rollback-segment, if it is attempting to write to a TEMPORARY table. A read-only transaction that needs to be assigned a RBS.

UNIV_INTERN 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

UNIV_INTERN void trx_commit ( trx_t trx)

Commits a transaction.

Parameters
trxin/out: transaction
UNIV_INTERN 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.

Parameters
trxin/out: transaction
UNIV_INTERN dberr_t trx_commit_for_mysql ( trx_t trx)

Does the transaction commit for MySQL.

Returns
DB_SUCCESS or error number in/out: transaction
UNIV_INTERN void trx_commit_low ( trx_t trx,
mtr_t mtr 
)

Commits a transaction and a mini-transaction.

Parameters
trxin/out: transaction
mtrin/out: mini-transaction (will be committed), or NULL if trx made no modifications
UNIV_INTERN 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
UNIV_INTERN void trx_commit_or_rollback_prepare ( trx_t trx)

Prepares a transaction for commit/rollback. in/out: transaction

UNIV_INTERN 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
UNIV_INTERN void trx_free_for_background ( trx_t trx)

Frees a transaction object of a background operation of the master thread. in, own: trx object

UNIV_INTERN void trx_free_for_mysql ( trx_t trx)

Frees a transaction object for MySQL. in, own: trx object

UNIV_INTERN void trx_free_prepared ( trx_t trx)

At shutdown, frees a transaction object that is in the PREPARED state.

Parameters
trxin, own: trx object
UNIV_INLINE enum trx_dict_op_t trx_get_dict_operation ( const trx_t trx)

Determine if a transaction is a dictionary operation.

Returns
dictionary operation mode
Parameters
trxin: transaction
UNIV_INLINE const dict_index_t* trx_get_error_info ( const trx_t trx)

Retrieves the error_info field from a trx.

Returns
the error info in: trx object

Retrieves the error_info field from a trx.

Returns
the error info
Parameters
trxin: trx object
UNIV_INLINE const char* trx_get_que_state_str ( const trx_t trx)

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

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
Parameters
trxin: transaction
UNIV_INTERN 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

Returns
trx or NULL; on match, the trx->xid will be invalidated; note that the trx may have been committed, unless the caller is holding lock_sys->mutex in: X/Open XA transaction identifier
UNIV_INTERN ibool trx_is_interrupted ( const trx_t trx)

Determines if the currently running transaction has been interrupted.

Returns
TRUE if interrupted in: transaction
UNIV_INTERN ibool trx_is_strict ( trx_t trx)

Determines if the currently running transaction is in strict mode.

Returns
TRUE if strict in: transaction
UNIV_INTERN 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.

UNIV_INTERN void trx_mark_sql_stat_end ( trx_t trx)

Marks the latest SQL statement ended. in: trx handle

UNIV_INTERN void trx_prepare_for_mysql ( trx_t trx)

Does the transaction prepare for MySQL. in/out: trx handle

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

Prints info about a transaction. Acquires and releases lock_sys->mutex and trx_sys->mutex.

Parameters
fin: output stream
trxin: transaction
max_query_lenin: max query length to print, or 0 to use the default max length
UNIV_INTERN 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->mutex and trx_sys->mutex. When possible, use trx_print() instead.

Parameters
fin: output stream
trxin: transaction
max_query_lenin: max query length to print, or 0 to use the default max length
UNIV_INTERN 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, or 0 to use the default max length
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)
UNIV_INTERN int trx_recover_for_mysql ( XID xid_list,
ulint  len 
)

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

Returns
number of prepared transactions in: number of slots in xid_list
Parameters
xid_listin/out: prepared transactions
UNIV_INLINE void trx_search_latch_release_if_reserved ( trx_t trx)

Releases the search latch if trx has reserved it. in: transaction

Releases the search latch if trx has reserved it.

Parameters
trxin: transaction
UNIV_INTERN void trx_set_detailed_error ( trx_t trx,
const char *  msg 
)

Set detailed error message for the transaction. in: detailed error message

Parameters
trxin: transaction struct
UNIV_INTERN 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

Parameters
trxin: transaction struct
UNIV_INLINE void trx_set_dict_operation ( trx_t trx,
enum trx_dict_op_t  op 
)

Flag a transaction a dictionary operation. in: operation, not TRX_DICT_OP_NONE

Flag a transaction a dictionary operation.

Parameters
trxin/out: transaction
opin: operation, not TRX_DICT_OP_NONE
UNIV_INTERN void trx_start_for_ddl_low ( trx_t trx,
trx_dict_op_t  op 
)

Starts the transaction for a DDL operation.

Parameters
trxin/out: transaction
opin: dictionary operation type
UNIV_INTERN void trx_start_if_not_started_low ( trx_t trx)

Starts the transaction if it is not yet started. in: transaction

UNIV_INTERN void trx_start_if_not_started_xa_low ( trx_t trx)

Starts the transaction if it is not yet started. in: transaction

UNIV_INLINE ibool trx_state_eq ( const trx_t trx,
trx_state_t  state 
)

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 transaction must be in trx_sys->ro_trx_list or trx_sys->rw_trx_list unless it is a non-locking autocommit read only transaction, which is only in trx_sys->mysql_trx_list.

Returns
TRUE if trx->state == state
Parameters
trxin: transaction
statein: state; if state != TRX_STATE_NOT_STARTED asserts that trx->state != TRX_STATE_NOT_STARTED
UNIV_INTERN ibool 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 second transaction to be compared
Parameters
ain: the first transaction to be compared

Variable Documentation

rw_lock_t* btr_search_latch_temp

The latch protecting the adaptive search system.

This latch protects the (1) hash index; (2) columns of a record to which we have a pointer in the hash index;

but does NOT protect:

(3) next record offset field in a record; (4) next or previous records on the same page.

Bear in mind (3) and (4) when using the hash index.

sess_t* trx_dummy_sess

Dummy session used currently in MySQL interface