aws-mysql-jdbc icon indicating copy to clipboard operation
aws-mysql-jdbc copied to clipboard

AWS MySQL JDBC Driver does not recognize Aurora endpoint in China

Open lpapp-zz opened this issue 2 years ago • 14 comments

Hi,

In China the autogenerated Aurora endpoints ends with '.com.cn'. Based on my experience the driver works in different regions except China becase with the same working config I got the following error there: "Caused by: java.sql.SQLException: The clusterInstanceHostPattern configuration property is required when an IP address or custom domain is used to connect to a cluster that provides topology information. If you would instead like to connect without failover functionality, set the enableClusterAwareFailover configuration property to false."

Could you verify the chinese domains are recognized as custom domain please?

Regards

lpapp-zz avatar Jun 28 '22 07:06 lpapp-zz

Thanks for the report!

davecramer avatar Jun 29 '22 12:06 davecramer

Hello @lpapp-zz,

Thanks for reaching out. Yes, to confirm, domains in China are currently not natively supported; however, the driver supports customization with the instance host pattern. Please refer to this section in our README.md and refer to the property clusterInstanceHostPattern for configuration instructions.

An example connection string would be: "jdbc:mysql:aws://mysql.cluster-hex.region.amazonaws.com.cn/?clusterInstanceHostPattern=?.cluster-hex.region.amazonaws.com.cn"

Once configured, the driver ought to recognize the domains in China and failover ought to work as expected.

Please let us know if any other questions regarding this.

karenc-bq avatar Jun 29 '22 22:06 karenc-bq

Hi @karenc-bq,

According to my test and comparison between the China region and US region, the clusterInstanceHostPattern option won't help much.

Please refer to the different between the below two endpoints, one from China region the other from the US region. And pay attention to the position of the string 'rds.' It is after the REGION section in the US endpoint, but it is in front of the REGION section in the China regions.

aurora-test.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn aurora-test.cluster-csqvnmyruu01.us-east-2.rds.amazonaws.com

As a result, the endpoint is not covered by the below regex in the code of the driver, and not considered as an Aurora endpoint. Therefor, the failover didn't work. Pattern.compile("(.+)\.(proxy-|cluster-|cluster-ro-|cluster-custom-)?([a-zA-Z0-9]+\.[a-zA-Z0-9\-]+\.rds\.amazonaws\.com)"

We are looking forward to this bug fix please. Thanks.

guodonb avatar Jul 01 '22 13:07 guodonb

Hi @guodonb

Thank you for pointing out this mistake in China region domain name. You can try to use the following connection string with a correct clusterInstanceHostPattern:

"jdbc:mysql:aws://aurora-test.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn/?clusterInstanceHostPattern=?.ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn"

Regex expression you mentioned doesn't recognise China region however it doesn't affect failover support by the driver.

sergiyvamz avatar Jul 04 '22 18:07 sergiyvamz

Hi @sergiyvamz Thanks for the quick response.

Would you please double confirm if the clusterInstanceHostPattern you mentioned support Aurora failover? According to my test, it doesn't work, that was why I said "Therefor, the failover didn't work." at my earlier post.

I was using the below java code -- adjusted from the sample code at the Github https://github.com/awslabs/aws-mysql-jdbc#amazon-web-services-aws-jdbc-driver-for-mysql Basically, I connect to the aurora cluster and print the current server id every 3 seconds. During the script is running, I do failover and it unable to reconnect.

In comparison, the same java code with the normal connection string in non-China regions was running fine (I can do multiple failover and failover back)

If you have any questions, please feel free to let me know. ############################## private static final String CONNECTION_STRING = "jdbc:mysql:aws://guodonb-aurora-mysql57.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn:3306/mydb?clusterInstanceHostPattern=?.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn";

private static final String USERNAME = "username"; private static final String PASSWORD = "mypwd"; private static final int MAX_RETRIES = 5;

public static void main(String[] args) throws SQLException { aa: for (int i = 1; i <= 100; i++) { try (Connection conn = DriverManager.getConnection(CONNECTION_STRING, USERNAME, PASSWORD)) { // Configure the connection. setInitialSessionState(conn);

 String select_sql = "SELECT sleep(3) sl,@@aurora_server_id serverid FROM serverid limit 1";
     try (ResultSet rs = betterExecuteQuery(conn, select_sql)) {
     while (rs.next()) {
     System.out.println(rs.getString("serverid")); }
     }
     System.out.println(i);
    }
  }

} #####################################

guodonb avatar Jul 05 '22 02:07 guodonb

Hello @guodonb

Please check parameter in the connection string. The correct one is

?clusterInstanceHostPattern=?.ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn

The one I see in your code snippet is:

?clusterInstanceHostPattern=?.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn

sergiyvamz avatar Jul 05 '22 16:07 sergiyvamz

Hello again @sergiyvamz, thanks for your update.

Please pay attention to the Aurora endpoint pattern in China regions at my first post.

The point here is the section 'cluster-ctfz3i8jkise' (it is '-' instead of '.' ) guodonb-aurora-mysql57.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn

Actually, I tried the below syntaxes, no one works (was able to connect but unable to failover bypass the DNS resolution). ?clusterInstanceHostPattern=?.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn ?clusterInstanceHostPattern=?.ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn ?clusterInstanceHostPattern=?-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn ?clusterInstanceHostPattern=?.rds.cn-northwest-1.amazonaws.com.cn

If you don't have a cluster in China regions to test, please let me know.

Thanks.

guodonb avatar Jul 06 '22 01:07 guodonb

Hello @guodonb

Could you please provide URLs for the DB cluster that you use (the one in China region):

  • cluster writer endpoint
  • cluster reader endpoint
  • instance endpoint for any node on the cluster

sergiyvamz avatar Jul 06 '22 01:07 sergiyvamz

Hello @sergiyvamz

Cluster writer endpoint: guodonb-aurora-mysql57.cluster-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn Cluster reader endpoint: guodonb-aurora-mysql57.cluster-ro-ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn

Instance endpoint: guodonb-aurora-mysql57-instance-1.ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn guodonb-aurora-mysql57-instance-1-cn-northwest-1a.ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn guodonb-aurora-mysql57-instance-2-cn-northwest-1b.ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn

guodonb avatar Jul 06 '22 02:07 guodonb

Hello @guodonb

Based on provided URLs I believe that correct value should be

clusterInstanceHostPattern=?.ctfz3i8jkise.rds.cn-northwest-1.amazonaws.com.cn

Please make sure that instance endpoints (as you mentioned above) can be resolved by DNS by your application. In case you application still have the issue during failover, please provide driver logs with TRACE level.

sergiyvamz avatar Jul 06 '22 15:07 sergiyvamz

Hi @sergiyvamz

I believe the DNS resolution is working fine, I was able to update and select data from the cluster.

Please download the TRACE log generated with a failover through the following URL. Please pay attention to line 3674. As you can see, the failover took 10 minutes until the DNS was refreshed. Compare by running the same java code in Ohio, the failover took 3~5 sec only.

--##

guodonb avatar Jul 11 '22 06:07 guodonb

Hello @guodonb

Unfortunately the link you provided is expired. Would you mind to provide another link?

sergiyvamz avatar Jul 11 '22 16:07 sergiyvamz

Hi @sergiyvamz

Try again please.

guodonb avatar Jul 12 '22 02:07 guodonb

Hello @guodonb

Unfortunately log is still unavailable.

<Code>ExpiredToken</Code>
<Message>The provided token has expired.</Message>

sergiyvamz avatar Jul 12 '22 15:07 sergiyvamz