ablog

不器用で落着きのない技術者のメモ

MariaDB Connector/J で Failover パラメータで aurora を指定するとデフォルト値が変わるパラメータ

MariaDB Connector/J で Failover パラメータで aurora を指定すると、デフォルト値が socketTimeout が 10秒( aurora を指定しない場合は 0)、useBatchMultiSend が false(aurora を指定しない場合は true) に変わる。socketTimeout が 10秒なのはフェイルオーバーを検知できるようにするため。

MariaDB Connector/J

Connection strings

The format of the JDBC connection string is

jdbc:(mysql|mariadb):[replication:|failover:|sequential:|aurora:]//<hostDescription>[,<hostDescription>...]/[database][?<key1>=<value1>[&<key2>=<value2>]]
HostDescription:
<host>[:<portnumber>]  or address=(host=<host>)[(port=<portnumber>)][(type=(master|slave))]

(中略)

Failover parameters

Failover was introduced in Connector/J 1.2.0.

sequential Failover support for master replication cluster (for example Galera) without High availability. The hosts will be connected in the order in which they were declared.Example when using the jdbc url string "jdbc:mariadb:replication:host1,host2,host3/test" : When connecting, the driver will always first try host1, and if not available host2 and so on. After a host fail, the driver will reconnect according to this order.
since 1.3.0
failover High availability (random picking connection initialisation) with failover support for master replication cluster (for example Galera).
since 1.2.0
replication High availability (random picking connection initialisation) with failover support for master/slave replication cluster (one or multiple masters)
since 1.2.0
aurora High availability (random picking connection initialisation) with failover support for Amazon Aurora replication cluster
since 1.2.0

(中略)

Essential options
connectTimeout The connect timeout value, in milliseconds. Default: DriverManager.getLoginTimeout() value if set or 30s.
Since 1.1.8
useBatchMultiSend *Not compatible with aurora* Driver will can send queries by batch.If disable, queries are send one by one, waiting for result before sending next one. If enable, queries will be send by batch corresponding to option useBatchMultiSendNumber value (default 100) or according to server variable @@max_allowed_packet if packet size cannot permit to send as many queries. Results will be read afterwhile, avoiding a lot of network latency when client and server aren't on same host. There is 2 differents use case : JDBC executeBatch() and when option useServerPrepStmts is enable and MariaDB server >= 10.2.1, PREPARE commands will be delayed, to send PREPARE + EXECUTE in the same packet. This option if mainly effective when client is distant from server. more information Default: true (false if using aurora failover).
Since 1.5.0

(中略)

Infrequently used
socketTimeout Defined the network socket timeout (SO_TIMEOUT) in milliseconds. Value of 0 disable this timeout. Default: 0 (standard configuration) or 10 000ms (using "aurora" failover configuration).
since 1.1.7
mariadb-connector-j/use-mariadb-connector-j-driver.creole at master · mariadb-corporation/mariadb-connector-j · GitHub

MySQL Connector/J

  • MySQL Server 5.6、5.7、8.0 では MySQL Connector/J 8.0 の使用が推奨されている。

MySQL Connector/J 8.0 is highly recommended for use with MySQL Server 8.0, 5.7, and 5.6. Please upgrade to MySQL Connector/J 8.0.

MySQL :: MySQL Connector/J 5.1 Developer Guide
  • MySQL Connector/J のパラメータのデフォルト値は下記ドキュメント参照。
connectTimeout Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer.
Defaults to '0'.
Default: 0 Since version: 3.0.1
socketTimeout Timeout (in milliseconds) on network socket operations (0, the default means no timeout).
Default: 0
Since version: 3.0.1
MySQL :: MySQL Connector/J 8.0 Developer Guide :: 6.3 Configuration Properties

参考

Hi,

We are using MariaDB Connector/J against our production AWS Aurora RDS and noticed that default socketTimeout is set to 10 seconds against Aurora. Is there a reason behind this default value? Is there any implication of increasing timeout that I should be aware?

We do have transaction layer that times out at 60 seconds. So was thinking to up it to match our higher layer timeout.

any advice is greatly appreciated.

Answer Answered by Diego Dupin in this comment.

Good question !

The value of the timeout socket option does not have to be related to the max time of a transaction.

The connector connects to the database with a socket. The socketTimeout option defined the Socket.setSoTimeout value. A read on that socket that take more time than this value will result as an exception, and kill the socket. This is an error that will be catched by the failover implementation.

Since aurora is design by default to be use as master / slave, socketTimeout has been set to 10s by default to permit failover. 10 seconds is already a lot, and to have an efficient failover, it is necessary that this value be as low as possible.

To be effective, the failover implementation need to detect the problem quickly. If not, new problem will arise : Assuming you are using a connection pool, it implies that the affected connections will not be released until the value of socketTimout . The appplication will not stop during that time, so the connection pool will create many new connections to meet the demands . This will cause a significant increase in resources used in your server and depending of the kind of problem possibly affect the database server. That may cause a lot more problems.

MariaDB Connector/J - MariaDB Knowledge Base