MySQL 8.0.40
Source Code Documentation
|
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...
#include <rpl_gtid.h>
Public Member Functions | |
Gtid_state (Checkable_rwlock *_sid_lock, Sid_map *_sid_map) | |
Constructs a new Gtid_state object. More... | |
int | init () |
Add @GLOBAL.SERVER_UUID to this binlog's Sid_map. More... | |
int | clear (THD *thd) |
Reset the state and persistor after RESET MASTER: remove all logged and lost gtids, but keep owned gtids as they are. More... | |
bool | is_executed (const Gtid >id) const |
Returns true if the given GTID is logged. More... | |
bool | is_owned (const Gtid >id) const |
Returns true if GTID is owned, otherwise returns 0. More... | |
enum_return_status | acquire_ownership (THD *thd, const Gtid >id) |
Acquires ownership of the given GTID, on behalf of the given thread. More... | |
void | update_commit_group (THD *first_thd) |
This function updates both the THD and the Gtid_state to reflect that the transaction set of transactions has ended, and it does this for the whole commit group (by following the thd->next_to_commit pointer). More... | |
void | update_on_commit (THD *thd) |
Remove the GTID owned by thread from owned GTIDs, stating that thd->owned_gtid was committed. More... | |
void | update_on_rollback (THD *thd) |
Update the state after the given thread has rollbacked. More... | |
void | acquire_anonymous_ownership () |
Acquire anonymous ownership. More... | |
void | release_anonymous_ownership () |
Release anonymous ownership. More... | |
int32 | get_anonymous_ownership_count () |
Return the number of clients that hold anonymous ownership. More... | |
void | begin_automatic_gtid_violating_transaction () |
Increase the global counter when starting a GTID-violating transaction having GTID_NEXT=AUTOMATIC. More... | |
void | end_automatic_gtid_violating_transaction () |
Decrease the global counter when ending a GTID-violating transaction having GTID_NEXT=AUTOMATIC. More... | |
int32 | get_automatic_gtid_violating_transaction_count () |
Return the number of ongoing GTID-violating transactions having GTID_NEXT=AUTOMATIC. More... | |
void | begin_anonymous_gtid_violating_transaction () |
Increase the global counter when starting a GTID-violating transaction having GTID_NEXT=ANONYMOUS. More... | |
void | end_anonymous_gtid_violating_transaction () |
Decrease the global counter when ending a GTID-violating transaction having GTID_NEXT=ANONYMOUS. More... | |
void | end_gtid_violating_transaction (THD *thd) |
int32 | get_anonymous_gtid_violating_transaction_count () |
Return the number of ongoing GTID-violating transactions having GTID_NEXT=AUTOMATIC. More... | |
void | begin_gtid_wait () |
Increase the global counter when starting a call to WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS. More... | |
void | end_gtid_wait () |
Decrease the global counter when ending a call to WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS. More... | |
int32 | get_gtid_wait_count () |
Return the number of clients that have an ongoing call to WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS. More... | |
rpl_gno | get_automatic_gno (rpl_sidno sidno) const |
Computes the next available GNO. More... | |
rpl_gno | get_last_executed_gno (rpl_sidno sidno) const |
Return the last executed GNO for a given SIDNO, e.g. More... | |
enum_return_status | generate_automatic_gtid (THD *thd, rpl_sidno specified_sidno=0, rpl_gno specified_gno=0, rpl_sidno *locked_sidno=nullptr) |
Generates the GTID (or ANONYMOUS, if GTID_MODE = OFF or OFF_PERMISSIVE) for the THD, and acquires ownership. More... | |
void | lock_sidno (rpl_sidno sidno) |
Locks a mutex for the given SIDNO. More... | |
void | unlock_sidno (rpl_sidno sidno) |
Unlocks a mutex for the given SIDNO. More... | |
void | broadcast_sidno (rpl_sidno sidno) |
Broadcasts updates for the given SIDNO. More... | |
void | assert_sidno_lock_owner (rpl_sidno sidno) const |
Assert that we own the given SIDNO. More... | |
bool | wait_for_sidno (THD *thd, rpl_sidno sidno, struct timespec *abstime, bool update_thd_status=true) |
Wait for a signal on the given SIDNO. More... | |
bool | wait_for_gtid (THD *thd, const Gtid >id, struct timespec *abstime=nullptr) |
This is only a shorthand for wait_for_sidno, which contains additional debug printouts and assertions for the case when the caller waits for one specific GTID. More... | |
bool | wait_for_gtid_set (THD *thd, Gtid_set *gtid_set, double timeout, bool update_thd_status=true) |
Wait until the given Gtid_set is included in @GLOBAL.GTID_EXECUTED. More... | |
void | lock_sidnos (const Gtid_set *set) |
Locks one mutex for each SIDNO where the given Gtid_set has at least one GTID. More... | |
void | unlock_sidnos (const Gtid_set *set) |
Unlocks the mutex for each SIDNO where the given Gtid_set has at least one GTID. More... | |
void | broadcast_sidnos (const Gtid_set *set) |
Broadcasts the condition variable for each SIDNO where the given Gtid_set has at least one GTID. More... | |
enum_return_status | ensure_sidno () |
Ensure that owned_gtids, executed_gtids, lost_gtids, gtids_only_in_table, previous_gtids_logged and sid_locks have room for at least as many SIDNOs as sid_map. More... | |
enum_return_status | add_lost_gtids (Gtid_set *gtid_set, bool starts_with_plus) |
Adds the given Gtid_set to lost_gtids and executed_gtids. More... | |
void | update_prev_gtids (Gtid_set *write_gtid_set) |
Updates previously logged GTID set before writing to table. More... | |
const Gtid_set * | get_lost_gtids () const |
Return a pointer to the Gtid_set that contains the lost gtids. More... | |
const Gtid_set * | get_executed_gtids () const |
const Gtid_set * | get_gtids_only_in_table () const |
const Gtid_set * | get_previous_gtids_logged () const |
const Owned_gtids * | get_owned_gtids () const |
Return a pointer to the Owned_gtids that contains the owned gtids. More... | |
rpl_sidno | get_server_sidno () const |
Return the server's SID's SIDNO. More... | |
const rpl_sid & | get_server_sid () const |
Return the server's SID. More... | |
size_t | get_max_string_length () const |
Debug only: Returns an upper bound on the length of the string generated by to_string(), not counting '\0'. More... | |
int | to_string (char *buf) const |
Debug only: Generate a string in the given buffer and return the length. More... | |
char * | to_string () const |
Debug only: return a newly allocated string, or NULL on out-of-memory. More... | |
void | print () const |
Debug only: print this Gtid_state to stdout. More... | |
void | dbug_print (const char *text="") const |
Print this Gtid_state to the trace file if debug is enabled; no-op otherwise. More... | |
int | save (THD *thd) |
Save gtid owned by the thd into executed_gtids variable and gtid_executed table. More... | |
int | save (const Gtid_set *gtid_set) |
Insert the gtid set into table. More... | |
int | save_gtids_of_last_binlog_into_table () |
Save the set of gtids logged in the last binlog into gtid_executed table. More... | |
int | read_gtid_executed_from_table () |
Fetch gtids from gtid_executed table and store them into gtid_executed set. More... | |
int | compress (THD *thd) |
Compress the gtid_executed table, read each row by the PK(sid, gno_start) in increasing order, compress the first consecutive gtids range (delete consecutive gtids from the second consecutive gtid, then update the first gtid) within a single transaction. More... | |
int | warn_or_err_on_modify_gtid_table (THD *thd, Table_ref *table) |
Push a warning to client if user is modifying the gtid_executed table explicitly by a non-XA transaction. More... | |
Private Member Functions | |
void | update_gtids_impl (THD *thd, bool is_commit) |
Remove the GTID owned by thread from owned GTIDs. More... | |
void | unlock_owned_sidnos (const THD *thd) |
Unlock all SIDNOs owned by the given THD. More... | |
void | broadcast_owned_sidnos (const THD *thd) |
Broadcast the condition for all SIDNOs owned by the given THD. More... | |
bool | update_gtids_impl_check_skip_gtid_rollback (THD *thd) |
Used by unit tests that need to access private members. More... | |
bool | update_gtids_impl_do_nothing (THD *thd) |
This is a sub task of update_gtids_impl responsible only to handle the case of a thread that owns nothing and does not violate GTID consistency. More... | |
bool | update_gtids_impl_begin (THD *thd) |
This is a sub task of update_gtids_impl responsible only to evaluate if the thread is committing in the middle of a statement by checking THD's is_commit_in_middle_of_statement flag. More... | |
void | update_gtids_impl_own_gtid_set (THD *thd, bool is_commit) |
Handle the case that the thread own a set of GTIDs. More... | |
void | update_gtids_impl_lock_sidno (rpl_sidno sidno) |
Lock a given sidno of a transaction being updated. More... | |
void | update_gtids_impl_lock_sidnos (THD *thd) |
Locks the sidnos of all the GTIDs of the commit group starting on the transaction passed as parameter. More... | |
void | update_gtids_impl_own_gtid (THD *thd, bool is_commit) |
Handle the case that the thread own a single non-anonymous GTID. More... | |
void | update_gtids_impl_broadcast_and_unlock_sidno (rpl_sidno sidno) |
Unlock a given sidno after broadcasting its changes. More... | |
void | update_gtids_impl_broadcast_and_unlock_sidnos () |
Unlocks all locked sidnos after broadcasting their changes. More... | |
void | update_gtids_impl_own_anonymous (THD *thd, bool *more_trx) |
Handle the case that the thread owns ANONYMOUS GTID. More... | |
void | update_gtids_impl_own_nothing (THD *thd) |
Handle the case that the thread owns nothing. More... | |
void | update_gtids_impl_end (THD *thd, bool more_trx) |
Handle the final part of update_gtids_impl. More... | |
enum_return_status | ensure_commit_group_sidnos (rpl_sidno sidno) |
Ensure that commit_group_sidnos have room for the SIDNO passed as parameter. More... | |
Private Attributes | |
rpl_gno | next_free_gno |
The next_free_gno variable will be set with the supposed next free GNO every time a new GNO is delivered automatically or when a transaction is rolled back, releasing a GNO smaller than the last one delivered. More... | |
Checkable_rwlock * | sid_lock |
Read-write lock that protects updates to the number of SIDs. More... | |
Sid_map * | sid_map |
The Sid_map used by this Gtid_state. More... | |
Mutex_cond_array | sid_locks |
Contains one mutex/cond pair for every SIDNO. More... | |
Gtid_set | lost_gtids |
The set of GTIDs that existed in some previously purged binary log. More... | |
Gtid_set | executed_gtids |
Gtid_set | gtids_only_in_table |
Gtid_set | previous_gtids_logged |
Owned_gtids | owned_gtids |
The set of GTIDs that are owned by some thread. More... | |
rpl_sidno | server_sidno |
The SIDNO for this server. More... | |
std::atomic< int32 > | atomic_anonymous_gtid_count {0} |
The number of anonymous transactions owned by any client. More... | |
std::atomic< int32 > | atomic_automatic_gtid_violation_count {0} |
The number of GTID-violating transactions that use GTID_NEXT=AUTOMATIC. More... | |
std::atomic< int32 > | atomic_anonymous_gtid_violation_count {0} |
The number of GTID-violating transactions that use GTID_NEXT=AUTOMATIC. More... | |
std::atomic< int32 > | atomic_gtid_wait_count {0} |
The number of clients that are executing WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS. More... | |
Prealloced_array< bool, 8 > | commit_group_sidnos |
This array is used by Gtid_state_update_gtids_impl* functions. More... | |
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.
Locking:
This data structure has a read-write lock that protects the number of SIDNOs, and a Mutex_cond_array that contains one mutex per SIDNO. The rwlock is always the global_sid_lock.
Access methods generally assert that the caller already holds the appropriate lock:
The access type (read/write) does not matter; the write lock only implies that the entire data structure is locked whereas the read lock implies that everything except SID-specific data is locked.
|
inline |
Constructs a new Gtid_state object.
_sid_lock | Read-write lock that protects updates to the number of SIDs. |
_sid_map | Sid_map used by this Gtid_state. |
|
inline |
Acquire anonymous ownership.
The caller must hold either sid_lock.rdlock or sid_lock.wrlock. (The caller must have taken the lock and checked that gtid_mode!=ON before calling this function, or else the gtid_mode could have changed to ON by a concurrent SET GTID_MODE.)
enum_return_status Gtid_state::acquire_ownership | ( | THD * | thd, |
const Gtid & | gtid | ||
) |
Acquires ownership of the given GTID, on behalf of the given thread.
The caller must lock the SIDNO before invoking this function.
thd | The thread that will own the GTID. |
gtid | The Gtid to acquire ownership of. |
enum_return_status Gtid_state::add_lost_gtids | ( | Gtid_set * | gtid_set, |
bool | starts_with_plus | ||
) |
Adds the given Gtid_set to lost_gtids and executed_gtids.
lost_gtids must be a subset of executed_gtids. purged_gtid and executed_gtid sets are appended with the argument set provided the latter is disjoint with gtid_executed owned_gtids.
Requires that the caller holds global_sid_lock.wrlock.
[in,out] | gtid_set | The gtid_set to add. If the gtid_set does not start with a plus sign (starts_with_plus is false), @GLOBAL.GTID_PURGED will be removed from the gtid_set. |
starts_with_plus | If true, the gtid_set passed is required to be disjoint from @GLOBAL.GTID_PURGED; if false, the gtid_set passed is required to be a superset of @GLOBAL.GTID_PURGED. |
|
inline |
Assert that we own the given SIDNO.
|
inline |
Increase the global counter when starting a GTID-violating transaction having GTID_NEXT=ANONYMOUS.
|
inline |
Increase the global counter when starting a GTID-violating transaction having GTID_NEXT=AUTOMATIC.
|
inline |
Increase the global counter when starting a call to WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS.
|
private |
Broadcast the condition for all SIDNOs owned by the given THD.
|
inline |
Broadcasts updates for the given SIDNO.
void Gtid_state::broadcast_sidnos | ( | const Gtid_set * | set | ) |
Broadcasts the condition variable for each SIDNO where the given Gtid_set has at least one GTID.
int Gtid_state::clear | ( | THD * | thd | ) |
Reset the state and persistor after RESET MASTER: remove all logged and lost gtids, but keep owned gtids as they are.
The caller must hold the write lock on sid_lock before calling this function.
thd | Thread requesting to reset the persistor |
0 | Success |
-1 | Error |
int Gtid_state::compress | ( | THD * | thd | ) |
Compress the gtid_executed table, read each row by the PK(sid, gno_start) in increasing order, compress the first consecutive gtids range (delete consecutive gtids from the second consecutive gtid, then update the first gtid) within a single transaction.
thd | Thread requesting to compress the table |
0 | OK |
1 | The table was not found. |
-1 | Error |
|
inline |
Print this Gtid_state to the trace file if debug is enabled; no-op otherwise.
|
inline |
Decrease the global counter when ending a GTID-violating transaction having GTID_NEXT=ANONYMOUS.
|
inline |
Decrease the global counter when ending a GTID-violating transaction having GTID_NEXT=AUTOMATIC.
void Gtid_state::end_gtid_violating_transaction | ( | THD * | thd | ) |
|
inline |
Decrease the global counter when ending a call to WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS.
|
private |
Ensure that commit_group_sidnos have room for the SIDNO passed as parameter.
This function must only be called in one place: Gtid_state::ensure_sidno().
sidno | The SIDNO. |
enum_return_status Gtid_state::ensure_sidno | ( | ) |
Ensure that owned_gtids, executed_gtids, lost_gtids, gtids_only_in_table, previous_gtids_logged and sid_locks have room for at least as many SIDNOs as sid_map.
This function must only be called in one place: Sid_map::add_sid().
Requires that the write lock on sid_locks is held. If any object needs to be resized, then the lock will be temporarily upgraded to a write lock and then degraded to a read lock again; there will be a short period when the lock is not held at all.
enum_return_status Gtid_state::generate_automatic_gtid | ( | THD * | thd, |
rpl_sidno | specified_sidno = 0 , |
||
rpl_gno | specified_gno = 0 , |
||
rpl_sidno * | locked_sidno = nullptr |
||
) |
Generates the GTID (or ANONYMOUS, if GTID_MODE = OFF or OFF_PERMISSIVE) for the THD, and acquires ownership.
thd | The thread. | |
specified_sidno | Externally generated sidno. | |
specified_gno | Externally generated gno. | |
[in,out] | locked_sidno | This parameter should be used when there is a need of generating many GTIDs without having to acquire/release a sidno_lock many times. The caller must hold global_sid_lock and unlock the locked_sidno after invocation when locked_sidno > 0 if locked_sidno!=NULL. The caller must not hold global_sid_lock when locked_sidno==NULL. See comments on function code to more details. |
|
inline |
Return the number of ongoing GTID-violating transactions having GTID_NEXT=AUTOMATIC.
|
inline |
Return the number of clients that hold anonymous ownership.
Computes the next available GNO.
sidno | The GTID's SIDNO. |
-1 | The range of GNOs was exhausted (i.e., more than 1<<63-1 GTIDs with the same UUID have been generated). |
>0 | The GNO for the GTID. |
|
inline |
Return the number of ongoing GTID-violating transactions having GTID_NEXT=AUTOMATIC.
|
inline |
|
inline |
Return the number of clients that have an ongoing call to WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS.
|
inline |
Return the last executed GNO for a given SIDNO, e.g.
for the following set: UUID:1-10, UUID:12, UUID:15-20 20 will be returned.
sidno | The GTID's SIDNO. |
The | GNO or 0 if set is empty. |
|
inline |
Return a pointer to the Gtid_set that contains the lost gtids.
|
inline |
Debug only: Returns an upper bound on the length of the string generated by to_string(), not counting '\0'.
The actual length may be shorter.
|
inline |
Return a pointer to the Owned_gtids that contains the owned gtids.
|
inline |
|
inline |
Return the server's SID.
|
inline |
Return the server's SID's SIDNO.
int Gtid_state::init | ( | ) |
Add @GLOBAL.SERVER_UUID to this binlog's Sid_map.
This can't be done in the constructor because the constructor is invoked at server startup before SERVER_UUID is initialized.
The caller must hold the read lock or write lock on sid_locks before invoking this function.
0 | Success |
1 | Error (out of memory or IO error). |
|
inline |
Returns true if the given GTID is logged.
gtid | The Gtid to check. |
true | The gtid is logged in the binary log. |
false | The gtid is not logged in the binary log. |
|
inline |
Returns true if GTID is owned, otherwise returns 0.
gtid | The Gtid to check. |
|
inline |
Locks a mutex for the given SIDNO.
void Gtid_state::lock_sidnos | ( | const Gtid_set * | set | ) |
Locks one mutex for each SIDNO where the given Gtid_set has at least one GTID.
Locks are acquired in order of increasing SIDNO.
|
inline |
Debug only: print this Gtid_state to stdout.
int Gtid_state::read_gtid_executed_from_table | ( | ) |
Fetch gtids from gtid_executed table and store them into gtid_executed set.
0 | OK |
1 | The table was not found. |
-1 | Error |
|
inline |
Release anonymous ownership.
int Gtid_state::save | ( | const Gtid_set * | gtid_set | ) |
Insert the gtid set into table.
gtid_set | contains a set of gtid, which holds the sidno and the gno. |
0 | OK |
-1 | Error |
int Gtid_state::save | ( | THD * | thd | ) |
Save gtid owned by the thd into executed_gtids variable and gtid_executed table.
thd | Session to commit |
0 | OK |
-1 | Error |
int Gtid_state::save_gtids_of_last_binlog_into_table | ( | ) |
Save the set of gtids logged in the last binlog into gtid_executed table.
0 | OK |
-1 | Error |
|
inline |
Debug only: return a newly allocated string, or NULL on out-of-memory.
|
inline |
Debug only: Generate a string in the given buffer and return the length.
|
private |
Unlock all SIDNOs owned by the given THD.
|
inline |
Unlocks a mutex for the given SIDNO.
void Gtid_state::unlock_sidnos | ( | const Gtid_set * | set | ) |
Unlocks the mutex for each SIDNO where the given Gtid_set has at least one GTID.
void Gtid_state::update_commit_group | ( | THD * | first_thd | ) |
This function updates both the THD and the Gtid_state to reflect that the transaction set of transactions has ended, and it does this for the whole commit group (by following the thd->next_to_commit pointer).
It will:
first_thd | The first thread of the group commit that needs GTIDs to be updated. |
|
private |
Remove the GTID owned by thread from owned GTIDs.
This will:
[in] | thd | Thread for which owned gtids are updated. |
[in] | is_commit | If true, the update is for a commit (not a rollback). |
|
private |
This is a sub task of update_gtids_impl responsible only to evaluate if the thread is committing in the middle of a statement by checking THD's is_commit_in_middle_of_statement flag.
This flag is true for anonymous transactions, when the 'transaction' has been split into multiple transactions in the binlog, and the present transaction is not the last one.
This means two things:
The flag is set in two cases:
We are committing the statement cache when there are more changes in the transaction cache.
This happens either because a single statement in the beginning of a transaction updates both transactional and non-transactional tables, or because we are committing a non-transactional update in the middle of a transaction when binlog_direct_non_transactional_updates=1.
In this case, the flag is set further down in this function.
The statement is one of the special statements that may generate multiple transactions: CREATE...SELECT, DROP TABLE, DROP DATABASE. See comment for THD::owned_gtid in sql/sql_class.h.
In this case, the THD::is_commit_in_middle_of_statement flag is set by the caller and the flag becomes true here.
[in] | thd | - Thread to be evaluated. |
|
private |
Unlock a given sidno after broadcasting its changes.
This is a sub task of update_gtids_impl responsible only to unlock the sidno of the GTID being updated after broadcasting its changes.
[in] | sidno | - The sidno to be broadcasted and unlocked. |
|
private |
Unlocks all locked sidnos after broadcasting their changes.
This is a sub task of update_commit_group responsible only to unlock the sidno(s) of the GTID(s) being updated after broadcasting their changes.
|
private |
Used by unit tests that need to access private members.
This is a sub task of update_on_rollback responsible only to handle the case of a thread that needs to skip GTID operations when it has "failed to commit".
Administrative commands [CHECK|REPAIR|OPTIMIZE|ANALYZE] TABLE are written to the binary log even when they fail. When the commands fail, they will call update_on_rollback; later they will write the binary log. But we must not do any of the things in update_gtids_impl if we are going to write the binary log. So these statements set the skip_gtid_rollback flag, which tells update_on_rollback to return early. When the statements are written to the binary log they will call update_on_commit as usual.
[in] | thd | - Thread to be evaluated. |
true | The transaction should skip the rollback, false otherwise. |
|
private |
This is a sub task of update_gtids_impl responsible only to handle the case of a thread that owns nothing and does not violate GTID consistency.
If the THD does not own anything, there is nothing to do, so we can do an early return of the update process. Except if there is a GTID consistency violation; then we need to decrease the counter, so then we can continue executing inside update_gtids_impl.
[in] | thd | - Thread to be evaluated. |
true | The transaction can be skipped because it owns nothing and does not violate GTID consistency, false otherwise. |
|
private |
Handle the final part of update_gtids_impl.
This is a sub task of update_gtids_impl responsible only to handle the call to end_gtid_violating_transaction function when there is no more transactions split after the current transaction.
[in] | thd | - Thread for which owned GTID is updated. |
[in] | more_trx | - This is the value returned from Gtid_state::update_gtids_impl_begin and can be changed for transactions owning anonymous GTID at Gtid_state::update_gtids_impl_own_anonymous. |
|
private |
Lock a given sidno of a transaction being updated.
This is a sub task of update_gtids_impl responsible only to lock the sidno of the GTID being updated.
[in] | sidno | - The sidno to be locked. |
|
private |
Locks the sidnos of all the GTIDs of the commit group starting on the transaction passed as parameter.
This is a sub task of update_commit_group responsible only to lock the sidno(s) of the GTID(s) being updated.
The function should follow thd->next_to_commit to lock all sidnos of all transactions being updated in a group.
[in] | thd | - Thread that owns the GTID(s) to be updated or leader of the commit group in the case of a commit group update. |
|
private |
Handle the case that the thread owns ANONYMOUS GTID.
This is a sub task of update_gtids_impl responsible only to handle the case of a thread with an ANONYMOUS GTID being updated.
[in] | thd | - Thread to be updated that owns anonymous GTID. |
[in,out] | more_trx | - If the 'transaction' has been split into multiple transactions in the binlog. This is firstly assigned with the return of Gtid_state::update_gtids_impl_begin function, and its value can be set to true when Gtid_state::update_gtids_impl_anonymous_gtid detects more content on the transaction cache. |
|
private |
Handle the case that the thread own a single non-anonymous GTID.
This is a sub task of update_gtids_impl responsible only to handle the case of a thread with a single non-anonymous GTID being updated either for commit or rollback.
[in] | thd | - Thread to be updated that owns single non-anonymous GTID. |
[in] | is_commit | - If the thread is being updated by a commit. |
|
private |
Handle the case that the thread own a set of GTIDs.
This is a sub task of update_gtids_impl responsible only to handle the case of a thread with a set of GTIDs being updated.
[in] | thd | - Thread for which owned GTID set should be updated. |
[in] | is_commit | - If the thread is being updated by a commit. |
|
private |
Handle the case that the thread owns nothing.
This is a sub task of update_gtids_impl responsible only to handle the case of a thread that owns nothing being updated.
There are two cases when this happens:
[in] | thd | - Thread to be updated that owns anonymous GTID. |
void Gtid_state::update_on_commit | ( | THD * | thd | ) |
Remove the GTID owned by thread from owned GTIDs, stating that thd->owned_gtid was committed.
This will:
thd | Thread for which owned gtids are updated. |
void Gtid_state::update_on_rollback | ( | THD * | thd | ) |
Update the state after the given thread has rollbacked.
This will:
thd | Thread for which owned gtids are updated. |
void Gtid_state::update_prev_gtids | ( | Gtid_set * | write_gtid_set | ) |
Updates previously logged GTID set before writing to table.
bool Gtid_state::wait_for_gtid | ( | THD * | thd, |
const Gtid & | gtid, | ||
struct timespec * | abstime = nullptr |
||
) |
This is only a shorthand for wait_for_sidno, which contains additional debug printouts and assertions for the case when the caller waits for one specific GTID.
bool Gtid_state::wait_for_gtid_set | ( | THD * | thd, |
Gtid_set * | gtid_set, | ||
double | timeout, | ||
bool | update_thd_status = true |
||
) |
Wait until the given Gtid_set is included in @GLOBAL.GTID_EXECUTED.
thd | The calling thread. | |
gtid_set | Gtid_set to wait for. | |
[in] | timeout | The maximum number of milliseconds that the function should wait, or 0 to wait indefinitely. |
[in] | update_thd_status | when true updates the stage info with the new wait condition, when false keeps the current stage info. |
false | Success. |
true | Failure: either timeout or thread was killed. If thread was killed, the error has been generated. |
bool Gtid_state::wait_for_sidno | ( | THD * | thd, |
rpl_sidno | sidno, | ||
struct timespec * | abstime, | ||
bool | update_thd_status = true |
||
) |
Wait for a signal on the given SIDNO.
NOTE: This releases a lock!
This requires that the caller holds a read lock on sid_lock. It will release the lock before waiting; neither global_sid_lock nor the mutex lock on SIDNO will not be held when this function returns.
thd | THD object of the caller. | |
sidno | Sidno to wait for. | |
[in] | abstime | The absolute point in time when the wait times out and stops, or NULL to wait indefinitely. |
[in] | update_thd_status | when true updates the stage info with the new wait condition, when false keeps the current stage info. |
false | Success. |
true | Failure: either timeout or thread was killed. If thread was killed, the error has been generated. |
Push a warning to client if user is modifying the gtid_executed table explicitly by a non-XA transaction.
Push an error to client if user is modifying it explicitly by a XA transaction.
thd | Thread requesting to access the table |
table | The table is being accessed. |
0 | No warning or error was pushed to the client. |
1 | Push a warning to client. |
2 | Push an error to client. |
|
private |
The number of anonymous transactions owned by any client.
|
private |
The number of GTID-violating transactions that use GTID_NEXT=AUTOMATIC.
|
private |
The number of GTID-violating transactions that use GTID_NEXT=AUTOMATIC.
|
private |
The number of clients that are executing WAIT_FOR_EXECUTED_GTID_SET or WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS.
|
private |
This array is used by Gtid_state_update_gtids_impl* functions.
The array items (one per sidno of the sid_map) will be set as true for each sidno that requires to be locked when updating a set of GTIDs (at Gtid_set::update_gtids_impl_lock_sidnos).
The array items will be set false at Gtid_set::update_gtids_impl_broadcast_and_unlock_sidnos.
It is used to so that lock, unlock, and broadcast operations are only called once per sidno per commit group, instead of once per transaction.
Its access is protected by:
|
private |
|
private |
|
private |
The set of GTIDs that existed in some previously purged binary log.
This is always a subset of executed_gtids.
|
private |
The next_free_gno variable will be set with the supposed next free GNO every time a new GNO is delivered automatically or when a transaction is rolled back, releasing a GNO smaller than the last one delivered.
It was introduced in an optimization of Gtid_state::get_automatic_gno and Gtid_state::generate_automatic_gtid functions.
Locking scheme
This variable can be read and modified in four places:
|
private |
The set of GTIDs that are owned by some thread.
|
private |
|
private |
The SIDNO for this server.
|
mutableprivate |
Read-write lock that protects updates to the number of SIDs.
|
private |
Contains one mutex/cond pair for every SIDNO.
|
mutableprivate |
The Sid_map used by this Gtid_state.