MySQL 8.3.0
Source Code Documentation
rpl_gtid.h File Reference
#include <atomic>
#include <cinttypes>
#include <list>
#include <mutex>
#include <vector>
#include "map_helpers.h"
#include "my_dbug.h"
#include "my_thread_local.h"
#include "mysql/binlog/event/compression/base.h"
#include "mysql/gtid/global.h"
#include "mysql/gtid/gtid.h"
#include "mysql/gtid/tsid.h"
#include "mysql/gtid/uuid.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/utils/return_status.h"
#include "prealloced_array.h"
#include "sql/changestreams/index/locked_sidno_set.h"
#include "sql/changestreams/index/sidno.h"
#include "sql/rpl_reporting.h"
#include "template_utils.h"

Go to the source code of this file.

Classes

class  Checkable_rwlock
 This has the functionality of mysql_rwlock_t, with two differences: More...
 
class  Checkable_rwlock::Guard
 RAII class to acquire a lock for the duration of a block. More...
 
class  Gtid_mode
 Class to access the value of @global.gtid_mode in an efficient and thread-safe manner. More...
 
class  Tsid_map
 Represents a bidirectional map between TSID and SIDNO. More...
 
class  Mutex_cond_array
 Represents a growable array where each element contains a mutex and a condition variable. More...
 
struct  Mutex_cond_array::Mutex_cond
 A mutex/cond pair. More...
 
struct  Gtid_interval
 Holds information about a GTID interval: the sidno, the first gno and the last gno of this interval. More...
 
struct  Gtid
 TODO: Move this structure to mysql/binlog/event/control_events.h when we start using C++11. More...
 
struct  Trx_monitoring_info
 Structure to store the GTID and timing information. More...
 
class  Gtid_monitoring_info
 Stores information to monitor a transaction during the different replication stages. More...
 
class  Gtid_set
 Represents a set of GTIDs. More...
 
struct  Gtid_set::String_format
 Class Gtid_set::String_format defines the separators used by Gtid_set::to_string. More...
 
struct  Gtid_set::Interval
 Represents one element in the linked list of intervals associated with a SIDNO. More...
 
class  Gtid_set::Interval_iterator_base< Gtid_set_p, Interval_p >
 Iterator over intervals for a given SIDNO. More...
 
class  Gtid_set::Const_interval_iterator
 Iterator over intervals of a const Gtid_set. More...
 
class  Gtid_set::Interval_iterator
 Iterator over intervals of a non-const Gtid_set, with additional methods to modify the Gtid_set. More...
 
class  Gtid_set::Gtid_iterator
 Iterator over all gtids in a Gtid_set. More...
 
struct  Gtid_set::Interval_chunk
 Contains a list of intervals allocated by this Gtid_set. More...
 
class  Gtid_set::Free_intervals_lock
 Class representing a lock on free_intervals_mutex. More...
 
struct  Gtid_set_or_null
 Holds information about a Gtid_set. More...
 
class  Owned_gtids
 Represents the set of GTIDs that are owned by some thread. More...
 
struct  Owned_gtids::Node
 Represents one owned GTID. More...
 
class  Owned_gtids::Gtid_iterator
 Iterator over all gtids in a Owned_gtids set. More...
 
class  Gtid_state
 Represents the server's GTID state: the set of committed GTIDs, the set of lost gtids, the set of owned gtids, the owner of each owned gtid, and a Mutex_cond_array that protects updates to gtids of each SIDNO. More...
 
struct  Gtid_specification
 This struct represents a specification of a GTID for a statement to be executed: either "AUTOMATIC", "AUTOMATIC:<tag>", "ANONYMOUS" or "TSID:GNO". More...
 

Namespaces

namespace  cs
 
namespace  cs::index
 

Macros

#define BINLOG_ERROR(MYSQLBINLOG_ERROR, SERVER_ERROR)   my_error SERVER_ERROR
 Report an error from code that can be linked into either the server or mysqlbinlog. More...
 
#define SKIP_WHITESPACE()    while (my_isspace(&my_charset_utf8mb3_general_ci, *s)) s++
 This macro is used to check that the given character, pointed to by the character pointer, is a space or not. More...
 
