MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Gtid_state Class Reference

#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 &gtid) const
my_thread_id get_owner (const Gtid &gtid) const
enum_return_status acquire_ownership (THD *thd, const Gtid &gtid)
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 &gtid)
enum_return_status ensure_sidno ()
enum_return_status add_lost_gtids (const char *text)
const Gtid_setget_logged_gtids () const
 Return a pointer to the Gtid_set that contains the logged groups.
const Gtid_setget_lost_gtids () const
 Return a pointer to the Gtid_set that contains the logged groups.
const Owned_gtidsget_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.
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

Detailed Description

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:

  • before accessing any global data, hold at least the rdlock.
  • before accessing a specific SIDNO in a Gtid_set or Owned_gtids (e.g., calling Gtid_set::_add_gtid(Gtid)), hold either the rdlock and the SIDNO's mutex lock; or the wrlock. If you need to hold multiple mutexes, they must be acquired in order of increasing SIDNO.
  • before starting an operation that needs to access all SIDs (e.g. Gtid_set::to_string()), hold the wrlock.

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.

Definition at line 2062 of file rpl_gtid.h.

Constructor & Destructor Documentation

Gtid_state::Gtid_state ( Checkable_rwlock _sid_lock,
Sid_map _sid_map 
)
inline

Constructs a new Gtid_state object.

Parameters
_sid_lockRead-write lock that protects updates to the number of SIDs.
_sid_mapSid_map used by this group log.

Definition at line 2072 of file rpl_gtid.h.

Member Function Documentation

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.

Parameters
thdThe thread that will own the GTID.
gtidThe Gtid to acquire ownership of.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 36 of file rpl_gtid_state.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
textThe string to parse, see Gtid_set:add_gtid_text(const char *, bool) for format details.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 344 of file rpl_gtid_state.cc.

Here is the call graph for this function:

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.

Definition at line 25 of file rpl_gtid_state.cc.

Here is the call graph for this function:

Here is the caller graph for 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.

Definition at line 2299 of file rpl_gtid.h.

Here is the call graph for this function:

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.

Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 320 of file rpl_gtid_state.cc.

Here is the call graph for this function:

rpl_gno Gtid_state::get_automatic_gno ( rpl_sidno  sidno) const

Allocates a GNO for an automatically numbered group.

Parameters
sidnoThe group's SIDNO.
Return values
negativethe numeric value of GS_ERROR_OUT_OF_MEMORY
otherThe GNO for the group.

Definition at line 241 of file rpl_gtid_state.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Definition at line 2261 of file rpl_gtid.h.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
gtidThe Gtid to check.
Returns
my_thread_id of the thread that owns the group, or 0 if the group is not owned.

Definition at line 2121 of file rpl_gtid.h.

Here is the call graph for this function:

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.

Return values
0Success
1Error (out of memory or IO error).

Definition at line 374 of file rpl_gtid_state.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Gtid_state::is_logged ( const Gtid gtid) const
inline

Returns true if the given GTID is logged.

Parameters
gtidThe Gtid to check.
Return values
trueThe group is logged in the binary log.
falseThe group is not logged in the binary log.

Definition at line 2108 of file rpl_gtid.h.

Here is the call graph for this function:

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:

  • remove owned GTID from owned_gtids;
  • remove all owned GTIDS from thd->owned_gtid and thd->owned_gtid_set;
Parameters
thdThread for which owned groups are updated.

Definition at line 178 of file rpl_gtid_state.cc.

enum_return_status Gtid_state::update_on_flush ( THD *  thd)

Update the state after the given thread has flushed cache to binlog.

This will:

  • release ownership of all GTIDs owned by the THD;
  • add all GTIDs in the Group_cache to logged_gtids;
  • send a broadcast on the condition variable for every sidno for which we released ownership.
Parameters
thdThread for which owned groups are updated.

Definition at line 129 of file rpl_gtid_state.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void Gtid_state::update_on_rollback ( THD *  thd)

Update the state after the given thread has rollbacked.

This will:

  • release ownership of all GTIDs owned by the THD;
  • remove owned GTID from owned_gtids;
  • remove all owned GTIDS from thd->owned_gtid and thd->owned_gtid_set;
  • send a broadcast on the condition variable for every sidno for which we released ownership.
Parameters
thdThread for which owned groups are updated.

Definition at line 186 of file rpl_gtid_state.cc.

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.

Parameters
thdTHD object of the caller.
gGtid to wait for.

Definition at line 268 of file rpl_gtid_state.cc.

Here is the call graph for this function:


The documentation for this class was generated from the following files: