MySQL 8.4.0
Source Code Documentation
Gtid_set Class Reference

Represents a set of GTIDs. More...

#include <rpl_gtid.h>

Inheritance diagram for Gtid_set:
[legend]

Classes

class  Const_interval_iterator
 Iterator over intervals of a const Gtid_set. More...
 
class  Free_intervals_lock
 Class representing a lock on free_intervals_mutex. More...
 
class  Gtid_iterator
 Iterator over all gtids in a Gtid_set. More...
 
struct  Interval
 Represents one element in the linked list of intervals associated with a SIDNO. More...
 
struct  Interval_chunk
 Contains a list of intervals allocated by this Gtid_set. More...
 
class  Interval_iterator
 Iterator over intervals of a non-const Gtid_set, with additional methods to modify the Gtid_set. More...
 
class  Interval_iterator_base
 Iterator over intervals for a given SIDNO. More...
 
struct  String_format
 Class Gtid_set::String_format defines the separators used by Gtid_set::to_string. More...
 

Public Member Functions

 Gtid_set (Tsid_map *tsid_map, Checkable_rwlock *tsid_lock=nullptr)
 Constructs a new, empty Gtid_set. More...
 
 Gtid_set (Tsid_map *tsid_map, const char *text, enum_return_status *status, Checkable_rwlock *tsid_lock=nullptr)
 Constructs a new Gtid_set that contains the gtids in the given string, in the same format as add_gtid_text(char *). More...
 
 ~Gtid_set ()
 Destroy this Gtid_set. More...
 
void clear ()
 Removes all gtids from this Gtid_set. More...
 
void clear_set_and_tsid_map ()
 Removes all gtids from this Gtid_set and clear all the sidnos used by the Gtid_set and it's TSID map. More...
 
void _add_gtid (rpl_sidno sidno, rpl_gno gno)
 Adds the given GTID to this Gtid_set. More...
 
void _remove_gtid (rpl_sidno sidno, rpl_gno gno)
 Removes the given GTID from this Gtid_set. More...
 
void _add_gtid (const Gtid &gtid)
 Adds the given GTID to this Gtid_set. More...
 
void _remove_gtid (const Gtid &gtid)
 Removes the given GTID from this Gtid_set. More...
 
enum_return_status add_gtid_set (const Gtid_set *other)
 Adds all gtids from the given Gtid_set to this Gtid_set. More...
 
void remove_gtid_set (const Gtid_set *other)
 Removes all gtids in the given Gtid_set from this Gtid_set. More...
 
void remove_intervals_for_sidno (Gtid_set *other, rpl_sidno sidno)
 Removes all intervals of 'other' for a given SIDNO, from 'this'. More...
 
enum_return_status add_gtid_text (const char *text, bool *anonymous=nullptr, bool *starts_with_plus=nullptr)
 Adds the set of GTIDs represented by the given string to this Gtid_set. More...
 
enum_return_status add_gtid (const mysql::gtid::Gtid &gtid)
 Adds specified GTID (TSID+GNO) to this Gtid_set. More...
 
enum_return_status add_gtid_encoding (const uchar *encoded, size_t length, size_t *actual_length=nullptr)
 Decodes a Gtid_set from the given string. More...
 
bool contains_gtid (rpl_sidno sidno, rpl_gno gno) const
 Return true iff the given GTID exists in this set. More...
 
bool contains_gtid (const Gtid &gtid) const
 Return true iff the given GTID exists in this set. More...
 
rpl_gno get_last_gno (rpl_sidno sidno) const
 
rpl_sidno get_max_sidno () const
 Returns the maximal sidno that this Gtid_set currently has space for. More...
 
enum_return_status ensure_sidno (rpl_sidno sidno)
 Allocates space for all sidnos up to the given sidno in the array of intervals. More...
 
bool is_subset (const Gtid_set *super) const
 Returns true if this Gtid_set is a subset of the other Gtid_set. More...
 
bool is_subset_not_equals (const Gtid_set *super) const
 Returns true if this Gtid_set is a non equal subset of the other Gtid_set. More...
 
bool is_subset_for_sidno (const Gtid_set *super, rpl_sidno superset_sidno, rpl_sidno subset_sidno) const
 Returns true if this Gtid_set is a subset of the given gtid_set on the given superset_sidno and subset_sidno. More...
 