#define __CHECK_RETURN_STATUS(STATUS, ACTION, STATUS_NAME, ALLOW_UNREPORTED)    check_return_status(STATUS, ACTION, STATUS_NAME, ALLOW_UNREPORTED);
 Lowest level macro used in the PROPAGATE_* and RETURN_* macros below. More...
 
#define __PROPAGATE_ERROR(STATUS, RETURN_VALUE, ALLOW_UNREPORTED)
 Low-level macro that checks if STATUS is RETURN_STATUS_OK; if it is not, then RETURN_VALUE is returned. More...
 
#define __RETURN_STATUS(STATUS, ALLOW_UNREPORTED)
 Low-level macro that returns STATUS. More...
 
#define PROPAGATE_ERROR(STATUS)    __PROPAGATE_ERROR(STATUS, __propagate_error_status, true)
 If STATUS (of type enum_return_status) returns RETURN_STATUS_OK, does nothing; otherwise, does a DBUG_PRINT and returns STATUS. More...
 
#define PROPAGATE_REPORTED_ERROR(STATUS)    __PROPAGATE_ERROR(STATUS, __propagate_error_status, false)
 If STATUS (of type enum_return_status) returns RETURN_STATUS_OK, does nothing; otherwise asserts that STATUS == RETURN_STATUS_REPORTED_ERROR, does a DBUG_PRINT, and returns STATUS. More...
 
#define PROPAGATE_REPORTED_ERROR_INT(STATUS)   __PROPAGATE_ERROR(STATUS, 1, false)
 If STATUS (of type enum_return_status) returns RETURN_STATUS_OK, does nothing; otherwise asserts that STATUS == RETURN_STATUS_REPORTED_ERROR, does a DBUG_PRINT, and returns 1. More...
 
#define RETURN_STATUS(STATUS)   __RETURN_STATUS(STATUS, true)
 If STATUS returns something else than RETURN_STATUS_OK, does a DBUG_PRINT. More...
 
#define RETURN_REPORTED_STATUS(STATUS)   __RETURN_STATUS(STATUS, false)
 Asserts that STATUS is not RETURN_STATUS_UNREPORTED_ERROR. More...
 
#define RETURN_OK   return RETURN_STATUS_OK
 Returns RETURN_STATUS_OK. More...
 
#define RETURN_REPORTED_ERROR   RETURN_STATUS(RETURN_STATUS_REPORTED_ERROR)
 Does a DBUG_PRINT and returns RETURN_STATUS_REPORTED_ERROR. More...
 
#define RETURN_UNREPORTED_ERROR   RETURN_STATUS(RETURN_STATUS_UNREPORTED_ERROR)
 Does a DBUG_PRINT and returns RETURN_STATUS_UNREPORTED_ERROR. More...
 

Typedefs

using rpl_sidno = cs::index::rpl_sidno
 Type of SIDNO (source ID number, first component of GTID) More...
 
using rpl_gno = mysql::gtid::gno_t
 GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t. More...
 
typedef int64 rpl_binlog_pos
 
typedef mysql::gtid::Uuid rpl_sid
 

Enumerations

enum  enum_return_status { RETURN_STATUS_OK = 0 , RETURN_STATUS_UNREPORTED_ERROR = 1 , RETURN_STATUS_REPORTED_ERROR = 2 }
 Generic return type for many functions that can succeed or fail. More...
 
enum  enum_gtid_consistency_mode { GTID_CONSISTENCY_MODE_OFF = 0 , GTID_CONSISTENCY_MODE_ON = 1 , GTID_CONSISTENCY_MODE_WARN = 2 }
 Possible values for ENFORCE_GTID_CONSISTENCY. More...
 
enum  enum_gtid_type {
  AUTOMATIC_GTID = 0 , ASSIGNED_GTID , ANONYMOUS_GTID , UNDEFINED_GTID ,
  NOT_YET_DETERMINED_GTID , PRE_GENERATE_GTID
}
 Enumeration of different types of values for Gtid_specification, i.e, the different internal states that @session.gtid_next can be in. More...
 
