MySQL 8.4.3
Source Code Documentation
|
#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... | |
const mysql::gtid::Tsid & | get_tsid_from_global_tsid_map (rpl_sidno sidno) |
Return Tsid for a given sidno on the global_tsid_map. 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... | |
#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.
STATUS | The status to return. |
ACTION | A text that describes what we are doing: either "Returning" or "Propagating" (used in DBUG_PRINT macros) |
STATUS_NAME | The stringified version of the STATUS (used in DBUG_PRINT macros). |
ALLOW_UNREPORTED | If false, the macro asserts that STATUS is not RETURN_STATUS_UNREPORTED_ERROR. |
#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.
#define __RETURN_STATUS | ( | STATUS, | |
ALLOW_UNREPORTED | |||
) |
#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).
MYSQLBINLOG_ERROR | arguments to mysqlbinlog's 'error' function, including the function call parentheses |
SERVER_ERROR | arguments to my_error, including the function call parentheses. |
#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.
#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.
#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.
#define RETURN_OK return RETURN_STATUS_OK |
Returns RETURN_STATUS_OK.
#define RETURN_REPORTED_ERROR RETURN_STATUS(RETURN_STATUS_REPORTED_ERROR) |
Does a DBUG_PRINT and returns RETURN_STATUS_REPORTED_ERROR.
#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.
#define RETURN_STATUS | ( | STATUS | ) | __RETURN_STATUS(STATUS, true) |
If STATUS returns something else than RETURN_STATUS_OK, does a DBUG_PRINT.
Then, returns STATUS.
#define RETURN_UNREPORTED_ERROR RETURN_STATUS(RETURN_STATUS_UNREPORTED_ERROR) |
Does a DBUG_PRINT and returns RETURN_STATUS_UNREPORTED_ERROR.
#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 int64 rpl_binlog_pos |
using rpl_gno = mysql::gtid::gno_t |
GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t.
typedef mysql::gtid::Uuid rpl_sid |
using rpl_sidno = cs::index::rpl_sidno |
Type of SIDNO (source ID number, first component of GTID)
Indicates if a statement should be skipped or not.
Used as return value from gtid_before_statement.
enum 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.
enum 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:
void check_return_status | ( | enum_return_status | status, |
const char * | action, | ||
const char * | status_name, | ||
int | allow_unreported | ||
) |
int format_gno | ( | char * | s, |
rpl_gno | gno | ||
) |
Formats a GNO as a string.
s | The buffer. |
gno | The GNO. |
enum_gtid_consistency_mode get_gtid_consistency_mode | ( | ) |
Return the current value of ENFORCE_GTID_CONSISTENCY.
Caller must hold global_tsid_lock.rdlock.
|
inline |
Return the current value of ENFORCE_GTID_CONSISTENCY as a string.
Caller must hold global_tsid_lock.rdlock.
|
inline |
Return the given GTID_CONSISTENCY_MODE as a string.
Return last gno for a given sidno, see Gtid_state::get_last_executed_gno() for details.
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.
const mysql::gtid::Tsid & get_tsid_from_global_tsid_map | ( | rpl_sidno | sidno | ) |
Return Tsid for a given sidno on the global_tsid_map.
See Tsid_map::sidno_to_tsid() for details.
enum_gtid_statement_status gtid_pre_statement_checks | ( | THD * | thd | ) |
Perform GTID-related checks before executing a statement:
thd | THD object for the session. |
GTID_STATEMENT_EXECUTE | The normal case: the checks succeeded, and statement can execute. |
GTID_STATEMENT_CANCEL | The checks failed; an error has be generated and the statement must stop. |
GTID_STATEMENT_SKIP | The 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. |
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.
thd | THD object for the session |
false | Success. |
true | Error. Error can happen if GTID_MODE=ON. The error has been reported by (a function called by) this function. |
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.
thd | Thread. |
true | Error (can happen if gtid_mode=ON and gtid_next=anonymous). The error has already been reported using my_error. |
false | Success. |
void gtid_set_performance_schema_values | ( | const THD * | thd | ) |
|
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.
thd | Thread context |
needs_to | The actual work will be done when the parameter is true |
do_commit | When true the gtid state changes are committed, otherwise they are rolled back. |
bool is_already_logged_transaction | ( | const THD * | thd | ) |
Check if current transaction should be skipped, that is, if GTID_NEXT was already logged.
thd | The calling thread. |
true | Transaction was already logged. |
false | Transaction 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.
|
inline |
enum to map the result of Uuid::parse to the above Macros
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.
std::ostream & operator<< | ( | std::ostream & | oss, |
Gtid_mode::value_type const & | mode | ||
) |
rpl_gno parse_gno | ( | const char ** | s | ) |
Parse a GNO from a string.
s | Pointer to the string. *s will advance to the end of the parsed GNO, if a correct GNO is found. |
GNO | if a correct GNO (i.e., 0 or positive number) was found. |
-1 | otherwise. |
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.
thd | The thread that acquires ownership. |
spec | The Gtid_specification. |
false | Success: either we have acquired ownership of the GTID, or it is already included in GTID_EXECUTED and will be skipped. |
true | Failure; the thread was killed or an error occurred. The error has been reported using my_error. |
|
extern |
Current value for ENFORCE_GTID_CONSISTENCY.
Don't use this directly; use get_gtid_consistency_mode.
|
extern |
The one and only instance of Gtid_mode.
All access to @global.gtid_mode should use this object.
|
extern |
Protects Gtid_state. See comment above gtid_state for details.
|
extern |
const rpl_gno GNO_END = INT64_MAX |
One-past-the-max value of GNO.
If the GNO goes above the number, generate a warning.
|
extern |
Strings holding the enumeration values for gtid_consistency_mode_names.
Use get_gtid_consistency_mode_string instead of accessing this directly.
|
extern |
Global state of GTIDs.
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
const int MAX_GNO_TEXT_LENGTH = 19 |
The length of MAX_GNO when printed in decimal.
const int MAX_THREAD_ID_TEXT_LENGTH = 19 |
The maximal possible length of thread_id when printed in decimal.