Tuesday Sep 23, 2014

Accessing Fabric HA Groups from Java

It's been almost a year now since the initial release of MySQL Fabric. It is maturing and reached a GA state earlier this year as part of MySQL Utilities 1.4. Developers and architects are evaluating it for their applications, learning the capabilities of the system, and providing feedback for future features and usability enhancements. Connector/J has supported Fabric from the very beginning and continues to support the latest features. This blog post is an introductory level guide to using Fabric for high-availability from Java applications. Sharding features and Java APIs will be covered in a later post. The commands shown and feature descriptions are current for Fabric 1.5.1. In addition, Connector/J 5.1.32 and later support only Fabric 1.5 due to communication protocol differences from Fabric 1.4.

High-availability is a core concept in Fabric and is implemented by HA groups. An HA group is a set of servers configured with MySQL replication in a master/slaves topology. Fabric can take care of the replication configuration, so you only need to have the servers configured properly and Fabric will take care of the rest. The example included here will use three MySQL servers for the application; one master and two slaves. There is an additional database for the backing store for the Fabric node, but it's not considered from the application's perspective. If you plan to follow along, you should setup your Fabric node, MySQL backing store for Fabric and three MySQL 5.6 instances for the application.

[Read More]

Wednesday Apr 02, 2014

Connector/J 5.1.30 is out with Fabric support

Today marks the release of several exciting pieces of software from Oracle. In addition to MySQL server 5.7.4 DMR, MySQL Fabric is out as a release candidate 1.4.2 and Connector/J 5.1.30 has full support. MySQL Fabric is a new way to implement high-availability and scale-out with MySQL server. It provides a way to group sets of servers into high-availability groups with automatic replication configuration. If scale-out is important, sharding can be defined in terms of these high-availability groups.

To use Connector/J with Fabric, you only need to add the jar to your classpath. If you are still using Java 5, you will need to manually load the com.mysql.fabric.jdbc.FabricMySQLDriver class to register the driver. Fabric-aware connections are made with a JDBC URL of the form jdbc:mysql:fabric://host:port/db. Several connection properties are available to influence the behavior of Fabric-aware connections. You can find the documentation for them at Connection Properties. Fabric-aware connections also expose a separate API called FabricMySQLConnection.

Connector/J supports both high-availability configurations and sharding on top of them. A basic high-availability configuration would consist of several servers in a master-slave configuration all belonging to the same group in Fabric. Connector/J can create a Fabric-aware connection to this group and send all writes to the master and load-balance between the slaves for all reads. This type of connection can be made by specifying the fabricServerGroup connection property or using the setServerGroupName() method in the FabricMySQLConnection API.

To implement a Fabric-aware connection with a sharded setup, you would typically specify the table name with the fabricShardTable connection property and use the setShardKey() method of the FabricMySQLConnection API to choose a shard. If the shard key is not provided, or set to null, all queries will be sent to the global group associate with the chosen shard table. If you only need to access a single shard for the duration of a connection, you can just as easily specify the fabricShardKey as a connection property. It doesn't become fixed for the duration of the connection, so you can also use it as a default if most connections won't need to change it.

There are plenty of other ways to use connection properties and APIs to interact with Fabric. You can find the full Connector/J documentation for Fabric-aware connections at Using Connector/J with MySQL Fabric. There are also several demos in the Connector/J source under the src/demo/fabric directory. Check out other resources available at:


Do you want to participate?

There is a lot you can do if you want to help improve MySQL Fabric.

Blogs about MySQL Fabric



MySQL and Java


« April 2016