MySQL 8.4.3
Source Code Documentation
Tsid_map Class Reference

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

#include <rpl_gtid.h>

Public Types

using Tsid = mysql::gtid::Tsid
 
using Tag = mysql::gtid::Tag
 
using Tsid_to_sidno_allocator = Map_allocator_type< Tsid, rpl_sidno >
 
using Tsid_to_sidno_umap = malloc_unordered_map< Tsid, rpl_sidno, Tsid::Hash >
 
using Tsid_to_sidno_map = Map_myalloc< Tsid, rpl_sidno >
 
using Tsid_to_sidno_it = Tsid_to_sidno_map::const_iterator
 
using Tsid_ref = std::reference_wrapper< const Tsid >
 
using Sidno_to_tsid_cont = std::vector< Tsid_ref, Malloc_allocator< Tsid_ref > >
 

Public Member Functions

 Tsid_map (Checkable_rwlock *tsid_lock)
 Create this Tsid_map. More...
 
 ~Tsid_map ()
 Destroy this Tsid_map. More...
 
enum_return_status clear ()
 Clears this Tsid_map (for RESET REPLICA) More...
 
rpl_sidno add_tsid (const Tsid &tsid)
 Add the given TSID to this map if it does not already exist. More...
 
rpl_sidno tsid_to_sidno (const Tsid &tsid) const
 Get the SIDNO for a given TSID. More...
 
const Tsidsidno_to_tsid (rpl_sidno sidno, bool need_lock=false) const
 Get the TSID for a given SIDNO. More...
 
const Tsid_to_sidno_mapget_sorted_sidno () const
 Returns TSID to SID map. More...
 
const rpl_sidnoget_sidno (const Tsid_to_sidno_it &it) const
 
const Tsidget_tsid (const Tsid_to_sidno_it &it) const
 
rpl_sidno get_max_sidno () const
 Return the biggest sidno in this Tsid_map. More...
 
Checkable_rwlockget_tsid_lock () const
 Return the tsid_lock. More...
 
enum_return_status copy (Tsid_map *dest)
 Deep copy this Tsid_map to dest. More...
 

Private Member Functions

enum_return_status add_node (rpl_sidno sidno, const Tsid &tsid)
 Create a Node from the given SIDNO and a TSID and add it to _sidno_to_tsid, _tsid_to_sidno, and _sorted. More...
 

Private Attributes

Checkable_rwlocktsid_lock
 Read-write lock that protects updates to the number of SIDNOs. More...
 
Sidno_to_tsid_cont _sidno_to_tsid
 Array that maps SIDNO to TSID; the element at index N points to a Node with SIDNO N-1. More...
 
Tsid_to_sidno_umap _tsid_to_sidno {key_memory_tsid_map_Node}
 Hash that maps TSID to SIDNO. More...
 
Tsid_to_sidno_map _sorted {Tsid_to_sidno_allocator{key_memory_tsid_map_Node}}
 Data structure that maps numbers in the interval [0, get_max_sidno()-1] to SIDNOs, in order of increasing TSID. More...
 

Detailed Description

Represents a bidirectional map between TSID 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.

Member Typedef Documentation

◆ Sidno_to_tsid_cont

◆ Tag

◆ Tsid

◆ Tsid_ref

using Tsid_map::Tsid_ref = std::reference_wrapper<const Tsid>

◆ Tsid_to_sidno_allocator

◆ Tsid_to_sidno_it

using Tsid_map::Tsid_to_sidno_it = Tsid_to_sidno_map::const_iterator

◆ Tsid_to_sidno_map

◆ Tsid_to_sidno_umap

Constructor & Destructor Documentation

◆ Tsid_map()

Tsid_map::Tsid_map ( Checkable_rwlock tsid_lock)

Create this Tsid_map.

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

◆ ~Tsid_map()

Tsid_map::~Tsid_map ( )

Destroy this Tsid_map.

Member Function Documentation

◆ add_node()

enum_return_status Tsid_map::add_node ( rpl_sidno  sidno,
const Tsid tsid 
)
private

Create a Node from the given SIDNO and a TSID and add it to _sidno_to_tsid, _tsid_to_sidno, and _sorted.

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

Parameters
sidnoThe SIDNO to add.
tsidThe TSID to add.
Returns
RETURN_STATUS_OK or RETURN_STATUS_REPORTED_ERROR.

◆ add_tsid()

rpl_sidno Tsid_map::add_tsid ( const Tsid tsid)

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

The caller must hold the read lock or write lock on tsid_lock before invoking this function. If the TSID 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
tsidThe TSID.
Return values
SIDNOThe SIDNO for the TSID (a new SIDNO if the TSID did not exist, an existing if it did exist).
negativeError. This function calls my_error.

◆ clear()

enum_return_status Tsid_map::clear ( )

Clears this Tsid_map (for RESET REPLICA)

Returns
RETURN_STATUS_OK or RETURN_STAUTS_REPORTED_ERROR

◆ copy()

enum_return_status Tsid_map::copy ( Tsid_map dest)

Deep copy this Tsid_map to dest.

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

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

◆ get_max_sidno()

rpl_sidno Tsid_map::get_max_sidno ( ) const
inline

Return the biggest sidno in this Tsid_map.

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

◆ get_sidno()

const rpl_sidno & Tsid_map::get_sidno ( const Tsid_to_sidno_it it) const
inline

◆ get_sorted_sidno()

const Tsid_to_sidno_map & Tsid_map::get_sorted_sidno ( ) const
inline

Returns TSID to SID map.

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

Returns
constant reference to sid_to_sidno container

◆ get_tsid()

const Tsid & Tsid_map::get_tsid ( const Tsid_to_sidno_it it) const
inline

◆ get_tsid_lock()

Checkable_rwlock * Tsid_map::get_tsid_lock ( ) const
inline

Return the tsid_lock.

◆ sidno_to_tsid()

const Tsid & Tsid_map::sidno_to_tsid ( rpl_sidno  sidno,
bool  need_lock = false 
) const
inline

Get the TSID for a given SIDNO.

Raises an assertion if the SIDNO is not valid.

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

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

◆ tsid_to_sidno()

rpl_sidno Tsid_map::tsid_to_sidno ( const Tsid tsid) const
inline

Get the SIDNO for a given TSID.

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

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

Member Data Documentation

◆ _sidno_to_tsid

Sidno_to_tsid_cont Tsid_map::_sidno_to_tsid
private
Initial value:
{
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:63
PSI_memory_key key_memory_tsid_map_Node
Definition: rpl_gtid_tsid_map.cc:44

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

◆ _sorted

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

See also
Tsid_map::get_sorted_sidno.

◆ _tsid_to_sidno

Tsid_to_sidno_umap Tsid_map::_tsid_to_sidno {key_memory_tsid_map_Node}
private

Hash that maps TSID to SIDNO.

◆ tsid_lock

Checkable_rwlock* Tsid_map::tsid_lock
mutableprivate

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


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