Skip to content

Commit 3ce6f99

Browse files
authored
Merge pull request #4578 from nielsvogell/aws_auto-discovery_patch
Disabling AWS RDS topology auto-discovery by default
2 parents 538bfb8 + 89a3247 commit 3ce6f99

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

include/MySQL_Monitor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ class MySQL_Monitor {
448448
static void trigger_dns_cache_update();
449449

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

452453
private:
453454
std::vector<table_def_t *> *tables_defs_monitor;

lib/MySQL_Monitor.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,35 @@ void MySQL_Monitor::process_discovered_topology(const std::string& originating_s
33533353
}
33543354
}
33553355

3356+
/**
3357+
* @brief Check if a list of servers is matching the description of an AWS RDS Multi-AZ DB Cluster.
3358+
* @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.
3359+
* @param discovered_servers A vector of servers discovered when querying the cluster's topology.
3360+
* @return Returns 'true' if all conditions are met and 'false' otherwise.
3361+
*/
3362+
bool MySQL_Monitor::is_aws_rds_multi_az_db_cluster_topology(const std::vector<MYSQL_ROW>& discovered_servers) {
3363+
if (discovered_servers.size() != 3) {
3364+
return false;
3365+
}
3366+
3367+
const std::vector<std::string> instance_names = {"-instance-1", "-instance-2", "-instance-3"};
3368+
int identified_hosts = 0;
3369+
for (const std::string& instance_str : instance_names) {
3370+
for (MYSQL_ROW server : discovered_servers) {
3371+
if (server[2] == NULL || (server[2][0] == '\0')) {
3372+
continue;
3373+
}
3374+
3375+
std::string current_discovered_hostname = server[2];
3376+
if (current_discovered_hostname.find(instance_str) != std::string::npos) {
3377+
++identified_hosts;
3378+
break;
3379+
}
3380+
}
3381+
}
3382+
return (identified_hosts == 3);
3383+
}
3384+
33563385
void * MySQL_Monitor::monitor_read_only() {
33573386
mysql_close(mysql_init(NULL));
33583387
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
@@ -3367,9 +3396,9 @@ void * MySQL_Monitor::monitor_read_only() {
33673396
unsigned long long t2;
33683397
unsigned long long next_loop_at=0;
33693398
int topology_loop = 0;
3370-
int topology_loop_max = mysql_thread___monitor_aws_rds_topology_discovery_interval;
33713399

33723400
while (GloMyMon->shutdown==false && mysql_thread___monitor_enabled==true) {
3401+
int topology_loop_max = mysql_thread___monitor_aws_rds_topology_discovery_interval;
33733402
bool do_discovery_check = false;
33743403

33753404
unsigned int glover;
@@ -3404,11 +3433,13 @@ void * MySQL_Monitor::monitor_read_only() {
34043433
goto __end_monitor_read_only_loop;
34053434
}
34063435

3407-
if (topology_loop >= topology_loop_max) {
3408-
do_discovery_check = true;
3409-
topology_loop = 0;
3436+
if (topology_loop_max > 0) { // if the discovery interval is set to zero, do not query for the topology
3437+
if (topology_loop >= topology_loop_max) {
3438+
do_discovery_check = true;
3439+
topology_loop = 0;
3440+
}
3441+
topology_loop += 1;
34103442
}
3411-
topology_loop += 1;
34123443

34133444
// resultset must be initialized before calling monitor_read_only_async
34143445
monitor_read_only_async(resultset, do_discovery_check);
@@ -7386,8 +7417,8 @@ VALGRIND_ENABLE_ERROR_REPORTING;
73867417
discovered_servers.push_back(row);
73877418
}
73887419

7389-
// Process the discovered servers and add them to 'runtime_mysql_servers'
7390-
if (!discovered_servers.empty()) {
7420+
// Process the discovered servers and add them to 'runtime_mysql_servers' (process only for AWS RDS Multi-AZ DB Clusters)
7421+
if (!discovered_servers.empty() && is_aws_rds_multi_az_db_cluster_topology(discovered_servers)) {
73917422
process_discovered_topology(originating_server_hostname, discovered_servers, mmsd->reader_hostgroup);
73927423
}
73937424
} else {

lib/MySQL_Thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
985985
variables.monitor_ping_interval=8000;
986986
variables.monitor_ping_max_failures=3;
987987
variables.monitor_ping_timeout=1000;
988-
variables.monitor_aws_rds_topology_discovery_interval=1000;
988+
variables.monitor_aws_rds_topology_discovery_interval=0;
989989
variables.monitor_read_only_interval=1000;
990990
variables.monitor_read_only_timeout=800;
991991
variables.monitor_read_only_max_timeout_count=3;
@@ -2153,7 +2153,7 @@ char ** MySQL_Threads_Handler::get_variables_list() {
21532153
VariablesPointers_int["monitor_ping_timeout"] = make_tuple(&variables.monitor_ping_timeout, 100, 600*1000, false);
21542154
VariablesPointers_int["monitor_ping_max_failures"] = make_tuple(&variables.monitor_ping_max_failures, 1, 1000*1000, false);
21552155

2156-
VariablesPointers_int["monitor_aws_rds_topology_discovery_interval"] = make_tuple(&variables.monitor_aws_rds_topology_discovery_interval, 1, 100000, false);
2156+
VariablesPointers_int["monitor_aws_rds_topology_discovery_interval"] = make_tuple(&variables.monitor_aws_rds_topology_discovery_interval, 0, 100000, false);
21572157
VariablesPointers_int["monitor_read_only_interval"] = make_tuple(&variables.monitor_read_only_interval, 100, 7*24*3600*1000, false);
21582158
VariablesPointers_int["monitor_read_only_timeout"] = make_tuple(&variables.monitor_read_only_timeout, 100, 600*1000, false);
21592159
VariablesPointers_int["monitor_read_only_max_timeout_count"] = make_tuple(&variables.monitor_read_only_max_timeout_count, 1, 1000*1000, false);

0 commit comments

Comments
 (0)