Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions include/Base_HostGroups_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ class MySQL_HostGroups_Manager {
* and 'hostgroup_server_mapping' should be rebuild.
*/
uint64_t hgsm_mysql_replication_hostgroups_checksum = 0;
/**
* @brief Holds the previous checksum for the 'MYSQL_AWS_AURORA_HOSTGROUPS'.
* @details Used during 'commit' to determine if config has changed for 'MYSQL_AWS_AURORA_HOSTGROUPS',
* and 'hostgroup_server_mapping' should be rebuild.
*/
uint64_t hgsm_mysql_aws_aurora_hostgroups_checksum = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The new member hgsm_mysql_aws_aurora_hostgroups_checksum is added inside the #if 0 block (lines 605–965) of Base_HostGroups_Manager.h, which contains a legacy, never-compiled copy of the MySQL_HostGroups_Manager class. This addition has no effect; the live class is MySQL_HostGroups_Manager in include/MySQL_HostGroups_Manager.h, where the same member was added. Keeping the dead copy in sync is misleading and the change here is dead code — remove it (or drop the whole #if 0 block).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At include/Base_HostGroups_Manager.h, line 733:

<comment>The new member `hgsm_mysql_aws_aurora_hostgroups_checksum` is added inside the `#if 0` block (lines 605–965) of `Base_HostGroups_Manager.h`, which contains a legacy, never-compiled copy of the `MySQL_HostGroups_Manager` class. This addition has no effect; the live class is `MySQL_HostGroups_Manager` in `include/MySQL_HostGroups_Manager.h`, where the same member was added. Keeping the dead copy in sync is misleading and the change here is dead code — remove it (or drop the whole `#if 0` block).</comment>

<file context>
@@ -725,6 +725,12 @@ class MySQL_HostGroups_Manager {
+	 * @details Used during 'commit' to determine if config has changed for 'MYSQL_AWS_AURORA_HOSTGROUPS',
+	 *   and 'hostgroup_server_mapping' should be rebuild.
+	 */
+	uint64_t hgsm_mysql_aws_aurora_hostgroups_checksum = 0;
 
 
</file context>



PtrArray *MyHostGroups;
Expand Down
6 changes: 6 additions & 0 deletions include/MySQL_HostGroups_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@ class MySQL_HostGroups_Manager : public Base_HostGroups_Manager<MyHGC> {
* and 'hostgroup_server_mapping' should be rebuild.
*/
uint64_t hgsm_mysql_replication_hostgroups_checksum = 0;
/**
* @brief Holds the previous checksum for the 'MYSQL_AWS_AURORA_HOSTGROUPS'.
* @details Used during 'commit' to determine if config has changed for 'MYSQL_AWS_AURORA_HOSTGROUPS',
* and 'hostgroup_server_mapping' should be rebuild.
*/
uint64_t hgsm_mysql_aws_aurora_hostgroups_checksum = 0;


#if 0
Expand Down
28 changes: 21 additions & 7 deletions lib/Base_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,13 @@ void MySQL_HostGroups_Manager::commit_update_checksums_from_tables(SpookyHash& m
void MySQL_HostGroups_Manager::update_hostgroup_manager_mappings() {

if (hgsm_mysql_servers_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS] ||
hgsm_mysql_replication_hostgroups_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS])
hgsm_mysql_replication_hostgroups_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS] ||
hgsm_mysql_aws_aurora_hostgroups_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_AWS_AURORA_HOSTGROUPS])
{
proxy_info("Rebuilding 'Hostgroup_Manager_Mapping' due to checksums change - mysql_servers { old: 0x%lX, new: 0x%lX }, mysql_replication_hostgroups { old:0x%lX, new:0x%lX }\n",
proxy_info("Rebuilding 'Hostgroup_Manager_Mapping' due to checksums change - mysql_servers { old: 0x%lX, new: 0x%lX }, mysql_replication_hostgroups { old:0x%lX, new:0x%lX }, mysql_aws_aurora_hostgroups { old:0x%lX, new:0x%lX }\n",
hgsm_mysql_servers_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS],
hgsm_mysql_replication_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS]);
hgsm_mysql_replication_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS],
hgsm_mysql_aws_aurora_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_AWS_AURORA_HOSTGROUPS]);

