Oracle 5.0 Reference Manual page 2591

Table of Contents

Advertisement

Mysqlnd replication and load balancing plugin (mysqlnd_ms)
request a list of candidates from a central instance. Thus, a more efficient way
of checking the slaves lag is not available.
Please, note the limitations and properties of
explained in the MySQL reference manual.
To prevent mysqlnd_ms from emitting a warning if no slaves can be found that lag no more than the
defined number of seconds behind the master, it is necessary to enable master fail over in the plugins
configuration file. If no slaves can be found and fail over is turned on, the plugin picks a master for
executing the statement.
If no slave can be found and fail over is turned off, the plugin emits a warning, it does not execute the
statement and it sets an error on the connection.
Example 20.236. Fail over not set
{
"myapp": {
"master": {
"master_0": {
"host": "localhost",
"socket": "\/tmp\/mysql.sock"
}
},
"slave": {
"slave_0": {
"host": "127.0.0.1",
"port": "3306"
}
}
}
}
Example 20.237. No slave within time limit
<?php
$mysqli = new mysqli("myapp", "username", "password", "database");
if (!$mysqli)
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
/* Read from slaves lagging no more than four seconds */
$ret = mysqlnd_ms_set_qos($mysqli,
MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL,
MYSQLND_MS_QOS_OPTION_AGE, 4);
if (!$ret)
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
/* Plugin picks any slave, which may or may not have the changes */
if (!$res = $mysqli->query("SELECT item, price FROM daytrade"))
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
/* Back to default: use of all slaves and masters permitted */
if (!mysqlnd_ms_set_qos($mysqli, MYSQLND_MS_QOS_CONSISTENCY_EVENTUAL))
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
?>
The above example will output:
PHP Warning:
mysqli::query(): (mysqlnd_ms) Couldn't find the appropriate slave connection. 0 slaves to
SHOW SLAVE STATUS
2571
as

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents