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

#include <rpl_gtid.h>

Collaboration diagram for Gtid_set:

Classes

class  Const_interval_iterator
class  Free_intervals_lock
class  Gtid_iterator
struct  Interval
struct  Interval_chunk
class  Interval_iterator
class  Interval_iterator_base
struct  String_format

Public Member Functions

 Gtid_set (Sid_map *sid_map, Checkable_rwlock *sid_lock=NULL)
 Gtid_set (Sid_map *sid_map, const char *text, enum_return_status *status, Checkable_rwlock *sid_lock=NULL)
 ~Gtid_set ()
 Destroy this Gtid_set.
void clear ()
enum_return_status _add_gtid (rpl_sidno sidno, rpl_gno gno)
enum_return_status _remove_gtid (rpl_sidno sidno, rpl_gno gno)
enum_return_status _add_gtid (const Gtid &gtid)
enum_return_status add_gtid_set (const Gtid_set *other)
enum_return_status remove_gtid_set (const Gtid_set *other)
enum_return_status add_gtid_text (const char *text, bool *anonymous=NULL)
enum_return_status add_gtid_encoding (const uchar *encoded, size_t length, size_t *actual_length=NULL)
bool contains_gtid (rpl_sidno sidno, rpl_gno gno) const
 Return true iff the given GTID exists in this set.
bool contains_gtid (const Gtid &gtid) const
 Return true iff the given GTID exists in this set.
rpl_sidno get_max_sidno () const
 Returns the maximal sidno that this Gtid_set currently has space for.
enum_return_status ensure_sidno (rpl_sidno sidno)
bool is_subset (const Gtid_set *super) const
 Returns true if this Gtid_set is a subset of the other Gtid_set.
bool is_intersection_nonempty (const Gtid_set *other) const
enum_return_status intersection (const Gtid_set *other, Gtid_set *result)
bool is_empty () const
 Returns true if this Gtid_set is empty.
bool contains_sidno (rpl_sidno sidno) const
char * to_string () const
void print () const
 Debug only: Print this Gtid_set to stdout.
void dbug_print (const char *text="") const
int get_string_length (const String_format *string_format=NULL) const
int to_string (char *buf, const String_format *string_format=NULL) const
int to_string (char **buf, const String_format *string_format=NULL) const
Sid_mapget_sid_map () const
 Return the Sid_map associated with this Gtid_set.
void add_interval_memory (int n_intervals, Interval *intervals_param)
void encode (uchar *buf) const
size_t get_encoded_length () const

Static Public Member Functions

static bool is_valid (const char *text)

Static Public Attributes

static const String_format default_string_format
static const String_format sql_string_format
static const String_format commented_string_format

Friends

class Gtid_set::Free_intervals_lock
 Used by unit tests that need to access private members.

Detailed Description

Represents a set of GTIDs.

This is structured as an array, indexed by SIDNO, where each element contains a linked list of intervals.

This data structure OPTIONALLY knows of a Sid_map that gives a correspondence between SIDNO and SID. If the Sid_map is NULL, then operations that require a Sid_map - printing and parsing - raise an assertion.

This data structure OPTIONALLY knows of a read-write lock that protects the number of SIDNOs. The lock is provided by the invoker of the constructor and it is generally the caller's responsibility to acquire the read lock. If the lock is not NULL, access methods assert that the caller already holds the read (or write) lock. If the lock is not NULL and a method of this class grows the number of SIDNOs, then the method temporarily upgrades this lock to a write lock and then degrades it to a read lock again; there will be a short period when the lock is not held at all.

Definition at line 842 of file rpl_gtid.h.

Constructor & Destructor Documentation

Gtid_set::Gtid_set ( Sid_map sid_map,
Checkable_rwlock sid_lock = NULL 
)

Constructs a new, empty Gtid_set.

Parameters
sid_mapThe Sid_map to use, or NULL if this Gtid_set should not have a Sid_map.
sid_lockRead-write lock that protects updates to the number of SIDs. This may be NULL if such changes do not need to be protected.

Definition at line 50 of file rpl_gtid_set.cc.

Gtid_set::Gtid_set ( Sid_map sid_map,
const char *  text,
enum_return_status *  status,
Checkable_rwlock sid_lock = NULL 
)

Constructs a new Gtid_set that contains the groups in the given string, in the same format as add_gtid_text(char *).

Parameters
sid_mapThe Sid_map to use for SIDs.
textThe text to parse.
statusWill be set GS_SUCCESS or GS_ERROR_PARSE or GS_ERROR_OUT_OF_MEMORY.
sid_lockRead/write lock to protect changes in the number of SIDs with. This may be NULL if such changes do not need to be protected.