char* error = NULL;
int cols = 0;
Expand All @@ -1062,10 +1064,21 @@ void MySQL_HostGroups_Manager::update_hostgroup_manager_mappings() {

hostgroup_server_mapping.clear();

const char* query = "SELECT DISTINCT hostname, port, '1' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=writer_hostgroup WHERE status<>3 \
UNION \
SELECT DISTINCT hostname, port, '0' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=reader_hostgroup WHERE status<>3 \
ORDER BY hostname, port";
const char* query =
"SELECT DISTINCT hostname, port, '1' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer "
"FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=writer_hostgroup WHERE status<>3 "
"UNION "
"SELECT DISTINCT hostname, port, '0' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer "
"FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=reader_hostgroup WHERE status<>3 "
"UNION "
"SELECT DISTINCT srv.hostname, srv.port, '1' is_writer, srv.status, aur.reader_hostgroup, aur.writer_hostgroup, srv.mem_pointer "
"FROM mysql_aws_aurora_hostgroups aur JOIN mysql_servers srv ON srv.hostgroup_id=aur.writer_hostgroup "
"WHERE aur.active=1 AND srv.status<>3 "
"UNION "
"SELECT DISTINCT srv.hostname, srv.port, '0' is_writer, srv.status, aur.reader_hostgroup, aur.writer_hostgroup, srv.mem_pointer "
"FROM mysql_aws_aurora_hostgroups aur JOIN mysql_servers srv ON srv.hostgroup_id=aur.reader_hostgroup "
"WHERE aur.active=1 AND srv.status<>3 "
"ORDER BY hostname, port";

mydb->execute_statement(query, &error, &cols, &affected_rows, &resultset);

Expand Down Expand Up @@ -1109,6 +1122,7 @@ void MySQL_HostGroups_Manager::update_hostgroup_manager_mappings() {

hgsm_mysql_servers_checksum = table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS];
hgsm_mysql_replication_hostgroups_checksum = table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS];
hgsm_mysql_aws_aurora_hostgroups_checksum = table_resultset_checksum[HGM_TABLES::MYSQL_AWS_AURORA_HOSTGROUPS];
}
}

Expand Down
49 changes: 42 additions & 7 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,13 @@
void MySQL_HostGroups_Manager::update_hostgroup_manager_mappings() {

if (hgsm_mysql_servers_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS] ||
hgsm_mysql_replication_hostgroups_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS])
hgsm_mysql_replication_hostgroups_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS] ||
hgsm_mysql_aws_aurora_hostgroups_checksum != table_resultset_checksum[HGM_TABLES::MYSQL_AWS_AURORA_HOSTGROUPS])
{
proxy_info("Rebuilding 'Hostgroup_Manager_Mapping' due to checksums change - mysql_servers { old: 0x%lX, new: 0x%lX }, mysql_replication_hostgroups { old:0x%lX, new:0x%lX }\n",
proxy_info("Rebuilding 'Hostgroup_Manager_Mapping' due to checksums change - mysql_servers { old: 0x%lX, new: 0x%lX }, mysql_replication_hostgroups { old:0x%lX, new:0x%lX }, mysql_aws_aurora_hostgroups { old:0x%lX, new:0x%lX }\n",
hgsm_mysql_servers_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS],
hgsm_mysql_replication_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS]);
hgsm_mysql_replication_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS],
hgsm_mysql_aws_aurora_hostgroups_checksum, table_resultset_checksum[HGM_TABLES::MYSQL_AWS_AURORA_HOSTGROUPS]);

char* error = NULL;
int cols = 0;
Expand All @@ -1059,10 +1061,21 @@

hostgroup_server_mapping.clear();

const char* query = "SELECT DISTINCT hostname, port, '1' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=writer_hostgroup WHERE status<>3 \
UNION \
SELECT DISTINCT hostname, port, '0' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=reader_hostgroup WHERE status<>3 \
ORDER BY hostname, port";
const char* query =
"SELECT DISTINCT hostname, port, '1' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer "
"FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=writer_hostgroup WHERE status<>3 "
"UNION "
"SELECT DISTINCT hostname, port, '0' is_writer, status, reader_hostgroup, writer_hostgroup, mem_pointer "
"FROM mysql_replication_hostgroups JOIN mysql_servers ON hostgroup_id=reader_hostgroup WHERE status<>3 "
"UNION "
"SELECT DISTINCT srv.hostname, srv.port, '1' is_writer, srv.status, aur.reader_hostgroup, aur.writer_hostgroup, srv.mem_pointer "
"FROM mysql_aws_aurora_hostgroups aur JOIN mysql_servers srv ON srv.hostgroup_id=aur.writer_hostgroup "
"WHERE aur.active=1 AND srv.status<>3 "
"UNION "
"SELECT DISTINCT srv.hostname, srv.port, '0' is_writer, srv.status, aur.reader_hostgroup, aur.writer_hostgroup, srv.mem_pointer "
"FROM mysql_aws_aurora_hostgroups aur JOIN mysql_servers srv ON srv.hostgroup_id=aur.reader_hostgroup "
"WHERE aur.active=1 AND srv.status<>3 "
"ORDER BY hostname, port";

mydb->execute_statement(query, &error, &cols, &affected_rows, &resultset);

Expand Down Expand Up @@ -1106,6 +1119,7 @@

