MySQL 8.0.40
Source Code Documentation
|
Class to store all the Master_info objects of a slave to access them in the replication code base or performance schema replication tables. More...
#include <rpl_msr.h>
Public Member Functions | |
Multisource_info () | |
~Multisource_info () | |
bool | add_mi (const char *channel_name, Master_info *mi) |
Adds the Master_info object to both replication_channel_map and rpl_pfs_mi. More... | |
Master_info * | get_mi (const char *channel_name) |
Find the master_info object corresponding to a channel explicitly from replication channel_map; Return if it exists, otherwise return 0. More... | |
Master_info * | get_default_channel_mi () |
Return the master_info object corresponding to the default channel. More... | |
bool | delete_mi (const char *channel_name) |
Remove the entry corresponding to the channel, from the replication_channel_map and sets index in the multisource_mi to 0; And also delete the {mi, rli} pair corresponding to this channel. More... | |
const char * | get_default_channel () |
Get the default channel for this multisourced_slave;. More... | |
size_t | get_num_instances (bool all=false) |
Get the number of instances of Master_info in the map. More... | |
size_t | get_number_of_connection_auto_failover_channels_running () |
Get the number of running channels which have asynchronous replication failover feature, i.e. More... | |
uint | get_max_channels () |
Get max channels allowed for this map. More... | |
bool | is_valid_channel_count () |
Returns true if the current number of channels in this slave is less than the MAX_CHANNLES. More... | |
bool | is_group_replication_channel_name (const char *channel, bool is_applier=false) |
Returns if a channel name is one of the reserved group replication names. More... | |
mi_map::iterator | begin (enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL) |
Forward iterators to initiate traversing of a map. More... | |
mi_map::iterator | end (enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL) |
Master_info * | get_mi_at_pos (uint pos) |
Used only by replication performance schema indices to get the master_info at the position 'pos' from the rpl_pfs_mi array. More... | |
void | rdlock () |
Acquire the read lock. More... | |
int | tryrdlock () |
Try to acquire a read lock, return 0 if the read lock is held, otherwise an error will be returned. More... | |
void | wrlock () |
Acquire the write lock. More... | |
int | trywrlock () |
Try to acquire a write lock, return 0 if the write lock is held, otherwise an error will be returned. More... | |
void | unlock () |
Release the lock (whether it is a write or read lock). More... | |
void | assert_some_lock () const |
Assert that some thread holds either the read or the write lock. More... | |
void | assert_some_wrlock () const |
Assert that some thread holds the write lock. More... | |
Private Member Functions | |
void | init_rpl_pfs_mi () |
bool | add_mi_to_rpl_pfs_mi (Master_info *mi) |
Add a master info pointer to the rpl_pfs_mi array at the first NULL;. More... | |
int | get_index_from_rpl_pfs_mi (const char *channel_name) |
Get the index of the master info corresponding to channel name from the rpl_pfs_mi array. More... | |
Private Attributes | |
replication_channel_map | rep_channel_map |
uint | current_mi_count |
Master_info * | default_channel_mi |
Checkable_rwlock * | m_channel_map_lock |
This lock was designed to protect the channel_map from adding or removing master_info objects from the map (adding or removing replication channels). More... | |
Master_info * | rpl_pfs_mi [MAX_CHANNELS] |
mi_map | empty_mi_map |
Static Private Attributes | |
static const unsigned int | MAX_CHANNELS = 256 |
static const char * | default_channel = "" |
Default_channel for this instance, currently is predefined and cannot be modified. More... | |
static const char * | group_replication_channel_names [] |
Class to store all the Master_info objects of a slave to access them in the replication code base or performance schema replication tables.
In a Multisourced replication setup, a slave connects to several masters (also called as sources). This class stores the Master_infos where each Master_info belongs to a slave.
The important objects for a slave are the following: i) Master_info and Relay_log_info (replica_parallel_workers == 0) ii) Master_info, Relay_log_info and Slave_worker(replica_parallel_workers >0 )
Master_info is always associated with a Relay_log_info per channel. So, it is enough to store Master_infos and call the corresponding Relay_log_info by mi->rli;
This class is not yet thread safe. Any part of replication code that calls this class member function should always lock the channel_map.
Only a single global object for a server instance should be created.
The two important data structures in this class are i) C++ std map to store the Master_info pointers with channel name as a key. These are the base channel maps.
ii) C++ std map to store the channel maps with a channel type as its key. This map stores slave channel maps, group replication channels or others iii) An array of Master_info pointers to access from performance schema tables. This array is specifically implemented in a way to make a) pfs indices simple i.e a simple integer counter b) To avoid recalibration of data structure if master info is deleted. Consider the following high level implementation of a pfs table to make a row.
However, we lock channel_map lock for every rnd_next(); There is a gap where an addition/deletion of a channel would rearrange the map making the integer indices of the pfs table point to a wrong value. Either missing a row or duplicating a row.
We solve this problem, by using an array exclusively to use in replciation pfs tables, by marking a master_info defeated as 0 (i.e NULL). A new master info is added to this array at the first NULL always.
|
inline |
|
inline |
bool Multisource_info::add_mi | ( | const char * | channel_name, |
Master_info * | mi | ||
) |
Adds the Master_info object to both replication_channel_map and rpl_pfs_mi.
[in] | channel_name | channel name |
[in] | mi | pointer to master info corresponding to this channel |
false | successfully added |
true | couldn't add channel |
|
private |
Add a master info pointer to the rpl_pfs_mi array at the first NULL;.
[in] | mi | master info object to be added. |
|
inline |
Assert that some thread holds either the read or the write lock.
|
inline |
Assert that some thread holds the write lock.
|
inline |
Forward iterators to initiate traversing of a map.
bool Multisource_info::delete_mi | ( | const char * | channel_name | ) |
Remove the entry corresponding to the channel, from the replication_channel_map and sets index in the multisource_mi to 0; And also delete the {mi, rli} pair corresponding to this channel.
[in] | channel_name | Name of the channel for a Master_info object which must exist. |
|
inline |
|
inline |
Get the default channel for this multisourced_slave;.
|
inline |
Return the master_info object corresponding to the default channel.
pointer | to the master info object if exists. Otherwise, NULL; |
|
private |
Get the index of the master info corresponding to channel name from the rpl_pfs_mi array.
[in] | channel_name | Channel name to get the index from |
|
inline |
Get max channels allowed for this map.
Master_info * Multisource_info::get_mi | ( | const char * | channel_name | ) |
Find the master_info object corresponding to a channel explicitly from replication channel_map; Return if it exists, otherwise return 0.
[in] | channel_name | channel name for the master info object. |
Master_info * Multisource_info::get_mi_at_pos | ( | uint | pos | ) |
Used only by replication performance schema indices to get the master_info at the position 'pos' from the rpl_pfs_mi array.
[in] | pos | the index in the rpl_pfs_mi array |
pointer | to the master info object at pos 'pos'; |
|
inline |
Get the number of instances of Master_info in the map.
all | If it should count all channels. If false, only slave channels are counted. |
|
inline |
Get the number of running channels which have asynchronous replication failover feature, i.e.
CHANGE MASTER TO option SOURCE_CONNECTION_AUTO_FAILOVER, enabled.
|
inlineprivate |
bool Multisource_info::is_group_replication_channel_name | ( | const char * | channel, |
bool | is_applier = false |
||
) |
Returns if a channel name is one of the reserved group replication names.
channel | the channel name to test |
is_applier | compare only with applier name |
true | the name is a reserved name |
false | non reserved name |
|
inline |
Returns true if the current number of channels in this slave is less than the MAX_CHANNLES.
|
inline |
Acquire the read lock.
|
inline |
Try to acquire a read lock, return 0 if the read lock is held, otherwise an error will be returned.
|
inline |
Try to acquire a write lock, return 0 if the write lock is held, otherwise an error will be returned.
|
inline |
Release the lock (whether it is a write or read lock).
|
inline |
Acquire the write lock.
|
private |
|
staticprivate |
Default_channel for this instance, currently is predefined and cannot be modified.
|
private |
|
private |
|
staticprivate |
|
private |
This lock was designed to protect the channel_map from adding or removing master_info objects from the map (adding or removing replication channels).
In fact it also acts like the LOCK_active_mi of MySQL 5.6, preventing two replication administrative commands to run in parallel.
|
staticprivate |
|
private |
|
private |