|
MySQL Fabric
MySQL Fabric is a system for managing farms of MySQL servers to achive High Availability and optionally support sharding. Technically, it is a middleware to manage and monitor MySQL servers. Clients query MySQL Fabric to obtain lists of MySQL servers, their state and their roles. For example, clients can request a list of slaves for a MySQL Replication group and whether they are ready to handle SQL requests. Another example is a cluster of sharded MySQL servers where the client seeks to know which shard to query for a given table and shard key. If configured to use Fabric, the plugin uses XML RCP over HTTP to obtain the list at runtime from a MySQL Fabric host. The XML remote procedure call itself is done in the background and transparent from a developers point of view. Instead of listing MySQL servers directly in the plugins configuration file it contains a list of one or more MySQL Fabric hosts
Example #1 Plugin config: Fabric hosts instead of MySQL servers { "myapp": { "fabric": { "hosts": [ { "host" : "127.0.0.1", "port" : 8080 } ] } } } Users utilize the new functions mysqlnd_ms_fabric_select_shard and mysqlnd_ms_fabric_select_global to switch to the set of servers responsible for a given shard key. Then, the plugin picks an appropriate server for running queries on. When doing so, the plugin takes care of additional load balancing rules set. The below example assumes that MySQL Fabric has been setup to shard the table test.fabrictest using the id column of the table as a shard key.
Example #2 Manual partitioning using SQL hints
<?php The example creates the sharded table, inserts a record and reads the record thereafter. All SQL data definition language (DDL) operations on a sharded table must be applied to the so called global server group. Prior to creating or altering a sharded table, mysqlnd_ms_fabric_select_global is called to switch the given connection to the corresponding servers of the global group. Data manipulation (DML) SQL statements must be sent to the shards directly. The mysqlnd_ms_fabric_select_shard switches a connection to shards handling a certain shard key. |