MySQL 8.4.2
Source Code Documentation
Multisource_info Class Reference

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_infoget_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_infoget_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_applier_channel_name (const char *channel)
 Checks if a channel is the group replication applier channel. More...
 
bool is_group_replication_recovery_channel_name (const char *channel)
 Checks if a channel is the group replication recovery channel. More...
 
bool is_group_replication_channel_name (const char *channel)
 Returns if a channel name is one of the reserved group replication names. More...
 
bool is_channel_configured (Master_info *mi)
 Check if the channel has an hostname or is a GR channel. 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_infoget_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_infodefault_channel_mi
 
Checkable_rwlockm_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_inforpl_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 []
 

Detailed Description

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.

highlevel_pfs_funciton()
{
while(replication_table_xxxx.rnd_next())
{
do stuff;
}
}

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.

Constructor & Destructor Documentation

◆ Multisource_info()

Multisource_info::Multisource_info ( )
inline

◆ ~Multisource_info()

Multisource_info::~Multisource_info ( )
inline

Member Function Documentation

◆ add_mi()

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.

Parameters
[in]channel_namechannel name
[in]mipointer to master info corresponding to this channel
Return values
falsesuccessfully added
truecouldn't add channel

◆ add_mi_to_rpl_pfs_mi()

bool Multisource_info::add_mi_to_rpl_pfs_mi ( Master_info mi)
private

Add a master info pointer to the rpl_pfs_mi array at the first NULL;.

Parameters
[in]mimaster info object to be added.
Returns
false if success.Else true.

◆ assert_some_lock()

void Multisource_info::assert_some_lock ( ) const
inline

Assert that some thread holds either the read or the write lock.

◆ assert_some_wrlock()

void Multisource_info::assert_some_wrlock ( ) const
inline

Assert that some thread holds the write lock.

◆ begin()

mi_map::iterator Multisource_info::begin ( enum_channel_type  channel_type = SLAVE_REPLICATION_CHANNEL)
inline

Forward iterators to initiate traversing of a map.

◆ delete_mi()

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.

Note
this requires the caller to hold the mi->channel_wrlock. If the method succeeds the master info object is deleted and the lock is released. If the an error occurs and the method return true, the {mi} object won't be deleted and the caller should release the channel_wrlock.
Parameters
[in]channel_nameName of the channel for a Master_info object which must exist.
Returns
true if an error occurred, false otherwise

◆ end()

mi_map::iterator Multisource_info::end ( enum_channel_type  channel_type = SLAVE_REPLICATION_CHANNEL)
inline

◆ get_default_channel()

const char * Multisource_info::get_default_channel ( )
inline

Get the default channel for this multisourced_slave;.

◆ get_default_channel_mi()

Master_info * Multisource_info::get_default_channel_mi ( )
inline

Return the master_info object corresponding to the default channel.

Return values
pointerto the master info object if exists. Otherwise, NULL;

◆ get_index_from_rpl_pfs_mi()

int Multisource_info::get_index_from_rpl_pfs_mi ( const char *  channel_name)
private

Get the index of the master info corresponding to channel name from the rpl_pfs_mi array.

Parameters
[in]channel_nameChannel name to get the index from
Returns
index of mi for the channel_name. Else -1;

◆ get_max_channels()

uint Multisource_info::get_max_channels ( )
inline

Get max channels allowed for this map.

◆ get_mi()

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.

Parameters
[in]channel_namechannel name for the master info object.
Returns
pointer to the master info object if exists in the map. Otherwise, NULL;

◆ get_mi_at_pos()

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.

Parameters
[in]posthe index in the rpl_pfs_mi array
Return values
pointerto the master info object at pos 'pos';

◆ get_num_instances()

size_t Multisource_info::get_num_instances ( bool  all = false)
inline

Get the number of instances of Master_info in the map.

Parameters
allIf it should count all channels. If false, only slave channels are counted.
Returns
The number of channels or 0 if empty.

◆ get_number_of_connection_auto_failover_channels_running()

size_t Multisource_info::get_number_of_connection_auto_failover_channels_running ( )
inline

Get the number of running channels which have asynchronous replication failover feature, i.e.

CHANGE REPLICATION SOURCE TO option SOURCE_CONNECTION_AUTO_FAILOVER, enabled.

Returns
The number of channels.

◆ init_rpl_pfs_mi()

void Multisource_info::init_rpl_pfs_mi ( )
inlineprivate

◆ is_channel_configured()

bool Multisource_info::is_channel_configured ( Master_info mi)
inline

Check if the channel has an hostname or is a GR channel.

Returns
true if the channel is configured or is a gr channel, false otherwise

◆ is_group_replication_applier_channel_name()

bool Multisource_info::is_group_replication_applier_channel_name ( const char *  channel)

Checks if a channel is the group replication applier channel.

Parameters
[in]channelName of the channel to check
Returns
true if it is the gr applier channel

◆ is_group_replication_channel_name()

bool Multisource_info::is_group_replication_channel_name ( const char *  channel)

Returns if a channel name is one of the reserved group replication names.

Parameters
channelthe channel name to test
Return values
truethe name is a reserved name
falsenon reserved name

◆ is_group_replication_recovery_channel_name()

bool Multisource_info::is_group_replication_recovery_channel_name ( const char *  channel)

Checks if a channel is the group replication recovery channel.

Parameters
[in]channelName of the channel to check
Returns
true if it is the gr recovery channel

◆ is_valid_channel_count()

bool Multisource_info::is_valid_channel_count ( )
inline

Returns true if the current number of channels in this slave is less than the MAX_CHANNLES.

◆ rdlock()

void Multisource_info::rdlock ( )
inline

Acquire the read lock.

◆ tryrdlock()

int Multisource_info::tryrdlock ( )
inline

Try to acquire a read lock, return 0 if the read lock is held, otherwise an error will be returned.

Returns
0 in case of success, or 1 otherwise.

◆ trywrlock()

int Multisource_info::trywrlock ( )
inline

Try to acquire a write lock, return 0 if the write lock is held, otherwise an error will be returned.

Returns
0 in case of success, or 1 otherwise.

◆ unlock()

void Multisource_info::unlock ( )
inline

Release the lock (whether it is a write or read lock).

◆ wrlock()

void Multisource_info::wrlock ( )
inline

Acquire the write lock.

Member Data Documentation

◆ current_mi_count

uint Multisource_info::current_mi_count
private

◆ default_channel

const char * Multisource_info::default_channel = ""
staticprivate

Default_channel for this instance, currently is predefined and cannot be modified.

◆ default_channel_mi

Master_info* Multisource_info::default_channel_mi
private

◆ empty_mi_map

mi_map Multisource_info::empty_mi_map
private

◆ group_replication_channel_names

const char * Multisource_info::group_replication_channel_names
staticprivate
Initial value:
= {
"group_replication_applier", "group_replication_recovery"}

◆ m_channel_map_lock

Checkable_rwlock* Multisource_info::m_channel_map_lock
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.

◆ MAX_CHANNELS

const unsigned int Multisource_info::MAX_CHANNELS = 256
staticprivate

◆ rep_channel_map

replication_channel_map Multisource_info::rep_channel_map
private

◆ rpl_pfs_mi

Master_info* Multisource_info::rpl_pfs_mi[MAX_CHANNELS]
private

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