MySQL  8.0.18
Source Code Documentation
rpl_gtid.h File Reference
#include <atomic>
#include <list>
#include "libbinlogevents/include/uuid.h"
#include "map_helpers.h"
#include "my_dbug.h"
#include "my_thread_local.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_rwlock.h"
#include "prealloced_array.h"
#include "sql/rpl_reporting.h"
#include "template_utils.h"
#include "typelib.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  Sid_map
 Represents a bidirectional map between SID and SIDNO. More...
 
struct  Sid_map::Node
 Node pointed to by both the hash and the array. 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 libbinlogevents/include/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", "ANONYMOUS", or "SID:GNO". More...
 
class  Gtid_mode_copy
 An optimized way of checking GTID_MODE without acquiring locks every time. More...
 

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_utf8_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

typedef int rpl_sidno
 Type of SIDNO (source ID number, first component of GTID) More...
 
typedef long long int rpl_gno
 Type of GNO, the second (numeric) component of GTID. More...
 
typedef int64 rpl_binlog_pos
 
typedef binary_log::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_mode {
  GTID_MODE_OFF = 0, DEFAULT_GTID_MODE = GTID_MODE_OFF, GTID_MODE_OFF_PERMISSIVE = 1, GTID_MODE_ON_PERMISSIVE = 2,
  GTID_MODE_ON = 3
}
 Possible values for @GLOBAL.GTID_MODE. More...
 
enum  enum_gtid_mode_lock { GTID_MODE_LOCK_NONE, GTID_MODE_LOCK_GTID_MODE, GTID_MODE_LOCK_SID, GTID_MODE_LOCK_CHANNEL_MAP }
 Locks needed to access gtid_mode. 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
}
 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_mode get_gtid_mode (const char *string, bool *error)
 Return the given string GTID_MODE as an enumeration value. More...
 
const char * get_gtid_mode_string (enum_gtid_mode gtid_mode_arg)
 Return the given GTID_MODE as a string. More...
 
enum_gtid_mode get_gtid_mode (enum_gtid_mode_lock have_lock)
 Return the current GTID_MODE as an enumeration value. More...
 
const char * get_gtid_mode_string (enum_gtid_mode_lock have_lock)
 Return the current GTID_MODE as a string. 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...
 
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_sid_map (rpl_sid sid)
 Return sidno for a given sid, see Sid_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
 
std::atomic< ulonggtid_mode_counter
 
ulong _gtid_mode
 The gtid_mode. More...
 
const char * gtid_mode_names []
 Strings holding the enumeration values for gtid_mode. More...
 
TYPELIB gtid_mode_typelib
 'Typelib' for the mode names. More...
 
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 MAX_GNO = LLONG_MAX
 The maximum value of GNO. 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_sid_lock
 Protects Gtid_state. See comment above gtid_state for details. More...
 
Checkable_rwlockgtid_mode_lock
 One of the locks that protects GTID_MODE. More...
 
Sid_mapglobal_sid_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 DBUG_OFF 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)
The function completed successfully.
Definition: rpl_gtid.h:120
Definition: mysql.cc:138

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)
Definition: mysql.cc:138

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/errmsg-utf8.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_utf8_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

typedef long long int rpl_gno

Type of GNO, the second (numeric) component of GTID.

◆ rpl_sid

◆ rpl_sidno

typedef int 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_mode

Possible values for @GLOBAL.GTID_MODE.

Enumerator
GTID_MODE_OFF 

New transactions are anonymous.

Replicated transactions must be anonymous; replicated GTID-transactions generate an error.

DEFAULT_GTID_MODE 
GTID_MODE_OFF_PERMISSIVE 

New transactions are anonyomus.

Replicated transactions can be either anonymous or GTID-transactions.

GTID_MODE_ON_PERMISSIVE 

New transactions are GTID-transactions.

Replicated transactions can be either anonymous or GTID-transactions.

GTID_MODE_ON 

New transactions are GTID-transactions.

Replicated transactions must be GTID-transactions; replicated anonymous transactions generate an error.

◆ enum_gtid_mode_lock

Locks needed to access gtid_mode.

When writing, all these locks must be held (for the rwlocks, the wrlock must be held).

When reading, one of them must be held (for the wrlocks, the rdlock suffices).

Enumerator
GTID_MODE_LOCK_NONE 

No lock held.

GTID_MODE_LOCK_GTID_MODE 

The specific gtid_mode_lock is held.

GTID_MODE_LOCK_SID 

global_sid_lock held.

GTID_MODE_LOCK_CHANNEL_MAP 

read or write lock on channel_map lock is held.

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

