MySQL  8.0.16
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...
 
void 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...
 
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_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...
 
void wrlock ()
 Acquire the write lock. 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 (slave_parallel_workers == 0) ii) Master_info, Relay_log_info and Slave_worker(slave_parallel_workers >0 )

Master_info is always assosiated 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
Returns
Return values
falsesuccesfully 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()

void 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.

Parameters
[in]channel_nameName of the channel for a Master_info object which must exist.

◆ 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
Return values
pointerto 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.

◆ init_rpl_pfs_mi()

void Multisource_info::init_rpl_pfs_mi ( )
inlineprivate

◆ is_group_replication_channel_name()

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.

Parameters
channelthe channel name to test
is_appliercompare only with applier name
Returns
Return values
truethe name is a reserved name
falsenon reserved name

◆ 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.

◆ 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: