Oracle 5.0 Reference Manual page 2601

Table of Contents

Advertisement

Mysqlnd replication and load balancing plugin (mysqlnd_ms)
Manual partitioning or sharding is supported through the node grouping filter, and SQL hints as of
1.5.0. The node_groups filter lets you assign a symbolic name to a group of master and slave servers.
In the example, the master
is entirely up to you to decide what makes up a group. For example, you may use node groups for
sharding, and use the group names to address shards like Shard_A_Range_0_100.
Example 20.252. Cluster node groups
{
"myapp": {
"master": {
"master_0": {
"host": "localhost",
"socket": "\/tmp\/mysql.sock"
}
},
"slave": {
"slave_0": {
"host": "simulate_slave_failure",
"port": "0"
},
"slave_1": {
"host": "127.0.0.1",
"port": 3311
}
},
"filters": {
"node_groups": {
"Partition_A" : {
"master": ["master_0"],
"slave": ["slave_0"]
}
},
"roundrobin": []
}
}
}
Example 20.253. Manual partitioning using SQL hints
<?php
function select($mysqli, $msg, $hint = '') {
/* Note: weak test, two connections to two servers may have the same thread id */
$sql = sprintf("SELECT CONNECTION_ID() AS _thread, '%s' AS _hint FROM DUAL", $msg);
if ($hint) {
$sql = $hint . $sql;
}
if (!($res = $mysqli->query($sql))) {
printf("[%d] %s", $mysqli->errno, $mysqli->error);
return false;
}
$row =
$res->fetch_assoc();
printf("%d - %s - %s\n", $row['_thread'], $row['_hint'], $sql);
return true;
}
$mysqli = new mysqli("myapp", "user", "password", "database");
if (!$mysqli)
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
/* All slaves allowed */
select($mysqli, "slave_0");
select($mysqli, "slave_1");
/* only servers of node group "Partition_A" allowed */
select($mysqli, "slave_1", "/*Partition_A*/");
and
master_0
slave_0
2581
form a group with the name Partition_A. It

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents