作者:侯曉陽
愛可生 DBA 團隊成員,主要負責 MySQL 故障處理和 SQL 審核優化。對技術執著,為客戶負責。
本文來源:原創投稿
*愛可生開源社區出品,原創內容未經授權不得隨意使用,轉載請聯系小編并注明來源。
問題背景
MySQL 從庫報錯如下:
錯誤信息如下:
...
Last_Errno:1317
Last_Error:Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction 'a838ba08-c009-11e9-85e1-fa163ea2992d:31622919405' at master log master-bin.005599, end_log_pos 2297. See error log and/or performance_schema.replication_Applier_status_by_worker table for more details about this failure or others, if any.
...
Last_SQL_Errno:1317
Last_SQL_Error:Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction 'a838ba08-c009-11e9-85e1-fa163ea2992d:31622919405' at master log master-bin.005599, end_log_pos 2297. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
排查方式
1.首先我們先通過 performance_schema 查看一下造成報錯的原因
mysql> select * from performance_schema.replication_applier_status_by_worker;
從這里報錯看到,某條語句在回放的時候查詢執行被中斷了。
2.然后我們再查看 MySQL 的 error-log
日志中也提示了我們,因為工作線程被斷開,查詢中斷,它在當前這個位置點停止了,如果想要恢復重新啟動主從即可。
3.嘗試重新啟動主從
mysql> stop slave;
mysql> start slave;
重啟復制通道后,復制確實正常了,接下來需要知道為什么查詢被中斷了。
4.帶著疑問,去看了下在報錯的這個時間里 MySQL 或是服務器做了什么,然后發現了這個時間 MySQL 在做備份,之后查看 xtrabackup 備份參數是帶著 --kill-long-queries-timeout=60 和 --kill-long-query-type=all。
簡單來說就是,當 --kill-long-query-type=all,--kill-long-queries-timeout=60,從開始執行 FLUSH TABLES WITH READ LOCK 到 kill 掉阻塞它的這些查詢之間等待的秒數為 60 秒,默認值為 0,不會 kill 任何查詢,使用這個選項 xtrabackup 需要有 Process 和 super 權限。
5.然后查看 xtrabackup 的備份日志,一切答案見了分曉






