Skip to content

Fix AWS RDS Blue/Green discovery for Aurora-only hostgroup configurations - #6158

Open
Hyunho-Jung wants to merge 1 commit into
sysown:v3.0from
Hyunho-Jung:fix/aurora-hostgroup-mapping-bgd-guard
Open

Fix AWS RDS Blue/Green discovery for Aurora-only hostgroup configurations#6158
Hyunho-Jung wants to merge 1 commit into
sysown:v3.0from
Hyunho-Jung:fix/aurora-hostgroup-mapping-bgd-guard

Conversation

@Hyunho-Jung

@Hyunho-Jung Hyunho-Jung commented Sep 1, 2026

Copy link
Copy Markdown

Summary

ProxySQL currently builds hostgroup_server_mapping only from mysql_replication_hostgroups and mysql_servers. This leaves a gap for AWS Aurora configurations that use mysql_aws_aurora_hostgroups instead of mysql_replication_hostgroups: Aurora writer/reader servers are not present in hostgroup_server_mapping, even though they are valid backend servers managed by ProxySQL.

AWS RDS Blue/Green Deployment handling relies on hostgroup_server_mapping when creating and applying Blue/Green hostgroup entries, so Aurora-only configurations can fail to provide the mapping needed to perform writer transitions correctly (AWS RDS BGD: server :0 not found in hostgroup_server_mapping).

Separately, update_aws_aurora_set_writer() / update_aws_aurora_set_reader() have no guard against an in-progress AWS RDS Blue/Green switchover. This lets the Aurora monitor race with the B/G switchover state machine over the same server's hostgroup membership during a transition (e.g. reverting a shun the B/G logic just applied).

What changed

  • Extends the hostgroup_server_mapping rebuild query (update_hostgroup_manager_mappings()) to also include active mysql_aws_aurora_hostgroups entries (both writer_hostgroup and reader_hostgroup members), alongside the existing mysql_replication_hostgroups-based mapping.
  • Adds checksum tracking (hgsm_mysql_aws_aurora_hostgroups_checksum) for mysql_aws_aurora_hostgroups so hostgroup_server_mapping is rebuilt whenever the Aurora hostgroup configuration changes.
  • Adds a guard to update_aws_aurora_set_writer() and update_aws_aurora_set_reader() so Aurora writer/reader auto-movement is skipped while an AWS RDS Blue/Green switchover is already in progress for the same server (MySQL_Monitor::is_aws_rds_bgd_server_in_progress()).

Files changed

  • include/Base_HostGroups_Manager.h
  • include/MySQL_HostGroups_Manager.h
  • lib/Base_HostGroups_Manager.cpp
  • lib/MySQL_HostGroups_Manager.cpp

Testing

This logic was originally developed and validated as a local patch on top of the v3.0.11 tag, and exercised against real AWS Aurora MySQL Blue/Green Deployment switchovers (multiple switchover attempts, confirming the previously-observed hostgroup duplication/oscillation issue no longer reproduced with these changes applied).

This PR rebases that same change onto current v3.0 HEAD. The rebase is a straightforward reapplication (no drift found in the touched functions between the v3.0.11 tag and current v3.0), but it has not yet been independently recompiled/re-tested in this exact form — happy to follow up with a fresh build/switchover test if useful before merge.

Notes

This does not change any admin table schema. It does not remove or bypass the existing hostgroup_server_mapping validation in the B/G writer-configuration path — it only expands the mapping source so Aurora-hostgroup-only servers can be found through the same validation path.

