[CONJ-510] Permit connection creation to allow execution of read-only statements on slaves when master is down Created: 2017-08-07  Updated: 2020-08-25  Resolved: 2017-11-08

Status: Closed
Project: MariaDB Connector/J
Component/s: Failover
Affects Version/s: 2.1.0
Fix Version/s: 2.2.0

Type: Task Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Attachments: Java Source File TestDriverFailoverNoMaster.java    

 Description   

Some users would like their application to be able to execute read-only statements on slaves even if the master is down. Unfortunately, MariaDB Connector/J does not currently seem to allow this. If the master is down, MariaDB Connector/J throws an exception saying that it failed to connect.

Would it make sense to add an option that would allow the application to continue executing read-only queries when the master is down? Maybe it could be called "masterDownAllowReadOnly" or something?

For an example of what I mean, please see the test program that I will attach to the issue. When running the program, I see the following output:

[ec2-user@ip-172-30-0-249 ~]$ export CLASSPATH=/home/ec2-user/mariadb-java-client-2.1.0.jar:.
[ec2-user@ip-172-30-0-249 ~]$ javac TestDriverFailoverNoMaster.java
[ec2-user@ip-172-30-0-249 ~]$ java TestDriverFailoverNoMaster
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0
SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
SQLState: 08
VendorError: 0



 Comments   
Comment by Diego Dupin [ 2017-08-17 ]

Actually, existing connection permit that functionnality :
if masters are down, and application ask for a read-only connection, connection to a slave will be used.

But driver doesn't permit to create new connection since JDBC default to use master connection.

This option make sense to permit creating a new connection even if no master connection is up.

Comment by Geoff Montee (Inactive) [ 2018-02-09 ]

Based on the code changes in the commit for this feature request, it looks like "allowMasterDownConnection=true" needs to be set in order to make this work. Is that correct? If so, I don't see this new option documented yet:

https://github.com/MariaDB/mariadb-connector-j/commit/cc2cfbd4b01c2480f3c3d8a38a080039f72fec9b#diff-3bea78d9419402bb147fda9c505a1281R536

https://mariadb.com/kb/en/library/about-mariadb-connector-j/#optional-url-parameters

Comment by Diego Dupin [ 2018-02-13 ]

Exactly.
You're right about the missing documentation, i'll add it tomorrow

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