enum  enum_gtid_statement_status { GTID_STATEMENT_EXECUTE , GTID_STATEMENT_CANCEL , GTID_STATEMENT_SKIP }
 Indicates if a statement should be skipped or not. More...
 

Functions

void check_return_status (enum_return_status status, const char *action, const char *status_name, int allow_unreported)
 
enum_return_status map_macro_enum (int status)
 enum to map the result of Uuid::parse to the above Macros More...
 
enum_gtid_consistency_mode get_gtid_consistency_mode ()
 Return the current value of ENFORCE_GTID_CONSISTENCY. More...
 
const char * get_gtid_consistency_mode_string (enum_gtid_consistency_mode mode)
 Return the given GTID_CONSISTENCY_MODE as a string. More...
 
const char * get_gtid_consistency_mode_string ()
 Return the current value of ENFORCE_GTID_CONSISTENCY as a string. More...
 
rpl_gno parse_gno (const char **s)
 Parse a GNO from a string. More...
 
int format_gno (char *s, rpl_gno gno)
 Formats a GNO as a string. More...
 
std::ostream & operator<< (std::ostream &oss, Gtid_mode::value_type const &mode)
 
std::ostream & operator<< (std::ostream &oss, Gtid_mode const &mode)
 Typically, code will print Gtid_mode only after reading and acting on the enum value. More...
 
bool is_already_logged_transaction (const THD *thd)
 Check if current transaction should be skipped, that is, if GTID_NEXT was already logged. 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...
 
bool set_gtid_next (THD *thd, const Gtid_specification &spec)
 Acquire ownership of the given Gtid_specification. More...
 
rpl_sidno get_sidno_from_global_tsid_map (const mysql::gtid::Tsid &tsid)
 Return sidno for a given tsid, see Tsid_map::add_sid() for details. More...
 
rpl_gno get_last_executed_gno (rpl_sidno sidno)
 Return last gno for a given sidno, see Gtid_state::get_last_executed_gno() for details. More...
 
void gtid_set_performance_schema_values (const THD *thd)
 
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...
 
void gtid_state_commit_or_rollback (THD *thd, bool needs_to, bool do_commit)
 The function commits or rolls back the gtid state if it needs to. More...
 

Variables

PSI_memory_key key_memory_Gtid_set_to_string
 
PSI_memory_key key_memory_Owned_gtids_to_string
 
PSI_memory_key key_memory_Gtid_state_to_string
 
PSI_memory_key key_memory_Gtid_cache_to_string
 
PSI_memory_key key_memory_Gtid_set_Interval_chunk
 
PSI_memory_key key_memory_Gtid_state_group_commit_sidno
 
const char * gtid_consistency_mode_names []
 Strings holding the enumeration values for gtid_consistency_mode_names. More...
 
ulong _gtid_consistency_mode
 Current value for ENFORCE_GTID_CONSISTENCY. More...
 
const rpl_gno GNO_END = INT64_MAX
 One-past-the-max value of GNO. More...
 
const rpl_gno GNO_WARNING_THRESHOLD = (GNO_END / 100) * 99
 If the GNO goes above the number, generate a warning. More...
 
const int MAX_GNO_TEXT_LENGTH = 19
 The length of MAX_GNO when printed in decimal. More...
 
const int MAX_THREAD_ID_TEXT_LENGTH = 19
 The maximal possible length of thread_id when printed in decimal. More...
 
Checkable_rwlockglobal_tsid_lock
 Protects Gtid_state. See comment above gtid_state for details. More...
 
Gtid_mode global_gtid_mode
 The one and only instance of Gtid_mode. More...
 
Tsid_mapglobal_tsid_map
 
Gtid_stategtid_state
 Global state of GTIDs. More...
 

Macro Definition Documentation

◆ __CHECK_RETURN_STATUS

#define __CHECK_RETURN_STATUS (   STATUS,
  ACTION,
  STATUS_NAME,
  ALLOW_UNREPORTED 
)     check_return_status(STATUS, ACTION, STATUS_NAME, ALLOW_UNREPORTED);

Lowest level macro used in the PROPAGATE_* and RETURN_* macros below.

