MySQL 9.1.0
Source Code Documentation
transaction.h File Reference
#include <sys/types.h>
#include "lex_string.h"
#include "my_inttypes.h"

Go to the source code of this file.

Functions

bool trans_check_state (THD *thd)
 Check if we have a condition where the transaction state must not be changed (committed or rolled back). More...
 
void trans_reset_one_shot_chistics (THD *thd)
 Helper: transaction ended, SET TRANSACTION one-shot variables revert to session values. More...
 
void trans_track_end_trx (THD *thd)
 Helper: Tell tracker (if any) that transaction ended. More...
 
bool trans_begin (THD *thd, uint flags=0)
 Begin a new transaction. More...
 
bool trans_commit (THD *thd, bool ignore_global_read_lock=false)
 Commit the current transaction, making its changes permanent. More...
 
bool trans_commit_implicit (THD *thd, bool ignore_global_read_lock=false)
 Implicitly commit the current transaction. More...
 
bool trans_rollback (THD *thd)
 Rollback the current transaction, canceling its changes. More...
 
bool trans_rollback_implicit (THD *thd)
 Implicitly rollback the current transaction, typically after deadlock was discovered. More...
 
bool trans_commit_stmt (THD *thd, bool ignore_global_read_lock=false)
 Commit the single statement transaction. More...
 
bool trans_rollback_stmt (THD *thd)
 Rollback the single statement transaction. More...
 
bool trans_commit_attachable (THD *thd)
 Commit the attachable transaction. More...
 
bool trans_savepoint (THD *thd, LEX_STRING name)
 Set a named transaction savepoint. More...
 
bool trans_rollback_to_savepoint (THD *thd, LEX_STRING name)
 Rollback a transaction to the named savepoint. More...
 
bool trans_release_savepoint (THD *thd, LEX_STRING name)
 Remove the named savepoint from the set of savepoints of the current transaction. More...
 

Function Documentation

◆ trans_begin()

bool trans_begin ( THD thd,
uint  flags 
)

Begin a new transaction.

Note
Beginning a transaction implicitly commits any current transaction and releases existing locks.
Parameters
thdCurrent thread
flagsTransaction flags
Return values
falseSuccess
trueFailure

◆ trans_check_state()

bool trans_check_state ( THD thd)

Check if we have a condition where the transaction state must not be changed (committed or rolled back).

Currently we check that we are not executing a stored program and that we don't have an active XA transaction.

Returns
true if the commit/rollback cannot be executed, false otherwise.

◆ trans_commit()

bool trans_commit ( THD thd,
bool  ignore_global_read_lock 
)

Commit the current transaction, making its changes permanent.

Parameters
[in]thdCurrent thread
[in]ignore_global_read_lockAllow commit to complete even if a global read lock is active. This can be used to allow changes to internal tables (e.g. slave status tables, analyze table).
Return values
falseSuccess
trueFailure

◆ trans_commit_attachable()

bool trans_commit_attachable ( THD thd)

Commit the attachable transaction.

Note
This is slimmed down version of trans_commit_stmt() which commits attachable transaction but skips code which is unnecessary and unsafe for them (like dealing with GTIDs).
Parameters
thdCurrent thread
Return values
False- Success
True- Failure

◆ trans_commit_implicit()

bool trans_commit_implicit ( THD thd,
bool  ignore_global_read_lock 
)

Implicitly commit the current transaction.

Note
A implicit commit does not releases existing table locks.
Parameters
[in]thdCurrent thread
[in]ignore_global_read_lockAllow commit to complete even if a global read lock is active. This can be used to allow changes to internal tables (e.g. slave status tables, analyze table).
Return values
falseSuccess
trueFailure

◆ trans_commit_stmt()

bool trans_commit_stmt ( THD thd,
bool  ignore_global_read_lock 
)

Commit the single statement transaction.

Note
Note that if the autocommit is on, then the following call inside InnoDB will commit or rollback the whole transaction (= the statement). The autocommit mechanism built into InnoDB is based on counting locks, but if the user has used LOCK TABLES then that mechanism does not know to do the commit.
Parameters
[in]thdCurrent thread
[in]ignore_global_read_lockAllow commit to complete even if a global read lock is active. This can be used to allow changes to internal tables (e.g. slave status tables, analyze table).
Return values
falseSuccess
trueFailure

◆ trans_release_savepoint()

bool trans_release_savepoint ( THD thd,
LEX_STRING  name 
)

Remove the named savepoint from the set of savepoints of the current transaction.

Note
No commit or rollback occurs. It is an error if the savepoint does not exist.
Parameters
thdCurrent thread
nameSavepoint name
Return values
falseSuccess
trueFailure

◆ trans_reset_one_shot_chistics()

void trans_reset_one_shot_chistics ( THD thd)

Helper: transaction ended, SET TRANSACTION one-shot variables revert to session values.

Let the transaction state tracker know.

◆ trans_rollback()

bool trans_rollback ( THD thd)

Rollback the current transaction, canceling its changes.

Parameters
thdCurrent thread
Return values
falseSuccess
trueFailure

◆ trans_rollback_implicit()

bool trans_rollback_implicit ( THD thd)

Implicitly rollback the current transaction, typically after deadlock was discovered.

Parameters
thdCurrent thread
Return values
FalseSuccess
TrueFailure
Note
ha_rollback_low() which is indirectly called by this function will mark XA transaction for rollback by setting appropriate RM error status if there was transaction rollback request.

◆ trans_rollback_stmt()

bool trans_rollback_stmt ( THD thd)

Rollback the single statement transaction.

Parameters
thdCurrent thread
Return values
falseSuccess
trueFailure

◆ trans_rollback_to_savepoint()

bool trans_rollback_to_savepoint ( THD thd,
LEX_STRING  name 
)

Rollback a transaction to the named savepoint.

Note
Modifications that the current transaction made to rows after the savepoint was set are undone in the rollback.
Savepoints that were set at a later time than the named savepoint are deleted.
Parameters
thdCurrent thread
nameSavepoint name
Return values
falseSuccess
trueFailure

Checking whether it is safe to release metadata locks acquired after savepoint, if rollback to savepoint is successful.

Whether it is safe to release MDL after rollback to savepoint depends on storage engines participating in transaction:

  • InnoDB doesn't release any row-locks on rollback to savepoint so it is probably a bad idea to release MDL as well.
  • Binary log implementation in some cases (e.g when non-transactional tables involved) may choose not to remove events added after savepoint from transactional cache, but instead will write them to binary log accompanied with ROLLBACK TO SAVEPOINT statement. Since the real write happens at the end of transaction releasing MDL on tables mentioned in these events (i.e. acquired after savepoint and before rollback of it) can break replication, as concurrent DROP TABLES statements will be able to drop these tables before events will get into binary log,

◆ trans_savepoint()

bool trans_savepoint ( THD thd,
LEX_STRING  name 
)

Set a named transaction savepoint.

Parameters
thdCurrent thread
nameSavepoint name
Return values
falseSuccess
trueFailure

◆ trans_track_end_trx()

void trans_track_end_trx ( THD thd)

Helper: Tell tracker (if any) that transaction ended.