Debian Codegraph @

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

raw
1 #
2 # This include file is used by more than one test suite
3 # (currently rpl and binlog_encryption).
4 # Please check all dependent tests after modifying it
5 #
6
7 -- source include/have_innodb.inc
8 -- source include/master-slave.inc
9
10 --disable_warnings
11 call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. .*Statement: insert into t2 set data=repeat.*'a', @act_size.*");
12 call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. .*Statement: insert into t1 values.* NAME_CONST.*'n',.*, @data .*");
13 --enable_warnings
14
15 connection master;
16 set @save_binlog_cache_size = @@global.binlog_cache_size;
17 set @save_binlog_checksum = @@global.binlog_checksum;
18 set @save_master_verify_checksum = @@global.master_verify_checksum;
19 set @@global.binlog_cache_size = 4096;
20 set @@global.binlog_checksum = CRC32;
21 set @@global.master_verify_checksum = 1;
22
23 # restart slave to force the dump thread to verify events (on master side)
24 connection slave;
25 source include/stop_slave.inc;
26 source include/start_slave.inc;
27
28 connection master;
29
30 #
31 # Testing a critical part of checksum handling dealing with transaction cache.
32 # The cache's buffer size is set to be less than the transaction's footprint
33 # in binlog.
34 #
35 # To verify combined buffer-by-buffer read out of the file and fixing crc per event
36 # there are the following parts:
37 #
38 # 1. the event size is much less than the cache's buffer
39 # 2. the event size is bigger than the cache's buffer
40 # 3. the event size if approximately the same as the cache's buffer
41 # 4. all in above
42
43 #
44 # 1. the event size is much less than the cache's buffer
45 #
46
47 flush global status;
48 show status like "binlog_cache_use";
49 show status like "binlog_cache_disk_use";
50 --disable_warnings
51 drop table if exists t1;
52 --enable_warnings
53
54 #
55 # parameter to ensure the test slightly varies binlog content
56 # between different invocations
57 #
58 let $deviation_size=32;
59 eval create table t1 (a int PRIMARY KEY, b CHAR($deviation_size)) engine=innodb;
60
61 # Now we are going to create transaction which is long enough so its
62 # transaction binlog will be flushed to disk...
63
64 delimiter |;
65 create procedure test.p_init (n int, size int)
66 begin
67 while n > 0 do
68 select round(RAND() * size) into @act_size;
69 set @data = repeat('a', @act_size);
70 insert into t1 values(n, @data );
71 set n= n-1;
72 end while;
73 end|
74
75 delimiter ;|
76
77 let $1 = 4000; # PB2 can run it slow to time out on following sync_slave_with_master:s
78
79 begin;
80 --disable_warnings
81 # todo: check if it is really so.
82 #+Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a system function whose value may differ on slave.
83 eval call test.p_init($1, $deviation_size);
84 --enable_warnings
85 commit;
86
87 show status like "binlog_cache_use";
88 --echo *** binlog_cache_disk_use must be non-zero ***
89 show status like "binlog_cache_disk_use";
90
91 sync_slave_with_master;
92
93 let $diff_tables=master:test.t1, slave:test.t1;
94 source include/diff_tables.inc;
95
96 # undoing changes with verifying the above once again
97 connection master;
98
99 begin;
100 delete from t1;
101 commit;
102
103 sync_slave_with_master;
104
105
106 #
107 # 2. the event size is bigger than the cache's buffer
108 #
109 connection master;
110
111 flush global status;
112 let $t2_data_size= `select 3 * @@global.binlog_cache_size`;
113 let $t2_aver_size= `select 2 * @@global.binlog_cache_size`;
114 let $t2_max_rand= `select 1 * @@global.binlog_cache_size`;
115
116 eval create table t2(a int auto_increment primary key, data VARCHAR($t2_data_size)) ENGINE=Innodb;
117 let $1=100;
118 --disable_query_log
119 begin;
120 while ($1)
121 {
122 --disable_cursor_protocol
123 eval select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size;
124 --enable_cursor_protocol
125 set @data = repeat('a', @act_size);
126 insert into t2 set data = @data;
127 dec $1;
128 }
129 commit;
130 --enable_query_log
131 show status like "binlog_cache_use";
132 --echo *** binlog_cache_disk_use must be non-zero ***
133 show status like "binlog_cache_disk_use";
134
135 sync_slave_with_master;
136
137 let $diff_tables=master:test.t2, slave:test.t2;
138 source include/diff_tables.inc;
139
140 # undoing changes with verifying the above once again
141 connection master;
142
143 begin;
144 delete from t2;
145 commit;
146
147 sync_slave_with_master;
148
149 #
150 # 3. the event size if approximately the same as the cache's buffer
151 #
152
153 connection master;
154
155 flush global status;
156 let $t3_data_size= `select 2 * @@global.binlog_cache_size`;
157 let $t3_aver_size= `select (9 * @@global.binlog_cache_size) / 10`;
158 let $t3_max_rand= `select (2 * @@global.binlog_cache_size) / 10`;
159
160 eval create table t3(a int auto_increment primary key, data VARCHAR($t3_data_size)) engine=innodb;
161
162 let $1= 300;
163 --disable_query_log
164 begin;
165 while ($1)
166 {
167 --disable_cursor_protocol
168 eval select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size;
169 --enable_cursor_protocol
170 insert into t3 set data= repeat('a', @act_size);
171 dec $1;
172 }
173 commit;
174 --enable_query_log
175 show status like "binlog_cache_use";
176 --echo *** binlog_cache_disk_use must be non-zero ***
177 show status like "binlog_cache_disk_use";
178
179 sync_slave_with_master;
180
181 let $diff_tables=master:test.t3, slave:test.t3;
182 source include/diff_tables.inc;
183
184 # undoing changes with verifying the above once again
185 connection master;
186
187 begin;
188 delete from t3;
189 commit;
190
191 sync_slave_with_master;
192
193
194 #
195 # 4. all in above
196 #
197
198 connection master;
199 flush global status;
200
201 delimiter |;
202 eval create procedure test.p1 (n int)
203 begin
204 while n > 0 do
205 case (select (round(rand()*100) % 3) + 1)
206 when 1 then
207 select round(RAND() * $deviation_size) into @act_size;
208 set @data = repeat('a', @act_size);
209 insert into t1 values(n, @data);
210 when 2 then
211 begin
212 select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size;
213 insert into t2 set data=repeat('a', @act_size);
214 end;
215 when 3 then
216 begin
217 select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size;
218 insert into t3 set data= repeat('a', @act_size);
219 end;
220 end case;
221 set n= n-1;
222 end while;
223 end|
224 delimiter ;|
225
226 let $1= 1000;
227 set autocommit= 0;
228 begin;
229 --disable_warnings
230 eval call test.p1($1);
231 --enable_warnings
232 commit;
233
234 show status like "binlog_cache_use";
235 --echo *** binlog_cache_disk_use must be non-zero ***
236 show status like "binlog_cache_disk_use";
237
238 sync_slave_with_master;
239
240 let $diff_tables=master:test.t1, slave:test.t1;
241 source include/diff_tables.inc;
242
243 let $diff_tables=master:test.t2, slave:test.t2;
244 source include/diff_tables.inc;
245
246 let $diff_tables=master:test.t3, slave:test.t3;
247 source include/diff_tables.inc;
248
249
250 --echo *** Test switching checksum algorithm while ongoing transactions have pre-computed checksum in their binlog cache ***
251
252 --connection master
253 CREATE TABLE t4 (a INT, b INT, c VARCHAR(1024), PRIMARY KEY (a,b)) ENGINE=InnoDB;
254
255 # Create a couple transactions that will precompute checksums but commit
256 # without them.
257
258 BEGIN;
259 INSERT INTO t4 VALUES (1, 1, "small, pre-computed checksums");
260
261 --connection server_1
262 BEGIN;
263 INSERT INTO t4 VALUES (2, 1, "big, pre-computed checksums");
264 --let $i= 20
265 --disable_query_log
266 while ($i) {
267 eval INSERT INTO t4 VALUES (2, 22-$i, REPEAT("x", FLOOR(RAND()*100) + 831));
268 dec $i;
269 }
270 --enable_query_log
271
272 # Disable checksums dynamically, so MYSQL_BIN_LOG::write_cache() will have
273 # to drop the pre-computed checksums.
274 set @@global.binlog_checksum = NONE;
275
276 --connection master
277 INSERT INTO t4 VALUES (1, 2, "done");
278 COMMIT;
279 --connection server_1
280 INSERT INTO t4 VALUES (2, 22, "done");
281 COMMIT;
282
283 # Create a couple transactions that will not precompute checksums but commit
284 # with them.
285
286 --connection master
287 BEGIN;
288 INSERT INTO t4 VALUES (3, 1, "small, no pre-computed checksums");
289
290 --connection server_1
291 BEGIN;
292 INSERT INTO t4 VALUES (4, 1, "big, no pre-computed checksums");
293 --let $i= 20
294 --disable_query_log
295 while ($i) {
296 eval INSERT INTO t4 VALUES (4, 22-$i, REPEAT("x", FLOOR(RAND()*100) + 853));
297 dec $i;
298 }
299 --enable_query_log
300
301 # Ebable checksums dynamically, so MYSQL_BIN_LOG::write_cache() will have
302 # to recompute the checksums.
303 set @@global.binlog_checksum = CRC32;
304
305 --connection master
306 INSERT INTO t4 VALUES (3, 2, "done");
307 COMMIT;
308 --connection server_1
309 INSERT INTO t4 VALUES (4, 22, "done");
310 COMMIT;
311
312 sync_slave_with_master;
313
314
315 --echo *** Test the --binlog-legacy-event-pos option.
316 --connection master
317 FLUSH BINARY LOGS;
318 --source include/wait_for_binlog_checkpoint.inc
319
320 --let $query_file= query_get_value(SHOW MASTER STATUS, File, 1)
321 --let $query_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
322 BEGIN;
323 INSERT INTO t4 VALUES (5, 1, "Zero end_log_pos");
324 COMMIT;
325 --let $end_log_pos= query_get_value(SHOW BINLOG EVENTS IN "$query_file" FROM $query_pos LIMIT 3, End_log_pos, 2)
326 if ($end_log_pos!=0) {
327 eval SHOW BINLOG EVENTS IN "$query_file";
328 --die Wrong End_log_pos=$end_log_pos, expected zero.
329 }
330
331 set @@global.binlog_legacy_event_pos= 1;
332 --let $query_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
333 BEGIN;
334 INSERT INTO t4 VALUES (6, 1, "Non-zero end_log_pos");
335 COMMIT;
336 --let $end_log_pos= query_get_value(SHOW BINLOG EVENTS IN "$query_file" FROM $query_pos LIMIT 3, End_log_pos, 2)
337 if ($end_log_pos==0) {
338 eval SHOW BINLOG EVENTS IN "$query_file";
339 --die Wrong End_log_pos=$end_log_pos, expected non-zero.
340 }
341 set @@global.binlog_legacy_event_pos= 0;
342
343 sync_slave_with_master;
344
345
346 connection master;
347
348 begin;
349 delete from t1;
350 delete from t2;
351 delete from t3;
352 commit;
353
354 drop table t1, t2, t3, t4;
355 set @@global.binlog_cache_size = @save_binlog_cache_size;
356 set @@global.binlog_checksum = @save_binlog_checksum;
357 set @@global.master_verify_checksum = @save_master_verify_checksum;
358 drop procedure test.p_init;
359 drop procedure test.p1;
360
361 --source include/rpl_end.inc