MySQL 8.0.40
Source Code Documentation
Source_IO_monitor Class Reference

Class that contains functionality to monitor group member's state, role and quorum changes on all the potential senders in the Sender List, and if it finds any changes or lost quorum it does automatic update of the sender list. More...

#include <rpl_io_monitor.h>

Public Member Functions

 Source_IO_monitor ()
 
virtual ~Source_IO_monitor ()
 
 Source_IO_monitor (const Source_IO_monitor &)=delete
 
Source_IO_monitoroperator= (const Source_IO_monitor &)=delete
 
bool launch_monitoring_process (PSI_thread_key thread_key)
 Creates and launches new Monitor IO thread. More...
 
int terminate_monitoring_process ()
 Terminate the Monitor IO thread. More...
 
bool is_monitor_killed (THD *thd, Master_info *mi)
 Check if Monitor IO thread is killed. More...
 
uint get_monitoring_wait ()
 Gets the delay time between each iteration where it fetches group details. More...
 
bool is_monitoring_process_running ()
 Gets the status of monitor IO thread whether its running. More...
 
std::tuple< bool, std::vector< SENDER_CONN_MERGE_TUPLE > > get_senders_details (const std::string &channel_name)
 It gets stored senders details for channel from replication_asynchronous_connection_failover table. More...
 
void source_monitor_handler ()
 The function started by Monitor IO thread which does monitor group member's state, role and quorum changes on all the potential senders in the Sender List, and if it finds any changes or lost quorum it does automatic update of the sender list. More...
 
void set_monitoring_wait (uint wait_time)
 Sets the delay between each iteration where it fetches group details. More...
 
std::string get_query (enum_sql_query_tag qtag)
 Gets the sql query string. More...
 

Static Public Member Functions

static Source_IO_monitorget_instance ()
 Fetch Source_IO_monitor class instance. More...
 

Private Types

enum  enum_res_col {
  COL_GROUP_NAME = 0 , COL_HOST , COL_PORT , COL_STATE ,
  COL_ROLE
}
 

Private Member Functions

int sync_senders_details (THD *thd)
 It gets stored senders details for channel from replication_asynchronous_connection_failover table, and then connects to it. More...
 
int connect_senders (THD *thd, const std::string &channel_name)
 It gets stored senders details for channel from replication_asynchronous_connection_failover table, and then connects to it. More...
 
bool check_connection_and_run_query (THD *thd, Master_info *mi, RPL_FAILOVER_SOURCE_TUPLE &conn_detail)
 It connects to server and runs a simple query. More...
 
std::tuple< int, bool, bool, std::tuple< std::string, std::string, uint > > get_online_members (THD *thd, Master_info *mi, const Mysql_connection *conn, SENDER_CONN_MERGE_TUPLE source_conn_detail, std::vector< RPL_FAILOVER_SOURCE_TUPLE > &group_membership_detail, uint &curr_highest_group_weight, uint &curr_conn_weight)
 It connects to each stored sender in connect_senders() and check for quorum and group replication plugin enabled. More...
 
int save_group_members (std::string channel_name, std::string managed_name, std::vector< RPL_FAILOVER_SOURCE_TUPLE > &source_conn_list)
 Store gathered membership details to replication_asynchronous_connection_failover table. More...
 
std::tuple< bool, std::string > delete_rows (Rpl_sys_table_access &table_op, TABLE *table, std::vector< std::string > field_name, std::tuple< std::string, std::string, uint > conn_detail)
 Delete provided row to the table with commit. More...
 
std::tuple< bool, std::string > write_rows (Rpl_sys_table_access &table_op, TABLE *table, std::vector< std::string > field_name, RPL_FAILOVER_SOURCE_TUPLE conn_detail)
 Insert provided row to the table with commit. More...
 
bool has_primary_lost_contact_with_majority ()
 Checks if primary member has lost contact with majority. More...
 
const char * primary_weight_str ()
 Gets the Json key for primary weight for the Configuration column of replication_asynchronous_connection_failover_managed table. More...
 
const char * secondary_weight_str ()
 Gets the Json key for secondary weight for the Configuration column of replication_asynchronous_connection_failover_managed table. More...
 

Private Attributes

THDm_monitor_thd {nullptr}
 
bool m_abort_monitor {false}
 
uint m_retry_monitor_wait {5}
 
mysql_mutex_t m_run_lock
 
mysql_cond_t m_run_cond
 
my_thread_handle m_th
 
thread_state m_monitor_thd_state
 
bool m_primary_lost_contact_with_majority_warning_logged {false}
 

Detailed Description

Class that contains functionality to monitor group member's state, role and quorum changes on all the potential senders in the Sender List, and if it finds any changes or lost quorum it does automatic update of the sender list.

Member Enumeration Documentation

◆ enum_res_col

Enumerator
COL_GROUP_NAME 
COL_HOST 
COL_PORT 
COL_STATE 
COL_ROLE 

