Debian Codegraph @

mysql-test/suite/rpl/t/rpl_skip_error.test

raw
1 # ==== Purpose ====
2 #
3 # Verify that --slave-skip-errors works correctly. The error messages
4 # specified by --slave-skip-errors on slave should be ignored. If
5 # such errors occur, they should not be reported and not cause the
6 # slave to stop. If a skipped-due-to-error statement is a part of a
7 # larger transaction, and the error is not a deadlock error, the rest
8 # of the transaction should still commit, with just the errored statement
9 # ignored (note transactions which are skipped due to deadlocks are
10 # rolled back fully, see rpl_temporary_error2_skip_all.test).
11 #
12 # ==== Method ====
13 #
14 # We run the slave with --slave-skip-errors=1062 (the code for
15 # duplicate key). Then we have two set of tests. In the first
16 # set, we insert value 1 in a table on the slave, and then, on
17 # master, we insert value 1 in the table. In the second set, we
18 # insert several values on the master, disable the binlog and
19 # delete one of the values and re-enable the binlog. Right after,
20 # we perform an update on the set of values in order to generate
21 # a duplicate key on the slave. The errors should be ignored on
22 # the slave.
23 #
24 # ==== Related bugs ====
25 #
26 # BUG#28839: Errors in strict mode silently stop SQL thread if --slave-skip-errors exists
27 # bug in this test: BUG#30594: rpl.rpl_skip_error is nondeterministic:
28 # BUG#39393: slave-skip-errors does not work when using ROW based replication
29 # BUG#38624: ER_CONNECTION_KILLED must not be skippable via --slave-skip-errors
30
31 source include/have_innodb.inc;
32 source include/master-slave.inc;
33 --source include/check_slave_skip_errors.inc
34
35 --connection slave
36 let $initial_skipped_error= query_get_value(show global status like "Slave_skipped_errors", Value, 1);
37
38 connection master;
39 --echo ==== Test Without sql_mode=strict_trans_tables ====
40
41 create table t1 (n int not null primary key);
42
43 sync_slave_with_master;
44 insert into t1 values (1);
45
46 connection master;
47 # Here we expect (ignored) error, since 1 is already in slave table
48 insert into t1 values (1);
49 # These should work fine
50 insert into t1 values (2),(3);
51
52 sync_slave_with_master;
53 select * from t1 order by n;
54
55 --echo ==== Test With sql_mode=strict_trans_tables ====
56 insert into t1 values (7),(8);
57 connection master;
58 set sql_mode=strict_trans_tables;
59 insert into t1 values (7), (8), (9);
60 sync_slave_with_master;
61 select * from t1 order by n;
62 source include/check_slave_is_running.inc;
63
64 --echo ==== Clean Up ====
65 connection master;
66 drop table t1;
67 sync_slave_with_master;
68 # End of 4.1 tests
69
70 #
71 # #28839 Errors in strict mode silently stop SQL thread if --slave-skip-errors exists
72 #
73 connection master;
74 create table t1(a int primary key);
75 insert into t1 values (1),(2);
76 SET SQL_LOG_BIN=0;
77 delete from t1;
78 SET SQL_LOG_BIN=1;
79 set sql_mode=strict_trans_tables;
80 insert into t1 values (1), (2), (3);
81
82 sync_slave_with_master;
83 select * from t1;
84 source include/check_slave_is_running.inc;
85
86
87 --echo ==== Clean Up ====
88
89 connection master;
90 drop table t1;
91 sync_slave_with_master;
92 # End of 5.0 tests
93
94 #
95 # BUG#39393: slave-skip-errors does not work when using ROW based replication
96 #
97 --echo ==== Using Innodb ====
98
99 connection master;
100
101 SET SQL_LOG_BIN=0;
102 CREATE TABLE t1(id INT NOT NULL PRIMARY KEY, data INT) Engine=InnoDB;
103 SHOW CREATE TABLE t1;
104 SET SQL_LOG_BIN=1;
105
106 connection slave;
107
108 call mtr.add_suppression("Slave SQL.*Could not execute .*te_rows event on table test.t.; Duplicate entry.* error.* 1062");
109
110 CREATE TABLE t1(id INT NOT NULL PRIMARY KEY, data INT) Engine=InnoDB;
111 SHOW CREATE TABLE t1;
112
113 connection master;
114
115 INSERT INTO t1 VALUES(1, 1);
116 INSERT INTO t1 VALUES(2, 1);
117 INSERT INTO t1 VALUES(3, 1);
118 INSERT INTO t1 VALUES(4, 1);
119
120 SET SQL_LOG_BIN=0;
121 DELETE FROM t1 WHERE id = 4;
122 SET SQL_LOG_BIN=1;
123 UPDATE t1 SET id= id + 3, data = 2;
124
125 sync_slave_with_master;
126
127 let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
128 echo $error;
129
130 --echo **** We cannot execute a select as there are differences in the
131 --echo **** behavior between STMT and RBR.
132
133 --echo ==== Using MyIsam ====
134
135 connection master;
136
137 SET SQL_LOG_BIN=0;
138 CREATE TABLE t2(id INT NOT NULL PRIMARY KEY, data INT) Engine=MyIsam;
139 SHOW CREATE TABLE t2;
140 SET SQL_LOG_BIN=1;
141
142 connection slave;
143
144 CREATE TABLE t2(id INT NOT NULL PRIMARY KEY, data INT) Engine=MyIsam;
145 SHOW CREATE TABLE t2;
146 let $current_skipped_error= query_get_value(show global status like "Slave_skipped_errors", Value, 1);
147 --let $delta_skipped_error= `select $current_skipped_error - $initial_skipped_error from dual`
148 --echo # Slave_skipped_errros = $delta_skipped_error
149 connection master;
150
151 INSERT INTO t2 VALUES(1, 1);
152 INSERT INTO t2 VALUES(2, 1);
153 INSERT INTO t2 VALUES(3, 1);
154 INSERT INTO t2 VALUES(5, 1);
155
156 SET SQL_LOG_BIN=0;
157 DELETE FROM t2 WHERE id = 5;
158 SET SQL_LOG_BIN=1;
159 UPDATE t2 SET id= id + 3, data = 2;
160
161 sync_slave_with_master;
162
163 let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
164 echo $error;
165
166 let $current_skipped_error= query_get_value(show global status like "Slave_skipped_errors", Value, 1);
167 --let $delta_skipped_error= `select $current_skipped_error - $initial_skipped_error from dual`
168 --echo # Slave_skipped_errros = $delta_skipped_error
169
170 --echo **** We cannot execute a select as there are differences in the
171 --echo **** behavior between STMT and RBR.
172
173
174 --echo ****
175 --echo **** Ensure transactions which are skipped due to encountering a
176 --echo **** non-deadlock error which is present in --slave-skip-errors result
177 --echo **** in partially committed transactions
178 # Slave will insert 3 first, and master will insert 3 within a larger trx
179 --let $value_preexisting_on_slave= 3
180
181 --connection master
182 CREATE TABLE t3 (a INT UNIQUE) ENGINE=InnoDB;
183
184 --sync_slave_with_master
185 --connection slave
186 --eval INSERT INTO t3 VALUES ($value_preexisting_on_slave)
187
188 --connection master
189 BEGIN;
190 INSERT INTO t3 VALUES (1);
191 INSERT INTO t3 VALUES (2);
192 --eval INSERT INTO t3 VALUES ($value_preexisting_on_slave)
193 INSERT INTO t3 VALUES (4);
194 COMMIT;
195 --sync_slave_with_master
196
197 --echo **** Master and slave tables should have the same data, due to the
198 --echo **** partially replicated transaction's data overlapping with the data
199 --echo **** that pre-existed on the slave. That is, despite the transaction
200 --echo **** consisting of 4 statements, the errored statement should be ignored
201 --echo **** and the other 3 should commit successfully.
202 let $diff_tables=master:t3,slave:t3;
203 source include/diff_tables.inc;
204
205 --connection master
206 DROP TABLE t3;
207
208
209 --echo ==== Clean Up ====
210
211 connection master;
212
213 DROP TABLE t1;
214 DROP TABLE t2;
215
216 sync_slave_with_master;
217 --source include/rpl_end.inc