My Project
|
#include <rpl_gtid.h>
Public Member Functions | |
Gtid_state (Checkable_rwlock *_sid_lock, Sid_map *_sid_map) | |
int | init () |
void | clear () |
bool | is_logged (const Gtid >id) const |
my_thread_id | get_owner (const Gtid >id) const |
enum_return_status | acquire_ownership (THD *thd, const Gtid >id) |
enum_return_status | update_on_flush (THD *thd) |
void | update_on_commit (THD *thd) |
void | update_on_rollback (THD *thd) |
rpl_gno | get_automatic_gno (rpl_sidno sidno) const |
void | lock_sidno (rpl_sidno sidno) |
Locks a mutex for the given SIDNO. | |
void | unlock_sidno (rpl_sidno sidno) |
Unlocks a mutex for the given SIDNO. | |
void | broadcast_sidno (rpl_sidno sidno) |
Broadcasts updates for the given SIDNO. | |
void | assert_sidno_lock_owner (rpl_sidno sidno) |
Assert that we own the given SIDNO. | |
void | wait_for_gtid (THD *thd, const Gtid >id) |
enum_return_status | ensure_sidno () |
enum_return_status | add_lost_gtids (const char *text) |
const Gtid_set * | get_logged_gtids () const |
Return a pointer to the Gtid_set that contains the logged groups. | |
const Gtid_set * | get_lost_gtids () const |
Return a pointer to the Gtid_set that contains the logged groups. | |
const Owned_gtids * | get_owned_gtids () const |
Return a pointer to the Owned_gtids that contains the owned groups. | |
rpl_sidno | get_server_sidno () const |
Return the server's SID's SIDNO. | |
const rpl_sid & | get_server_sid () const |
Return the server's SID. | |
size_t | get_max_string_length () const |
int | to_string (char *buf) const |
Debug only: Generate a string in the given buffer and return the length. | |
char * | to_string () const |
Debug only: return a newly allocated string, or NULL on out-of-memory. | |
void | print () const |
Debug only: print this Gtid_state to stdout. | |
void | dbug_print (const char *text="") const |
Represents the state of the group log: the set of logged groups, the set of lost groups, the set of owned groups, the owner of each owned group, and a Mutex_cond_array that protects updates to groups 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.
Gtid_state::Gtid_state | ( | Checkable_rwlock * | _sid_lock, |
Sid_map * | _sid_map | ||
) | [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 group log. |
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 | ( | const char * | text | ) |
Adds the given Gtid_set that contains the groups in the given string to lost_gtids and logged_gtids, since lost_gtids must be a subset of executed_gtids. Requires that the write lock on sid_locks is held.
text | The string to parse, see Gtid_set:add_gtid_text(const char *, bool) for format details. |
void Gtid_state::clear | ( | ) |
Reset the state after RESET MASTER: remove all logged and lost groups, but keep owned groups as they are.
The caller must hold the write lock on sid_lock before calling this function.
void Gtid_state::dbug_print | ( | const char * | text = "" | ) | const [inline] |
Print this Gtid_state to the trace file if debug is enabled; no-op otherwise.
enum_return_status Gtid_state::ensure_sidno | ( | ) |
Ensure that owned_gtids, logged_gtids, lost_gtids, 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.
rpl_gno Gtid_state::get_automatic_gno | ( | rpl_sidno | sidno | ) | const |
Allocates a GNO for an automatically numbered group.
sidno | The group's SIDNO. |
negative | the numeric value of GS_ERROR_OUT_OF_MEMORY |
other | The GNO for the group. |
size_t Gtid_state::get_max_string_length | ( | ) | const [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.
my_thread_id Gtid_state::get_owner | ( | const Gtid & | gtid | ) | const [inline] |
Returns the owner of the given GTID, or 0 if the group is not owned.
gtid | The Gtid to check. |
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). |
bool Gtid_state::is_logged | ( | const Gtid & | gtid | ) | const [inline] |
Returns true if the given GTID is logged.
gtid | The Gtid to check. |
true | The group is logged in the binary log. |
false | The group is not logged in the binary log. |
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 groups are updated. |
enum_return_status Gtid_state::update_on_flush | ( | THD * | thd | ) |
Update the state after the given thread has flushed cache to binlog.
This will:
thd | Thread for which owned groups 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 groups are updated. |
void Gtid_state::wait_for_gtid | ( | THD * | thd, |
const Gtid & | gtid | ||
) |
Waits until the given GTID is not owned by any other thread.
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. |
g | Gtid to wait for. |