1###############################################################################
2# Bug#17942050:KILL OF TRUNCATE TABLE WILL LEAD TO BINARY LOG WRITTEN WHILE
3# ROWS REMAINS
4#
5# Problem:
6# ========
7# When truncate table fails while using transactional based engines even
8# though the operation errors out we still continue and log it to binlog.
9# Because of this master has data but the truncate will be written to binary
10# log which will cause inconsistency.
11#
12# Test:
13# =====
14# Make master to wait in "open_table" call during the execution of truncate
15# table command and kill the truncate table from other connection. This causes
16# open table to return an error saying truncate failed during open table. This
17# statement should not be binlogged.
18###############################################################################
19--source include/have_innodb.inc
20--source include/have_debug_sync.inc
21--source include/have_binlog_format_statement.inc
22RESET MASTER;
23--connection default
24CREATE TABLE t1(id INT AUTO_INCREMENT PRIMARY KEY, a INT, b INT) ENGINE=INNODB;
25INSERT INTO t1(a, b) VALUES(1,2),(2,4),(3,6),(4,8),(5,10);
26SET DEBUG_SYNC = "open_and_process_table signal truncate_before_lock wait_for forever";
27--send TRUNCATE t1
28
29connect(con1,localhost,root,,);
30SET DEBUG_SYNC = "now wait_for truncate_before_lock";
31# Wait for one connection to reach open_and_process_table.
32--let $show_statement= SHOW PROCESSLIST
33--let $field= State
34--let $condition= 'debug sync point: open_and_process_table';
35--source include/wait_show_condition.inc
36
37SELECT ((@id := id) - id) FROM information_schema.processlist WHERE processlist.info LIKE '%TRUNCATE t1%' AND state LIKE '%open_and_process_table%';
38# Test killing from mysql server
39KILL QUERY @id;
40
41connection default;
42--ERROR ER_QUERY_INTERRUPTED
43--reap
44
45connection con1;
46--source include/show_binlog_events.inc
47
48disconnect con1;
49--source include/wait_until_disconnected.inc
50connection default;
51
52SELECT * FROM t1;
53
54DROP TABLE t1;
55SET DEBUG_SYNC= 'RESET';
56