[CONJ-584] Connector setReadOnly silently fails if aurora cluster URL is a DNS CNAME Created: 2018-03-06  Updated: 2020-12-15

Status: Open
Project: MariaDB Connector/J
Component/s: aurora
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Alex Dommasch Assignee: Diego Dupin
Resolution: Unresolved Votes: 4
Labels: CNAME, DNS, isReadOnly, master, ro, secondary, setReadOnly


 Description   

Spent several days figuring out why my Aurora read replicas weren't getting any traffic. Realized that even after calling setReadOnly(true) on the Connection, isReadOnly() returned false immediately after (with no logging or error to indicate why), and all traffic went to master. I had to debug into the depths of the driver code to find AuroraListener:77 that hard -codes the expected URL pattern for a cluster.

However, in our case, we have friendly CNAME's for the two cluster endpoints (e.g., "myapp-writer.example.com" and "myapp-reader.example.com"). I know there's already a bug entered about being able to specify the cluster "ro" endpoint (CONJ-565), so this might be related. In any case, I would imagine the driver, once given any endpoint (regardless of specific URL pattern), might be able to query the DB to get the entire shape of the cluster.



 Comments   
Comment by Peter Lebedev [ 2018-03-19 ]

Regarding CNAME issue, the code in AuroraListener indeed matches the hard-coded url pattern to get cluster suffix. The driver then runs a query to get all available end point (AuroraListener.getCurrentEndpointIdentifiers) but the end points returned do not include suffix. So, the listener appends a cluster suffix it parsed out of the cluster url. This does not work with CNAMEs since the suffix will be wrong.

I have a fairly simple change in my fork of v1.7.2 that will do a DNS lookup if it can't match the cluster pattern, then take the first CNAME and try to match again. So, if your CNAME points to .cluster-, this will work.

Here is the change:
https://github.com/plebedev/mariadb-connector-j/tree/dns_resolution

Unfortunately, I do not have time at this point to make a pull request but you can try it out to see if it helps in your case.

Comment by Anton Sakhno [ 2020-12-15 ]

We faced the same issue for Aurora cluster using maria db driver 2.2.2, are there any plans or updates on this?

Generated at Thu Feb 08 03:16:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.