{"id":461,"date":"2013-12-07T13:26:25","date_gmt":"2013-12-07T05:26:25","guid":{"rendered":"http:\/\/www.gpfeng.com\/?p=461"},"modified":"2014-06-08T10:42:42","modified_gmt":"2014-06-08T02:42:42","slug":"%e4%bd%bf%e7%94%a8dbug_sync%e6%8e%92%e6%9f%a5mysql-truncate%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.gpfeng.com\/?p=461","title":{"rendered":"\u4f7f\u7528DEBUG_SYNC\u6392\u67e5MySQL truncate\u95ee\u9898"},"content":{"rendered":"<h3>\u7ebf\u4e0a\u95ee\u9898<\/h3>\n<p>DBA\u7528\u811a\u672c\u53d1\u9001truncate\u64cd\u4f5c\u6e05\u7406MySQL\u8868\u4e2d\u6570\u636e\uff0c\u811a\u672c\u6267\u884c\u4e00\u6bb5\u65f6\u95f4\u4f7f\u7528ctrl+c\u60f3\u53d6\u6d88\u64cd\u4f5c\uff0c\u5374\u5bfc\u81f4slave\u540c\u6b65binlog\u540e\u6570\u636e\u4e0d\u4e00\u81f4\uff0c\u590d\u5236\u4e2d\u65ad\uff0c\u4e4b\u540e\u901a\u8fc7select\u53d1\u73b0master\u8868\u4e2d\u6570\u636e\u4f9d\u65e7\u5b58\u5728\uff0c\u4f46\u662ftruncate\u5bf9\u5e94\u7684binlog\u88ab\u8bb0\u5f55\u8bb0\u5f55\uff0c\u800cslave\u4e2d\u7684\u8868\u6570\u636e\u88ab\u6e05\u7406\uff0c\u56e0\u4e3abinlog\u590d\u5236\u8fc7\u6765\u540etruncate\u64cd\u4f5c\u6267\u884c\u6210\u529f<\/p>\n<h3>\u91cd\u73b0\u95ee\u9898<\/h3>\n<p>\u8fd9\u4e2a\u95ee\u9898\u6bd4\u8f83\u8be1\u5f02\uff0ctruncate\u5b9e\u9645\u4e0a\u662f\u5931\u8d25\uff0c\u4f46\u662fbinlog\u8bb0\u5f55\u4e0b\u6765\uff0c\u6211\u4eec\u77e5\u9053binlog\u8bb0\u5f55\u4e00\u4e2a\u5b8c\u6574\u4e8b\u52a1\uff0c\u53ea\u6709\u5f53\u4e8b\u52a1\u6210\u529f\u6267\u884c\u5b8c\u624d\u4f1a\u5199binlog\uff0c\u53ea\u6709\u95ee\u9898\u80fd\u591f\u91cd\u73b0\u624d\u53ef\u80fd\u627e\u5230\u539f\u56e0\uff0c\u9042\u6d4b\u8bd5truncate\u53d1\u9001\u540e\u9a6c\u4e0actrl+c\u53d6\u6d88\uff0c\u7136\u800c\u6bcf\u6b21truncate\u90fd\u6210\u529f\uff0c\u8868\u4e2d\u6570\u636e\u88ab\u6e05\u7406\uff0cbinlog\u4e5f\u8bb0\u5f55\u4e0b\u6765\uff0c\u540e\u6765\u601d\u8003DBA\u5f53\u65f6\u4f7f\u7528\u7684\u662f\u811a\u672c\uff0c\u53d1\u9001\u7684\u662f\u591a\u6761truncat\u64cd\u4f5c\uff0c\u8fd9\u6837\u7684\u8bdd\u53ef\u4ee5\u8ba9truncate\u6267\u884c\u8fc7\u7a0b\u4e2d\u88ab\u6253\u65ad\u7684\u4f4d\u7f6e\u5c3d\u53ef\u80fd\u7684\u591a\uff0c\u8fd9\u6837\u590d\u73b0\u95ee\u9898\u7684\u53ef\u80fd\u6027\u4e5f\u9ad8\u4e00\u4e9b\uff0c\u7ecf\u8fc7\u591a\u8f6e\u5c1d\u8bd5\uff0c\u7ec8\u4e8e\u91cd\u73b0\u4e86\uff1a<!--more--><\/p>\n<h4>\u6267\u884ctruncate\u811a\u672c\u5e76ctrl+c\u53d6\u6d88<\/h4>\n<pre lang=\"mysql\">\r\nmysql -uroot -Nse \"show tables in tt;\"|while read table; do mysql -uroot -e \"truncate tt.$table\";done\r\nCtrl-C -- query aborted.\r\n^CCtrl-C -- sending \"KILL 230\" to server ...\r\nCtrl-C -- query aborted.\r\nERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query\r\n^CCtrl-C -- sending \"KILL QUERY 233\" to server ...\r\nCtrl-C -- query aborted.\r\nERROR 1317 (70100) at line 1: Query execution was interrupted\r\n^CCtrl-C -- sending \"KILL QUERY 235\" to server ...\r\nCtrl-C -- query aborted.\r\n<\/pre>\n<h4>\u67e5\u770bbinlog<\/h4>\n<pre lang=\"mysql\">\r\nroot@tt 09:19:11>show binlog events in 'mysql-bin.000174';\r\n+------------------+-----+-------------+------------+-------------+--------------------------------------------+\r\n| Log_name         | Pos | Event_type  | Server_id  | End_log_pos | Info                                       |\r\n+------------------+-----+-------------+------------+-------------+--------------------------------------------+\r\n| mysql-bin.000174 |   4 | Format_desc | 2552760298 |         107 | Server ver: 5.5.18.2-tb-log, Binlog ver: 4 |\r\n| mysql-bin.000174 | 107 | Query       | 2552760298 |         180 | truncate tt.t1                             |\r\n| mysql-bin.000174 | 180 | Query       | 2552760298 |         254 | truncate tt.t10                            |\r\n| mysql-bin.000174 | 254 | Query       | 2552760298 |         327 | truncate tt.t4                             |\r\n| mysql-bin.000174 | 327 | Query       | 2552760298 |         400 | truncate tt.t2                             |\r\n| mysql-bin.000174 | 400 | Query       | 2552760298 |         473 | truncate tt.t3                             |\r\n| mysql-bin.000174 | 473 | Query       | 2552760298 |         546 | truncate tt.t5                             |\r\n| mysql-bin.000174 | 546 | Query       | 2552760298 |         619 | truncate tt.t7                             |\r\n| mysql-bin.000174 | 619 | Query       | 2552760298 |         692 | truncate tt.t6                             |\r\n| mysql-bin.000174 | 692 | Query       | 2552760298 |         765 | truncate tt.t8                             |\r\n| mysql-bin.000174 | 765 | Query       | 2552760298 |         838 | truncate tt.t9                             |\r\n+------------------+-----+-------------+------------+-------------+--------------------------------------------+\r\n<\/pre>\n<h4>\u67e5\u770b\u8868\u4e2d\u6570\u636e\u91cf<\/h4>\n<pre lang=\"mysql\">\r\nmysql -uroot -Nse \"show tables in tt;\"|while read table; do echo -e $table'\\t'`mysql -uroot -e \"select count(*) as rows from tt.$table\"`;done\r\nt1      rows 0\r\nt10     rows 0\r\nt2      rows 0\r\nt3      rows 69108864\r\nt4      rows 2000000\r\nt5      rows 2000000\r\nt6      rows 2000000\r\nt7      rows 2000000\r\nt8      rows 0\r\nt9      rows 0\r\n<\/pre>\n<h3>\u5206\u6790\u95ee\u9898<\/h3>\n<p>\u95ee\u9898\u5f97\u5230\u91cd\u73b0\uff0c\u5c31\u79bb\u627e\u5230\u539f\u56e0\u548c\u89e3\u51b3\u529e\u6cd5\u4e0d\u8fdc\u4e86\uff0c\u96be\u63a9\u5fc3\u4e2d\u6fc0\u52a8\uff0c\u4ece\u53d1\u9001ctrl+c\u51fa\u53d1\u5206\u6790\uff1a\u4ece\u4e0a\u6765\u7684log\u6765\u770b\uff0cctrl+c\u5b9e\u9645\u4e0a\u53d1\u9001\u4e86kill query\u5230server\uff0c\u5728\u4ee3\u7801\u4e2d\u4e5f\u8bc1\u5b9e\u4e86\uff0c\u800ckill query\u505a\u7684\u4e8b\u60c5\u5f88\u7b80\u5355\uff1a\u5c06\u5bf9\u5e94thd\u7684killed\u6210\u5458\u7f6e\u4e3aTHD::KILL_QUERY\uff08sql_kill\u51fd\u6570\uff09\uff0c\u56e0\u6b64\u53ef\u4ee5\u731c\u6d4b\u53ef\u80fd\u7684\u539f\u56e0\uff1atruncate\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0csql_kill\u5c06thd->killed\u7f6e\u4e3aTHD::KILL_QUERY\uff0ctruncate\u5728\u67d0\u5904\u68c0\u67e5thd\u7684killed\u72b6\u6001\uff0c\u53d1\u73b0\u95ee\u9898\u5bfc\u81f4\u9000\u51fa\uff0c\u7528gdb\u8ddf\u8e2a\u4ee3\u7801\u8def\u5f84\uff1a<\/p>\n<pre lang=\"c\">\r\n#0  Truncate_statement::handler_truncate (this=<value optimized out>, thd=0x78c11480, table_ref=0x2ba5dc004c30, is_tmp_table=<value optimized out>)\r\n    at sql\/sql_truncate.cc:226\r\n#1  0x00000000007a9c20 in Truncate_statement::truncate_table (this=0x2ba5dc005160, thd=0x78c11480, table_ref=0x2ba5dc004c30)\r\n    at sql\/sql_truncate.cc:475\r\n#2  0x00000000007a9cde in Truncate_statement::execute (this=0x2ba5dc005160, thd=0x78c11480) at sql\/sql_truncate.cc:529\r\n#3  0x0000000000587a1e in mysql_execute_command (thd=0x78c11480) at sql\/sql_parse.cc:4813\r\n#4  0x000000000058a094 in mysql_parse (thd=0x78c11480, rawbuf=<value optimized out>, length=11, parser_state=0x2ba5d807fbd0)\r\n    at sql\/sql_parse.cc:6047\r\n#5 0x000000000058bfce in dispatch_command (command=COM_QUERY, thd=0x78c11480, packet=0x2ba5d807fcb8 \"\", packet_length=11)\r\n<\/pre>\n<p>\u5728Truncate_statement::truncate_table\u4e2d\u53d1\u73b0\u4e86\u53ef\u80fd\u539f\u56e0\uff1a<\/p>\n<pre lang=\"mysql\">\r\n    ...\r\n    error= handler_truncate(thd, table_ref, FALSE);\r\n    binlog_stmt= !error || error != HA_ERR_WRONG_COMMAND;\r\n  ...\r\n  \/* DDL is logged in statement format, regardless of binlog format. *\/\r\n  if (binlog_stmt)\r\n    error|= write_bin_log(thd, !error, thd->query(), thd->query_length());\r\n  ...\r\n<\/pre>\n<p>\u5728handler_truncate\u6267\u884c\u5931\u8d25\u65f6\uff08\u6267\u884c\u6210\u529f\u8fd4\u56de0\uff09\uff0c\u5982\u679c\u8fd4\u56de\u503c\u4e0d\u4e3aHA_ERR_WRONG_COMMAND\uff0c\u4f1a\u5bfc\u81f4binlog\u88ab\u8bb0\u5f55\u4e0b\u6765\uff0c\u5373\u51fa\u73b0\u6587\u7ae0\u5f00\u5934\u7684\u95ee\u9898\uff0c\u8fdb\u5165\u5230handler_truncate\u4e2d\u7ee7\u7eed\u5206\u6790\uff1a<\/p>\n<pre lang=\"c\">\r\n\/*\r\n  Open and truncate a locked table.\r\n\r\n  @param  thd           Thread context.\r\n  @param  table_ref     Table list element for the table to be truncated.\r\n  @param  is_tmp_table  True if element refers to a temp table.\r\n\r\n  @retval  0    Success.\r\n  @retval  > 0  Error code.\r\n*\/\r\nint Truncate_statement::handler_truncate(THD *thd, TABLE_LIST *table_ref,\r\n                                         bool is_tmp_table)\r\n{\r\n  ...\r\n  \/* Open the table as it will handle some required preparations. *\/\r\n  if (open_and_lock_tables(thd, table_ref, FALSE, flags))\r\n    DBUG_RETURN(1);\r\n\r\n  \/* Whether to truncate regardless of foreign keys. *\/\r\n  if (! (thd->variables.option_bits & OPTION_NO_FOREIGN_KEY_CHECKS))\r\n    error= fk_truncate_illegal_if_parent(thd, table_ref->table);\r\n\r\n  if (!error && (error= table_ref->table->file->ha_truncate()))\r\n    table_ref->table->file->print_error(error, MYF(0));\r\n  ...\r\n<\/pre>\n<p>table->file->ha_truncate()\u624d\u662f\u771f\u6b63\u8fdb\u5165\u5230storage engine\u5c42\uff0c\u4e00\u822c\u8fdb\u5165\u5230innodb\u5c42\u540e\u5c31\u57fa\u672c\u4e0d\u68c0\u67e5thd->killed\u72b6\u6001\u4e86\uff0c\u8fd9\u91cc\u627e\u5230\u4e86\u4e00\u4e2a\u53ef\u7591\u7684\u70b9\uff1aopen_and_lock_tables\uff0c\u5982\u679c\u6b64\u5904\u6267\u884c\u5931\u8d25\uff0chandler_truncate\u8fd4\u56de1\uff08\u4e0d\u4e3aHA_ERR_WRONG_COMMAND\uff09\uff0cTruncate_statement::truncate_table\u4e2d\u7684binlog_stmt\u4e3a1\uff0c\u6700\u7ec8\u5bfc\u81f4\u7684\u7ed3\u679c\u548c\u6211\u4eec\u9047\u5230\u7684\u95ee\u9898\u5b8c\u5168\u7b26\u5408\uff0c\u9700\u8981\u786e\u8ba4\uff0c\u8ddf\u7740\u4ee3\u7801\u7ee7\u7eed\u8ddf\u8e2a\uff0c\u627e\u5230\u4e86\u5bfc\u81f4\u95ee\u9898\u7684backtrace\uff1a<\/p>\n<pre lang=\"c\">\r\n#0  open_table (thd=0x78c11480, table_list=0x2ba5dc004c30, mem_root=0x2ba5d807e3d0, ot_ctx=0x2ba5d807e410) at sql\/sql_base.cc:2683\r\n#1  0x000000000054d5c1 in open_and_process_table (thd=0x78c11480, start=0x2ba5d807e498, counter=0x2ba5d807e4bc, flags=130, prelocking_strategy=0x2ba5d807e5f0)\r\n    at sql\/sql_base.cc:4482\r\n#2  open_tables (thd=0x78c11480, start=0x2ba5d807e498, counter=0x2ba5d807e4bc, flags=130, prelocking_strategy=0x2ba5d807e5f0)\r\n    at sql\/sql_base.cc:4930\r\n#3  0x000000000054e194 in open_and_lock_tables (thd=<value optimized out>, tables=0x2ba5dc004c30, derived=false, flags=130, \r\n    prelocking_strategy=<value optimized out>) at sql\/sql_base.cc:5527\r\n#4  0x00000000007a93f9 in open_and_lock_tables (this=<value optimized out>, thd=0x78c11480, table_ref=0x2ba5dc004c30, is_tmp_table=<value optimized out>)\r\n    at sql\/sql_base.h:475\r\n#5  Truncate_statement::handler_truncate (this=<value optimized out>, thd=0x78c11480, table_ref=0x2ba5dc004c30, is_tmp_table=<value optimized out>)\r\n    at sql\/sql_truncate.cc:226\r\n#6  0x00000000007a9c20 in Truncate_statement::truncate_table (this=0x2ba5dc005160, thd=0x78c11480, table_ref=0x2ba5dc004c30)\r\n    at sql\/sql_truncate.cc:475\r\n#7  0x00000000007a9cde in Truncate_statement::execute (this=0x2ba5dc005160, thd=0x78c11480) at sql\/sql_truncate.cc:529\r\n#8  0x0000000000587a1e in mysql_execute_command (thd=0x78c11480) at sql\/sql_parse.cc:4813\r\n#9  0x000000000058a094 in mysql_parse (thd=0x78c11480, rawbuf=<value optimized out>, length=11, parser_state=0x2ba5d807fbd0)\r\n    at sql\/sql_parse.cc:6047\r\n#10 0x000000000058bfce in dispatch_command (command=COM_QUERY, thd=0x78c11480, packet=0x2ba5d807fcb8 \"\", packet_length=11)\r\n    at sql\/sql_parse.cc:1273\r\n<\/pre>\n<p>\u800c\u5728open_table\u4e2d\u627e\u5230\u4e86\u8bc1\u636e\uff1a<\/p>\n<pre lang=\"c\">\r\n  ...\r\n  \/* an open table operation needs a lot of the stack space *\/\r\n  if (check_stack_overrun(thd, STACK_MIN_SIZE_FOR_OPEN, (uchar *)&alias))\r\n    DBUG_RETURN(TRUE);\r\n\r\n  if (thd->killed)\r\n    DBUG_RETURN(TRUE);\r\n  ...\r\n<\/pre>\n<p>\u56e0\u6b64\u8ddf\u8e2a\u6e90\u7801\u627e\u5230\u4e86\u4e00\u4e2a\u53ef\u80fd\u7684\u89e3\u91ca\uff1atruncate table\u6267\u884c\u8fc7\u7a0b\u4e2dctrl+c\u5c06\u5bfc\u81f4thd->killed\u88ab\u8bbe\u7f6e\uff0copen_table\u5728thd->killed\u7684\u60c5\u51b5\u4e0b\u8fd4\u56deTRUE\uff0c\u6700\u7ec8\u4f1a\u5bfc\u81f4Truncate_statement::handler_truncate\u51fd\u6570\u5728\u6267\u884ctable->file->ha_truncate()\u4e4b\u524d\u63d0\u524d\u8fd4\u56deTRUE<\/p>\n<h3>DEBUG_SYNC\u8fd8\u539f\u95ee\u9898<\/h3>\n<p>\u4ee5\u4e0a\u662f\u4e00\u4e2a\u5408\u7406\u7684\u89e3\u91ca\uff0c\u4f46\u662f\u9700\u8981\u5c06\u95ee\u9898\u8fd8\u539f\u51fa\u6765\u4ee5\u8bc1\u660e\u731c\u6d4b\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981DEBUG_SYNC\u4e86\uff0c\u5728Truncate_statement::handler_truncate\u4e2dopen_and_lock_tables\u4e4b\u524d\u6dfb\u52a0\u4e00\u4e2aDEBUG_SYNC\u70b9before_open_and_lock_tables\uff0c\u5728sql_kill\u4e4b\u540e\u589e\u52a0\u4e00\u4e2aDEBUG_SYNC\u70b9after_kill\uff0c\u7ebf\u7a0b1\u6267\u884ctruncate\uff0c\u5728before_open_and_lock_tables\u5904\u7b49\u5f85\uff0c\u76f4\u5230\u7ebf\u7a0b2\u6267\u884c\u5230after_kill\uff0c\u4e4b\u540e\u7ebf\u7a0b1\u7ee7\u7eed\u6267\u884c<\/p>\n<pre lang=\"c\">\r\nIndex: sql\/sql_parse.cc\r\n===================================================================\r\n--- sql\/sql_parse.cc    (revision 4589)\r\n+++ sql\/sql_parse.cc    (working copy)\r\n@@ -4109,6 +4109,7 @@\r\n       goto error;\r\n     }\r\n     sql_kill(thd, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY);\r\n+    DEBUG_SYNC(thd, \"after_kill\");\r\n     break;\r\n   }\r\n #ifndef NO_EMBEDDED_ACCESS_CHECKS\r\nIndex: sql\/sql_truncate.cc\r\n===================================================================\r\n--- sql\/sql_truncate.cc (revision 4589)\r\n+++ sql\/sql_truncate.cc (working copy)\r\n@@ -222,6 +222,8 @@\r\n     table_ref->mdl_request.ticket= NULL;\r\n   }\r\n \r\n+  DEBUG_SYNC(thd, \"before_open_and_lock_tables\");\r\n+\r\n   \/* Open the table as it will handle some required preparations. *\/\r\n   if (open_and_lock_tables(thd, table_ref, FALSE, flags))\r\n     DBUG_RETURN(1);\r\n<\/pre>\n<p>\u6784\u9020test case\uff1atruncate_bug.test<\/p>\n<pre lang=\"mysql\">\r\nsource include\/have_binlog_format_row_or_statement.inc;\r\n\r\nconnection default;\r\nuse test;\r\ncreate table t1(id int auto_increment primary key, a int, b int) engine=innodb;\r\ninsert into t1(a, b) values(1,2),(2,4),(3,6),(4,8),(5,10);\r\nset debug_sync = \"before_open_and_lock_tables signal truncate_before_lock wait_for kill_finish\";\r\nsend truncate t1; \r\n\r\n  connect(con1,localhost,root,,);\r\n  connection con1;\r\n  set debug_sync = \"now wait_for truncate_before_lock\";\r\n  set debug_sync = \"after_kill signal kill_finish\";\r\n  send kill query 2;\r\n\r\nconnection default;\r\n--ERROR 1317\r\nreap;\r\n\r\nconnection con1;\r\nreap;\r\nshow binlog events in \"master-bin.000001' from 107;                         \r\nselect * from t1; \r\ndrop table t1; \r\n<\/pre>\n<p>\u5728mysql-test\u4e0b\u6267\u884ctest case:<br \/>\n.\/mtr &#8211;record truncate_bug<br \/>\n\u67e5\u770b\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n<pre lang=\"mysql\">\r\nuse test;\r\ncreate table t1(id int auto_increment primary key, a int, b int) engine=innodb;\r\ninsert into t1(a, b) values(1,2),(2,4),(3,6),(4,8),(5,10);\r\nset debug_sync = \"before_open_and_lock_tables signal truncate_before_lock wait_for kill_finish\";\r\ntruncate t1; \r\nset debug_sync = \"now wait_for truncate_before_lock\";\r\nset debug_sync = \"after_kill signal kill_finish\";\r\nkill query 2;\r\nERROR 70100: Query execution was interrupted                                                                                          \r\nshow binlog events in 'master-bin.000001' from 107;\r\nLog_name        Pos     Event_type      Server_id       End_log_pos     Info\r\nmaster-bin.000001       107     Query   1       248     use `test`; create table t1(id int auto_increment primary key, a int, b int) e\r\nngine=innodb\r\nmaster-bin.000001       248     Query   1       316     BEGIN\r\nmaster-bin.000001       316     Intvar  1       344     INSERT_ID=1\r\nmaster-bin.000001       344     Query   1       464     use `test`; insert into t1(a, b) values(1,2),(2,4),(3,6),(4,8),(5,10)\r\nmaster-bin.000001       464     Xid     1       491     COMMIT \/* xid=16 *\/\r\nselect * from t1; \r\nid      a       b   \r\n1       1       2   \r\n2       2       4   \r\n3       3       6   \r\n4       4       8   \r\n5       5       10  \r\ndrop table t1;\r\n<\/pre>\n<p>\u89c2\u5bdf\u5230\uff1abinlog\u4e2dtruncate\u88ab\u8bb0\u5f55\u4e0b\u6765\uff0c\u800c\u8868\u4e2d\u6570\u636e\u4f9d\u65e7\u5b58\u5728\uff0c\u9a8c\u8bc1\u4e86\u731c\u60f3\u662f\u6b63\u786e\u7684\uff0c\u95ee\u9898\u51fa\u5728ctrl+c\u5bfc\u81f4Truncate_statement::handler_truncate\u4e2dopen_and_lock_tables\u8fd4\u56de1\uff0c\u627e\u5230\u539f\u56e0\u540e\uff0c\u4fee\u590d\u5c31\u5f88\u7b80\u5355\u4e86\uff0c\u6700\u7b80\u5355\u7684\u4fee\u590d\uff1a\u5c06open_and_lock_tables\u5931\u8d25\u8fd4\u56de1\u6539\u6210\u8fd4\u56deHA_ERR_WRONG_COMMAND\uff1b\u590d\u6742\u4e00\u70b9\u7684\u4fee\u590d\uff1aopen_and_lock_tables\u8fd4\u56de\u4e00\u4e2a\u8d1f\u6570\uff0c\u5728Truncate_statement::truncate_table\u4e2d\u589e\u52a0\u76f8\u5e94\u7684\u5224\u65ad\uff1a<\/p>\n<pre lang=\"c\">\r\nbinlog_stmt= !error || (error > 0 && error != HA_ERR_WRONG_COMMAND);\r\n<\/pre>\n<p>\u4e8e\u662f\u5411\u5b98\u65b9report\u4e86\u4e00\u4e2abug\u5e76\u63d0\u4f9b\u4e86fast fix\uff1a<a href=\"http:\/\/bugs.mysql.com\/bug.php?id=71070\">MySQL bug#71070<\/a><\/p>\n<h3>truncate\u8fdb\u5165innodb\u540e\u8fd8\u53ef\u4ee5\u901a\u8fc7ctrl+c\u6216\u8005kill\u53d6\u6d88\u5417\uff1f<\/h3>\n<p>\u6709\u4e86\u4e0a\u9762\u7684\u57fa\u7840\uff0c\u9a8c\u8bc1\u8fd9\u4e2a\u5c31\u5f88easy\u4e86\uff0c\u5728Truncate_statement::handler_truncate\u4e2dopen_and_lock_tables\u4e4b\u540e\u589e\u52a0\u4e00\u4e2aDEBUG_SYNC\u70b9after_open_and_lock_tables\uff0c\u7136\u540e\u6267\u884c\u4e0b\u9762\u7684test case\uff1a<\/p>\n<pre lang=\"mysql\">\r\nsource include\/have_binlog_format_row_or_statement.inc;\r\n\r\nconnection default;\r\nuse test;\r\ncreate table t1(id int auto_increment primary key, a int, b int) engine=innodb;\r\ninsert into t1(a, b) values(1,2),(2,4),(3,6),(4,8),(5,10);\r\nset debug_sync = \"after_open_and_lock_tables signal truncate_after_lock wait_for kill_finish\";\r\nsend truncate t1; \r\n\r\n  connect(con1,localhost,root,,);\r\n  connection con1;\r\n  set debug_sync = \"now wait_for truncate_after_lock\";\r\n  set debug_sync = \"after_kill signal kill_finish\";\r\n  send kill query 2;\r\n\r\nconnection default;\r\n#--ERROR 1317;                                                                                                         \r\nreap;\r\n\r\nconnection con1;\r\nreap;\r\n# ignore the first binlog\r\nshow binlog events in 'master-bin.000001' from 107;\r\nselect * from t1; \r\ndrop table t1;\r\n<\/pre>\n<p>\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n<pre lang=\"mysql\">\r\nuse test;\r\ncreate table t1(id int auto_increment primary key, a int, b int) engine=innodb;\r\ninsert into t1(a, b) values(1,2),(2,4),(3,6),(4,8),(5,10);\r\nset debug_sync = \"after_open_and_lock_tables signal truncate_after_lock wait_for kill_finish\";\r\ntruncate t1; \r\nset debug_sync = \"now wait_for truncate_after_lock\";\r\nset debug_sync = \"after_kill signal kill_finish\";\r\nkill query 2;\r\nshow binlog events in 'master-bin.000001' from 107;                                                                                   \r\nLog_name        Pos     Event_type      Server_id       End_log_pos     Info\r\nmaster-bin.000001       107     Query   1       248     use `test`; create table t1(id int auto_increment primary key, a int, b int) e\r\nngine=innodb\r\nmaster-bin.000001       248     Query   1       316     BEGIN\r\nmaster-bin.000001       316     Intvar  1       344     INSERT_ID=1\r\nmaster-bin.000001       344     Query   1       464     use `test`; insert into t1(a, b) values(1,2),(2,4),(3,6),(4,8),(5,10)\r\nmaster-bin.000001       464     Xid     1       491     COMMIT \/* xid=16 *\/\r\nmaster-bin.000001       491     Query   1       565     use `test`; truncate t1\r\nselect * from t1; \r\nid      a       b   \r\ndrop table t1;\r\n<\/pre>\n<h4>\u7ed3\u8bba<\/h4>\n<p>\u4e00\u65e6truncate\u64cd\u4f5c\u6267\u884c\u5b8c\u4e86open_table_and_lock_tables\u8fdb\u5165\u5230innodb\u5c42\uff0c\u901a\u8fc7kill\u6216\u8005ctrl+c\u662f\u65e0\u6cd5\u53d6\u6d88\u7684\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ebf\u4e0a\u95ee\u9898 DBA\u7528\u811a\u672c\u53d1\u9001truncate\u64cd\u4f5c\u6e05\u7406MySQL\u8868\u4e2d\u6570\u636e\uff0c\u811a\u672c\u6267\u884c\u4e00\u6bb5\u65f6\u95f4\u4f7f\u7528ctrl+c\u60f3\u53d6\u6d88\u64cd &hellip; <a href=\"http:\/\/www.gpfeng.com\/?p=461\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u4f7f\u7528DEBUG_SYNC\u6392\u67e5MySQL truncate\u95ee\u9898<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3tPZp-7r","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/461"}],"collection":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=461"}],"version-history":[{"count":12,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":651,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/461\/revisions\/651"}],"wp:attachment":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}