Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling AWS RDS topology auto-discovery by default #4578

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/MySQL_Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class MySQL_Monitor {
static void trigger_dns_cache_update();

void process_discovered_topology(const std::string& originating_server_hostname, const vector<MYSQL_ROW>& discovered_servers, int reader_hostgroup);
bool is_aws_rds_multi_az_db_cluster_topology(const std::vector<MYSQL_ROW>& discovered_servers);

private:
std::vector<table_def_t *> *tables_defs_monitor;
Expand Down
41 changes: 34 additions & 7 deletions lib/MySQL_Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,31 @@ void MySQL_Monitor::process_discovered_topology(const std::string& originating_s
}
}

/**
* @brief Check if a list of servers is matching the description of an AWS RDS Multi-AZ DB Cluster.
* @details This method takes a vector of discovered servers and checks that there are exactly three which are named "instance-[1|2|3]" respectively, as expected on an AWS RDS Multi-AZ DB Cluster.
* @param discovered_servers A vector of servers discovered when querying the cluster's topology.
* @return Returns 'true' if all conditions are met and 'false' otherwise.
*/
bool MySQL_Monitor::is_aws_rds_multi_az_db_cluster_topology(const std::vector<MYSQL_ROW>& discovered_servers) {
if (discovered_servers.size() != 3) {
return false;
}

const std::vector<std::string> instance_names = {"-instance-1", "-instance-2", "-instance-3"};
int identified_hosts = 0;
for (std::string instance_str : instance_names) {
JavierJF marked this conversation as resolved.
Show resolved Hide resolved
for (MYSQL_ROW server : discovered_servers) {
std::string current_discovered_hostname = server[2];
JavierJF marked this conversation as resolved.
Show resolved Hide resolved
if (current_discovered_hostname.find(instance_str) != std::string::npos) {
++identified_hosts;
break;
}
}
}
return (identified_hosts == 3);
}

void * MySQL_Monitor::monitor_read_only() {
mysql_close(mysql_init(NULL));
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
Expand All @@ -3367,9 +3392,9 @@ void * MySQL_Monitor::monitor_read_only() {
unsigned long long t2;
unsigned long long next_loop_at=0;
int topology_loop = 0;
int topology_loop_max = mysql_thread___monitor_aws_rds_topology_discovery_interval;

while (GloMyMon->shutdown==false && mysql_thread___monitor_enabled==true) {
int topology_loop_max = mysql_thread___monitor_aws_rds_topology_discovery_interval;
bool do_discovery_check = false;

unsigned int glover;
Expand Down Expand Up @@ -3404,11 +3429,13 @@ void * MySQL_Monitor::monitor_read_only() {
goto __end_monitor_read_only_loop;
}

if (topology_loop >= topology_loop_max) {
do_discovery_check = true;
topology_loop = 0;
if (topology_loop_max > 0) { // if the discovery interval is set to zero, do not query for the topology
if (topology_loop >= topology_loop_max) {
do_discovery_check = true;
topology_loop = 0;
}
topology_loop += 1;
}
topology_loop += 1;

// resultset must be initialized before calling monitor_read_only_async
monitor_read_only_async(resultset, do_discovery_check);
Expand Down Expand Up @@ -7386,8 +7413,8 @@ VALGRIND_ENABLE_ERROR_REPORTING;
discovered_servers.push_back(row);
}

// Process the discovered servers and add them to 'runtime_mysql_servers'
if (!discovered_servers.empty()) {
// Process the discovered servers and add them to 'runtime_mysql_servers' (process only for AWS RDS Multi-AZ DB Clusters)
if (!discovered_servers.empty() && is_aws_rds_multi_az_db_cluster_topology(discovered_servers)) {
process_discovered_topology(originating_server_hostname, discovered_servers, mmsd->reader_hostgroup);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
variables.monitor_ping_interval=8000;
variables.monitor_ping_max_failures=3;
variables.monitor_ping_timeout=1000;
variables.monitor_aws_rds_topology_discovery_interval=1000;
variables.monitor_aws_rds_topology_discovery_interval=0;
variables.monitor_read_only_interval=1000;
variables.monitor_read_only_timeout=800;
variables.monitor_read_only_max_timeout_count=3;
Expand Down Expand Up @@ -2153,7 +2153,7 @@ char ** MySQL_Threads_Handler::get_variables_list() {
VariablesPointers_int["monitor_ping_timeout"] = make_tuple(&variables.monitor_ping_timeout, 100, 600*1000, false);
VariablesPointers_int["monitor_ping_max_failures"] = make_tuple(&variables.monitor_ping_max_failures, 1, 1000*1000, false);

VariablesPointers_int["monitor_aws_rds_topology_discovery_interval"] = make_tuple(&variables.monitor_aws_rds_topology_discovery_interval, 1, 100000, false);
VariablesPointers_int["monitor_aws_rds_topology_discovery_interval"] = make_tuple(&variables.monitor_aws_rds_topology_discovery_interval, 0, 100000, false);
VariablesPointers_int["monitor_read_only_interval"] = make_tuple(&variables.monitor_read_only_interval, 100, 7*24*3600*1000, false);
VariablesPointers_int["monitor_read_only_timeout"] = make_tuple(&variables.monitor_read_only_timeout, 100, 600*1000, false);
VariablesPointers_int["monitor_read_only_max_timeout_count"] = make_tuple(&variables.monitor_read_only_max_timeout_count, 1, 1000*1000, false);
Expand Down