bool is_subset_for_sid (const Gtid_set *super, const rpl_sid &sid) const
 Returns true if this Gtid_set is a subset of the given gtid_set with respect to the given sid. More...
 
bool 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. More...
 
enum_return_status intersection (const Gtid_set *other, Gtid_set *result)
 Add the intersection of this Gtid_set and the other Gtid_set to result. More...
 
bool is_empty () const
 Returns true if this Gtid_set is empty. More...
 
bool is_size_greater_than_or_equal (ulonglong num) const
 Return true if the size of the set is greater than or equal to the given number. More...
 
ulonglong get_gtid_count (rpl_sidno sidno) const
 What is the count of all the GTIDs in all intervals for a sidno. More...
 
bool contains_sidno (rpl_sidno sidno) const
 Returns true if this Gtid_set contains at least one GTID with the given SIDNO. More...
 
bool contains_tags () const
 Checks if this Gtid set contains any tagged GTIDs. More...
 
size_t get_string_length (const String_format *string_format=nullptr) const
 Returns the length of the output from to_string. More...
 
size_t to_string (char *buf, bool need_lock=false, const String_format *string_format=nullptr) const
 Formats this Gtid_set as a string and saves in a given buffer. More...
 
long to_string (char **buf, bool need_lock=false, const String_format *string_format=nullptr) const
 Formats a Gtid_set as a string and saves in a newly allocated buffer. More...
 
void print (bool need_lock=false, const Gtid_set::String_format *sf=nullptr) const
 Debug only: Print this Gtid_set to stdout. More...
 
void dbug_print (const char *text="", bool need_lock=false, const Gtid_set::String_format *sf=nullptr) const
 Print this Gtid_set to the trace file if debug is enabled; no-op otherwise. More...
 
void get_gtid_intervals (std::list< Gtid_interval > *gtid_intervals) const
 Gets all gtid intervals from this Gtid_set. More...
 
Tsid_mapget_tsid_map () const
 Return the Tsid_map associated with this Gtid_set. More...
 
void add_interval_memory (int n_intervals, Interval *intervals_param)
 Provides an array of Intervals that this Gtid_set can use when gtids are subsequently added. More...
 
void encode (uchar *buf, bool skip_tagged_gtids=false) const
 Encodes this Gtid_set as a binary string. More...
 
size_t get_encoded_length (bool skip_tagged_gtids=false) const
 Returns the length of this Gtid_set when encoded using the encode() function. More...
 
std::size_t get_encoded_length (const mysql::gtid::Gtid_format &format, bool skip_tagged_gtids) const
 Returns the length of this Gtid_set when encoded using the encode() function. More...
 
bool equals (const Gtid_set *other) const
 Returns true if this Gtid_set is equal to the other Gtid_set. More...
 

Static Public Member Functions

static bool is_valid (const char *text)
 Returns true if the given string is a valid specification of a Gtid_set, false otherwise. More...
 

Static Public Attributes

static PSI_mutex_key key_gtid_executed_free_intervals_mutex
 
static const String_format default_string_format
 The default String_format: the format understood by add_gtid_text(const char *). More...
 
static const String_format sql_string_format
 String_format useful to generate an SQL string: the string is wrapped in single quotes and there is a newline between SIDs. More...
 
static const String_format commented_string_format
 String_format for printing the Gtid_set commented: the string is not quote-wrapped, and every TSID is on a new line with a leading '# '. More...
 

Private Member Functions

void init ()
 Worker for the constructor. More...
 
bool sidno_equals (rpl_sidno sidno, const Gtid_set *other, rpl_sidno other_sidno) const
 Return true if the given sidno of this Gtid_set contains the same intervals as the given sidno of the other Gtid_set. More...
 
int get_n_intervals (rpl_sidno sidno) const
 Return the number of intervals for the given sidno. More...
 
int get_n_intervals () const
 Return the number of intervals in this Gtid_set. More...
 
mysql::gtid::Gtid_format analyze_encoding_format (bool skip_tagged_gtids) const
 Goes through recorded tsids. More...
 
void create_new_chunk (int size)
 Allocates a new chunk of Intervals and adds them to the list of unused intervals. More...
 
void get_free_interval (Interval **out)
 Returns a fresh new Interval object. More...
 
void put_free_interval (Interval *iv)
 Puts the given interval in the list of free intervals. More...
 
