一些锟街诧拷式锟斤拷锟斤拷锟捷匡拷群锟斤拷使锟矫短达拷锟斤拷一锟斤拷锟教达拷锟斤拷只锟斤拷一锟斤拷时锟斤拷锟节碉拷一锟斤拷锟斤拷时锟斤拷锟斤拷 锟斤拷一锟斤拷锟侥讹拷一锟铰o拷锟斤拷锟街猴拷锟皆短达拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷同一锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟斤拷薪锟斤拷谐锟斤拷锟斤拷锟� 锟斤拷全锟侥o拷锟斤拷锟皆达拷锟斤拷钥突锟斤拷瞬锟斤拷锟斤拷锟接帮拷臁o拷突锟斤拷私锟斤拷锟斤拷岜伙拷锟斤拷锟街癸拷锟斤拷堑墓锟斤拷锟斤拷锟斤拷锟斤拷锟饺ワ拷锟斤拷锟� 锟斤拷锟斤拷一锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟斤拷拇锟斤拷锟斤拷锟斤拷墙锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷源锟斤拷锟斤拷锟斤拷锟窖拷锟斤拷锟斤拷锟斤拷锟斤拷锟揭拷却锟斤拷锟斤拷锟� 锟斤拷息锟斤拷失锟斤拷锟斤拷锟界,锟斤拷使锟斤拷 MySQL Cluster时锟斤拷锟斤拷锟皆匡拷锟斤拷锟斤拷锟街短达拷锟斤拷锟斤拷息锟斤拷锟斤拷锟角诧拷锟斤拷锟结被 锟斤拷锟斤拷锟截讹拷锟斤拷群锟斤拷锟斤拷锟斤拷锟斤拷锟叫★拷
锟斤拷锟斤拷锟斤拷锟斤拷峁╋拷诙檀锟斤拷锟斤拷械锟斤拷远锟斤拷锟斤拷源锟斤拷锟窖拷锟斤拷锟斤拷饨拷锟竭分诧拷锟斤拷锟斤拷锟酵革拷锟斤拷龋锟斤拷锟斤拷叶锟斤拷锟� 应锟矫筹拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟揭恢憋拷锟斤拷锟斤拷菘锟斤拷锟斤拷群锟斤拷执锟叫憋拷酶锟斤拷蛹虻ァ锟�
锟皆讹拷锟侥筹拷锟斤拷循锟斤拷锟斤拷锟斤拷锟斤拷锟较的筹拷锟皆o拷直锟斤拷锟矫伙拷锟斤拷锟斤拷锟侥硷拷指锟斤拷锟侥达拷锟斤拷锟斤拷锟斤拷锟揭革拷锟斤拷锟斤拷锟斤拷指锟斤拷锟斤拷 锟斤拷锟绞憋拷锟斤拷锟叫讹拷锟捷的等达拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟窖拷锟斤拷锟斤拷锟斤拷锟斤拷锟绞э拷锟接︼拷贸锟斤拷蚪锟斤拷锟斤拷倏锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷息锟斤拷锟斤拷锟斤拷锟斤拷锟矫伙拷锟斤拷锟绞э拷锟斤拷锟斤拷蠼锟斤拷峤伙拷锟接︼拷贸锟斤拷锟斤拷锟叫达拷锟斤拷
锟斤拷锟斤拷姆锟斤拷锟斤拷校锟絛uplicate key 锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷锟结交锟斤拷应锟矫筹拷锟斤拷锟斤拷前锟斤拷锟结被锟斤拷锟皆达拷锟斤拷 2 锟轿o拷 锟斤拷锟轿筹拷锟斤拷之锟斤拷锟斤拷 100 ms锟斤拷
Example #1 Provoking a transient error
mysqlnd_ms.enable=1 mysqlnd_ms.collect_statistics=1
{ "myapp": { "master": { "master_0": { "host": "localhost" } }, "slave": { "slave_0": { "host": "192.168.78.136", "port": "3306" } }, "transient_error": { "mysql_error_codes": [ 1062 ], "max_retries": 2, "usleep_retry": 100 } } }
Example #2 锟教达拷锟斤拷锟斤拷循锟斤拷
<?php
$mysqli = new mysqli("myapp", "username", "password", "database");
if (mysqli_connect_errno())
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
!$mysqli->query("CREATE TABLE test(id INT PRIMARY KEY)") ||
!$mysqli->query("INSERT INTO test(id) VALUES (1))")) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
}
/* Retry loop is completely transparent. Checking statistics is
the only way to know about implicit retries */
$stats = mysqlnd_ms_get_stats();
printf("Transient error retries before error: %d\n", $stats['transient_error_retries']);
/* Provoking duplicate key error to see statistics change */
if (!$mysqli->query("INSERT INTO test(id) VALUES (1))")) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
}
$stats = mysqlnd_ms_get_stats();
printf("Transient error retries after error: %d\n", $stats['transient_error_retries']);
$mysqli->close();
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
Transient error retries before error: 0 [1062] Duplicate entry '1' for key 'PRIMARY' Transient error retries before error: 2
Because the execution of the retry loop is transparent from a users point of view, the example checks the statistics provided by the plugin to learn about it.
As the example shows, the plugin can be instructed to consider any error
transient regardless of the database servers error semantics. The only error
that a stock MySQL server considers temporary has the error code
1297
. When configuring other error codes but
1297
make sure your configuration reflects
the semantics of your clusters error codes.
The following mysqlnd C API calls are monitored by the plugin to check for transient errors: query(), change_user(), select_db(), set_charset(), set_server_option() prepare(), execute(), set_autocommit(), tx_begin(), tx_commit(), tx_rollback(), tx_commit_or_rollback(). The corresponding user API calls have similar names.
The maximum time the plugin may sleep during the retry loop depends on the function in question. The a retry loop for query(), prepare() or execute() will sleep for up to max_retries * usleep_retry milliseconds.
However, functions that control connection state are dispatched to all all connections. The retry loop settings are applied to every connection on which the command is to be run. Thus, such a function may interrupt program execution for longer than a function that is run on one server only. For example, set_autocommit() is dispatched to connections and may sleep up to (max_retries * usleep_retry) * number_of_open_connections) milliseconds. Please, keep this in mind when setting long sleep times and large retry numbers. Using the default settings of max_retries=1, usleep_retry=100 and lazy_connections=1 it is unlikely that you will ever see a delay of more than 1 second.