MySQL  8.0.17
Source Code Documentation
Sid_map Class Reference

Represents a bidirectional map between SID and SIDNO. More...

#include <rpl_gtid.h>

Classes

struct  Node
 Node pointed to by both the hash and the array. More...
 

Public Member Functions

 Sid_map (Checkable_rwlock *sid_lock)
 Create this Sid_map. More...
 
 ~Sid_map ()
 Destroy this Sid_map. More...
 
enum_return_status clear ()
 Clears this Sid_map (for RESET SLAVE) More...
 
rpl_sidno add_sid (const rpl_sid &sid)
 Add the given SID to this map if it does not already exist. More...
 
rpl_sidno sid_to_sidno (const rpl_sid &sid) const
 Get the SIDNO for a given SID. More...
 
const rpl_sidsidno_to_sid (rpl_sidno sidno, bool need_lock=false) const
 Get the SID for a given SIDNO. More...
 
rpl_sidno get_sorted_sidno (rpl_sidno n) const
 Return the n'th smallest sidno, in the order of the SID's UUID. More...
 
rpl_sidno get_max_sidno () const
 Return the biggest sidno in this Sid_map. More...
 
Checkable_rwlockget_sid_lock () const
 Return the sid_lock. More...
 
enum_return_status copy (Sid_map *dest)
 Deep copy this Sid_map to dest. More...
 

Private Member Functions

enum_return_status add_node (rpl_sidno sidno, const rpl_sid &sid)
 Create a Node from the given SIDNO and SID and add it to _sidno_to_sid, _sid_to_sidno, and _sorted. More...
 

Static Private Member Functions

static const ucharsid_map_get_key (const uchar *ptr, size_t *length)
 

Private Attributes

Checkable_rwlocksid_lock
 Read-write lock that protects updates to the number of SIDNOs. More...
 
Prealloced_array< Node *, 8 > _sidno_to_sid
 Array that maps SIDNO to SID; the element at index N points to a Node with SIDNO N-1. More...
 
malloc_unordered_map< rpl_sid, unique_ptr_my_free< Node >, binary_log::Hash_Uuid_sid_to_sidno {key_memory_Sid_map_Node}
 Hash that maps SID to SIDNO. More...
 
Prealloced_array< rpl_sidno, 8 > _sorted
 Array that maps numbers in the interval [0, get_max_sidno()-1] to SIDNOs, in order of increasing SID. More...
 

Detailed Description

Represents a bidirectional map between SID and SIDNO.

SIDNOs are always numbers greater or equal to 1.

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

◆ Sid_map()

Sid_map::Sid_map ( Checkable_rwlock sid_lock)

Create this Sid_map.

Parameters
sid_lockRead-write lock that protects updates to the number of SIDNOs.

◆ ~Sid_map()

Sid_map::~Sid_map ( )

Destroy this Sid_map.

Member Function Documentation

◆ add_node()

enum_return_status Sid_map::add_node ( rpl_sidno  sidno,
const rpl_sid sid 
)
private

Create a Node from the given SIDNO and SID and add it to _sidno_to_sid, _sid_to_sidno, and _sorted.

The caller must hold the write lock on sid_lock before invoking this function.

Parameters
sidnoThe SIDNO to add.
sidThe SID to add.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ add_sid()

rpl_sidno Sid_map::add_sid ( const rpl_sid sid)

Add the given SID to this map if it does not already exist.

The caller must hold the read lock or write lock on sid_lock before invoking this function. If the SID does not exist in this map, it will release the read lock, take a write lock, update the map, release the write lock, and take the read lock again.

Parameters
sidThe SID.
Return values
SIDNOThe SIDNO for the SID (a new SIDNO if the SID did not exist, an existing if it did exist).
negativeError. This function calls my_error.

◆ clear()

enum_return_status Sid_map::clear ( )

Clears this Sid_map (for RESET SLAVE)

Returns
RETURN_STATUS_OK or RETURN_STAUTS_REPORTED_ERROR

◆ copy()

enum_return_status Sid_map::copy ( Sid_map dest)

Deep copy this Sid_map to dest.

The caller must hold: the read lock on this sid_lock the write lock on the dest sid_lock before invoking this function.

Parameters
[out]destThe Sid_map to which the sids and sidnos will be copied.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ get_max_sidno()

rpl_sidno Sid_map::get_max_sidno ( ) const
inline

Return the biggest sidno in this Sid_map.

The caller must hold the read or write lock on sid_lock before invoking this function.

◆ get_sid_lock()

Checkable_rwlock* Sid_map::get_sid_lock ( ) const
inline

Return the sid_lock.

◆ get_sorted_sidno()

rpl_sidno Sid_map::get_sorted_sidno ( rpl_sidno  n) const
inline

Return the n'th smallest sidno, in the order of the SID's UUID.

The caller must hold the read or write lock on sid_lock before invoking this function.

Parameters
nA number in the interval [0, get_max_sidno()-1], inclusively.

◆ sid_map_get_key()

static const uchar* Sid_map::sid_map_get_key ( const uchar ptr,
size_t *  length 
)
inlinestaticprivate

◆ sid_to_sidno()

rpl_sidno Sid_map::sid_to_sidno ( const rpl_sid sid) const
inline

Get the SIDNO for a given SID.

The caller must hold the read lock on sid_lock before invoking this function.

Parameters
sidThe SID.
Return values
SIDNOif the given SID exists in this map.
0if the given SID does not exist in this map.

◆ sidno_to_sid()

const rpl_sid& Sid_map::sidno_to_sid ( rpl_sidno  sidno,
bool  need_lock = false 
) const
inline

Get the SID for a given SIDNO.

Raises an assertion if the SIDNO is not valid.

If need_lock is true, acquires sid_lock->rdlock; otherwise asserts that it is held already.

Parameters
sidnoThe SIDNO.
need_lockIf true, and sid_lock!=NULL, this function will acquire sid_lock before looking up the sid, and then release it. If false, and sid_lock!=NULL, this function will assert the sid_lock is already held. If sid_lock==NULL, nothing is done w.r.t. locking.
Return values
NULLThe SIDNO does not exist in this map.
pointerPointer to the SID. The data is shared with this Sid_map, so should not be modified. It is safe to read the data even after this Sid_map is modified, but not if this Sid_map is destroyed.

Member Data Documentation

◆ _sid_to_sidno

Hash that maps SID to SIDNO.

◆ _sidno_to_sid

Prealloced_array<Node *, 8> Sid_map::_sidno_to_sid
private

Array that maps SIDNO to SID; the element at index N points to a Node with SIDNO N-1.

◆ _sorted

Prealloced_array<rpl_sidno, 8> Sid_map::_sorted
private

Array that maps numbers in the interval [0, get_max_sidno()-1] to SIDNOs, in order of increasing SID.

See also
Sid_map::get_sorted_sidno.

◆ sid_lock

Checkable_rwlock* Sid_map::sid_lock
mutableprivate

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


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