(Supersedes #6157, closed due to a commit-author identity mismatch.)


Summary by cubic

Fixes hostgroup discovery for Aurora-only configurations so AWS RDS Blue/Green deployments can locate writer/reader servers in hostgroup_server_mapping. Previously the mapping was built only from mysql_replication_hostgroups and mysql_servers, so Aurora setups using mysql_aws_aurora_hostgroups failed with "server :0 not found in hostgroup_server_mapping". Also prevents the Aurora monitor from racing with an in-progress Blue/Green switchover over the same server's hostgroup membership.

  • Includes active mysql_aws_aurora_hostgroups writer and reader entries in the hostgroup_server_mapping rebuild query.
  • Tracks a checksum for mysql_aws_aurora_hostgroups so the mapping rebuilds when Aurora config changes.
  • Skips Aurora writer/reader auto-movement during an in-progress Blue/Green switchover for the same server.

No admin schema changes; the existing hostgroup_server_mapping validation in the Blue/Green writer path is unchanged.

Written for commit 0e4fe3e. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Aurora hostgroup configurations are now included when rebuilding hostgroup-to-server mappings.
    • Active writer and reader servers from Aurora hostgroups are automatically reflected in mappings.
  • Bug Fixes

    • Mapping updates now occur when Aurora hostgroup configuration changes.
    • Writer and reader updates are safely skipped while an Aurora switchover is in progress, preventing conflicting changes.

…ions

ProxySQL currently builds Hostgroup_Server_Mapping only from
mysql_replication_hostgroups and mysql_servers.

This leaves a gap for AWS Aurora configurations that use
mysql_aws_aurora_hostgroups instead of mysql_replication_hostgroups.
In that case, Aurora writer/reader servers are not present in
hostgroup_server_mapping, even though they are valid backend servers
managed by ProxySQL. AWS RDS Blue/Green Deployment handling relies on
hostgroup_server_mapping when creating and applying Blue/Green
hostgroup entries, so Aurora-only configurations can fail to provide
the mapping needed to perform writer transitions correctly.

This commit:

- Extends the Hostgroup_Server_Mapping rebuild query to also include
  active mysql_aws_aurora_hostgroups entries (both writer_hostgroup
  and reader_hostgroup members), alongside the existing
  mysql_replication_hostgroups-based mapping.

- Adds checksum tracking for mysql_aws_aurora_hostgroups so
  Hostgroup_Server_Mapping is rebuilt whenever the Aurora hostgroup
  configuration changes.

- Adds a guard to update_aws_aurora_set_writer() and
  update_aws_aurora_set_reader() so Aurora writer/reader
  auto-movement is skipped while an AWS RDS Blue/Green switchover is
  already in progress for the same server. This prevents the Aurora
  monitor from reverting hostgroup state (for example, undoing a
  shun issued by the B/G switchover logic) while a switchover is in
  progress.

Together these changes let Aurora-only configurations
(mysql_aws_aurora_hostgroups without mysql_replication_hostgroups)
participate correctly in AWS RDS Blue/Green Deployment handling, and
prevent the Aurora monitor and the B/G switchover logic from racing
over the same server's hostgroup membership during a transition.
@gitar-bot

gitar-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: a0ab309e-b617-4f30-9811-76a1cda49205

📥 Commits

Reviewing files that changed from the base of the PR and between 8dad803 and 0e4fe3e.

📒 Files selected for processing (4)
  • include/Base_HostGroups_Manager.h
  • include/MySQL_HostGroups_Manager.h
  • lib/Base_HostGroups_Manager.cpp
  • lib/MySQL_HostGroups_Manager.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (2)
Header include guards use the `#ifndef __CLASS_*_H` convention.

📄 CodeRabbit inference engine (CLAUDE.md)

Files:

  • include/Base_HostGroups_Manager.h
  • include/MySQL_HostGroups_Manager.h
Class names must use `PascalCase` with protocol prefixes such as `MySQL_`, `PgSQL_`, and `ProxySQL_`.

📄 CodeRabbit inference engine (CLAUDE.md)

Files:

  • include/Base_HostGroups_Manager.h
  • include/MySQL_HostGroups_Manager.h
  • lib/Base_HostGroups_Manager.cpp
  • lib/MySQL_HostGroups_Manager.cpp
🪛 Cppcheck (2.21.0)
lib/MySQL_HostGroups_Manager.cpp

[warning] 6983-6983: If memory allocation fails, then there is a possible null pointer dereference

(nullPointerOutOfMemory)


[warning] 7218-7218: If memory allocation fails, then there is a possible null pointer dereference

(nullPointerOutOfMemory)

🔇 Additional comments (4)
include/Base_HostGroups_Manager.h (1)

728-733: LGTM!

include/MySQL_HostGroups_Manager.h (1)

649-654: LGTM!

lib/Base_HostGroups_Manager.cpp (1)

1052-1058: LGTM!

Also applies to: 1067-1081, 1125-1125

lib/MySQL_HostGroups_Manager.cpp (1)

1049-1055: LGTM!

Also applies to: 1064-1078, 1122-1122, 6983-6991, 7218-7226


📝 Walkthrough

Walkthrough

The change adds Aurora hostgroup checksum tracking, includes active Aurora writer and reader members in hostgroup_server_mapping, and skips Aurora role updates during an endpoint BGD switchover.

Changes

Aurora hostgroup mapping

Layer / File(s) Summary
Checksum tracking and mapping rebuild
include/Base_HostGroups_Manager.h, include/MySQL_HostGroups_Manager.h, lib/Base_HostGroups_Manager.cpp, lib/MySQL_HostGroups_Manager.cpp
The manager stores the previous Aurora hostgroup checksum. Mapping rebuilds now detect Aurora checksum changes, query active non-offline-hard writer and reader members, and update the stored checksum after rebuilding.

Aurora BGD update guards

Layer / File(s) Summary
Writer and reader switchover checks
lib/MySQL_HostGroups_Manager.cpp
Aurora writer and reader updates return early when is_aws_rds_bgd_server_in_progress() reports an active BGD switchover for the target endpoint.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0e4fe

The PR expands Aurora hostgroup discovery and prevents monitor movement during an in-progress Blue/Green switchover; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: renecannao, wazir-ahmed

Sequence Diagram(s)

sequenceDiagram
  participant MySQL_HostGroups_Manager
  participant AuroraHostgroups
  participant MySQLServers
  participant hostgroup_server_mapping
  MySQL_HostGroups_Manager->>AuroraHostgroups: Check checksum and select active writer/reader members
  AuroraHostgroups->>MySQLServers: Join member server records
  MySQL_HostGroups_Manager->>hostgroup_server_mapping: Rebuild mapping
Loading

Poem

I’m a rabbit guarding hosts in a row
Aurora writers and readers now show
Checksums mark changes with care
BGD pauses updates mid-air
The mapping stays tidy below

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing AWS RDS Blue/Green discovery for Aurora-only hostgroup configurations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="include/Base_HostGroups_Manager.h">

<violation number="1" location="include/Base_HostGroups_Manager.h:733">
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).</violation>
</file>

<file name="lib/MySQL_HostGroups_Manager.cpp">

<violation number="1" location="lib/MySQL_HostGroups_Manager.cpp:6984">
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.</violation>

<violation number="2" location="lib/MySQL_HostGroups_Manager.cpp:6990">
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.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

}

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>

* @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>

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>

@sonarqubecloud

sonarqubecloud Bot commented Sep 1, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant