Debian Codegraph @

mysql-test/suite/mariabackup/log_page_corruption.test

raw
1 --source include/long_test.inc
2 --source include/have_debug.inc
3 --source include/innodb_undo_tablespaces.inc
4
5 --echo ########
6 --echo # Test for generating "innodb_corrupted_pages" file during full and
7 --echo # incremental backup, including DDL processing
8 --echo ###
9 --echo
10
11 CREATE TABLE t1_corrupted(c INT) ENGINE INNODB;
12 CREATE TABLE t2_corrupted(c INT) ENGINE INNODB;
13 CREATE TABLE t3(c INT) ENGINE INNODB;
14 CREATE TABLE t5_corrupted_to_rename(c INT) ENGINE INNODB;
15 CREATE TABLE t6_corrupted_to_drop(c INT) ENGINE INNODB;
16 CREATE TABLE t7_corrupted_to_alter(c INT) ENGINE INNODB;
17
18 CREATE TABLE t1_inc_corrupted(c INT) ENGINE INNODB;
19 CREATE TABLE t2_inc_corrupted(c INT) ENGINE INNODB;
20 CREATE TABLE t3_inc(c INT) ENGINE INNODB;
21 CREATE TABLE t5_inc_corrupted_to_rename(c INT) ENGINE INNODB;
22 CREATE TABLE t6_inc_corrupted_to_drop(c INT) ENGINE INNODB;
23 CREATE TABLE t7_inc_corrupted_to_alter(c INT) ENGINE INNODB;
24
25 # Fill tables with several pages
26 INSERT INTO t1_corrupted VALUES (3), (4), (5), (6), (7), (8), (9);
27 INSERT INTO t2_corrupted VALUES (3), (4), (5), (6), (7), (8), (9);
28 INSERT INTO t3 VALUES (3), (4), (5), (6), (7), (8), (9);
29 INSERT INTO t5_corrupted_to_rename VALUES (3), (4), (5), (6), (7), (8), (9);
30 INSERT INTO t6_corrupted_to_drop VALUES (3), (4), (5), (6), (7), (8), (9);
31 INSERT INTO t7_corrupted_to_alter VALUES (3), (4), (5), (6), (7), (8), (9);
32
33 --let MYSQLD_DATADIR=`select @@datadir`
34 --let INNODB_PAGE_SIZE=`select @@innodb_page_size`
35
36 --source include/shutdown_mysqld.inc
37 --echo # Corrupt tables
38 perl;
39 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
40 my $schema = "$ENV{MYSQLD_DATADIR}/test";
41
42 my $last_page_no = extend_space("$schema/t1_corrupted.ibd", 4);
43 corrupt_space_page_id("$schema/t1_corrupted.ibd",
44 $last_page_no, $last_page_no + 2, $last_page_no + 3);
45
46 $last_page_no = extend_space("$schema/t2_corrupted.ibd", 5);
47 corrupt_space_page_id("$schema/t2_corrupted.ibd",
48 $last_page_no + 1, $last_page_no + 2, $last_page_no + 4);
49
50 $last_page_no = extend_space("$schema/t5_corrupted_to_rename.ibd", 1);
51 corrupt_space_page_id("$schema/t5_corrupted_to_rename.ibd", $last_page_no);
52
53 $last_page_no = extend_space("$schema/t6_corrupted_to_drop.ibd", 1);
54 corrupt_space_page_id("$schema/t6_corrupted_to_drop.ibd", $last_page_no);
55 EOF
56 --source include/start_mysqld.inc
57
58 --let targetdir=$MYSQLTEST_VARDIR/tmp/backup
59 --let $backuplog=$MYSQLTEST_VARDIR/tmp/backup.log
60 --let corrupted_pages_file = $targetdir/innodb_corrupted_pages
61 --let corrupted_pages_file_filt = $MYSQLTEST_VARDIR/tmp/innodb_corrupted_pages_filt
62 --let perl_result_file=$MYSQLTEST_VARDIR/tmp/perl_result
63
64 --echo # Backup must fail due to page corruption
65 --disable_result_log
66 --error 1
67 exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir > $backuplog;
68 --enable_result_log
69
70 --let SEARCH_PATTERN=Database page corruption detected.*
71 --let SEARCH_FILE=$backuplog
72 --source include/search_pattern_in_file.inc
73 --echo # "innodb_corrupted_pages" file must not exist
74 --error 1
75 --file_exists $corrupted_pages_file
76 --rmdir $targetdir
77
78 --echo # Backup must not fail, but "innodb_corrupted_pages" file must be created due to --log-innodb-page-corruption option, and the file must contain all corrupted pages info, including those, which are supposed to be absent in the next test due to "DROP TABLE" execution during backup
79 --disable_result_log
80 --exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --log-innodb-page-corruption --target-dir=$targetdir
81 --enable_result_log
82
83 --echo --- "innodb_corrupted_pages" file content: ---
84 perl;
85 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
86 print_corrupted_pages_file($ENV{corrupted_pages_file},
87 $ENV{corrupted_pages_file_filt});
88 EOF
89 --cat_file $corrupted_pages_file_filt
90 --echo ------
91 --rmdir $targetdir
92
93 --let after_load_tablespaces=CREATE TABLE test.t4_corrupted_new ENGINE=INNODB SELECT UUID() from test.seq_1_to_10
94 --let add_corrupted_page_for_test_t4_corrupted_new=1
95 --let after_copy_test_t5_corrupted_to_rename=RENAME TABLE test.t5_corrupted_to_rename TO test.t5_corrupted_to_rename_renamed
96 --let after_copy_test_t6_corrupted_to_drop=DROP TABLE test.t6_corrupted_to_drop
97 --let after_copy_test_t7_corrupted_to_alter=ALTER TABLE test.t7_corrupted_to_alter ADD COLUMN (d INT)
98 --let add_corrupted_page_for_test_t7_corrupted_to_alter=3
99
100 --echo # Backup must not fail, but "innodb_corrupted_pages" file must be created due to --log-innodb-page-corruption option
101 --disable_result_log
102 --exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --log-innodb-page-corruption --target-dir=$targetdir --dbug=+d,mariabackup_events,mariabackup_inject_code > $backuplog
103 --enable_result_log
104
105 --let SEARCH_PATTERN=Database page corruption detected.*
106 --let SEARCH_FILE=$backuplog
107 --source include/search_pattern_in_file.inc
108
109 --let SEARCH_PATTERN=completed OK!
110 --let SEARCH_FILE=$backuplog
111 --source include/search_pattern_in_file.inc
112
113 --echo --- "innodb_corrupted_pages" file content: ---
114 perl;
115 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
116 print_corrupted_pages_file($ENV{corrupted_pages_file},
117 $ENV{corrupted_pages_file_filt});
118 EOF
119 --cat_file $corrupted_pages_file_filt
120 --echo ------
121 --let after_load_tablespaces=
122 --let add_corrupted_page_for_test_t4_corrupted_new=
123 --let after_copy_test_t5_corrupted_to_rename=
124 --let after_copy_test_t6_corrupted_to_drop=
125 --let after_copy_test_t7_corrupted_to_alter=
126 --let add_corrupted_page_for_test_t7_corrupted_to_alter=
127 # Fill tables for incremental backup with several pages
128 INSERT INTO t1_inc_corrupted VALUES (3), (4), (5), (6), (7), (8), (9);
129 INSERT INTO t2_inc_corrupted VALUES (3), (4), (5), (6), (7), (8), (9);
130 INSERT INTO t3_inc VALUES (3), (4), (5), (6), (7), (8), (9);
131
132 --source include/shutdown_mysqld.inc
133 perl;
134 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
135 my $schema="$ENV{MYSQLD_DATADIR}/test";
136
137 open(my $fh, '>', $ENV{perl_result_file}) or die $!;
138
139 my $last_page_no = extend_space("$schema/t1_inc_corrupted.ibd", 4);
140 corrupt_space_page_id("$schema/t1_inc_corrupted.ibd",
141 $last_page_no, $last_page_no + 2, $last_page_no + 3);
142 print $fh "$last_page_no\n";
143
144 $last_page_no = extend_space("$schema/t2_inc_corrupted.ibd", 5);
145 corrupt_space_page_id("$schema/t2_inc_corrupted.ibd",
146 $last_page_no + 1, $last_page_no + 2, $last_page_no + 4);
147 print $fh "$last_page_no\n";
148
149 $last_page_no = extend_space("$schema/t5_inc_corrupted_to_rename.ibd", 1);
150 corrupt_space_page_id("$schema/t5_inc_corrupted_to_rename.ibd", $last_page_no);
151 print $fh "$last_page_no\n";
152
153 $last_page_no = extend_space("$schema/t6_inc_corrupted_to_drop.ibd", 1);
154 corrupt_space_page_id("$schema/t6_inc_corrupted_to_drop.ibd", $last_page_no);
155
156 close $fh;
157 EOF
158 --source include/start_mysqld.inc
159
160 --let incdir=$MYSQLTEST_VARDIR/tmp/backup_inc
161
162 --echo # Backup must not fail, but "innodb_corrupted_pages" file must be created due to --log-innodb-page-corruption option, and the file must contain all corrupted pages info, including those, which are supposed to be absent in the next test due to "DROP TABLE" execution during backup
163 --disable_result_log
164 --exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --log-innodb-page-corruption --target-dir=$incdir --incremental-basedir=$targetdir --dbug=+d,mariabackup_events,mariabackup_inject_code
165 --disable_result_log
166
167 --let corrupted_pages_file = $incdir/innodb_corrupted_pages
168 --echo --- "innodb_corrupted_pages" file content: ---
169 perl;
170 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
171 print_corrupted_pages_file($ENV{corrupted_pages_file},
172 $ENV{corrupted_pages_file_filt});
173 EOF
174 --cat_file $corrupted_pages_file_filt
175 --echo ------
176 --remove_file $corrupted_pages_file_filt
177 --rmdir $incdir
178
179 --let after_load_tablespaces=CREATE TABLE test.t4_inc_corrupted_new ENGINE=INNODB SELECT UUID() from test.seq_1_to_10
180 --let add_corrupted_page_for_test_t4_inc_corrupted_new=1
181 --let after_copy_test_t5_inc_corrupted_to_rename=RENAME TABLE test.t5_inc_corrupted_to_rename TO test.t5_inc_corrupted_to_rename_renamed
182 --let after_copy_test_t6_inc_corrupted_to_drop=DROP TABLE test.t6_inc_corrupted_to_drop
183 --let after_copy_test_t7_inc_corrupted_to_alter=ALTER TABLE test.t7_inc_corrupted_to_alter ADD COLUMN (d INT)
184 --let add_corrupted_page_for_test_t7_inc_corrupted_to_alter=3
185
186 --echo # Backup must not fail, but "innodb_corrupted_pages" file must be created due to --log-innodb-page-corruption option
187 --disable_result_log
188 --exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --log-innodb-page-corruption --target-dir=$incdir --incremental-basedir=$targetdir --dbug=+d,mariabackup_events,mariabackup_inject_code > $backuplog
189 --disable_result_log
190
191 --let after_load_tablespaces=
192 --let add_corrupted_page_for_test_t4_inc_corrupted_new=
193 --let after_copy_test_t5_inc_corrupted_to_rename=
194 --let after_copy_test_t6_inc_corrupted_to_drop=
195 --let after_copy_test_t7_inc_corrupted_to_alter=
196 --let add_corrupted_page_for_test_t7_inc_corrupted_to_alter=
197
198 --let SEARCH_PATTERN=Database page corruption detected.*
199 --let SEARCH_FILE=$backuplog
200 --source include/search_pattern_in_file.inc
201 --let SEARCH_PATTERN=completed OK!
202 --source include/search_pattern_in_file.inc
203
204 --let corrupted_pages_file = $incdir/innodb_corrupted_pages
205 --echo --- "innodb_corrupted_pages" file content: ---
206 perl;
207 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
208 print_corrupted_pages_file($ENV{corrupted_pages_file},
209 $ENV{corrupted_pages_file_filt});
210 EOF
211 --cat_file $corrupted_pages_file_filt
212 --echo ------
213
214 --echo # Check if corrupted pages were copied to delta files, and non-corrupted pages are not copied.
215 perl;
216 use strict;
217 use warnings;
218 my $schema = "$ENV{incdir}/test";
219
220 open(my $fh, '<', $ENV{perl_result_file}) or die $!;
221
222 my $last_page_no = <$fh>;
223 die_if_no_pages("$schema/t1_corrupted.ibd.delta",
224 $last_page_no, $last_page_no + 2, $last_page_no + 3);
225
226 $last_page_no = <$fh>;
227 die_if_no_pages("$schema/t2_corrupted.ibd.delta",
228 $last_page_no + 1, $last_page_no + 2, $last_page_no + 4);
229
230 $last_page_no = <$fh>;
231 die_if_no_pages("$schema/t5_corrupted_to_rename_renamed.ibd.delta",
232 $last_page_no);
233
234 close $fh;
235
236 die_if_not_empty("$schema/t3.ibd.delta");
237
238 sub read_first_page_from_delta {
239 my $file_name = shift;
240 my $pages_count = shift;
241
242 open my $file, '<:raw', $file_name || die "Cannot open $file_name\n";
243 read $file, my $buffer, $pages_count*4 || die "Cannot read $file_name\n";
244 close $file;
245
246 return unpack("N[$pages_count]", $buffer);
247 }
248
249 sub die_if_no_pages {
250 my $file_name = shift;
251 my @check_pages = @_;
252 my @read_pages =
253 read_first_page_from_delta($file_name, scalar(@check_pages) + 1);
254 for (my $i = 1; $i < @check_pages + 1; ++$i) {
255 my $check_page_no = $check_pages[$i - 1];
256 die "Corrupted page $check_page_no was not copied to $file_name."
257 if ($i >= @read_pages || $read_pages[$i] != $check_page_no);
258 }
259 }
260
261 sub die_if_not_empty {
262 my $file_name = shift;
263 my ($magic, $full) = read_first_page_from_delta($file_name, 2);
264 die "Delta $file_name must be empty."
265 if ($full != 0xFFFFFFFF);
266 }
267 EOF
268 --rmdir $incdir
269 --rmdir $targetdir
270
271 DROP TABLE t1_corrupted;
272 DROP TABLE t2_corrupted;
273 DROP TABLE t4_corrupted_new;
274 DROP TABLE t5_corrupted_to_rename_renamed;
275 DROP TABLE t7_corrupted_to_alter;
276 DROP TABLE t1_inc_corrupted;
277 DROP TABLE t2_inc_corrupted;
278 DROP TABLE t4_inc_corrupted_new;
279 DROP TABLE t5_inc_corrupted_to_rename_renamed;
280 DROP TABLE t7_inc_corrupted_to_alter;
281
282 --echo
283 --echo ########
284 --echo # Test for --prepare with "innodb_corrupted_pages" file
285 --echo ###
286 --echo
287
288 --echo # Extend some tablespace and corrupt extended pages for full backup
289 --source include/shutdown_mysqld.inc
290 perl;
291 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
292 my $schema="$ENV{MYSQLD_DATADIR}/test";
293 my $last_page_no = extend_space("$schema/t3.ibd", 3);
294 corrupt_space_page_id("$schema/t3.ibd", $last_page_no, $last_page_no + 2);
295 open(my $fh, '>', $ENV{perl_result_file}) or die $!;
296 print $fh "$last_page_no\n";
297 close $fh;
298 EOF
299 --source include/start_mysqld.inc
300
301 --echo # Full backup with --log-innodb-page-corruption
302 --disable_result_log
303 --exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --log-innodb-page-corruption --target-dir=$targetdir
304 --enable_result_log
305 --let corrupted_pages_file = $targetdir/innodb_corrupted_pages
306 --echo --- "innodb_corrupted_pages" file content: ---
307 perl;
308 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
309 print_corrupted_pages_file($ENV{corrupted_pages_file},
310 $ENV{corrupted_pages_file_filt});
311 EOF
312 --cat_file $corrupted_pages_file_filt
313 --echo ------
314
315 --echo # Extend some tablespace and corrupt extended pages for incremental backup
316 --source include/shutdown_mysqld.inc
317 perl;
318 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
319 my $schema="$ENV{MYSQLD_DATADIR}/test";
320 my $last_page_no = extend_space("$schema/t3_inc.ibd", 3);
321 corrupt_space_page_id("$schema/t3_inc.ibd", $last_page_no, $last_page_no + 2);
322 open(my $fh, '>>', $ENV{perl_result_file}) or die $!;
323 print $fh "$last_page_no";
324 close $fh;
325 EOF
326 --source include/start_mysqld.inc
327
328 --echo # Incremental backup --log-innodb-page-corruption
329 --disable_result_log
330 --exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --log-innodb-page-corruption --target-dir=$incdir --incremental-basedir=$targetdir --dbug=+d,mariabackup_events,mariabackup_inject_code > $backuplog
331 --disable_result_log
332 --let corrupted_pages_file = $incdir/innodb_corrupted_pages
333 --echo --- "innodb_corrupted_pages" file content: ---
334 perl;
335 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
336 print_corrupted_pages_file($ENV{corrupted_pages_file},
337 $ENV{corrupted_pages_file_filt});
338 EOF
339 --cat_file $corrupted_pages_file_filt
340 --echo ------
341
342 --let targetdir2=$targetdir-2
343 --let incdir2=$incdir-2
344 perl;
345 use lib "lib";
346 use My::Handles { suppress_init_messages => 1 };
347 use My::File::Path;
348 copytree($ENV{'targetdir'}, $ENV{'targetdir2'});
349 copytree($ENV{'incdir'}, $ENV{'incdir2'});
350 EOF
351
352 --echo # Full backup prepare
353 --disable_result_log
354 exec $XTRABACKUP --prepare --target-dir=$targetdir > $backuplog;
355 --enable_result_log
356
357 --echo # "innodb_corrupted_pages" file must not exist after successful prepare
358 --error 1
359 --file_exists $targetdir/innodb_corrupted_pages
360 --let SEARCH_PATTERN=was successfully fixed.*
361 --let SEARCH_FILE=$backuplog
362 --source include/search_pattern_in_file.inc
363
364 --echo # Check that fixed pages are zero-filled
365 perl;
366 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
367 open(my $fh, '<', $ENV{perl_result_file}) or die $!;
368 my $last_page_no = <$fh>;
369 close $fh;
370 my $schema = "$ENV{targetdir}/test";
371 die_if_page_is_not_zero("$schema/t3.ibd", $last_page_no, $last_page_no + 2);
372 EOF
373
374 --echo # Incremental backup prepare
375 --disable_result_log
376 exec $XTRABACKUP --prepare --target-dir=$targetdir --incremental-dir=$incdir > $backuplog;
377 --enable_result_log
378
379 --echo # "innodb_corrupted_pages" file must not exist after successful prepare
380 --error 1
381 --file_exists $targetdir/innodb_corrupted_pages
382 --echo # do not remove "innodb_corrupted_pages" in incremental dir
383 --file_exists $incdir/innodb_corrupted_pages
384 --let SEARCH_PATTERN=was successfully fixed.*
385 --let SEARCH_FILE=$backuplog
386 --source include/search_pattern_in_file.inc
387
388 --echo # Check that fixed pages are zero-filled
389 perl;
390 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
391 open(my $fh, '<', $ENV{perl_result_file}) or die $!;
392 my $last_page_no_full = <$fh>;
393 my $last_page_no_inc = <$fh>;
394 close $fh;
395 my $schema = "$ENV{targetdir}/test";
396 die_if_page_is_not_zero("$schema/t3.ibd",
397 $last_page_no_full, $last_page_no_full + 2);
398 die_if_page_is_not_zero("$schema/t3_inc.ibd",
399 $last_page_no_inc, $last_page_no_inc + 2);
400 EOF
401
402 --source include/restart_and_restore.inc
403
404 SELECT * FROM t3;
405 SELECT * FROM t3_inc;
406
407 --echo # Test the case when not all corrupted pages are fixed
408 --echo
409 --echo # Add some fake corrupted pages
410 perl;
411 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
412 append_corrupted_pages(
413 "$ENV{targetdir2}/innodb_corrupted_pages", 'test/t3', '3 4');
414 append_corrupted_pages(
415 "$ENV{incdir2}/innodb_corrupted_pages", 'test/t3_inc', '4 5');
416 EOF
417
418 --echo # Full backup prepare
419 --disable_result_log
420 --error 1
421 exec $XTRABACKUP --prepare --target-dir=$targetdir2 > $backuplog;
422 --enable_result_log
423
424 --let SEARCH_PATTERN=Error: corrupted page.*
425 --let SEARCH_FILE=$backuplog
426 --source include/search_pattern_in_file.inc
427 --let corrupted_pages_file = $targetdir2/innodb_corrupted_pages
428 --echo --- "innodb_corrupted_pages" file content: ---
429 perl;
430 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
431 print_corrupted_pages_file($ENV{corrupted_pages_file},
432 $ENV{corrupted_pages_file_filt});
433 EOF
434 --cat_file $corrupted_pages_file_filt
435 --echo ------
436
437 --echo # Incremental backup prepare
438 --disable_result_log
439 --error 1
440 exec $XTRABACKUP --prepare --target-dir=$targetdir2 --incremental-dir=$incdir2 > $backuplog;
441 --enable_result_log
442
443 --let SEARCH_PATTERN=Error: corrupted page.*
444 --let SEARCH_FILE=$backuplog
445 --source include/search_pattern_in_file.inc
446 --let corrupted_pages_file = $targetdir2/innodb_corrupted_pages
447 --echo --- "innodb_corrupted_pages" file content: ---
448 perl;
449 do "$ENV{MTR_SUITE_DIR}/include/corrupt-page.pl";
450 print_corrupted_pages_file($ENV{corrupted_pages_file},
451 $ENV{corrupted_pages_file_filt});
452 EOF
453 --cat_file $corrupted_pages_file_filt
454 --echo ------
455
456 DROP TABLE t3;
457 DROP TABLE t3_inc;
458 --remove_file $backuplog
459 --remove_file $perl_result_file
460 --remove_file $corrupted_pages_file_filt
461 --rmdir $targetdir
462 --rmdir $targetdir2
463 --rmdir $incdir
464 --rmdir $incdir2