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

Using a custom domain with the Read/Write Splitting Plugin plugin does not work. #1129

Closed
briete opened this issue Sep 25, 2024 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@briete
Copy link

briete commented Sep 25, 2024

Describe the bug

I am trying to connect to Aurora's cluster reader endpoints using the Read/Write Splitting Plugin plugin, but it does not work with custom domains.

I currently have a custom domain set up for Aurora's cluster endpoints in Route53.

If I specify Aurora's cluster writer endpoint as it is in the JDBC URL, I can connect to the reader instance, but if I use the custom domain, I cannot connect to the reader instance. The following logs were output and the hostname was incorrect.

Failed to connect to reader host: '{instanceIndentifier}:3306/

I looked at the documentation and source code and thought I could use the clusterInstanceHostPattern parameter, but it seems that the subdomain depends on the DB instance identifier.

I don't want to change my custom domain for this.

Expected Behavior

Is there a way to simply specify the writer and reader endpoints for a cluster?

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

Read/Write Splitting Plugin

Current Behavior

Failed to connect to reader host: '{instanceIndentifier}:3306/

Reproduction Steps

We use Spring Boot:3.1.4. Methods that use reader instances are given @Transactional(readonly = true).

application.yml

spring:
  datasource:
    aws-jdbc-wrapper:
      url: jdbc:aws-wrapper:mysql://customdomain:3306/db
      username: ${DB_USERNAME}
      password: ${DB_PASSWORD}
      wrapper-plugins: readWriteSplitting,auroraConnectionTracker,failover,efm2
      wrapper-dialect: aurora-mysql
      reader-host-selector-strategy: roundRobin

Config

@Bean
fun dataSource(): DataSource {
    val ds = AwsWrapperDataSource()
    val properties = Properties()

    properties["wrapperPlugins"] = awsJdbcWrapperConfig.wrapperPlugins
    properties["wrapperDialect"] = awsJdbcWrapperConfig.wrapperDialect
    properties["readerHostSelectorStrategy"] = awsJdbcWrapperConfig.readerHostSelectorStrategy
    ds.targetDataSourceProperties = properties

    ds.jdbcUrl = awsJdbcWrapperConfig.url
    ds.user = awsJdbcWrapperConfig.username
    ds.password = awsJdbcWrapperConfig.password

    return ds
}

Possible Solution

Allow cluster reader endpoints to be set in the Read/Write Splitting Plugin parameters

Additional Information/Context

No response

The AWS Advanced JDBC Driver version used

2.3.9

JDK version used

openjdk 17.0.6 2023-01-17 LTS OpenJDK Runtime Environment Corretto-17.0.6.10.1 (build 17.0.6+10-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.6.10.1 (build 17.0.6+10-LTS, mixed mode, sharing)

Operating System and version

Linux

@briete briete added the bug Something isn't working label Sep 25, 2024
@sergiyvamz
Copy link
Contributor

Hi, @briete

Thank you for reaching out with this issue. Could you please provide more details about your custom domain? You can omit real domain name for your privacy and replace it with some fake domain name. We would like to understand your DNS aliases (CNAME).

The wrapper driver supports user custom domains. Let's assume that a user custom domain is foo.com and instance names of your database cluster have the following names:
instance-one
instance-reader-two
instance-for-reports

Instance names are completely made up and they could be any names.

The driver expects that DNS is configured to the following way.

CNAME instance-one.foo.com -> instance-one.XYZ.us-west-2.rds.amazonaws.com
CNAME instance-reader-two.foo.com -> instance-reader-two.XYZ.us-west-2.rds.amazonaws.com
CNAME instance-for-reports.foo.com -> instance-for-reports.XYZ.us-west-2.rds.amazonaws.com

clusterInstanceHostPattern=?.foo.com should be added to your connection string to configure the wrapper driver to work with your custom domain. I hope this will help to solve the issue.

Thank you!

@briete
Copy link
Author

briete commented Sep 26, 2024

Hi, @sergiyvamz

Thanks for the reply!

CNAME record is set on cluster endpoint, not on instance endpoint

  • Aurora cluster writer endpoint
    • CNAME rds.dev.example.com -> hoge.cluster-xxx.ap-northeast-1.rds.amazonaws.com
  • Aurora cluster reader endpoint
    • CNAME rds-ro.dev.example.com -> hoge.cluster-ro-xxx.ap-northeast-1.rds.amazonaws.com

The JDBC URL is set to the CNAME domain of the writer's cluster endpoint.

jdbc:aws-wrapper:mysql://rds.dev.example.com:3306/db?clusterInstanceHostPattern=?.dev.example.com

I would like the query to be routed to the cluster reader endpoint instead of the instance endpoint, is there such an option?

@briete
Copy link
Author

briete commented Oct 8, 2024

Hi, @sergiyvamz

Sorry, I solved myself.

I was able to set the clusterInstanceHostPattern to a placeholder for the Aurora instance endpoint to distribute to the leader instance while using a custom domain.

jdbc:aws-wrapper:mysql://rds.dev.example.com:3306/db?clusterInstanceHostPattern=?.xxx.ap-northeast-1.rds.amazonaws.com
```

@briete briete closed this as completed Oct 8, 2024
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