If NDEBUG is defined, does nothing. Otherwise, if STATUS is RETURN_STATUS_OK, does nothing; otherwise, make a dbug printout and (if ALLOW_UNREPORTED==0) assert that STATUS != RETURN_STATUS_UNREPORTED.

Parameters
STATUSThe status to return.
ACTIONA text that describes what we are doing: either "Returning" or "Propagating" (used in DBUG_PRINT macros)
STATUS_NAMEThe stringified version of the STATUS (used in DBUG_PRINT macros).
ALLOW_UNREPORTEDIf false, the macro asserts that STATUS is not RETURN_STATUS_UNREPORTED_ERROR.

◆ __PROPAGATE_ERROR

#define __PROPAGATE_ERROR (   STATUS,
  RETURN_VALUE,
  ALLOW_UNREPORTED 
)
Value:
do { \
enum_return_status __propagate_error_status = STATUS; \
if (__propagate_error_status != RETURN_STATUS_OK) { \
__CHECK_RETURN_STATUS(__propagate_error_status, "Propagating", #STATUS, \
ALLOW_UNREPORTED); \
return RETURN_VALUE; \
} \
} while (0)
@ RETURN_STATUS_OK
The function completed successfully.
Definition: rpl_gtid.h:138
Definition: mysql.cc:152

Low-level macro that checks if STATUS is RETURN_STATUS_OK; if it is not, then RETURN_VALUE is returned.

See also
__DO_RETURN_STATUS

◆ __RETURN_STATUS

#define __RETURN_STATUS (   STATUS,
  ALLOW_UNREPORTED 
)
Value:
do { \
enum_return_status __return_status_status = STATUS; \
__CHECK_RETURN_STATUS(__return_status_status, "Returning", #STATUS, \
ALLOW_UNREPORTED); \
return __return_status_status; \
} while (0)

Low-level macro that returns STATUS.

See also
__DO_RETURN_STATUS

◆ BINLOG_ERROR

#define BINLOG_ERROR (   MYSQLBINLOG_ERROR,
  SERVER_ERROR 
)    my_error SERVER_ERROR

Report an error from code that can be linked into either the server or mysqlbinlog.

There is no common error reporting mechanism, so we have to duplicate the error message (write it out in the source file for mysqlbinlog, write it in share/messages_to_clients.txt for the server).

Parameters
MYSQLBINLOG_ERRORarguments to mysqlbinlog's 'error' function, including the function call parentheses
SERVER_ERRORarguments to my_error, including the function call parentheses.

◆ PROPAGATE_ERROR

#define PROPAGATE_ERROR (   STATUS)     __PROPAGATE_ERROR(STATUS, __propagate_error_status, true)

If STATUS (of type enum_return_status) returns RETURN_STATUS_OK, does nothing; otherwise, does a DBUG_PRINT and returns STATUS.

◆ PROPAGATE_REPORTED_ERROR

#define PROPAGATE_REPORTED_ERROR (   STATUS)     __PROPAGATE_ERROR(STATUS, __propagate_error_status, false)

If STATUS (of type enum_return_status) returns RETURN_STATUS_OK, does nothing; otherwise asserts that STATUS == RETURN_STATUS_REPORTED_ERROR, does a DBUG_PRINT, and returns STATUS.

◆ PROPAGATE_REPORTED_ERROR_INT

#define PROPAGATE_REPORTED_ERROR_INT (   STATUS)    __PROPAGATE_ERROR(STATUS, 1, false)

If STATUS (of type enum_return_status) returns RETURN_STATUS_OK, does nothing; otherwise asserts that STATUS == RETURN_STATUS_REPORTED_ERROR, does a DBUG_PRINT, and returns 1.

◆ RETURN_OK

#define RETURN_OK   return RETURN_STATUS_OK

Returns RETURN_STATUS_OK.

◆ RETURN_REPORTED_ERROR

#define RETURN_REPORTED_ERROR   RETURN_STATUS(RETURN_STATUS_REPORTED_ERROR)

Does a DBUG_PRINT and returns RETURN_STATUS_REPORTED_ERROR.

◆ RETURN_REPORTED_STATUS

#define RETURN_REPORTED_STATUS (   STATUS)    __RETURN_STATUS(STATUS, false)

