Debian Codegraph @

mysql-test/suite/binlog/t/binlog_write_error.test

raw
1
2 #
3 # === Name ===
4 #
5 # binlog_write_error.test
6 #
7 # === Description ===
8 #
9 # This test case check if the error of writing binlog file is properly
10 # reported and handled when executing statements.
11 #
12 # === Related Bugs ===
13 #
14 # BUG#37148
15 #
16
17 source include/have_log_bin.inc;
18 source include/have_debug.inc;
19 source include/have_binlog_format_mixed_or_statement.inc;
20
21 --echo #
22 --echo # Initialization
23 --echo #
24
25 disable_warnings;
26 DROP TABLE IF EXISTS t1, t2;
27 DROP FUNCTION IF EXISTS f1;
28 DROP FUNCTION IF EXISTS f2;
29 DROP PROCEDURE IF EXISTS p1;
30 DROP PROCEDURE IF EXISTS p2;
31 DROP TRIGGER IF EXISTS tr1;
32 DROP TRIGGER IF EXISTS tr2;
33 DROP VIEW IF EXISTS v1, v2;
34 enable_warnings;
35
36 --echo #
37 --echo # Test injecting binlog write error when executing queries
38 --echo #
39
40 let $query= CREATE TABLE t1 (a INT);
41 source include/binlog_inject_error.inc;
42
43 --echo # The above CREATE TABLE should be rolled back.
44 --echo # Now we check this fact and create table for real.
45 --error ER_NO_SUCH_TABLE
46 SELECT * FROM t1;
47 CREATE TABLE t1 (a INT);
48
49 INSERT INTO t1 VALUES (1),(2),(3);
50
51 let $query= INSERT INTO t1 VALUES (4),(5),(6);
52 source include/binlog_inject_error.inc;
53
54 let $query= UPDATE t1 set a=a+1;
55 source include/binlog_inject_error.inc;
56
57 let $query= DELETE FROM t1;
58 source include/binlog_inject_error.inc;
59
60 --echo # Check that the above DML statements were rolled back and
61 --echo # had no effect on t1.
62 SELECT * FROM t1;
63
64 let $query= CREATE TRIGGER tr1 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t1 VALUES (new.a + 100);
65 source include/binlog_inject_error.inc;
66
67 # The statements CREATE/DROP TRIGGER fails in case error happen during write to binlog.
68 # Since the previous statement CREATE TRIGGER failed with error ER_ERROR_ON_WRITE
69 # the trigger tr1 wasn't created so SHOW CREATE TRIGGER should return ER_TRG_DOES_NOT_EXIST.
70 --error ER_TRG_DOES_NOT_EXIST
71 SHOW CREATE TRIGGER tr1;
72
73 let $query= ALTER TABLE t1 ADD (b INT);
74 source include/binlog_inject_error.inc;
75
76 --echo # The above ALTER TABLE was rolled back. Check this.
77 SHOW CREATE TABLE t1;
78
79 let $query= CREATE VIEW v1 AS SELECT a FROM t1;
80 source include/binlog_inject_error.inc;
81
82 --echo # The above CREATE VIEW was rolled back. Check this.
83 --error ER_NO_SUCH_TABLE
84 SHOW CREATE VIEW v1;
85
86 let $query= CREATE PROCEDURE p1(OUT `rows` INT) SELECT count(*) INTO `rows` FROM t1;
87 source include/binlog_inject_error.inc;
88
89 --echo # The above CREATE Procedure was rolled back. Check this.
90 --error ER_SP_DOES_NOT_EXIST
91 SHOW CREATE PROCEDURE p1;
92
93 let $query= DROP TABLE t1;
94 source include/binlog_inject_error.inc;
95
96 --echo # The above DROP TABLE was rolled back. Delete it for real
97 --echo # this also checks that table was not deleted by the above
98 --echo # attempt.
99 DROP TABLE t1;
100
101 let $query= CREATE FUNCTION f1() RETURNS INT return 1;
102 source include/binlog_inject_error.inc;
103
104 --echo # The above CREATE Procedure was rolled back. Check this.
105 --error ER_SP_DOES_NOT_EXIST
106 SHOW CREATE FUNCTION f1;
107
108 let $query= CREATE USER user1;
109 source include/binlog_inject_error.inc;
110
111 --echo # Since the previous CREATE USER is failed due to an error while writing
112 --echo # to binlog and changes made by the statement has been rolled back
113 --echo # we have to create user1 to be able to test REVOKE ALL and DROP USER.
114 CREATE USER user1;
115
116 let $query= REVOKE ALL PRIVILEGES, GRANT OPTION FROM user1;
117 source include/binlog_inject_error.inc;
118
119 let $query= DROP USER user1;
120 source include/binlog_inject_error.inc;
121
122 --echo # Since the previous DROP USER is failed we have to do a clean up explicitly.
123 DROP USER user1;
124
125 --echo #
126 --echo # Cleanup
127 --echo #
128
129 disable_warnings;
130 DROP FUNCTION IF EXISTS f1;
131 DROP PROCEDURE IF EXISTS p1;
132 DROP VIEW IF EXISTS v1, v2;
133 enable_warnings;