hgsm_mysql_servers_checksum = table_resultset_checksum[HGM_TABLES::MYSQL_SERVERS];
hgsm_mysql_replication_hostgroups_checksum = table_resultset_checksum[HGM_TABLES::MYSQL_REPLICATION_HOSTGROUPS];
hgsm_mysql_aws_aurora_hostgroups_checksum = table_resultset_checksum[HGM_TABLES::MYSQL_AWS_AURORA_HOSTGROUPS];
}
}

Expand Down Expand Up @@ -6966,6 +6980,16 @@
pthread_mutex_unlock(&AWS_Aurora_Info_mutex);
}

const std::string aurora_hostname { std::string(_server_id) + std::string(domain_name) };
if (GloMyMon != nullptr && GloMyMon->is_aws_rds_bgd_server_in_progress(aurora_hostname, aurora_port)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: A BGD switchover can begin after this check and before the Aurora movement commits, so the guard does not eliminate the race it is intended to prevent. Coordinate the flag with the movement, or recheck under a lock held through the update.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/MySQL_HostGroups_Manager.cpp, line 6984:

<comment>A BGD switchover can begin after this check and before the Aurora movement commits, so the guard does not eliminate the race it is intended to prevent. Coordinate the flag with the movement, or recheck under a lock held through the update.</comment>

<file context>
@@ -6966,6 +6980,16 @@ void MySQL_HostGroups_Manager::update_aws_aurora_set_writer(int _whid, int _rhid
 	}
 
+	const std::string aurora_hostname { std::string(_server_id) + std::string(domain_name) };
+	if (GloMyMon != nullptr && GloMyMon->is_aws_rds_bgd_server_in_progress(aurora_hostname, aurora_port)) {
+		proxy_info(
+			"AWS Aurora: skipping writer update for %s:%d because AWS RDS BGD switchover is in progress\n",
</file context>

proxy_info(
"AWS Aurora: skipping writer update for %s:%d because AWS RDS BGD switchover is in progress\n",
aurora_hostname.c_str(), aurora_port
);
free(domain_name);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: When BGD is already in progress, this return skips the writer transition but the caller still records an Aurora failover. Return whether movement occurred and suppress the failover log when it did not.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/MySQL_HostGroups_Manager.cpp, line 6990:

<comment>When BGD is already in progress, this return skips the writer transition but the caller still records an Aurora failover. Return whether movement occurred and suppress the failover log when it did not.</comment>

<file context>
@@ -6966,6 +6980,16 @@ void MySQL_HostGroups_Manager::update_aws_aurora_set_writer(int _whid, int _rhid
+			aurora_hostname.c_str(), aurora_port
+		);
+		free(domain_name);
+		return;
+	}
+
</file context>

}

query=(char *)malloc(strlen(q)+strlen(_server_id)+strlen(domain_name)+1024*1024);
sprintf(query, q, _server_id, domain_name, aurora_port, _whid, _rhid);
mydb->execute_statement(query, &error, &cols , &affected_rows , &resultset);
Expand Down Expand Up @@ -7182,7 +7206,7 @@
if (it2!=AWS_Aurora_Info_Map.end()) {
info=it2->second;
if (info->domain_name) {
free(domain_name);

Check failure on line 7209 in lib/MySQL_HostGroups_Manager.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AaBc_I7ByozT9MqYKEZD&open=AaBc_I7ByozT9MqYKEZD&pullRequest=6158
domain_name = strdup(info->domain_name);
}
aurora_port = info->aurora_port;
Expand All @@ -7190,6 +7214,17 @@
}
pthread_mutex_unlock(&AWS_Aurora_Info_mutex);
}

const std::string aurora_hostname { std::string(_server_id) + std::string(domain_name) };
if (GloMyMon != nullptr && GloMyMon->is_aws_rds_bgd_server_in_progress(aurora_hostname, aurora_port)) {
proxy_info(
"AWS Aurora: skipping reader update for %s:%d because AWS RDS BGD switchover is in progress\n",
aurora_hostname.c_str(), aurora_port
);
free(domain_name);

Check failure on line 7224 in lib/MySQL_HostGroups_Manager.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "free".

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AaBc_I7ByozT9MqYKEZE&open=AaBc_I7ByozT9MqYKEZE&pullRequest=6158
return;
}

q = (char*)"SELECT hostgroup_id FROM mysql_servers JOIN mysql_aws_aurora_hostgroups ON hostgroup_id=writer_hostgroup OR hostgroup_id=reader_hostgroup WHERE hostname='%s%s' AND port=%d AND status<>3 AND hostgroup_id IN (%d,%d)";
query=(char *)malloc(strlen(q)+strlen(_server_id)+strlen(domain_name)+32+32+32);
sprintf(query, q, _server_id, domain_name, aurora_port, _whid, _rhid);
Expand Down