If sid_lock != NULL, then the read lock on sid_lock must be held before calling this function. If the array is grown, sid_lock is temporarily upgraded to a write lock and then degraded again; there will be a short period when the lock is not held at all.

Definition at line 57 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Member Function Documentation

enum_return_status Gtid_set::_add_gtid ( rpl_sidno  sidno,
rpl_gno  gno 
)
inline

Adds the given GTID to this Gtid_set.

The SIDNO must exist in the Gtid_set before this function is called.

Parameters
sidnoSIDNO of the group to add.
gnoGNO of the group to add.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 895 of file rpl_gtid.h.

Here is the caller graph for this function:

enum_return_status Gtid_set::_add_gtid ( const Gtid gtid)
inline

Adds the given GTID to this Gtid_set.

The SIDNO must exist in the Gtid_set before this function is called.

Parameters
gtidGtid to add.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 930 of file rpl_gtid.h.

Here is the call graph for this function:

Here is the caller graph for this function:

enum_return_status Gtid_set::_remove_gtid ( rpl_sidno  sidno,
rpl_gno  gno 
)
inline

Removes the given GTID from this Gtid_set.

Parameters
sidnoSIDNO of the group to remove.
gnoGNO of the group to remove.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 910 of file rpl_gtid.h.

Here is the call graph for this function:

enum_return_status Gtid_set::add_gtid_encoding ( const uchar *  encoded,
size_t  length,
size_t *  actual_length = NULL 
)

Decodes a Gtid_set from the given string.

Parameters
stringThe string to parse.
lengthThe number of bytes.
actual_lengthIf this is not NULL, it is set to the number of bytes used by the encoding (which may be less than 'length'). If this is NULL, an error is generated if the encoding is shorter than the given 'length'.
Returns
GS_SUCCESS or GS_ERROR_PARSE or GS_ERROR_OUT_OF_MEMORY

Definition at line 1315 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

enum_return_status Gtid_set::add_gtid_set ( const Gtid_set other)

Adds all groups from the given Gtid_set to this Gtid_set.

If sid_lock != NULL, then the read lock must be held before calling this function. If a new sidno is added so that the array of lists of intervals is grown, sid_lock is temporarily upgraded to a write lock and then degraded again; there will be a short period when the lock is not held at all.

Parameters
otherThe Gtid_set to add.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 648 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

enum_return_status Gtid_set::add_gtid_text ( const char *  text,
bool *  anonymous = NULL 
)

Adds the set of GTIDs represented by the given string to this Gtid_set.

The string must have the format of a comma-separated list of zero or more of the following:

XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX(:NUMBER+(-NUMBER)?)* | ANONYMOUS

Each X is a hexadecimal digit (upper- or lowercase). NUMBER is a decimal, 0xhex, or 0oct number.

The start of an interval must be greater than 0. The end of an interval may be 0, but any interval that has an endpoint that is smaller than the start is discarded.

If sid_lock != NULL, then the read lock on sid_lock must be held before calling this function. If a new sidno is added so that the array of lists of intervals is grown, sid_lock is temporarily upgraded to a write lock and then degraded again; there will be a short period when the lock is not held at all.

Parameters
textThe string to parse.
anonymous[in,out]If this is NULL, ANONYMOUS is not allowed. If this is not NULL, it will be set to true if the anonymous group was found; false otherwise.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 408 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void Gtid_set::add_interval_memory ( int  n_intervals,
Interval intervals_param 
)
inline

Provides an array of Intervals that this Gtid_set can use when groups are subsequently added. This can be used as an optimization, to reduce allocation for sets that have a known number of intervals.

Parameters
n_intervalsThe number of intervals to add.
intervalsArray of n_intervals intervals.

Definition at line 1202 of file rpl_gtid.h.

void Gtid_set::clear ( )

Removes all groups from this Gtid_set.

This does not deallocate anything: if groups are added later, existing allocated memory will be re-used.

Definition at line 229 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Gtid_set::contains_sidno ( rpl_sidno  sidno) const
inline

Returns true if this Gtid_set contains at least one GTID with the given SIDNO.

Parameters
sidnoThe SIDNO to test.
Return values
trueThe SIDNO is less than or equal to the max SIDNO, and there is at least one group with this SIDNO.
falseThe SIDNO is greater than the max SIDNO, or there is no group with this SIDNO.

Definition at line 1048 of file rpl_gtid.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void Gtid_set::dbug_print ( const char *  text = "") const
inline

Print this Gtid_set to the trace file if debug is enabled; no-op otherwise.

Definition at line 1085 of file rpl_gtid.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void Gtid_set::encode ( uchar *  buf) const

Encodes this Gtid_set as a binary string.

Definition at line 1259 of file rpl_gtid_set.cc.

