Skip to content

Commit

Permalink
Addeda new attribute called 'monitor_slave_lag_when_null' in hostgrou…
Browse files Browse the repository at this point in the history
…p settings, which takes precedence over 'mysql_thread_monitor_slave_lag_when_null' if both are configured.
  • Loading branch information
rahim-kanji committed Apr 25, 2024
1 parent b3fa02a commit 40068b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions include/MySQL_HostGroups_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class MyHGC { // MySQL Host Group Container
char * ignore_session_variables_text; // this is the original version (text format) of ignore_session_variables
uint32_t max_num_online_servers;
uint32_t throttle_connections_per_sec;
int32_t monitor_slave_lag_when_null;
int8_t autocommit;
int8_t free_connections_pct;
int8_t handle_warnings;
Expand All @@ -310,6 +311,10 @@ class MyHGC { // MySQL Host Group Container
bool handle_warnings_enabled() const {
return attributes.configured == true && attributes.handle_warnings != -1 ? attributes.handle_warnings : mysql_thread___handle_warnings;
}
inline
int32_t get_monitor_slave_lag_when_null() const {
return attributes.configured == true && attributes.monitor_slave_lag_when_null != -1 ? attributes.monitor_slave_lag_when_null : mysql_thread___monitor_slave_lag_when_null;
}
MyHGC(int);
~MyHGC();
MySrvC *get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid, int max_lag_ms, MySQL_Session *sess);
Expand Down
1 change: 1 addition & 0 deletions lib/MyHGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void MyHGC::reset_attributes() {
attributes.autocommit = -1;
attributes.free_connections_pct = 10;
attributes.handle_warnings = -1;
attributes.monitor_slave_lag_when_null = -1;
attributes.multiplex = true;
attributes.connection_warming = false;
free(attributes.init_connect);
Expand Down
16 changes: 13 additions & 3 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2686,8 +2686,13 @@ void MySQL_HostGroups_Manager::add(MySrvC *mysrvc, unsigned int _hid) {
}

void MySQL_HostGroups_Manager::replication_lag_action_inner(MyHGC *myhgc, const char *address, unsigned int port, int current_replication_lag) {
int j;
for (j=0; j<(int)myhgc->mysrvs->cnt(); j++) {

if (current_replication_lag == -1) {
current_replication_lag = myhgc->get_monitor_slave_lag_when_null();
proxy_error("Replication lag on server %s:%d is NULL, using value %d\n", address, port, current_replication_lag);
}

for (int j=0; j<(int)myhgc->mysrvs->cnt(); j++) {
MySrvC *mysrvc=(MySrvC *)myhgc->mysrvs->servers->index(j);
if (strcmp(mysrvc->address,address)==0 && mysrvc->port==port) {
mysrvc->cur_replication_lag = current_replication_lag;
Expand Down Expand Up @@ -6219,8 +6224,13 @@ void init_myhgc_hostgroup_settings(const char* hostgroup_settings, MyHGC* myhgc)
nlohmann::json j = nlohmann::json::parse(hostgroup_settings);

const auto handle_warnings_check = [](int8_t handle_warnings) -> bool { return handle_warnings == 0 || handle_warnings == 1; };
int8_t handle_warnings = j_get_srv_default_int_val<int8_t>(j, hid, "handle_warnings", handle_warnings_check);
const int8_t handle_warnings = j_get_srv_default_int_val<int8_t>(j, hid, "handle_warnings", handle_warnings_check);
myhgc->attributes.handle_warnings = handle_warnings;

const auto monitor_slave_lag_when_null_check = [](int32_t monitor_slave_lag_when_null) -> bool
{ return (monitor_slave_lag_when_null >= 0 && monitor_slave_lag_when_null <= 604800); };
const int32_t monitor_slave_lag_when_null = j_get_srv_default_int_val<int32_t>(j, hid, "monitor_slave_lag_when_null", monitor_slave_lag_when_null_check);
myhgc->attributes.monitor_slave_lag_when_null = monitor_slave_lag_when_null;
}
catch (const json::exception& e) {
proxy_error(
Expand Down
4 changes: 0 additions & 4 deletions lib/MySQL_Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2792,11 +2792,9 @@ void * monitor_replication_lag_thread(void *arg) {
MYSQL_ROW row=mysql_fetch_row(mmsd->result);
if (row) {
repl_lag=-1; // this is old behavior
repl_lag=mysql_thread___monitor_slave_lag_when_null; // new behavior, see 669
if (row[j]) { // if Seconds_Behind_Master is not NULL
repl_lag=atoi(row[j]);
} else {
proxy_error("Replication lag on server %s:%d is NULL, using the value %d (mysql-monitor_slave_lag_when_null)\n", mmsd->hostname, mmsd->port, mysql_thread___monitor_slave_lag_when_null);
MyHGM->p_update_mysql_error_counter(p_mysql_error_type::proxysql, mmsd->hostgroup_id, mmsd->hostname, mmsd->port, ER_PROXYSQL_SRV_NULL_REPLICATION_LAG);
}
}
Expand Down Expand Up @@ -7820,11 +7818,9 @@ bool MySQL_Monitor::monitor_replication_lag_process_ready_tasks(const std::vecto
MYSQL_ROW row = mysql_fetch_row(mmsd->result);
if (row) {
repl_lag = -1; // this is old behavior
repl_lag = mysql_thread___monitor_slave_lag_when_null; // new behavior, see 669
if (row[j]) { // if Seconds_Behind_Master is not NULL
repl_lag = atoi(row[j]);
} else {
proxy_error("Replication lag on server %s:%d is NULL, using the value %d (mysql-monitor_slave_lag_when_null)\n", mmsd->hostname, mmsd->port, mysql_thread___monitor_slave_lag_when_null);
MyHGM->p_update_mysql_error_counter(p_mysql_error_type::proxysql, mmsd->hostgroup_id, mmsd->hostname, mmsd->port, ER_PROXYSQL_SRV_NULL_REPLICATION_LAG);
}
}
Expand Down

0 comments on commit 40068b1

Please sign in to comment.