Debian Codegraph @

mysql-test/suite/innodb/include/corrupt_page.inc

raw
1 # Requires three parameters
2 # 1. IBD_FILE :- the file to corrupt a page in it
3 # 2. INNODB_PAGE_SIZE :- page_size of IBD
4 # 3. PAGE_NUM :- the page to corrupt
5 # 4. ALL_ZEROES :- write the entire page as all-zeros (optional parameter)
6 # (innodb doesn't treat all-zero as corrupted page)
7
8 # Wait for the server to be fully closed. Otherwise we could try to open
9 # a file that is still used leading to an error on Windows. It should be
10 # caller's responsibility to do that, but all current usages allow to have it
11 # just once, here.
12 --source include/wait_until_disconnected.inc
13
14 perl;
15 use IO::Handle;
16 my $file = $ENV{'IBD_FILE'} or die "IBD_FILE is required";
17 my $page_size = $ENV{'INNODB_PAGE_SIZE'} or die "INNODB_PAGE_SIZE is required";
18 my $page_num = $ENV{'PAGE_NUM'} or die "PAGE_NUM is required";
19 my $all_zeroes = $ENV{'ALL_ZEROES'};
20
21 # On Windows something prevents opening files for up to several minutes
22 # (perhaps an antivirus). At any rate, even the mysqld process might
23 # still be going through termination logic while keeping files open.
24 my $attempts = 0;
25 while (!open(FILE, "+<", $file)) {
26 if($! == 13 && ++$attempts < 600){
27 sleep 1;
28 }else{
29 die "Could not open the $file due to error $!"
30 }
31 }
32
33 FILE->autoflush(1);
34 binmode FILE;
35 seek(FILE, $page_size * $page_num, SEEK_SET);
36 if ($all_zeroes) {
37 print FILE chr(0) x $page_size;
38 } else {
39 print FILE chr(0) x ($page_size/2);
40 }
41 close FILE;
42 EOF