MySQL 8.4.2
Source Code Documentation
rpl_gtid_execution.cc File Reference
#include <string.h>
#include <sys/types.h>
#include <atomic>
#include "lex_string.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_psi_config.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "mysql/psi/mysql_transaction.h"
#include "mysql/thread_type.h"
#include "mysqld_error.h"
#include "sql/mysqld.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_rli.h"
#include "sql/sql_class.h"
#include "sql/sql_lex.h"
#include "sql/sql_parse.h"
#include "sql/system_variables.h"

Functions

bool set_gtid_next (THD *thd, const Gtid_specification &spec)
 Acquire ownership of the given Gtid_specification. More...
 
bool is_already_logged_transaction (const THD *thd)
 Acquire ownership of all gtids in a Gtid_set. More...
 
static void skip_statement (THD *thd)
 Debug code executed when a transaction is skipped. More...
 
bool gtid_reacquire_ownership_if_anonymous (THD *thd)
 If gtid_next=ANONYMOUS or NOT_YET_DETERMINED, but the thread does not hold anonymous ownership, acquire anonymous ownership. More...
 
static bool is_stmt_taking_table_wr_locks (const THD *thd)
 Checks whether or not the statement held by the THD object is taking table write-locks. More...
 
static bool is_stmt_innocent (const THD *thd)
 Return true if the statement does not invoke any stored function, and is one of the following: More...
 
enum_gtid_statement_status gtid_pre_statement_checks (THD *thd)
 Perform GTID-related checks before executing a statement: More...
 
bool gtid_pre_statement_post_implicit_commit_checks (THD *thd)
 Perform GTID-related checks before executing a statement, but after executing an implicit commit before the statement, if any: More...
 
void gtid_set_performance_schema_values (const THD *thd)
 

Function Documentation

◆ gtid_pre_statement_checks()

enum_gtid_statement_status gtid_pre_statement_checks ( THD thd)

Perform GTID-related checks before executing a statement:

  • Check that the current statement does not contradict enforce_gtid_consistency.
  • Check that there is no implicit commit in a transaction when GTID_NEXT==UUID:NUMBER.
  • Change thd->variables.gtid_next.type to ANONYMOUS_GTID if it is currently NOT_YET_DETERMINED_GTID.
  • Check whether the statement should be cancelled.
Parameters
thdTHD object for the session.
Return values
GTID_STATEMENT_EXECUTEThe normal case: the checks succeeded, and statement can execute.
GTID_STATEMENT_CANCELThe checks failed; an error has be generated and the statement must stop.
GTID_STATEMENT_SKIPThe checks succeeded, but the GTID has already been executed (exists in GTID_EXECUTED). So the statement must not execute; however, if there are implicit commits, then the implicit commits must execute.

◆ gtid_pre_statement_post_implicit_commit_checks()

bool gtid_pre_statement_post_implicit_commit_checks ( THD thd)

Perform GTID-related checks before executing a statement, but after executing an implicit commit before the statement, if any:

If gtid_next=anonymous, but the thread does not hold anonymous ownership, then acquire anonymous ownership. (Do this only if this is not an 'innocent' statement, i.e., SET/SHOW/DO/SELECT that does not invoke a stored function.)

It is important that this is done after the implicit commit, because the implicit commit may release anonymous ownership.

Parameters
thdTHD object for the session
Return values
falseSuccess.
trueError. Error can happen if GTID_MODE=ON. The error has been reported by (a function called by) this function.

◆ gtid_reacquire_ownership_if_anonymous()

bool gtid_reacquire_ownership_if_anonymous ( THD thd)

If gtid_next=ANONYMOUS or NOT_YET_DETERMINED, but the thread does not hold anonymous ownership, acquire anonymous ownership.

Parameters
thdThread.
Return values
trueError (can happen if gtid_mode=ON and gtid_next=anonymous). The error has already been reported using my_error.
falseSuccess.

◆ gtid_set_performance_schema_values()

void gtid_set_performance_schema_values ( const THD thd)

◆ is_already_logged_transaction()

bool is_already_logged_transaction ( const THD thd)

Acquire ownership of all gtids in a Gtid_set.

Check if current transaction should be skipped, that is, if GTID_NEXT was already logged.

This is used to begin a commit-sequence when @SESSION.GTID_NEXT_LIST != NULL.

◆ is_stmt_innocent()

static bool is_stmt_innocent ( const THD thd)
static

Return true if the statement does not invoke any stored function, and is one of the following:

  • SET (except SET PASSWORD)
  • SHOW
  • SELECT
  • DO
  • An empty statement because of a skipped version comment That means it is guaranteed not to cause any changes in the database.

◆ is_stmt_taking_table_wr_locks()

static bool is_stmt_taking_table_wr_locks ( const THD thd)
static

Checks whether or not the statement held by the THD object is taking table write-locks.

Parameters
thdthe THD object holding the statement to examine
Returns
true if the statement held by the THD object is acquiring table write locks, false otherwise.

◆ set_gtid_next()

bool set_gtid_next ( THD thd,
const Gtid_specification spec 
)

Acquire ownership of the given Gtid_specification.

The Gtid_specification must be of type ASSIGNED_GTID or ANONYMOUS_GTID.

The caller must hold global_tsid_lock (normally the rdlock). The lock may be temporarily released and acquired again. In the end, the lock will be released, so the caller should not release the lock.

The function will try to acquire ownership of the GTID and update both THD::gtid_next, Gtid_state::owned_gtids, and THD::owned_gtid / THD::owned_sid.

Parameters
thdThe thread that acquires ownership.
specThe Gtid_specification.
Return values
falseSuccess: either we have acquired ownership of the GTID, or it is already included in GTID_EXECUTED and will be skipped.
trueFailure; the thread was killed or an error occurred. The error has been reported using my_error.

◆ skip_statement()

static void skip_statement ( THD thd)
inlinestatic

Debug code executed when a transaction is skipped.

Parameters
thdThe calling thread.