Constructor & Destructor Documentation

◆ Source_IO_monitor() [1/2]

Source_IO_monitor::Source_IO_monitor ( )

◆ ~Source_IO_monitor()

Source_IO_monitor::~Source_IO_monitor ( )
virtual

◆ Source_IO_monitor() [2/2]

Source_IO_monitor::Source_IO_monitor ( const Source_IO_monitor )
delete

Member Function Documentation

◆ check_connection_and_run_query()

bool Source_IO_monitor::check_connection_and_run_query ( THD thd,
Master_info mi,
RPL_FAILOVER_SOURCE_TUPLE conn_detail 
)
private

It connects to server and runs a simple query.

Parameters
[in]thdThe thread.
[in]miThe pointer to the Master_info object.
[in]conn_detailstd::tuple containing <channel, host, port, network_namespace, weight, group_name>
Returns
true on success false on failure like unable to connect or query fails

◆ connect_senders()

int Source_IO_monitor::connect_senders ( THD thd,
const std::string &  channel_name 
)
private

It gets stored senders details for channel from replication_asynchronous_connection_failover table, and then connects to it.

It also stores client connection object to all the connected stores.

Parameters
[in]thdThe thread.
[in]channel_nameThe channel name.
Returns
false if success, true otherwise.

◆ delete_rows()

std::tuple< bool, std::string > Source_IO_monitor::delete_rows ( Rpl_sys_table_access table_op,
TABLE table,
std::vector< std::string >  field_name,
std::tuple< std::string, std::string, uint conn_detail 
)
private

Delete provided row to the table with commit.

Parameters
[in]table_opThe Rpl_sys_table_access class object.
[in]tableThe table object.
[in]field_nameThe name of column/field of the table.
[in]conn_detailstd::tuple containing <channel, host, port>
Returns
std::tuple<bool, std::string> where each element has following meaning:

first element of tuple is function return value and determines: false Successful true Error

second element of tuple is error message.

◆ get_instance()

Source_IO_monitor * Source_IO_monitor::get_instance ( )
static

Fetch Source_IO_monitor class instance.

Returns
Pointer to the Source_IO_monitor class instance.

◆ get_monitoring_wait()

uint Source_IO_monitor::get_monitoring_wait ( )

Gets the delay time between each iteration where it fetches group details.

Returns
the delay time in seconds.

◆ get_online_members()

std::tuple< int, bool, bool, std::tuple< std::string, std::string, uint > > Source_IO_monitor::get_online_members ( THD thd,
Master_info mi,
const Mysql_connection conn,
SENDER_CONN_MERGE_TUPLE  source_conn_detail,
std::vector< RPL_FAILOVER_SOURCE_TUPLE > &  group_membership_detail,
uint curr_highest_group_weight,
uint curr_conn_weight 
)
private

It connects to each stored sender in connect_senders() and check for quorum and group replication plugin enabled.

It gets group membership list if group replication plugin is enabled and its also has quorum.

Parameters
[in]thdThe thread.
[in]miThe pointer to the Master_info object.
[in]connThe Mysql_connection class object to query remote source.
[in]source_conn_detailstd::tuple containing <channel, host, port, network_namespace, weight, group_name, primary_weight, secondary_weight>.
[out]group_membership_detailstd::tuple containing <channel, host, port, network_namespace, weight, group_name>
[out]curr_highest_group_weightthe highest weight of the source for the group
[out]curr_conn_weightweight for current connected sender
Returns
std::tuple<int, uint, bool, bool, std::tuple<std::string, std::string, uint>> where each element has following meaning:

first element of tuple is function return value and determines: false Successful true Error

second element of tuple determine if the current connected member through asynchronous channel has changed the group.

third element of tuple determine if the current connected member through asynchronous channel has lost quorum.

fourth element of tuple is also a tuple containing <channel, host, port> of member who lost quorum. It is only useful when fourth element of returned tuple is true.

◆ get_query()

std::string Source_IO_monitor::get_query ( enum_sql_query_tag  qtag)

Gets the sql query string.

Parameters
[in]qtagthe query to fetch.
Returns
the sql query string.

◆ get_senders_details()

std::tuple< bool, std::vector< SENDER_CONN_MERGE_TUPLE > > Source_IO_monitor::get_senders_details ( const std::string &  channel_name)

It gets stored senders details for channel from replication_asynchronous_connection_failover table.

Parameters
[in]channel_namethe channel from which get the senders
Returns
std::tuple<bool, List_of_Tuple> where each element has following meaning:

first element of tuple is function return value and determines: false Successful true Error

second element of the tuple contains following details in tuple <channel, host, port, network_namespace, weight, managed_name, primary_weight, secondary_weight>

◆ has_primary_lost_contact_with_majority()

bool Source_IO_monitor::has_primary_lost_contact_with_majority ( )
private

