Mysqlnd replication and load balancing plugin (
mysqlnd_ms
)
2627
As of PHP 5.4.0 the mysqlnd library allows the plugin
to monitor the
autocommit
mode set by calls to
the libraries
set_autocommit()
function. If setting
set_stickiness=master
and
autocommit
gets disabled by
a PHP MySQL extension invoking the
mysqlnd
library internal
function call
set_autocommit()
, the plugin is made aware of the
begin of a transaction. Then, the plugin stops load balancing and
directs all statements to the master server until
autocommit
is
enabled. Thus, no SQL hints are required.
An example of a PHP MySQL API function calling the
mysqlnd
library internal function call
set_autocommit()
is
mysqli_autocommit
.
Although setting
trx_stickiness=master
, the plugin cannot
be made aware of
autocommit
mode changes caused by SQL
statements such as
SET AUTOCOMMIT=0
or
BEGIN
.
As of PHP 5.5.0, the mysqlnd library features additional C API
calls to control transactions. The level of control matches the one
offered by SQL statements. The
mysqli
API has been modified
to use these calls. Since version 1.5.0, PECL/mysqlnd_ms can
monitor not only
mysqli_autocommit
, but also
mysqli_begin
,
mysqli_commit
and
mysqli_rollback
to detect transaction
boundaries and stop load balancing for the duration of a transaction.
Example 20.290. Using master to execute transactions
{
"myapp": {
"master": {
"master_0": {
"host": "localhost"
}
},
"slave": {
"slave_0": {
"host": "192.168.78.136",
"port": "3306"
}
},
"trx_stickiness": "master"
}
}
Since version 1.5.0 automatic and silent failover is disabled for
the duration of a transaction. If the boundaries of a transaction
have been properly detected, transaction stickiness is enabled
and a server fails, the plugin will not attempt to fail over to the next
server, if any, regardless of the failover policy configured. The user
must handle the error manually. Depending on the configuration,
the plugin may emit an error of type
E_WARNING
reading like
(mysqlnd_ms) Automatic failover is not permitted
in the middle of a transaction
. This error may then
be overwritten by follow up errors such as
(mysqlnd_ms) No
connection selected by the last filter
. Those errors
will be generated by the failing query function.
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 ...