void add_interval_memory_lock_taken (int n_ivs, Interval *ivs)
 Like add_interval_memory, but does not acquire free_intervals_mutex. More...
 
void assert_free_intervals_locked ()
 
void add_gno_interval (Interval_iterator *ivitp, rpl_gno start, rpl_gno end, Free_intervals_lock *lock)
 Adds the interval (start, end) to the given Interval_iterator. More...
 
void remove_gno_interval (Interval_iterator *ivitp, rpl_gno start, rpl_gno end, Free_intervals_lock *lock)
 Removes the interval (start, end) from the given Interval_iterator. More...
 
void add_gno_intervals (rpl_sidno sidno, Const_interval_iterator ivit, Free_intervals_lock *lock)
 Adds a list of intervals to the given SIDNO. More...
 
void remove_gno_intervals (rpl_sidno sidno, Const_interval_iterator ivit, Free_intervals_lock *lock)
 Removes a list of intervals from the given SIDNO. More...
 

Static Private Member Functions

static bool is_interval_subset (Const_interval_iterator *sub, Const_interval_iterator *super)
 Returns true if every interval of sub is a subset of some interval of super. More...
 
static bool is_interval_intersection_nonempty (Const_interval_iterator *ivit1, Const_interval_iterator *ivit2)
 Returns true if at least one sidno in ivit1 is also in ivit2. More...
 

Private Attributes

Checkable_rwlocktsid_lock
 Read-write lock that protects updates to the number of TSIDs. More...
 
mysql_mutex_t free_intervals_mutex
 Lock protecting the list of free intervals. More...
 
Tsid_maptsid_map
 Tsid_map associated with this Gtid_set. More...
 
Prealloced_array< Interval *, 8 > m_intervals
 Array where the N'th element contains the head pointer to the intervals of SIDNO N+1. More...
 
Intervalfree_intervals
 Linked list of free intervals. More...
 
Interval_chunkchunks
 Linked list of chunks. More...
 
bool has_cached_string_length
 If the string is cached. More...
 
size_t cached_string_length
 The string length. More...
 
const String_formatcached_string_format
 The String_format that was used when cached_string_length was computed. More...
 
int n_chunks
 The number of chunks. More...
 

Static Private Attributes

static const int CHUNK_GROW_SIZE = 8
 The default number of intervals in an Interval_chunk. More...
 

Friends

class Gtid_set::Free_intervals_lock
 Used by unit tests that need to access private members. More...
 
std::ostream & operator<< (std::ostream &os, const Gtid_set &in)
 For use with C++ std::ostream More...
 

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 Tsid_map that gives a correspondence between SIDNO and TSID. If the Tsid_map is NULL, then operations that require a Tsid_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.

Constructor & Destructor Documentation

◆ Gtid_set() [1/2]

Gtid_set::Gtid_set ( Tsid_map tsid_map,
Checkable_rwlock tsid_lock = nullptr 
)

Constructs a new, empty Gtid_set.

Parameters
tsid_mapThe Tsid_map to use, or NULL if this Gtid_set should not have a Tsid_map.
tsid_lockRead-write lock that protects updates to the number of TSIDs. This may be NULL if such changes do not need to be protected.

◆ Gtid_set() [2/2]

Gtid_set::Gtid_set ( Tsid_map tsid_map,
const char *  text,
enum_return_status status,
Checkable_rwlock tsid_lock = nullptr 
)

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

Parameters
tsid_mapThe Tsid_map to use for TSIDs.
textThe text to parse.
statusWill be set to RETURN_STATUS_OK on success or RETURN_STATUS_REPORTED_ERROR on error.
tsid_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 tsid_lock != NULL, then the read lock on tsid_lock must be held before calling this function. If the array is grown, tsid_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.

◆ ~Gtid_set()

Gtid_set::~Gtid_set ( )

Destroy this Gtid_set.

Member Function Documentation

◆ _add_gtid() [1/2]

void 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.

◆ _add_gtid() [2/2]

void 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 GTID to add.
gnoGNO of the GTID to add.

◆ _remove_gtid() [1/2]

void Gtid_set::_remove_gtid ( const Gtid gtid)
inline

Removes the given GTID from this Gtid_set.

Parameters
gtidGtid to remove.

◆ _remove_gtid() [2/2]

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