Checks if primary member has lost contact with majority.

Returns
status
Return values
trueprimary member has lost contact with majority
falseotherwise

◆ is_monitor_killed()

bool Source_IO_monitor::is_monitor_killed ( THD thd,
Master_info mi 
)

Check if Monitor IO thread is killed.

Parameters
[in]thdThe thread.
[in]mithe pointer to the Master_info object.
Returns
true if yes, false otherwise

◆ is_monitoring_process_running()

bool Source_IO_monitor::is_monitoring_process_running ( )

Gets the status of monitor IO thread whether its running.

Returns
true if monitor IO thread running, false otherwise.

◆ launch_monitoring_process()

bool Source_IO_monitor::launch_monitoring_process ( PSI_thread_key  thread_key)

Creates and launches new Monitor IO thread.

Parameters
[in]thread_keyinstrumentation key
Returns
false in case of success, or true otherwise.

◆ operator=()

Source_IO_monitor & Source_IO_monitor::operator= ( const Source_IO_monitor )
delete

◆ primary_weight_str()

const char * Source_IO_monitor::primary_weight_str ( )
inlineprivate

Gets the Json key for primary weight for the Configuration column of replication_asynchronous_connection_failover_managed table.

Returns
the Json key for primary weight for the Configuration column of replication_asynchronous_connection_failover_managed table.

◆ save_group_members()

int Source_IO_monitor::save_group_members ( std::string  channel_name,
std::string  managed_name,
std::vector< RPL_FAILOVER_SOURCE_TUPLE > &  source_conn_list 
)
private

Store gathered membership details to replication_asynchronous_connection_failover table.

Parameters
[in]channel_nameThe managed channel for which failover is enabled.
[in]managed_nameThe group name UID value of the group.
[in]source_conn_listThe list of std::tuple containing <channel, host, port, network_namespace, weight, managed_name>.
Returns
false if success, true otherwise.

◆ secondary_weight_str()

const char * Source_IO_monitor::secondary_weight_str ( )
inlineprivate

Gets the Json key for secondary weight for the Configuration column of replication_asynchronous_connection_failover_managed table.

Returns
the Json key for secondary weight for the Configuration column of replication_asynchronous_connection_failover_managed table.

◆ set_monitoring_wait()

void Source_IO_monitor::set_monitoring_wait ( uint  wait_time)

Sets the delay between each iteration where it fetches group details.

Parameters
[in]wait_timethe delay time in seconds to set.

◆ source_monitor_handler()

void Source_IO_monitor::source_monitor_handler ( )

The function started by Monitor IO thread which does monitor group member's state, role and quorum changes on all the potential senders in the Sender List, and if it finds any changes or lost quorum it does automatic update of the sender list.

The thread runs in infinite loop till its not killed.

◆ sync_senders_details()

int Source_IO_monitor::sync_senders_details ( THD thd)
private

It gets stored senders details for channel from replication_asynchronous_connection_failover table, and then connects to it.

It also stores client connection object to all the connected stores. Then it gets group membership list from each sender.

Parameters
[in]thdThe thread.
Returns
0 if success, error otherwise.

◆ terminate_monitoring_process()

int Source_IO_monitor::terminate_monitoring_process ( )

Terminate the Monitor IO thread.

Returns
0 in case of success, or 1 otherwise.

◆ write_rows()

std::tuple< bool, std::string > Source_IO_monitor::write_rows ( Rpl_sys_table_access table_op,
TABLE table,
std::vector< std::string >  field_name,
RPL_FAILOVER_SOURCE_TUPLE  conn_detail 
)
private

Insert provided row to the table with commit.

Parameters
[in]table_opThe Rpl_sys_table_access class object.
[in]tableThe table object.
[in]field_nameThe name of column/field of the table.
[in]conn_detailstd::tuple containing <channel, host, port, network_namespace, weight, group_name>
Returns
std::tuple<bool, std::string> where each element has following meaning:

first element of tuple is function return value and determines: false Successful true Error

second element of tuple is error message.

Member Data Documentation

◆ m_abort_monitor

bool Source_IO_monitor::m_abort_monitor {false}
private

◆ m_monitor_thd

THD* Source_IO_monitor::m_monitor_thd {nullptr}
private

◆ m_monitor_thd_state

thread_state Source_IO_monitor::m_monitor_thd_state
private

◆ m_primary_lost_contact_with_majority_warning_logged

bool Source_IO_monitor::m_primary_lost_contact_with_majority_warning_logged {false}
private

◆ m_retry_monitor_wait

uint Source_IO_monitor::m_retry_monitor_wait {5}
private

◆ m_run_cond

mysql_cond_t Source_IO_monitor::m_run_cond
private

◆ m_run_lock

mysql_mutex_t Source_IO_monitor::m_run_lock
private

◆ m_th

my_thread_handle Source_IO_monitor::m_th
private

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