Asserts that STATUS is not RETURN_STATUS_UNREPORTED_ERROR.

Then, if STATUS is RETURN_STATUS_REPORTED_ERROR, does a DBUG_PRINT. Then, returns STATUS.

◆ RETURN_STATUS

#define RETURN_STATUS (   STATUS)    __RETURN_STATUS(STATUS, true)

If STATUS returns something else than RETURN_STATUS_OK, does a DBUG_PRINT.

Then, returns STATUS.

◆ RETURN_UNREPORTED_ERROR

#define RETURN_UNREPORTED_ERROR   RETURN_STATUS(RETURN_STATUS_UNREPORTED_ERROR)

Does a DBUG_PRINT and returns RETURN_STATUS_UNREPORTED_ERROR.

◆ SKIP_WHITESPACE

#define SKIP_WHITESPACE ( )     while (my_isspace(&my_charset_utf8mb3_general_ci, *s)) s++

This macro is used to check that the given character, pointed to by the character pointer, is a space or not.

Typedef Documentation

◆ rpl_binlog_pos

◆ rpl_gno

GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t.

◆ rpl_sid

◆ rpl_sidno

Type of SIDNO (source ID number, first component of GTID)

Enumeration Type Documentation

◆ enum_gtid_consistency_mode

Possible values for ENFORCE_GTID_CONSISTENCY.

Enumerator
GTID_CONSISTENCY_MODE_OFF 
GTID_CONSISTENCY_MODE_ON 
GTID_CONSISTENCY_MODE_WARN 

◆ enum_gtid_statement_status

Indicates if a statement should be skipped or not.

Used as return value from gtid_before_statement.

Enumerator
GTID_STATEMENT_EXECUTE 

Statement can execute.

GTID_STATEMENT_CANCEL 

Statement should be cancelled.

GTID_STATEMENT_SKIP 

Statement should be skipped, but there may be an implicit commit after the statement if gtid_commit is set.

◆ enum_gtid_type

Enumeration of different types of values for Gtid_specification, i.e, the different internal states that @session.gtid_next can be in.

Enumerator
AUTOMATIC_GTID 

Specifies that the GTID has not been generated yet; it will be generated on commit.

It will depend on the GTID_MODE: if GTID_MODE<=OFF_PERMISSIVE, then the transaction will be anonymous; if GTID_MODE>=ON_PERMISSIVE, then the transaction will be assigned a new GTID.

In the latter case, the Gtid_specification may hold a tag. Then, the new GTID will be generated with that tag.

AUTOMATIC_GTID with an empty tag is the default value: thd->variables.gtid_next has this state when GTID_NEXT="AUTOMATIC".

It is important that AUTOMATIC_GTID==0 so that the default value for thd->variables->gtid_next.type is AUTOMATIC_GTID.

ASSIGNED_GTID 

Specifies that the transaction has been assigned a GTID (UUID:NUMBER).

thd->variables.gtid_next has this state when GTID_NEXT="UUID:NUMBER".

This is the state of GTID-transactions replicated to the slave.

ANONYMOUS_GTID 

Specifies that the transaction is anonymous, i.e., it does not have a GTID and will never be assigned one.

thd->variables.gtid_next has this state when GTID_NEXT="ANONYMOUS".

This is the state of any transaction generated on a pre-GTID server, or on a server with GTID_MODE==OFF.

UNDEFINED_GTID 

GTID_NEXT is set to this state after a transaction with GTID_NEXT=='UUID:NUMBER' is committed.

This is used to protect against a special case of unsafe non-transactional updates.

Background: Non-transactional updates are allowed as long as they are sane. Non-transactional updates must be single-statement transactions; they must not be mixed with transactional updates in the same statement or in the same transaction. Since non-transactional updates must be logged separately from transactional updates, a single mixed statement would generate two different transactions.

Problematic case: Consider a transaction, Tx1, that updates two transactional tables on the master, t1 and t2. Then slave (s1) later replays Tx1. However, t2 is a non-transactional table at s1. As such, s1 will report an error because it cannot split Tx1 into two different transactions. Had no error been reported, then Tx1 would be split into Tx1 and Tx2, potentially causing severe harm in case some form of fail-over procedure is later engaged by s1.

