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

failoverMode for read-only cluster endpoint is unexpectedly set to strict-writer #1199

Open
atrn0 opened this issue Nov 23, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@atrn0
Copy link

atrn0 commented Nov 23, 2024

Describe the bug

When connecting to a read-only cluster endpoint with the failover2 plugin and without the failoverMode property, it appears that failoverMode defaults to strict-writer.
As a result, when a cluster failover occurs, the failover2 plugin establishes a connection only to the writer instance.

Expected Behavior

When connecting to a read-only cluster endpoint, failoverMode should default to reader-or-writer. If a failover occurs, the plugin should reconnect to an available reader instance.

What plugins are used? What other connection properties were set?

auroraConnectionTracker,failover2,efm2

Current Behavior

I'm connecting to an Aurora RDS cluster via the read-only cluster endpoint using MySQL Connector/J. The JDBC URL is as follows:

jdbc:aws-wrapper:mysql://database-test-name.cluster-ro-XYZ.us-east-2.rds.amazonaws.com:3306/my_database

With finer logging enabled, the wrapper outputs the following log from FailoverConnectionPlugin.java:248:

failoverMode=STRICT_WRITER

During a failover, the following log is generated by FailoverConnectionPlugin.java:484:

Starting writer failover procedure.

After the failover process, the wrapper connects to the writer instance.

Reproduction Steps

  1. Middleware and library versions:

    • software.amazon.jdbc:aws-advanced-jdbc-wrapper:2.5.1
    • com.mysql:mysql-connector-j:8.4.0
    • Aurora MySQL 3.04.3
  2. Sample code:

    Properties properties = new Properties();
    // Without `failoverMode` property
    properties.setProperty("wrapperPlugins", "auroraConnectionTracker,failover2,efm2");
    
    try (final Connection conn = DriverManager.getConnection(
        "jdbc:aws-wrapper:mysql://database-test-name.cluster-ro-XYZ.us-east-2.rds.amazonaws.com:3306/my_database", properties);
         final Statement statement = conn.createStatement();
         final ResultSet result = statement.executeQuery("SELECT 1")) {
        System.out.println(Util.getResult(result));
    }
  3. Steps to reproduce:

    • Run the code with finer logging enabled.
    • Trigger a cluster failover.

Possible Solution

The failoverMode=STRICT_WRITER log appears to originate here:

It seems that software.amazon.jdbc.util.RdsUtils#identifyRdsType is called with the initialUrl, but perhaps only the hostname should be passed to this method. This might lead to an incorrect resUrlType being set:

Additional Information/Context

No response

The AWS Advanced JDBC Driver version used

2.5.1

JDK version used

Corretto-21

Operating System and version

amazoncorretto:21 docker image on ECS Fargate (x86)

@atrn0 atrn0 added the bug Something isn't working label Nov 23, 2024
@aaron-congo
Copy link
Contributor

Hi @atrn0 ,

Thanks for reporting this issue. The fix is now available in the recently released v2.5.3 of the driver.

Could you check it out let us know if the issue still persists?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants