Debian Codegraph @

mysql-test/suite/rpl/include/rpl_conflicts.test

raw
1 # ==== Purpose ====
2 #
3 # Test that slave behaves well in some conflict situations. The
4 # following are tested:
5 #
6 # - The slave SQL thread sees an 'INSERT' of a row with a key that
7 # already exists in the table;
8 #
9 # - The slave SQL thread sees a 'DELETE' of a row that does not
10 # exist in the table.
11 #
12 # In statement-logging mode, the first conflict type causes the slave
13 # to stop with an error and the second conflict is ignored.
14 #
15 # In row-logging mode, the slave behavior depends the value of
16 # @@slave_exec_mode on the slave: if @@slave_exec_mode is IDEMPOTENT,
17 # the slave should ignore the conflicting statement and continue
18 # normally. If @@slave_exec_mode is STRICT, the slave should stop
19 # with an error.
20 #
21 # This test was previously named rpl_stm_mystery22/rpl_row_mystery22.
22 #
23 #
24 # ==== Method ====
25 #
26 # Create a table on master and slave, insert a row on slave, and
27 # insert the same row on master.
28 #
29 # Create a table on master and slave, insert a row on master with
30 # binlogging turned off, and remove the row on master with binlogging
31 # turned on.
32 #
33 #
34 # ==== Related bugs ====
35 #
36 # BUG#31552: Replication breaks when deleting rows from out-of-sync table without PK
37 # BUG#31609: Not all RBR slave errors reported as errors
38 #
39 # Bug in this test case:
40 # BUG#37718: rpl.rpl_stm_mystery22 fails sporadically on pushbuild
41 #
42 #
43 # ==== Usage ====
44 #
45 # This file assumes the following:
46 #
47 # - The test language variable $slave_is_idempotent is set to 1 if the
48 # slave is expected to stop on duplicate key errors (i.e., if the
49 # binlog is in statement mode or
50 # @@global.slave_exec_mode=STRICT). It is set to 0 otherwise.
51 #
52 # - Replication has been initialized by include/master-slave.inc
53 #
54 # - The test adds a suppression for the following warning:
55 # Slave: Can't find record in 't1' error.* 1032
56
57
58 --echo ==== Initialize ====
59
60 connection master;
61 CREATE TABLE t1(a INT PRIMARY KEY);
62 sync_slave_with_master;
63
64
65 --echo ==== Test: SQL thread sees 'INSERT' of existing key ====
66
67 --echo ---- Prepare slave so that it will get duplicate key error ----
68 # This row will be in the way of the row inserted by master.
69 INSERT INTO t1 VALUES (1);
70
71 --echo ---- Insert rows on master ----
72 connection master;
73 # Insert the same row on master
74 INSERT INTO t1 VALUES (1);
75 save_master_pos;
76 SELECT * FROM t1;
77
78 connection slave;
79
80 # If we are statement-logging or if slave_exec_mode=STRICT, we now
81 # expect to see an error on the slave. Otherwise (i.e., we are
82 # row-logging and slave_exec_mode=IDEMPOTENT), we expect that the
83 # duplicate row is ignored by the slave and replication continues.
84 if (`SELECT @@global.binlog_format != 'ROW' OR @@global.slave_exec_mode = 'STRICT'`) {
85 --echo ---- Wait until slave stops with an error ----
86 # Wait until the slave tries to run the query, fails with duplicate
87 # key error, and stops the SQL thread.
88 let $slave_sql_errno= 1062; # ER_DUP_ENTRY
89 source include/wait_for_slave_sql_error.inc;
90
91 --let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1)
92 --replace_regex /end_log_pos [0-9]+/end_log_pos END_LOG_POS/
93 --disable_query_log
94 --eval SELECT "$err" as 'Last_SQL_Error (expected "duplicate key" error)'
95 --enable_query_log
96 call mtr.add_suppression("Slave SQL.*Duplicate entry .1. for key .PRIMARY.* error.* 1062");
97
98 SELECT * FROM t1;
99
100 --echo ---- Resolve the conflict on the slave and restart SQL thread ----
101 DELETE FROM t1 WHERE a = 1;
102 START SLAVE SQL_THREAD;
103 source include/wait_for_slave_sql_to_start.inc;
104 }
105
106 --echo ---- Sync slave and verify that there is no error ----
107 sync_with_master;
108 let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
109 --echo Last_SQL_Error = '$err' (expected no error)
110 SELECT * FROM t1;
111
112
113 --echo ==== Test: SQL thread sees 'DELETE' of non-existing row ====
114
115 --echo ---- On master, insert two rows, the second with binlogging off ----
116 connection master;
117 DELETE FROM t1;
118 INSERT INTO t1 VALUES (1);
119
120 sync_slave_with_master;
121 DELETE FROM t1 WHERE a = 1;
122
123 --echo ---- On master, remove the row that does not exist on slave ----
124 connection master;
125 DELETE FROM t1 WHERE a = 1;
126 SELECT * FROM t1;
127 save_master_pos;
128
129 connection slave;
130
131 # If we are row-logging and slave_exec_mode is STRICT, we now expect
132 # an error since the row to delete does not exist on slave. Otherwise
133 # (i.e., either we are statement-logging or slave_exec_mode is
134 # IDEMPOTENT), the absence of the row to delete is ignored and
135 # replication continues.
136 if (`SELECT @@global.binlog_format = 'ROW' AND @@global.slave_exec_mode = 'STRICT'`) {
137 --echo ---- Wait until slave stops with an error ----
138 call mtr.add_suppression("Slave SQL.*Can.t find record in .t1., error.* 1032");
139 let $slave_sql_errno= 1032; # ER_KEY_NOT_FOUND
140 source include/wait_for_slave_sql_error.inc;
141
142 --let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1)
143 --replace_regex /end_log_pos [0-9]+/end_log_pos END_LOG_POS/
144 --disable_query_log
145 --eval SELECT "$err" as 'Last_SQL_Error (expected "duplicate key" error)'
146 --enable_query_log
147
148 SELECT * FROM t1;
149
150 --echo ---- Resolve the conflict on the slave and restart SQL thread ----
151 INSERT INTO t1 VALUES (1);
152 START SLAVE SQL_THREAD;
153 source include/wait_for_slave_sql_to_start.inc;
154 }
155
156 --echo ---- Sync slave and verify that there is no error ----
157 # The slave should sync ok, and SHOW SLAVE STATUS should give no
158 # error.
159 sync_with_master;
160 let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
161 --echo Last_SQL_Error = $err (expected no error)
162 SELECT * FROM t1;
163
164
165 --echo ==== Clean up ====
166
167 connection master;
168 DROP TABLE t1;
169
170 --sync_slave_with_master