@@ -3353,6 +3353,35 @@ void MySQL_Monitor::process_discovered_topology(const std::string& originating_s
3353
3353
}
3354
3354
}
3355
3355
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
+
3356
3385
void * MySQL_Monitor::monitor_read_only () {
3357
3386
mysql_close (mysql_init (NULL ));
3358
3387
// 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() {
3367
3396
unsigned long long t2;
3368
3397
unsigned long long next_loop_at=0 ;
3369
3398
int topology_loop = 0 ;
3370
- int topology_loop_max = mysql_thread___monitor_aws_rds_topology_discovery_interval;
3371
3399
3372
3400
while (GloMyMon->shutdown ==false && mysql_thread___monitor_enabled==true ) {
3401
+ int topology_loop_max = mysql_thread___monitor_aws_rds_topology_discovery_interval;
3373
3402
bool do_discovery_check = false ;
3374
3403
3375
3404
unsigned int glover;
@@ -3404,11 +3433,13 @@ void * MySQL_Monitor::monitor_read_only() {
3404
3433
goto __end_monitor_read_only_loop;
3405
3434
}
3406
3435
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 ;
3410
3442
}
3411
- topology_loop += 1 ;
3412
3443
3413
3444
// resultset must be initialized before calling monitor_read_only_async
3414
3445
monitor_read_only_async (resultset, do_discovery_check);
@@ -7386,8 +7417,8 @@ VALGRIND_ENABLE_ERROR_REPORTING;
7386
7417
discovered_servers.push_back (row);
7387
7418
}
7388
7419
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) ) {
7391
7422
process_discovered_topology (originating_server_hostname, discovered_servers, mmsd->reader_hostgroup );
7392
7423
}
7393
7424
} else {
0 commit comments