To detect this case on the slave and generate an appropriate error message rather than causing an inconsistency in the GTID state, we do as follows. When committing a transaction that has GTID_NEXT==UUID:NUMBER, we set GTID_NEXT to UNDEFINED_GTID. When the next part of the transaction is being processed, an error is generated, because it is not allowed to execute a transaction when GTID_NEXT==UNDEFINED. In the normal case, the error is not generated, because there will always be a Gtid_log_event after the next transaction.

NOT_YET_DETERMINED_GTID 
GTID_NEXT is set to this state by the slave applier thread when it
reads a Format_description_log_event that does not originate from
this server.

Background: when the slave applier thread reads a relay log that
comes from a pre-GTID master, it must preserve the transactions as
anonymous transactions, even if GTID_MODE>=ON_PERMISSIVE.  This
may happen, e.g., if the relay log was received when master and
slave had GTID_MODE=OFF or when master and slave were old, and the
relay log is applied when slave has GTID_MODE>=ON_PERMISSIVE.

So the slave thread should set GTID_NEXT=ANONYMOUS for the next
transaction when it starts to process an old binary log.  However,
there is no way for the slave to tell if the binary log is old,
until it sees the first transaction.  If the first transaction
begins with a Gtid_log_event, we have the GTID there; if it begins
with query_log_event, row events, etc, then this is an old binary

log. So at the time the binary log begins, we just set GTID_NEXT=NOT_YET_DETERMINED_GTID. If it remains NOT_YET_DETERMINED when the next transaction begins, gtid_pre_statement_checks will automatically turn it into an anonymous transaction. If a Gtid_log_event comes across before the next transaction starts, then the Gtid_log_event will just set GTID_NEXT='UUID:NUMBER' accordingly.

PRE_GENERATE_GTID 

The applier sets GTID_NEXT this state internally, when it processes an Anonymous_gtid_log_event on a channel having ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS, before it calls set_gtid_next.

This tells set_gtid_next to generate a new, sequential GTID, and acquire ownership for it. Thus, this state is only used for a very brief period of time. It is not user-visible.

◆ enum_return_status

Generic return type for many functions that can succeed or fail.

This is used in conjunction with the macros below for functions where the return status either indicates "success" or "failure". It provides the following features:

  • The macros can be used to conveniently propagate errors from called functions back to the caller.
  • If a function is expected to print an error using my_error before it returns an error status, then the macros assert that my_error has been called.
  • Does a DBUG_PRINT before returning failure.
Enumerator
RETURN_STATUS_OK 

The function completed successfully.

RETURN_STATUS_UNREPORTED_ERROR 

The function completed with error but did not report it.

RETURN_STATUS_REPORTED_ERROR 

The function completed with error and has called my_error.

Function Documentation

◆ check_return_status()

void check_return_status ( enum_return_status  status,
const char *  action,
const char *  status_name,
int  allow_unreported 
)

◆ format_gno()

int format_gno ( char *  s,
rpl_gno  gno 
)

Formats a GNO as a string.

Parameters
sThe buffer.
gnoThe GNO.
Returns
Length of the generated string.

◆ get_gtid_consistency_mode()

enum_gtid_consistency_mode get_gtid_consistency_mode ( )

Return the current value of ENFORCE_GTID_CONSISTENCY.

Caller must hold global_tsid_lock.rdlock.

◆ get_gtid_consistency_mode_string() [1/2]

const char * get_gtid_consistency_mode_string ( )
inline

Return the current value of ENFORCE_GTID_CONSISTENCY as a string.

Caller must hold global_tsid_lock.rdlock.

◆ get_gtid_consistency_mode_string() [2/2]

const char * get_gtid_consistency_mode_string ( enum_gtid_consistency_mode  mode)
inline

Return the given GTID_CONSISTENCY_MODE as a string.

◆ get_last_executed_gno()

rpl_gno get_last_executed_gno ( rpl_sidno  sidno)

Return last gno for a given sidno, see Gtid_state::get_last_executed_gno() for details.

◆ get_sidno_from_global_tsid_map()

rpl_sidno get_sidno_from_global_tsid_map ( const Tsid tsid)

