[CONJ-288] Unable to connect to galera non primary node for maintenance Created: 2016-04-25  Updated: 2016-11-23  Resolved: 2016-04-29

Status: Closed
Project: MariaDB Connector/J
Component/s: Failover
Affects Version/s: 1.3.6, 1.4.3
Fix Version/s: 1.4.4

Type: Bug Priority: Minor
Reporter: Brendon Abbott Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

MariaDB galera server 10.0.24


Issue Links:
Relates
relates to CONJ-391 Improve connection using SELECT in pl... Closed
relates to MDEV-11016 wsrep_node_is_ready() check is too st... Closed

 Description   

If using the JDBC connector as part of a MariaDB/Galera management tool, it is not possible to connect to a non-primary server to query or force it to go primary.

This is due to the driver, internally, issuing a select command upon connection, which returns an exception as "data access" is not allowed whilst non primary. Only SHOW and SET are allowed on non primary nodes.

This prevents the connection from being returned to the caller.

org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.loadServerData()
 
LineNumber:  596
executeQuery(qr, "SELECT "
                    + "@@max_allowed_packet, "
                    + "@@system_time_zone, "
                    + "@@time_zone, "
                    + "@@sql_mode", ResultSet.TYPE_FORWARD_ONLY);

In 1.2 versions, the driver issued:

org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(String, int)
 
LineNumber:  392
qr = (SelectQueryResult) executeQuery(new MySQLQuery("show variables like 'max_allowed_packet'"));



 Comments   
Comment by Brendon Abbott [ 2016-04-25 ]

This use case is obviously an edge use case of the connector. Also, I expect that SELECTs are used for a good reason. Would the addition of a url parameter be a useful way around this, so the driver can then not bother with the SELECT?

Comment by Diego Dupin [ 2016-04-28 ]

Hi,
The driver is designed to be compatible with MariaDB database (of course ) and MySQL.
MySQL documentation tell that SHOW VARIABLES is "version-dependent display-width limit" (variable with very long values are not completly displayed, "use SELECT as a workaround" ). So when adding the "sql_mode" that as a varying size, that has been replace by SELECT to avoid any problem like this.

I will check what is exactly this problem to reuse SHOW VARIABLES.

Comment by Diego Dupin [ 2016-04-28 ]

Limits of "SHOW VARIABLES" are 1024 for mysql, mariadb 5.5 and 10.0, 2048 for mariadb 10.1.
So, there is no restriction to use "SHOW VARIABLES" instead of SELECT.
commit : https://github.com/MariaDB/mariadb-connector-j/commit/69c5997543e5b9503c8f2f5f826ba885fc7013fe

Comment by Brendon Abbott [ 2016-04-28 ]

Hi - would you like us to test to ensure there are no other issues in this scenario? If so, is there a current master branch build that I can obtain. I have the source, but haven't used maven before.

Comment by Brendon Abbott [ 2016-04-28 ]

and thanks for the quick fix by the way!

Comment by Diego Dupin [ 2016-04-28 ]

I'm definilty ok to have your confirmation !

Correction is available on maven :

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>1.4.4-SNAPSHOT</version>
    </dependency>
</dependencies> 

or here is the current snapshot upload : https://oss.sonatype.org/content/repositories/snapshots/org/mariadb/jdbc/mariadb-java-client/1.4.4-SNAPSHOT/
you can just download the Jar file mariadb-java-client-1.4.4-20160428.120706-1.jar

Comment by Brendon Abbott [ 2016-04-28 ]

I managed to get maven working in the end, and built my own.

We have tested, and I can confirm the driver now connects to a non-primary galera node. We were then able to promote the node to primary to recover the cluster.

Comment by Diego Dupin [ 2016-04-28 ]

Excellent.
I'm closing the issue so.
Release will be done in 1.4.4.

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