Removes the given GTID from this Gtid_set.

Parameters
sidnoSIDNO of the GTID to remove.
gnoGNO of the GTID to remove.

◆ add_gno_interval()

void Gtid_set::add_gno_interval ( Interval_iterator ivitp,
rpl_gno  start,
rpl_gno  end,
Free_intervals_lock lock 
)
private

Adds the interval (start, end) to the given Interval_iterator.

This is the lowest-level function that adds gtids; this is where Interval objects are added, grown, or merged.

Parameters
ivitpPointer to iterator. After this function returns, the current_element of the iterator will be the interval that contains start and end.
startThe first GNO in the interval.
endThe first GNO after the interval.
lockIf this function has to add or remove an interval, then this lock will be taken unless it is already taken. This mechanism means that the lock will be taken lazily by e.g. add_gtid_set() the first time that the list of free intervals is accessed, and automatically released when add_gtid_set() returns.

◆ add_gno_intervals()

void Gtid_set::add_gno_intervals ( rpl_sidno  sidno,
Const_interval_iterator  ivit,
Free_intervals_lock lock 
)
private

Adds a list of intervals to the given SIDNO.

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

Parameters
sidnoThe SIDNO to which intervals will be added.
ivitIterator over the intervals to add. This is typically an iterator over some other Gtid_set.
lockIf this function has to add or remove an interval, then this lock will be taken unless it is already taken. This mechanism means that the lock will be taken lazily by e.g. add_gtid_set() the first time that the list of free intervals is accessed, and automatically released when add_gtid_set() returns.

◆ add_gtid()

enum_return_status Gtid_set::add_gtid ( const mysql::gtid::Gtid gtid)

Adds specified GTID (TSID+GNO) to this Gtid_set.

Parameters
gtidmysql::gtid::Gtid object
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ add_gtid_encoding()

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

Decodes a Gtid_set from the given string.

Parameters
encodedThe 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
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ add_gtid_set()

enum_return_status Gtid_set::add_gtid_set ( const Gtid_set other)

Adds all gtids from the given Gtid_set to this Gtid_set.

If tsid_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, tsid_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.

◆ add_gtid_text()

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

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 items:

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.

The string can start with an optional '+' appender qualifier which triggers executed_gtids and lost_gtids set examination on the matter of disjointness with the one being added.

If tsid_lock != NULL, then the read lock on tsid_lock must be held before calling this function. If a new sidno is added so that the array of lists of intervals is grown, tsid_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.
[in,out]anonymousIf this is NULL, ANONYMOUS is not allowed. If this is not NULL, it will be set to true if the anonymous GTID was found; false otherwise.
[in,out]starts_with_plusIf this is not NULL, the string may optionally begin with a '+' character, and *starts_with_plus will be set to true if the plus character is present. If this is NULL, no plus is allowed at the begin of the string.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ add_interval_memory()

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 gtids 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.
intervals_paramArray of n_intervals intervals.

◆ add_interval_memory_lock_taken()

void Gtid_set::add_interval_memory_lock_taken ( int  n_ivs,
Interval ivs 
)
private

Like add_interval_memory, but does not acquire free_intervals_mutex.

See also
Gtid_set::add_interval_memory

◆ analyze_encoding_format()

mysql::gtid::Gtid_format Gtid_set::analyze_encoding_format ( bool  skip_tagged_gtids) const
private

Goes through recorded tsids.

In case any of the TSIDs has a tag, this function will return Gtid_format::tagged. Otherwise, it will return Gtid_format::untagged

Parameters
skip_tagged_gtidsWhen true, function will always return Gtid_format::untagged
Returns
Gtid encoding format

◆ assert_free_intervals_locked()

void Gtid_set::assert_free_intervals_locked ( )
inlineprivate

◆ clear()

void Gtid_set::clear ( )

Removes all gtids from this Gtid_set.

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

◆ clear_set_and_tsid_map()

void Gtid_set::clear_set_and_tsid_map ( )

Removes all gtids from this Gtid_set and clear all the sidnos used by the Gtid_set and it's TSID map.

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

◆ contains_gtid() [1/2]

bool Gtid_set::contains_gtid ( const Gtid gtid) const
inline

Return true iff the given GTID exists in this set.

◆ contains_gtid() [2/2]

