MySQL 8.3.0
Source Code Documentation
Owned_gtids Class Reference

Represents the set of GTIDs that are owned by some thread. More...

#include <rpl_gtid.h>

Classes

class  Gtid_iterator
 Iterator over all gtids in a Owned_gtids set. More...
 
struct  Node
 Represents one owned GTID. More...
 

Public Member Functions

 Owned_gtids (Checkable_rwlock *tsid_lock)
 Constructs a new, empty Owned_gtids object. More...
 
 ~Owned_gtids ()
 Destroys this Owned_gtids. More...
 
enum_return_status add_gtid_owner (const Gtid &gtid, my_thread_id owner)
 Add a GTID to this Owned_gtids. More...
 
void get_gtids (Gtid_set &gtid_set) const
 
void remove_gtid (const Gtid &gtid, const my_thread_id owner)
 Removes the given GTID. More...
 
enum_return_status ensure_sidno (rpl_sidno sidno)
 Ensures that this Owned_gtids object can accommodate SIDNOs up to the given SIDNO. More...
 
bool is_intersection_nonempty (const Gtid_set *other) const
 Returns true if there is a least one element of this Owned_gtids set in the other Gtid_set. More...
 
bool is_empty () const
 Returns true if this Owned_gtids is empty. More...
 
rpl_sidno get_max_sidno () const
 Returns the maximal sidno that this Owned_gtids currently has space for. More...
 
int to_string (char *out) const
 Write a string representation of this Owned_gtids to the given buffer. More...
 
size_t get_max_string_length () const
 Return an upper bound on the length of the string representation of this Owned_gtids. More...
 
bool thread_owns_anything (my_thread_id thd_id) const
 Return true if the given thread is the owner of any gtids. More...
 
char * to_string () const
 Debug only: return a newly allocated string representation of this Owned_gtids. More...
 
void print () const
 Debug only: print this Owned_gtids to stdout. More...
 
void dbug_print (const char *text="") const
 Print this Owned_gtids to the trace file if debug is enabled; no-op otherwise. More...
 
bool is_owned_by (const Gtid &gtid, const my_thread_id thd_id) const
 If thd_id==0, returns true when gtid is not owned by any thread. More...
 

Private Member Functions

malloc_unordered_multimap< rpl_gno, unique_ptr_my_free< Node > > * get_hash (rpl_sidno sidno) const
 Returns the hash for the given SIDNO. More...
 
bool contains_gtid (const Gtid &gtid) const
 Return true iff this Owned_gtids object contains the given gtid. More...
 

Private Attributes

Checkable_rwlocktsid_lock
 Read-write lock that protects updates to the number of TSIDs. More...
 
Prealloced_array< malloc_unordered_multimap< rpl_gno, unique_ptr_my_free< Node > > *, 8 > sidno_to_hash
 Growable array of hashes. More...
 

Detailed Description

Represents the set of GTIDs that are owned by some thread.

This data structure has 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. Access methods assert that the caller already holds the read (or write) lock. If 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.

The internal representation is a multi-valued map from GTIDs to threads, mapping GTIDs to one or more threads that owns it.

In Group Replication multiple threads can own a GTID whereas if GR is disabeld there is at most one owner per GTID.

Constructor & Destructor Documentation

◆ Owned_gtids()

Owned_gtids::Owned_gtids ( Checkable_rwlock tsid_lock)

Constructs a new, empty Owned_gtids object.

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

◆ ~Owned_gtids()

Owned_gtids::~Owned_gtids ( )

Destroys this Owned_gtids.

Member Function Documentation

◆ add_gtid_owner()

enum_return_status Owned_gtids::add_gtid_owner ( const Gtid gtid,
my_thread_id  owner 
)

Add a GTID to this Owned_gtids.

Parameters
gtidThe Gtid to add.
ownerThe my_thread_id of the gtid to add.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ contains_gtid()

bool Owned_gtids::contains_gtid ( const Gtid gtid) const
private

Return true iff this Owned_gtids object contains the given gtid.

◆ dbug_print()

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

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

◆ ensure_sidno()

enum_return_status Owned_gtids::ensure_sidno ( rpl_sidno  sidno)

Ensures that this Owned_gtids object can accommodate SIDNOs up to the given SIDNO.

If this Owned_gtids 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.

Parameters
sidnoThe SIDNO.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ get_gtids()

void Owned_gtids::get_gtids ( Gtid_set gtid_set) const

◆ get_hash()

malloc_unordered_multimap< rpl_gno, unique_ptr_my_free< Node > > * Owned_gtids::get_hash ( rpl_sidno  sidno) const
inlineprivate

Returns the hash for the given SIDNO.

◆ get_max_sidno()

rpl_sidno Owned_gtids::get_max_sidno ( ) const
inline

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

◆ get_max_string_length()

size_t Owned_gtids::get_max_string_length ( ) const
inline

Return an upper bound on the length of the string representation of this Owned_gtids.

The actual length may be smaller. This includes the trailing '\0'.

◆ is_empty()

bool Owned_gtids::is_empty ( ) const
inline

Returns true if this Owned_gtids is empty.

◆ is_intersection_nonempty()

bool Owned_gtids::is_intersection_nonempty ( const Gtid_set other) const

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

◆ is_owned_by()

bool Owned_gtids::is_owned_by ( const Gtid gtid,
const my_thread_id  thd_id 
) const

If thd_id==0, returns true when gtid is not owned by any thread.

If thd_id!=0, returns true when gtid is owned by that thread.

◆ print()

void Owned_gtids::print ( ) const
inline

Debug only: print this Owned_gtids to stdout.

◆ remove_gtid()

void Owned_gtids::remove_gtid ( const Gtid gtid,
const my_thread_id  owner 
)

Removes the given GTID.

If the gtid does not exist in this Owned_gtids object, does nothing.

Parameters
gtidThe Gtid.
ownerthread_id of the owner thread

◆ thread_owns_anything()

bool Owned_gtids::thread_owns_anything ( my_thread_id  thd_id) const
inline

Return true if the given thread is the owner of any gtids.

◆ to_string() [1/2]

char * Owned_gtids::to_string ( ) const
inline

Debug only: return a newly allocated string representation of this Owned_gtids.

◆ to_string() [2/2]

int Owned_gtids::to_string ( char *  out) const
inline

Write a string representation of this Owned_gtids to the given buffer.

Parameters
outBuffer to write to.
Returns
Number of characters written.

Member Data Documentation

◆ sidno_to_hash

Prealloced_array< malloc_unordered_multimap<rpl_gno, unique_ptr_my_free<Node> > *, 8> Owned_gtids::sidno_to_hash
private

Growable array of hashes.

◆ tsid_lock

Checkable_rwlock* Owned_gtids::tsid_lock
mutableprivate

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


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