MySQL 8.0.39
Source Code Documentation
|
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_sid & | sidno_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_rwlock * | get_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 uchar * | sid_map_get_key (const uchar *ptr, size_t *length) |
Private Attributes | |
Checkable_rwlock * | sid_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... | |
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.
Sid_map::Sid_map | ( | Checkable_rwlock * | sid_lock | ) |
Create this Sid_map.
sid_lock | Read-write lock that protects updates to the number of SIDNOs. |
Sid_map::~Sid_map | ( | ) |
Destroy this Sid_map.
|
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.
sidno | The SIDNO to add. |
sid | The SID to add. |
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.
sid | The SID. |
SIDNO | The SIDNO for the SID (a new SIDNO if the SID did not exist, an existing if it did exist). |
negative | Error. This function calls my_error. |
enum_return_status Sid_map::clear | ( | ) |
Clears this Sid_map (for RESET SLAVE)
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.
[out] | dest | The Sid_map to which the sids and sidnos will be copied. |
|
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.
|
inline |
Return the sid_lock.
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.
n | A number in the interval [0, get_max_sidno()-1], inclusively. |
|
inlinestaticprivate |
Get the SIDNO for a given SID.
The caller must hold the read lock on sid_lock before invoking this function.
sid | The SID. |
SIDNO | if the given SID exists in this map. |
0 | if the given SID does not exist in this map. |
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.
sidno | The SIDNO. |
need_lock | If 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. |
NULL | The SIDNO does not exist in this map. |
pointer | Pointer 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. |
|
private |
Hash that maps SID to SIDNO.
|
private |
Array that maps SIDNO to SID; the element at index N points to a Node with SIDNO N-1.
|
private |
Array that maps numbers in the interval [0, get_max_sidno()-1] to SIDNOs, in order of increasing SID.
|
mutableprivate |
Read-write lock that protects updates to the number of SIDNOs.