bool Gtid_set::contains_gtid ( rpl_sidno  sidno,
rpl_gno  gno 
) const

Return true iff the given GTID exists in this set.

◆ contains_sidno()

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 GTID with this SIDNO.
falseThe SIDNO is greater than the max SIDNO, or there is no GTID with this SIDNO.

◆ contains_tags()

bool Gtid_set::contains_tags ( ) const

Checks if this Gtid set contains any tagged GTIDs.

Return values
trueThis gtid set contains tagged GTIDs
falseThis gtid set contains only untagged GTIDs

◆ create_new_chunk()

void Gtid_set::create_new_chunk ( int  size)
private

Allocates a new chunk of Intervals and adds them to the list of unused intervals.

Parameters
sizeThe number of intervals in this chunk

◆ dbug_print()

void Gtid_set::dbug_print ( const char *  text = "",
bool  need_lock = false,
const Gtid_set::String_format sf = nullptr 
) const
inline

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

◆ encode()

void Gtid_set::encode ( uchar buf,
bool  skip_tagged_gtids = false 
) const

Encodes this Gtid_set as a binary string.

Parameters
bufBuffer to write into
skip_tagged_gtidsWhen true, tagged GTIDS will be filtered out

◆ ensure_sidno()

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 Tsid_map associated with this Gtid_set.

If tsid_lock != NULL, then the read lock on tsid_lock must be held before calling this function. If the array is grown, tsid_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.

◆ equals()

bool Gtid_set::equals ( const Gtid_set other) const

Returns true if this Gtid_set is equal to the other Gtid_set.

Parameters
[in]otherGtid set to compare against
Returns
true in case gtid sets contain the same GTIDs

◆ get_encoded_length() [1/2]

size_t Gtid_set::get_encoded_length ( bool  skip_tagged_gtids = false) const

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

Before calculation, analyzes GTID set format

Parameters
skip_tagged_gtidsWhen true, tagged GTIDS will be filtered out
Returns
length of Gtid_set encoding

◆ get_encoded_length() [2/2]

size_t Gtid_set::get_encoded_length ( const mysql::gtid::Gtid_format format,
bool  skip_tagged_gtids 
) const

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

Uses already analyzed GTID set format (faster version)

Parameters
formatGtid format
skip_tagged_gtidsWhen true, tagged GTIDS will be filtered out
Returns
Encoded gtid_set length

◆ get_free_interval()

void Gtid_set::get_free_interval ( Interval **  out)
private

Returns a fresh new Interval object.

This usually does not require any real allocation, it only pops the first interval from the list of free intervals. If there are no free intervals, it calls create_new_chunk.

Parameters
outThe resulting Interval* will be stored here.

◆ get_gtid_count()

ulonglong Gtid_set::get_gtid_count ( rpl_sidno  sidno) const
inline

What is the count of all the GTIDs in all intervals for a sidno.

Parameters
sidnoThe sidno that contains the intervals
Returns
the number of all GTIDs in all intervals

◆ get_gtid_intervals()

void Gtid_set::get_gtid_intervals ( std::list< Gtid_interval > *  gtid_intervals) const

Gets all gtid intervals from this Gtid_set.

Parameters
[out]gtid_intervalsStore all gtid intervals from this Gtid_set.

◆ get_last_gno()

rpl_gno Gtid_set::get_last_gno ( rpl_sidno  sidno) const

◆ get_max_sidno()

rpl_sidno Gtid_set::get_max_sidno ( ) const
inline

Returns the maximal sidno that this Gtid_set currently has space for.

◆ get_n_intervals() [1/2]

int Gtid_set::get_n_intervals ( ) const
inlineprivate

Return the number of intervals in this Gtid_set.

◆ get_n_intervals() [2/2]

int Gtid_set::get_n_intervals ( rpl_sidno  sidno) const
inlineprivate

Return the number of intervals for the given sidno.

◆ get_string_length()

size_t Gtid_set::get_string_length ( const String_format string_format = nullptr) 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.

◆ get_tsid_map()

Tsid_map * Gtid_set::get_tsid_map ( ) const
inline

Return the Tsid_map associated with this Gtid_set.

◆ init()

void Gtid_set::init ( )
private

Worker for the constructor.

◆ intersection()

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.

◆ is_empty()

bool Gtid_set::is_empty ( ) const
inline