Return sidno for a given tsid, see Tsid_map::add_sid() for details.

Return sidno for a given tsid, see Tsid_map::add_sid() for details.

◆ 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)

◆ gtid_state_commit_or_rollback()

void gtid_state_commit_or_rollback ( THD thd,
bool  needs_to,
bool  do_commit 
)
inline

The function commits or rolls back the gtid state if it needs to.

It's supposed to be invoked at the end of transaction commit or rollback, as well as as at the end of XA prepare.

Parameters
thdThread context
needs_toThe actual work will be done when the parameter is true
do_commitWhen true the gtid state changes are committed, otherwise they are rolled back.

◆ is_already_logged_transaction()

bool is_already_logged_transaction ( const THD thd)

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

Parameters
thdThe calling thread.
Return values
trueTransaction was already logged.
falseTransaction must be executed.

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.

◆ map_macro_enum()

enum_return_status map_macro_enum ( int  status)
inline

enum to map the result of Uuid::parse to the above Macros

◆ operator<<() [1/2]

std::ostream & operator<< ( std::ostream &  oss,
Gtid_mode const &  mode 
)

Typically, code will print Gtid_mode only after reading and acting on the enum value.

Then it is better to print the enum value than to read the shared resource again. Hence we enable this only in debug mode, since it makes more sense to just get the string when doing a debug printout.

◆ operator<<() [2/2]

std::ostream & operator<< ( std::ostream &  oss,
Gtid_mode::value_type const &  mode 
)

◆ parse_gno()

rpl_gno parse_gno ( const char **  s)

Parse a GNO from a string.

Parameters
sPointer to the string. *s will advance to the end of the parsed GNO, if a correct GNO is found.
Return values
GNOif a correct GNO (i.e., 0 or positive number) was found.
-1otherwise.

◆ 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.

Variable Documentation

◆ _gtid_consistency_mode

ulong _gtid_consistency_mode
extern

Current value for ENFORCE_GTID_CONSISTENCY.

Don't use this directly; use get_gtid_consistency_mode.

◆ global_gtid_mode

Gtid_mode global_gtid_mode
extern

The one and only instance of Gtid_mode.

All access to @global.gtid_mode should use this object.

◆ global_tsid_lock

Checkable_rwlock* global_tsid_lock
extern

Protects Gtid_state. See comment above gtid_state for details.

◆ global_tsid_map

Tsid_map* global_tsid_map
extern

◆ GNO_END

const rpl_gno GNO_END = INT64_MAX

One-past-the-max value of GNO.

◆ GNO_WARNING_THRESHOLD

const rpl_gno GNO_WARNING_THRESHOLD = (GNO_END / 100) * 99

If the GNO goes above the number, generate a warning.

◆ gtid_consistency_mode_names

const char* gtid_consistency_mode_names[]
extern

Strings holding the enumeration values for gtid_consistency_mode_names.

Use get_gtid_consistency_mode_string instead of accessing this directly.

◆ gtid_state

Gtid_state* gtid_state
extern

Global state of GTIDs.

◆ key_memory_Gtid_cache_to_string

PSI_memory_key key_memory_Gtid_cache_to_string
extern

◆ key_memory_Gtid_set_Interval_chunk

PSI_memory_key key_memory_Gtid_set_Interval_chunk
extern

◆ key_memory_Gtid_set_to_string

PSI_memory_key key_memory_Gtid_set_to_string
extern

◆ key_memory_Gtid_state_group_commit_sidno

PSI_memory_key key_memory_Gtid_state_group_commit_sidno
extern

◆ key_memory_Gtid_state_to_string

PSI_memory_key key_memory_Gtid_state_to_string
extern

◆ key_memory_Owned_gtids_to_string

PSI_memory_key key_memory_Owned_gtids_to_string
extern

◆ MAX_GNO_TEXT_LENGTH

const int MAX_GNO_TEXT_LENGTH = 19

The length of MAX_GNO when printed in decimal.

◆ MAX_THREAD_ID_TEXT_LENGTH

const int MAX_THREAD_ID_TEXT_LENGTH = 19

The maximal possible length of thread_id when printed in decimal.