[CONJ-704] Control using reader node when using Aurora cluster endpoint Created: 2019-05-20  Updated: 2023-12-15  Resolved: 2023-12-15

Status: Closed
Project: MariaDB Connector/J
Component/s: aurora
Affects Version/s: 2.3.0
Fix Version/s: N/A

Type: Task Priority: Minor
Reporter: Minwook Assignee: Diego Dupin
Resolution: Won't Do Votes: 0
Labels: None
Environment:

DBCP : Hikari
Java, Spring boot framework 1.5
org.mariadb.jdbc:mariadb-java-client:2.3
Connection String : jdbc:mariadb:aurora://**



 Description   

Hello, Team

We're using Mariadb connector/J to connect our Aurora database with cluster endpoint.
But sometimes select query is distributed to reader node so we would like to restrict all queries should be run on master server only.

1) Is this designed behavior that sometime select query is distributed to reader node when using cluster endpoint with MariaDB connector/J?

2) If yes, what is the exact condition when select query is distributed to reader node? Something like under high load on master?

3) If yes, is it possible to disable this behavior?



 Comments   
Comment by Diego Dupin [ 2019-06-03 ]

Using 'aurora' keyword in connection string does exactly that, and this is the expected result.
Connector will use master/reader according to current connection read-only setting.
Example:

connection = DriverManager.getConnection("jdbc:mariadb:aurora://someUrl/test");
stmt = connection.createStatement();
stmt.execute("SELECT 1"); // will execute query on master
connection.setReadOnly(true);
stmt.execute("SELECT 1"); // will execute query on slave

ORM like hibernate for example will set connection.setReadOnly automatically.

If needing to use only and always the master connection, then changing the connection string (removing "aurora" keyword) will be more appropriate, because then this is "standard" connection (aurora configuration will have 2 underlying socket connection to permit distribution to writer/reader)

Comment by Minwook [ 2019-06-03 ]

Thanks for your kind comment.

When we test connection string with 'aurora' keyword, sometimes select query is executed on slave even we didn't set setReadonly to True. (During load test, Initially all queries are executed on Master only but select query distributed to slave when load increased.)

So current design is using slave when only setReadOnly to True and no other scenarios, right?

Comment by Diego Dupin [ 2019-06-03 ]

>So current design is using slave when only setReadOnly to True and no other scenarios, right?
To be more complete: when creating a connection with 'aurora' prefix, there will be 2 underlying connections. One to master, second to slave.

There are 3 cases to have a query running on the slave :

  • When this connection is created, a few queries are executed, like "SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment"). those are only when initiating the connection.
  • When master connections fail, and reader connection is still active, it can be asked current master (aurora recovery can automatically promote a new master and DNS takes some time to point to the new master, but slave know immediately)
  • Or as indicated using setReadonly(true).

So for 'client' query, it's only by using setReadonly(true).

Comment by Minwook [ 2019-06-19 ]

@Diego Dupin

Thanks for your kind explanation about current design.
We've checked all 3 cases but not matched. We faced 'client' query was distributed to slave node while setReadonly flag was False.

To identify this issue, could you please guide us which log should be gathered or any points to check?

Comment by Diego Dupin [ 2023-12-15 ]

Closing, since 4 years without feedback and no reproduction

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