Returns true if this Gtid_set is empty.

◆ is_intersection_nonempty()

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.

◆ is_interval_intersection_nonempty()

bool Gtid_set::is_interval_intersection_nonempty ( Const_interval_iterator ivit1,
Const_interval_iterator ivit2 
)
staticprivate

Returns true if at least one sidno in ivit1 is also in ivit2.

◆ is_interval_subset()

bool Gtid_set::is_interval_subset ( Const_interval_iterator sub,
Const_interval_iterator super 
)
staticprivate

Returns true if every interval of sub is a subset of some interval of super.

◆ is_size_greater_than_or_equal()

bool Gtid_set::is_size_greater_than_or_equal ( ulonglong  num) const

Return true if the size of the set is greater than or equal to the given number.

The size is measure in number of GTIDs, i.e., total length of all intervals.

Parameters
numNumber to compare with
Return values
trueif the set contains >= num GTIDs.
falseif the set contains < num GTIDs.

◆ is_subset()

bool Gtid_set::is_subset ( const Gtid_set super) const

Returns true if this Gtid_set is a subset of the other Gtid_set.

◆ is_subset_for_sid()

bool Gtid_set::is_subset_for_sid ( const Gtid_set super,
const rpl_sid sid 
) const

Returns true if this Gtid_set is a subset of the given gtid_set with respect to the given sid.

This function will traverse all TSIDs with SID equal to "sid" parameter (all registered tags for a given SID)

Parameters
superGtid_set with which this->gtid_set needs to be compared
sidSid for which we will do the testing
Returns
True in case super is a superset for this gtid set w.r.t. the given sid; false otherwise

◆ is_subset_for_sidno()

bool Gtid_set::is_subset_for_sidno ( const Gtid_set super,
rpl_sidno  superset_sidno,
rpl_sidno  subset_sidno 
) const

Returns true if this Gtid_set is a subset of the given gtid_set on the given superset_sidno and subset_sidno.

Parameters
superGtid_set with which this->gtid_set needs to be compared
superset_sidnoThe sidno that will be compared, relative to super->tsid_map.
subset_sidnoThe sidno that will be compared, relative to this->tsid_map.
Returns
true If 'this' Gtid_set is subset of given 'super' Gtid_set. false If 'this' Gtid_set is not subset of given 'super' Gtid_set.

◆ is_subset_not_equals()

bool Gtid_set::is_subset_not_equals ( const Gtid_set super) const
inline

Returns true if this Gtid_set is a non equal subset of the other Gtid_set.

◆ is_valid()

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.

◆ print()

void Gtid_set::print ( bool  need_lock = false,
const Gtid_set::String_format sf = nullptr 
) const
inline

Debug only: Print this Gtid_set to stdout.

For use with C printf

◆ put_free_interval()

void Gtid_set::put_free_interval ( Interval iv)
private

Puts the given interval in the list of free intervals.

Does not unlink it from its place in any other list.

◆ remove_gno_interval()

void Gtid_set::remove_gno_interval ( Interval_iterator ivitp,
rpl_gno  start,
rpl_gno  end,
Free_intervals_lock lock 
)
private

Removes the interval (start, end) from the given Interval_iterator.

This is the lowest-level function that removes gtids; this is where Interval objects are removed, truncated, or split.

It is not required that the gtids in the interval exist in this Gtid_set.

Parameters
ivitpPointer to iterator. After this function returns, the current_element of the iterator will be the next interval after end.
startThe first GNO in the interval.
endThe first GNO after the interval.
lockIf this function has to add or remove an interval, then this lock will be taken unless it is already taken. This mechanism means that the lock will be taken lazily by e.g. add_gtid_set() the first time that the list of free intervals is accessed, and automatically released when add_gtid_set() returns.

◆ remove_gno_intervals()

void Gtid_set::remove_gno_intervals ( rpl_sidno  sidno,
Const_interval_iterator  ivit,
Free_intervals_lock lock 
)
private

Removes a list of intervals from the given SIDNO.

It is not required that the intervals exist in this Gtid_set.

Parameters
sidnoThe SIDNO from which intervals will be removed.
ivitIterator over the intervals to remove. This is typically an iterator over some other Gtid_set.
lockIf this function has to add or remove an interval, then this lock will be taken unless it is already taken. This mechanism means that the lock will be taken lazily by e.g. add_gtid_set() the first time that the list of free intervals is accessed, and automatically released when add_gtid_set() returns.

