Skip to content

Commit

Permalink
Merge pull request #3533 from sysown/v2.x-gr_replication_lag_action
Browse files Browse the repository at this point in the history
Changes current handling for replication lag in favor of setting lagging servers to SHUNNED state
  • Loading branch information
JavierJF authored Sep 14, 2021
2 parents 3a481ec + dd71fcd commit 4f94fd3
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 68 deletions.
27 changes: 26 additions & 1 deletion include/MySQL_HostGroups_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ class MySQL_HostGroups_Manager {
void p_update_connection_pool_update_counter(std::string& endpoint_id, std::map<std::string, std::string> labels, std::map<std::string, prometheus::Counter*>& m_map, unsigned long long value, p_hg_dyn_counter::metric idx);
void p_update_connection_pool_update_gauge(std::string& endpoint_id, std::map<std::string, std::string> labels, std::map<std::string, prometheus::Gauge*>& m_map, unsigned long long value, p_hg_dyn_gauge::metric idx);

void group_replication_lag_action_set_server_status(MyHGC* myhgc, char* address, int port, int lag_count, bool enable);

public:
std::mutex galera_set_writer_mutex;
pthread_rwlock_t gtid_rwlock;
Expand Down Expand Up @@ -558,7 +560,30 @@ class MySQL_HostGroups_Manager {
void update_group_replication_set_read_only(char *_hostname, int _port, int _writer_hostgroup, char *error);
void update_group_replication_set_writer(char *_hostname, int _port, int _writer_hostgroup);
void converge_group_replication_config(int _writer_hostgroup);

/**
* @brief Set the supplied server as SHUNNED, this function shall be called
* to 'SHUNNED' those servers which replication lag is bigger than:
* - `mysql_thread___monitor_groupreplication_max_transactions_behind_count`
*
* @details The function automatically handles the appropriate operation to
* perform on the supplied server, based on the supplied 'enable' flag and
* in 'monitor_groupreplication_max_transaction_behind_for_read_only'
* variable. In case the value of the variable is:
*
* * '0' or '2': It's required to search the writer hostgroup for
* finding the supplied server.
* * '1' or '2': It's required to search the reader hostgroup for
* finding the supplied server.
*
* @param _hid The writer hostgroup.
* @param address The server address.
* @param port The server port.
* @param lag_counts The computed lag for the sever.
* @param read_only Boolean specifying the read_only flag value of the server.
* @param enable Boolean specifying if the server needs to be disabled / enabled,
* 'true' for enabling the server if it's 'SHUNNED', 'false' for disabling it.
*/
void group_replication_lag_action(int _hid, char *address, unsigned int port, int lag_counts, bool read_only, bool enable);
void update_galera_set_offline(char *_hostname, int _port, int _writer_hostgroup, char *error, bool soft=false);
void update_galera_set_read_only(char *_hostname, int _port, int _writer_hostgroup, char *error);
void update_galera_set_writer(char *_hostname, int _port, int _writer_hostgroup);
Expand Down
1 change: 1 addition & 0 deletions include/MySQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class MySQL_Threads_Handler
int monitor_groupreplication_healthcheck_timeout;
int monitor_groupreplication_healthcheck_max_timeout_count;
int monitor_groupreplication_max_transactions_behind_count;
int monitor_groupreplication_max_transactions_behind_for_read_only;
int monitor_galera_healthcheck_interval;
int monitor_galera_healthcheck_timeout;
int monitor_galera_healthcheck_max_timeout_count;
Expand Down
7 changes: 7 additions & 0 deletions include/SQLite3_Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class SQLite3_Session {
~SQLite3_Session();
};

#ifdef TEST_GROUPREP
using group_rep_status = std::tuple<bool, bool, uint32_t>;
#endif

class SQLite3_Server {
private:
volatile int main_shutdown;
Expand Down Expand Up @@ -43,6 +47,7 @@ class SQLite3_Server {
std::vector<table_def_t *> *tables_defs_galera;
#endif // TEST_GALERA
#ifdef TEST_GROUPREP
std::unordered_map<std::string, group_rep_status> grouprep_map;
std::vector<table_def_t *> *tables_defs_grouprep;
#endif // TEST_GROUPREP
#if defined(TEST_AURORA) || defined(TEST_GALERA) || defined(TEST_GROUPREP)
Expand All @@ -69,9 +74,11 @@ class SQLite3_Server {
void init_galera_ifaces_string(std::string& s);
#endif // TEST_GALERA
#ifdef TEST_GROUPREP
unsigned int max_num_grouprep_servers;
pthread_mutex_t grouprep_mutex;
void populate_grouprep_table(MySQL_Session *sess, int txs_behind = 0);
void init_grouprep_ifaces_string(std::string& s);
group_rep_status grouprep_test_value(const std::string& srv_addr);
#endif // TEST_GROUPREP
SQLite3_Server();
~SQLite3_Server();
Expand Down
2 changes: 2 additions & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ __thread int mysql_thread___monitor_groupreplication_healthcheck_interval;
__thread int mysql_thread___monitor_groupreplication_healthcheck_timeout;
__thread int mysql_thread___monitor_groupreplication_healthcheck_max_timeout_count;
__thread int mysql_thread___monitor_groupreplication_max_transactions_behind_count;
__thread int mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only;
__thread int mysql_thread___monitor_galera_healthcheck_interval;
__thread int mysql_thread___monitor_galera_healthcheck_timeout;
__thread int mysql_thread___monitor_galera_healthcheck_max_timeout_count;
Expand Down Expand Up @@ -996,6 +997,7 @@ extern __thread int mysql_thread___monitor_replication_lag_count;
extern __thread int mysql_thread___monitor_groupreplication_healthcheck_interval;
extern __thread int mysql_thread___monitor_groupreplication_healthcheck_timeout;
extern __thread int mysql_thread___monitor_groupreplication_healthcheck_max_timeout_count;
extern __thread int mysql_thread___monitor_groupreplication_max_transaction_behind_for_read_only;
extern __thread int mysql_thread___monitor_groupreplication_max_transactions_behind_count;
extern __thread int mysql_thread___monitor_galera_healthcheck_interval;
extern __thread int mysql_thread___monitor_galera_healthcheck_timeout;
Expand Down
Loading

0 comments on commit 4f94fd3

Please sign in to comment.