What’s new in MariaDB Connector/J 3.0
Blog contributors: Diego Dupin and Ralf Gebhardt
We are pleased to announce the general availability (GA) of MariaDB Connector/J 3.0. MariaDB Connector/J 3.0 is the newest version of MariaDB Connector/J for Java 8+, licensed under LGPL 2.1.
MariaDB Connector/J 3.0 is a complete rewrite to simplify the code, reduce the size of the connector and to gain better performance compared to MariaDB Connector/J 2.7.
MariaDB Connector/J 3.0 includes the following new enhancements:
- Data exchange improvements
- Optimistic Prepare
- Faster network performance using the new MariaDB Server 10.6 feature to skip sending metadata
- Faster connection creation
- Transaction replay after a connector controlled failover
- Enhanced support for features in newer java versions
- New options
`tcpKeepInterval`for java 11+
- Full JPMS module descriptor support
- New options
- A new option
`restrictedAuth`enables restricting which authentication plugins can be used
- Logging can be enabled at runtime
- Simplified configuration for SSL/TLS
MariaDB Connector/J 3.0 provides significant performance improvements over MariaDB Connector/J 2.7.
The following real world TPCC benchmarks results compare MariaDB Connector/J 2.7.4 and 3.0.3. The first comparison is using the default setting, so client prepared statements are used. For the second comparison
`useServerPrepStmts` is enabled to use server prepared statements.
Data Exchange Improvements
With Connector/J 3.0, when the connector is using the binary protocol by enabling the option
`useServerPrepStmts`, any command is executed as a set of
EXECUTE commands. In contrast, Connector/J 2.7 requires the
PREPARE result to be received before sending the
EXECUTE command to the server.
With Connector/J 3.0, the connector will pipeline
EXECUTE commands, being optimistic that the
PREPARE command succeeds. (In case the
PREPARE fails, the
EXECUTE command won’t be executed). This avoids some network latency.
Faster network performance using MariaDB Server 10.6 metadata skip
MariaDB Server 10.6 provides a new feature to skip sending metadata when possible if the binary protocol is used.
When the option
`useServerPrepStmts` is enabled, which means that the binary protocol is used, the Connector is taking advantage of this. For SQL commands, which return a resultset, the server will only send metadata once while receiving the data.
Metadata skip improves performance by reducing network traffic and eliminating redundant metadata parsing.
The following Connector internal JMH Benchmark results compare MariaDB Connector/J 2.7.4 and MariaDB Connector/J 3.0.3, selecting one row of a 100
INT column table:
Faster Connection Creation
When connecting to the server, MariaDB Connector/J 2.7 set some options via statements to the server to ensure session state.
Those options correspond to current server default behavior and to what JDBC expects (safe truncation, setting autocommit, etc.).
MariaDB Connector/J 3.0 avoids executing additional queries on connection creation, resulting in faster connection creation, as shown in the following benchmark.
Transaction Replay After Failover
MariaDB Connector/J provides its own failover functionality. A reconnection will be automatically done after a failover occurs, according to the high-availability configuration.
A new non-default option
`transactionReplay` in MariaDB Connector/J 3.0 now allows caching a transaction, permitting the transaction to re-execute if a failover occurs. The driver requires applications to use idempotent queries only (queries can be “replayable”).
If a failover occurs, the driver will recreate a new connection and replay the transaction from the cache. There are a few limitations (for example, if failover occurs during a commit, or if the transaction can’t be cached, because it contains more statements than the value of the new transactionReplaySize option).
Enhanced Support for Features in Newer Java Versions
MariaDB Connector/J 3.0 uses Multi-Release JARs (MRJAR), so it contains Java-version-specific JAR files. This means MariaDB Connector/J 3.0 still supports Java 8 while also providing enhancements for higher versions of Java.
With Java 9, MariaDB Connector/J 3.0 now also provides a Java 9 Platform Module System (JPMS) descriptor, providing information as:
- the module name
- module dependencies
- the packages it makes available to other modules
- the services it offers and consumes
With Java 11 some extensions are available for sockets like options
TCP_KEEPINTERVAL. These are now configurable via the new options
`tcpKeepInterval`. These options don’t have any effect if a Java version lower than 11 is used.
Authentication Plugin Restriction
A new option
`restrictedAuth` allows restricting which authentication plugins can be used.
Example connection string:
This connection string only allows the authentication plugins
Logging can be enabled at runtime
Logging can now be easily enabled at runtime. Logging will use slf4j if it is present and will otherwise fallback to using JDK logger / console. The following Java logging levels are supported:
INFOto log connection errors
DEBUG / FINEto additionally log SQL commands
TRACE / FINESTto additionally log network exchanges
Simplified configuration for SSL/TLS
A new option
`sslMode` is available to simplify configuring SSL.
Possible value are :
|disable||No ssl (default)|
|trust||Encryption only (no certificate and hostname validation) (DEVELOPMENT ONLY)|
|verify-ca||Encryption, certificates validation, BUT no hostname verification|
|verify-full||Standard SSL use: Encryption, certificate validation and hostname validation|
MariaDB Connector/J 3.0 still supports the old way via the options
`trustServerCertificate` for compatibility.
For More Information
Download/Install MariaDB Connector/J 3.0
Upgrade to MariaDB Connector/J 3.0