◆ remove_gtid_set()

void Gtid_set::remove_gtid_set ( const Gtid_set other)

Removes all gtids in the given Gtid_set from this Gtid_set.

Parameters
otherThe Gtid_set to remove.

◆ remove_intervals_for_sidno()

void Gtid_set::remove_intervals_for_sidno ( Gtid_set other,
rpl_sidno  sidno 
)

Removes all intervals of 'other' for a given SIDNO, from 'this'.

Example: this = A:1-100, B:1-100 other = A:1-100, B:1-50, C:1-100 this.remove_intervals_for_sidno(other, B) = A:1-100, B:51-100

It is not required that the intervals exist in this Gtid_set.

Parameters
otherThe set to remove.
sidnoThe sidno to remove.

◆ sidno_equals()

bool Gtid_set::sidno_equals ( rpl_sidno  sidno,
const Gtid_set other,
rpl_sidno  other_sidno 
) const
private

Return true if the given sidno of this Gtid_set contains the same intervals as the given sidno of the other Gtid_set.

Parameters
sidnoSIDNO to check for this Gtid_set.
otherOther Gtid_set
other_sidnoSIDNO to check in other.
Returns
true if equal, false is not equal.

◆ to_string() [1/2]

long Gtid_set::to_string ( char **  buf,
bool  need_lock = false,
const String_format string_format = nullptr 
) 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.
need_lockIf this Gtid_set has a tsid_lock, then the write lock must be held while generating the string. If this parameter is true, then this function acquires and releases the lock; otherwise it asserts that the caller holds the lock.
string_formatSpecifies how to format the string.
Return values
Lengthof the generated string, or -1 on out of memory.

◆ to_string() [2/2]

size_t Gtid_set::to_string ( char *  buf,
bool  need_lock = false,
const String_format string_format = nullptr 
) 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.
need_lockIf this Gtid_set has a tsid_lock, then the write lock must be held while generating the string. If this parameter is true, then this function acquires and releases the lock; otherwise it asserts that the caller holds the lock.
string_formatString_format object that specifies separators in the resulting text.
Returns
Length of the generated string.

Friends And Related Function Documentation

◆ Gtid_set::Free_intervals_lock

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.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Gtid_set in 
)
friend

For use with C++ std::ostream

Member Data Documentation

◆ cached_string_format

const String_format* Gtid_set::cached_string_format
mutableprivate

The String_format that was used when cached_string_length was computed.

◆ cached_string_length

size_t Gtid_set::cached_string_length
mutableprivate

The string length.

◆ CHUNK_GROW_SIZE

const int Gtid_set::CHUNK_GROW_SIZE = 8
staticprivate

The default number of intervals in an Interval_chunk.

◆ chunks

Interval_chunk* Gtid_set::chunks
private

Linked list of chunks.

◆ commented_string_format

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

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

◆ default_string_format

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

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

◆ free_intervals

Interval* Gtid_set::free_intervals
private

Linked list of free intervals.

◆ free_intervals_mutex

mysql_mutex_t Gtid_set::free_intervals_mutex
private

Lock protecting the list of free intervals.

This lock is only used if tsid_lock is not NULL.

◆ has_cached_string_length

bool Gtid_set::has_cached_string_length
mutableprivate

If the string is cached.

◆ key_gtid_executed_free_intervals_mutex

PSI_mutex_key Gtid_set::key_gtid_executed_free_intervals_mutex
static

◆ m_intervals

Prealloced_array<Interval *, 8> Gtid_set::m_intervals
private

Array where the N'th element contains the head pointer to the intervals of SIDNO N+1.

◆ n_chunks

int Gtid_set::n_chunks
private

The number of chunks.

Used only to check some invariants when DBUG is on.

◆ sql_string_format

const Gtid_set::String_format Gtid_set::sql_string_format
static
Initial value:
= {
"'", "'", ":", ":", "-", ":", "',\n'", "''", 1, 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.

◆ tsid_lock

Checkable_rwlock* Gtid_set::tsid_lock
mutableprivate

Read-write lock that protects updates to the number of TSIDs.

◆ tsid_map

Tsid_map* Gtid_set::tsid_map
private

Tsid_map associated with this Gtid_set.


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