File: corrupt_page.inc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (42 lines) | stat: -rw-r--r-- 1,448 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Requires three parameters
# 1. IBD_FILE :- the file to corrupt a page in it
# 2. INNODB_PAGE_SIZE :- page_size of IBD
# 3. PAGE_NUM :- the page to corrupt
# 4. ALL_ZEROES :- write the entire page as all-zeros (optional parameter)
#                (innodb doesn't treat all-zero as corrupted page)

# Wait for the server to be fully closed. Otherwise we could try to open
# a file that is still used leading to an error on Windows. It should be
# caller's responsibility to do that, but all current usages allow to have it
# just once, here.
--source include/wait_until_disconnected.inc

perl;
use IO::Handle;
my $file        = $ENV{'IBD_FILE'}         or die "IBD_FILE is required";
my $page_size   = $ENV{'INNODB_PAGE_SIZE'} or die "INNODB_PAGE_SIZE is required";
my $page_num    = $ENV{'PAGE_NUM'}         or die "PAGE_NUM is required";
my $all_zeroes = $ENV{'ALL_ZEROES'};

# On Windows something prevents opening files for up to several minutes
# (perhaps an antivirus). At any rate, even the mysqld process might
# still be going through termination logic while keeping files open.
my $attempts = 0;
while (!open(FILE, "+<", $file)) {
 if($! == 13 && ++$attempts < 600){
  sleep 1;
 }else{
  die "Could not open the $file due to error $!"
 }
}

FILE->autoflush(1);
binmode FILE;
seek(FILE, $page_size * $page_num, SEEK_SET);
if ($all_zeroes) {
 print FILE chr(0) x $page_size;
} else {
 print FILE chr(0) x ($page_size/2);
}
close FILE;
EOF