Mysqlnd replication and load balancing plugin (
mysqlnd_ms
)
2568
$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()));
/* Disable autocommit, plugin will run all statements on the master */
$mysqli->autocommit(FALSE);
if (!$mysqli->query("INSERT INTO test(id) VALUES (1)")) {
/* Please do proper ROLLBACK in your code, don't just die */
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
if ($res = $mysqli->query("SELECT COUNT(*) AS _num FROM test")) {
$row = $res->fetch_assoc();
$res->close();
if ($row['_num'] > 1000) {
if (!$mysqli->query("INSERT INTO events(task) VALUES ('cleanup')")) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
}
} else {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
if (!$mysqli->query("UPDATE log SET last_update = NOW()")) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
if (!$mysqli->commit()) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
/* Plugin assumes that the transaction has ended and starts load balancing again */
$mysqli->autocommit(TRUE);
$mysqli->close();
?>
Version requirement
The plugin configuration option
trx_stickiness=master
requires PHP 5.4.0 or
newer.
Please note the restrictions outlined in the
transaction handling
concepts section.
20.7.6.4.6. Service level and consistency
Copyright 1997-2012 the PHP Documentation Group. [2230]
Version requirement
Service levels have been introduced in PECL mysqlnd_ms version 1.2.0-alpha.
mysqlnd_ms_set_qos
is available with PHP 5.4.0 or newer.
Different types of MySQL cluster solutions offer different service and data consistency levels to their
users. An asynchronous MySQL replication cluster offers eventual consistency by default. A read
executed on an asynchronous slave may return current, stale or no data at all, depending on whether
the slave has replayed all changesets from the master or not.
Applications using an MySQL replication cluster need to be designed to work correctly with eventual
consistent data. In some cases, however, stale data is not acceptable. In those cases only certain
slaves or even only master accesses are allowed to achieve the required quality of service from the
cluster.
As of PECL mysqlnd_ms 1.2.0 the plugin is capable of selecting MySQL replication nodes
automatically that deliver session consistency or strong consistency. Session consistency means that
one client can read its writes. Other clients may or may not see the clients' write. Strong consistency
means that all clients will see all writes from the client.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...