This 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 

◆ enum_return_status

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

This is used in conjuction 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_sid_lock.rdlock.

◆ get_gtid_consistency_mode_string() [1/2]

const char* get_gtid_consistency_mode_string ( enum_gtid_consistency_mode  mode)
inline

Return the given GTID_CONSISTENCY_MODE as a string.

◆ get_gtid_consistency_mode_string() [2/2]

const char* get_gtid_consistency_mode_string ( )
inline

Return the current value of ENFORCE_GTID_CONSISTENCY as a string.

Caller must hold global_sid_lock.rdlock.

◆ get_gtid_mode() [1/2]

enum_gtid_mode get_gtid_mode ( const char *  string,
bool error 
)
inline

Return the given string GTID_MODE as an enumeration value.

Parameters
stringThe string to decode.
[out]errorIf the string does not represent a valid GTID_MODE, this is set to true, otherwise it is left untouched.
Returns
The GTID_MODE.

◆ get_gtid_mode() [2/2]

enum_gtid_mode get_gtid_mode ( enum_gtid_mode_lock  have_lock)

Return the current GTID_MODE as an enumeration value.

This variable can be read while holding any one of the locks enumerated in enum_gtid_mode_lock (see above).

When the variable is updated by a SET GTID_MODE statement, all these locks will be taken (the wrlock on global_sid_map).

To avoid the mistake of reading the GTID_MODE with no lock, the caller has to pass the lock type as a parameter. The function will assert that the corresponding lock is held. If no lock is held, it will acquire and release global_sid_lock.rdlock.

Parameters
have_lockThe lock type held by the caller.

◆ get_gtid_mode_string() [1/2]

const char* get_gtid_mode_string ( enum_gtid_mode  gtid_mode_arg)
inline

Return the given GTID_MODE as a string.

◆ get_gtid_mode_string() [2/2]

const char* get_gtid_mode_string ( enum_gtid_mode_lock  have_lock)
inline

Return the current GTID_MODE as a string.

Used only for debugging.

Parameters
have_lockPass this parameter to get_gtid_mode(bool).

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

rpl_sidno get_sidno_from_global_sid_map ( rpl_sid  sid)

Return sidno for a given sid, see Sid_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.

◆ map_macro_enum()

enum_return_status map_macro_enum ( int  status)
inline

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

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

Current value for ENFORCE_GTID_CONSISTENCY.

Don't use this directly; use get_gtid_consistency_mode.

◆ _gtid_mode

ulong _gtid_mode

The gtid_mode.

Please do not access this directly - use the getters and setters defined below.

It is ulong rather than enum_gtid_mode because of how sys_vars are updated.

◆ global_sid_lock

Checkable_rwlock* global_sid_lock

Protects Gtid_state. See comment above gtid_state for details.

◆ global_sid_map

Sid_map* global_sid_map

◆ gtid_consistency_mode_names

const char* gtid_consistency_mode_names[]

Strings holding the enumeration values for gtid_consistency_mode_names.

Use get_gtid_consistency_mode_string instead of accessing this directly.

◆ gtid_mode_counter

std::atomic<ulong> gtid_mode_counter

◆ gtid_mode_lock

Checkable_rwlock* gtid_mode_lock

One of the locks that protects GTID_MODE.

See get_gtid_mode(enum_gtid_mode_lock).

◆ gtid_mode_names

const char* gtid_mode_names[]

Strings holding the enumeration values for gtid_mode.

Use get_gtid_mode_string instead of accessing this directly.

◆ gtid_mode_typelib

TYPELIB gtid_mode_typelib

'Typelib' for the mode names.

Use get_gtid_mode_string instead of accessing this directly.

◆ gtid_state

Gtid_state* gtid_state

Global state of GTIDs.

◆ key_memory_Gtid_cache_to_string

PSI_memory_key key_memory_Gtid_cache_to_string

◆ key_memory_Gtid_set_Interval_chunk

PSI_memory_key key_memory_Gtid_set_Interval_chunk

◆ key_memory_Gtid_set_to_string

PSI_memory_key key_memory_Gtid_set_to_string

◆ key_memory_Gtid_state_group_commit_sidno

PSI_memory_key key_memory_Gtid_state_group_commit_sidno

◆ key_memory_Gtid_state_to_string

PSI_memory_key key_memory_Gtid_state_to_string

◆ key_memory_Owned_gtids_to_string

PSI_memory_key key_memory_Owned_gtids_to_string

◆ MAX_GNO

const rpl_gno MAX_GNO = LLONG_MAX

The maximum value of GNO.

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