diff --git a/include/MySQL_HostGroups_Manager.h b/include/MySQL_HostGroups_Manager.h index eaa71a293c..995e340518 100644 --- a/include/MySQL_HostGroups_Manager.h +++ b/include/MySQL_HostGroups_Manager.h @@ -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; @@ -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); diff --git a/lib/MyHGC.cpp b/lib/MyHGC.cpp index 9a2a8a0629..9602f156a4 100644 --- a/lib/MyHGC.cpp +++ b/lib/MyHGC.cpp @@ -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); diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 705a06515a..d380c3b29a 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -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; @@ -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(j, hid, "handle_warnings", handle_warnings_check); + const int8_t handle_warnings = j_get_srv_default_int_val(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(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( diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index a943f10a98..1034129653 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -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); } } @@ -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); } }