Here is the call graph for this function:

enum_return_status Gtid_set::ensure_sidno ( rpl_sidno  sidno)

Allocates space for all sidnos up to the given sidno in the array of intervals. The sidno must exist in the Sid_map associated with this Gtid_set.

If sid_lock != NULL, then the read lock on sid_lock must be held before calling this function. If the array is grown, sid_lock is temporarily upgraded to a write lock and then degraded again; there will be a short period when the lock is not held at all.

Parameters
sidnoThe SIDNO.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 105 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

size_t Gtid_set::get_encoded_length ( ) const

Returns the length of this Gtid_set when encoded using the encode() function.

Definition at line 1411 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

int Gtid_set::get_string_length ( const String_format string_format = NULL) const

Returns the length of the output from to_string.

Warning
This does not include the trailing '\0', so your buffer needs space for get_string_length() + 1 characters.
Parameters
string_formatString_format object that specifies separators in the resulting text.
Returns
The length.

Definition at line 874 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

enum_return_status Gtid_set::intersection ( const Gtid_set other,
Gtid_set result 
)

Add the intersection of this Gtid_set and the other Gtid_set to result.

Parameters
otherThe Gtid_set to intersect with this Gtid_set
resultGtid_set where the result will be stored.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.
Todo:
: This algorithm is simple, a little bit slower than necessary. It would be more efficient to iterate over intervals of 'this' and 'other' similar to add_gno_interval(). At the moment the performance of this is not super-important. /Sven

Definition at line 1231 of file rpl_gtid_set.cc.

Here is the call graph for this function:

bool Gtid_set::is_intersection_nonempty ( const Gtid_set other) const

Returns true if there is a least one element of this Gtid_set in the other Gtid_set.

Definition at line 1167 of file rpl_gtid_set.cc.

Here is the call graph for this function:

bool Gtid_set::is_valid ( const char *  text)
static

Returns true if the given string is a valid specification of a Gtid_set, false otherwise.

Definition at line 556 of file rpl_gtid_set.cc.

Here is the call graph for this function:

enum_return_status Gtid_set::remove_gtid_set ( const Gtid_set other)

Removes all groups in the given Gtid_set from this Gtid_set.

Parameters
otherThe Gtid_set to remove.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

Definition at line 692 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

char* Gtid_set::to_string ( ) const
inline

Return a newly allocated string containing this Gtid_set, or NULL on out of memory.

Definition at line 1065 of file rpl_gtid.h.

Here is the call graph for this function:

Here is the caller graph for this function:

int Gtid_set::to_string ( char *  buf,
const String_format string_format = NULL 
) const

Formats this Gtid_set as a string and saves in a given buffer.

Parameters
[out]bufPointer to the buffer where the string should be stored. This should have size at least get_string_length()+1.
string_formatString_format object that specifies separators in the resulting text.
Returns
Length of the generated string.

Definition at line 769 of file rpl_gtid_set.cc.

Here is the call graph for this function:

int Gtid_set::to_string ( char **  buf,
const String_format string_format = NULL 
) const

Formats a Gtid_set as a string and saves in a newly allocated buffer.

Parameters
[out]bufPointer to pointer to string. The function will set it to point to the newly allocated buffer, or NULL on out of memory.
string_formatSpecifies how to format the string.
Return values
Lengthof the generated string, or -1 on out of memory.

Definition at line 758 of file rpl_gtid_set.cc.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class Gtid_set::Free_intervals_lock
friend

Used by unit tests that need to access private members.

Only Free_intervals_lock is allowed to access free_intervals_mutex.

Definition at line 1674 of file rpl_gtid.h.

Member Data Documentation

const Gtid_set::String_format Gtid_set::commented_string_format
static
Initial value:
{
"# ", "", ":", "-", ":", ",\n# ", "# [empty]",
2, 0, 1, 1, 1, 4, 9
}

String_format for printing the Gtid_set commented: the string is not quote-wrapped, and every SID is on a new line with a leading '# '.

Definition at line 1168 of file rpl_gtid.h.

const Gtid_set::String_format Gtid_set::default_string_format
static
Initial value:
{
"", "", ":", "-", ":", ",\n", "",
0, 0, 1, 1, 1, 2, 0
}

The default String_format: the format understood by add_gtid_text(const char *).

Definition at line 1158 of file rpl_gtid.h.

const Gtid_set::String_format Gtid_set::sql_string_format
static
Initial value:
{
"'", "'", ":", "-", ":", "',\n'", "''",
1, 1, 1, 1, 1, 4, 2
}

String_format useful to generate an SQL string: the string is wrapped in single quotes and there is a newline between SIDs.

Definition at line 1163 of file rpl_gtid.h.


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