Debian Codegraph @

mysql-test/suite/ndb_rpl/t/ndb_rpl_idempotent.test

raw
1 --source include/have_ndb.inc
2 --source include/have_binlog_format_mixed_or_row.inc
3 --source suite/ndb_rpl/ndb_master-slave.inc
4
5 #
6 # Currently test only works with NDB since it retrieves "old"
7 # binlog positions with mysql.ndb_binlog_index and ndb_apply_status;
8 #
9
10 # create a table
11 CREATE TABLE t1 (c1 CHAR(15), c2 CHAR(15), c3 INT, PRIMARY KEY (c3)) ENGINE = NDB ;
12
13 # Replicate the table creation, then reset the master log and
14 # slave to avoid the creation being replayed below
15 #
16 sync_slave_with_master;
17 --connection slave
18 STOP REPLICA;
19 --connection master
20 RESET MASTER;
21 --connection slave
22 RESET REPLICA;
23 START REPLICA;
24 --connection master
25
26 # with one row
27 INSERT INTO t1 VALUES ("row1","will go away",1);
28 SELECT * FROM t1 ORDER BY c3;
29
30 # sync slave and retrieve epoch
31 sync_slave_with_master;
32 SELECT MAX(epoch) FROM mysql.ndb_apply_status into @the_epoch;
33 --replace_column 1 <the_epoch>
34 SELECT @the_epoch;
35 let $the_epoch= `select @the_epoch` ;
36 SELECT * FROM t1 ORDER BY c3;
37
38 # get the master binlog pos from the epoch
39 connection master;
40 --disable_query_log
41 --disable_result_log
42 eval SELECT @the_pos:=Position,
43 @the_file:=SUBSTRING_INDEX(REPLACE(FILE,'\\\\','/'), '/', -1)
44 FROM mysql.ndb_binlog_index WHERE epoch = $the_epoch ;
45 let $the_pos= `SELECT @the_pos` ;
46 let $the_file= `SELECT @the_file` ;
47 let $the_epoch=`SELECT MAX(epoch) FROM mysql.ndb_apply_status`;
48 --enable_result_log
49 --enable_query_log
50
51 # insert some more values
52 INSERT INTO t1 VALUES ("row2","will go away",2),("row3","will change",3),("row4","D",4);
53 DELETE FROM t1 WHERE c3 = 1;
54 UPDATE t1 SET c2="should go away" WHERE c3 = 2;
55 UPDATE t1 SET c2="C" WHERE c3 = 3;
56 DELETE FROM t1 WHERE c3 = 2;
57
58 SELECT * FROM t1 ORDER BY c3;
59
60 # check that we have it on the slave
61 --sync_slave_with_master
62 SELECT * FROM t1 ORDER BY c3;
63
64 source include/check_slave_is_running.inc;
65
66 # stop slave and reset position to before the last changes
67 STOP REPLICA;
68 --disable_query_log
69 --disable_result_log
70 eval CHANGE REPLICATION SOURCE TO
71 SOURCE_LOG_FILE = '$the_file',
72 SOURCE_LOG_POS = $the_pos ;
73 --enable_result_log
74 --enable_query_log
75
76 source include/check_slave_no_error.inc;
77
78 --disable_query_log
79 call mtr.add_suppression("Replica: At SQL thread start applying epoch .*");
80 --enable_query_log
81
82 # start the slave again
83 # -> same events should have been applied again
84 # e.g. inserting rows that already there
85 # deleting a row which is not there
86 # updating a row which is not there
87 START REPLICA;
88
89 --connection master
90 SELECT * FROM t1 ORDER BY c3;
91 --sync_slave_with_master
92 SELECT * FROM t1 ORDER BY c3;
93
94 STOP REPLICA;
95
96 #
97 # cleanup
98 #
99 --connection master
100 DROP TABLE t1;
101 RESET master;
102 --connection slave
103 DROP TABLE t1;
104 RESET REPLICA;
105
106 START REPLICA;
107
108 #
109 # Test that we can handle update of a row that does not exist on the slave
110 # will trigger usage of AO_IgnoreError on slave side so that the INSERT
111 # still succeeds even if the replication of the UPDATE generates an error.
112 #
113 --connection master
114 CREATE TABLE t1 (c1 CHAR(15) NOT NULL, c2 CHAR(15) NOT NULL, c3 INT NOT NULL, PRIMARY KEY (c3)) ENGINE = NDB ;
115 INSERT INTO t1 VALUES ("row1","remove on slave",1);
116
117 --sync_slave_with_master
118 --connection slave
119 DELETE FROM t1;
120
121 --connection master
122 BEGIN;
123 UPDATE t1 SET c2="does not exist" WHERE c3=1;
124 INSERT INTO t1 VALUES ("row2","new on slave",2);
125 COMMIT;
126
127 --sync_slave_with_master
128 --connection slave
129 SELECT * FROM t1;
130 source include/check_slave_is_running.inc;
131
132 connection master;
133 DROP TABLE IF EXISTS t1;
134
135 #
136 # Test that the ndb_binlog_index table records
137 # the start position of an epoch transaction
138 # as the first position after the previous
139 # epoch transaction
140 #
141 --sync_slave_with_master
142 --connection slave
143 STOP REPLICA;
144 --connection master
145 RESET MASTER;
146 --connection slave
147 RESET REPLICA;
148 START REPLICA;
149 --connection master
150
151 --echo Let's interleave some DDL and DML in the Binlog
152
153 --echo Some DDL
154 create table t1(a int primary key) engine=ndb;
155
156 --echo First epoch transaction
157 begin;
158 insert into t1 values (1), (2), (3);
159 commit;
160
161 --echo Sync slave and retrieve epoch
162 --sync_slave_with_master
163 SELECT MAX(epoch) FROM mysql.ndb_apply_status into @first_epoch;
164 --replace_column 1 <first_epoch>
165 SELECT @first_epoch;
166 let $first_epoch= `select @first_epoch` ;
167
168 --echo Slave contents
169 select * from t1 ORDER by a;
170
171 --echo Get the next master binlog pos from the epoch
172 connection master;
173 --disable_query_log
174 --disable_result_log
175 eval SELECT @the_pos:=next_position,
176 @the_file:=SUBSTRING_INDEX(REPLACE(next_file,'\\\\','/'), '/', -1)
177 FROM mysql.ndb_binlog_index WHERE epoch = $first_epoch ;
178 let $the_pos= `SELECT @the_pos` ;
179 let $the_file= `SELECT @the_file` ;
180 --enable_result_log
181 --enable_query_log
182
183 --echo Now let's do some more DDL and DML
184 create table t2 (a int primary key) engine=ndb;
185
186 begin;
187 insert into t2 values (1), (2), (3);
188 commit;
189
190 --sync_slave_with_master
191
192 --connection slave
193 source include/check_slave_is_running.inc;
194
195 --echo Stop slave and reset position to start of the applied epoch
196 STOP REPLICA;
197 --disable_query_log
198 --disable_result_log
199
200 eval CHANGE REPLICATION SOURCE TO
201 SOURCE_LOG_FILE = '$the_file',
202 SOURCE_LOG_POS = $the_pos;
203
204 --enable_result_log
205 --enable_query_log
206
207 source include/check_slave_no_error.inc;
208
209 # Add a suppression for the warning that will appear in the
210 # replicas's .err file
211 call mtr.add_suppression("Table \'t2\' already exists.*");
212 call mtr.add_suppression("Worker 1 failed executing transaction.*");
213
214 START REPLICA;
215
216 --let $slave_sql_errno= 1050
217 # Don't show error message, it varies for replica worker
218 --let $show_slave_sql_error=0
219 --source include/wait_for_slave_sql_error.inc
220 # Check that expected error message can be found
221 SELECT COUNT(*) as FOUND_ERROR_MESSAGE
222 FROM performance_schema.replication_applier_status_by_worker
223 WHERE LAST_ERROR_NUMBER=1050 AND channel_name = '' AND
224 LAST_ERROR_MESSAGE LIKE "%Table 't2' already exists%";
225
226 STOP REPLICA;
227
228 # Cleanup
229 --connection master
230 RESET MASTER;
231
232 --connection slave
233 RESET REPLICA;
234 START REPLICA;
235
236 --connection master
237 DROP TABLE t1;
238 DROP TABLE t2;
239
240 --sync_slave_with_master
241
242 --source include/rpl_end.inc