Skip to content

Commit df51dc2

Browse files
committed
Fix tests for innodb_checksum_algorithm=strict_crc32
In tests that directly write InnoDB data file pages, compute the innodb_checksum_algorithm=crc32 checksums, instead of writing the 0xdeadbeef value used by innodb_checksum_algorithm=none. In this way, these tests will not cause failures when executing ./mtr --mysqld=--loose-innodb-checksum-algorithm=strict_crc32
1 parent e8b6c15 commit df51dc2

File tree

9 files changed

+118
-54
lines changed

9 files changed

+118
-54
lines changed

mysql-test/suite/innodb/include/ibd_convert.pl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,26 @@ sub convert_to_mariadb_101
1919
{
2020
warn "$file: changing $flags to $badflags\n";
2121
substr ($_, 54, 4) = pack("N", $badflags);
22-
# Replace the innodb_checksum_algorithm=none checksum
23-
substr ($_, 0, 4) = pack("N", 0xdeadbeef);
24-
substr ($_, $page_size - 8, 4) = pack("N", 0xdeadbeef);
22+
# Compute and replace the innodb_checksum_algorithm=crc32 checksum
23+
my $polynomial = 0x82f63b78; # CRC-32C
24+
if ($page_size == 1024)
25+
{
26+
# ROW_FORMAT=COMPRESSED
27+
substr($_,0,4)=pack("N",
28+
mycrc32(substr($_, 4, 12), 0, $polynomial) ^
29+
mycrc32(substr($_, 24, 2), 0, $polynomial) ^
30+
mycrc32(substr($_, 34, $page_size - 34), 0,
31+
$polynomial));
32+
}
33+
else
34+
{
35+
my $ck=pack("N",
36+
mycrc32(substr($_, 4, 22), 0, $polynomial) ^
37+
mycrc32(substr($_, 38, $page_size - 38 - 8), 0,
38+
$polynomial));
39+
substr($_, 0, 4) = $ck;
40+
substr ($_, $page_size - 8, 4) = $ck;
41+
}
2542
syswrite(FILE, $_, $page_size)==$page_size||die "Unable to write $file\n";
2643
}
2744
close(FILE);

mysql-test/suite/innodb/r/alter_kill.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ connection default;
1212
# Cleanly shutdown mysqld
1313
disconnect con1;
1414
# Corrupt FIL_PAGE_OFFSET in bug16720368.ibd,
15-
# and update the checksum to the "don't care" value.
15+
# and recompute innodb_checksum_algorithm=crc32
1616
# Restart mysqld
1717
# This will succeed after a clean shutdown, due to
1818
# fil_open_single_table_tablespace(check_space_id=FALSE).

mysql-test/suite/innodb/t/101_compatibility.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ perl;
4242
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
4343
ib_discard_tablespaces("test", "ti");
4444
ib_restore_tablespaces("test", "ti");
45+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
4546
do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
4647
my $ps = $ENV{INNODB_PAGE_SIZE};
4748
my $dd = $ENV{MYSQLD_DATADIR};
@@ -62,6 +63,7 @@ INSERT INTO ti VALUES(1);
6263
--source include/kill_mysqld.inc
6364

6465
perl;
66+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
6567
do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
6668
my $ps = $ENV{INNODB_PAGE_SIZE};
6769
my $dd = $ENV{MYSQLD_DATADIR};
@@ -81,6 +83,7 @@ CHECK TABLE tr,tc,td,tz,tdd,tp,ti;
8183
--source include/shutdown_mysqld.inc
8284

8385
perl;
86+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
8487
do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
8588
my $ps = $ENV{INNODB_PAGE_SIZE};
8689
my $dd = $ENV{MYSQLD_DATADIR};

mysql-test/suite/innodb/t/alter_kill.test

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,23 @@ connection default;
4444
disconnect con1;
4545

4646
-- echo # Corrupt FIL_PAGE_OFFSET in bug16720368.ibd,
47-
-- echo # and update the checksum to the "don't care" value.
47+
-- echo # and recompute innodb_checksum_algorithm=crc32
4848
perl;
49+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
4950
my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
5051
open(FILE, "+<$file") || die "Unable to open $file";
51-
print FILE pack("H*","deadbeefc001cafe") || die "Unable to write $file";
52-
seek(FILE, $ENV{PAGE_SIZE}-8, 0) || die "Unable to seek $file";
53-
print FILE pack("H*","deadbeef") || die "Unable to write $file";
52+
binmode FILE;
53+
my $ps= $ENV{PAGE_SIZE};
54+
my $page;
55+
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
56+
substr($page,4,4)=pack("N",0xc001cafe);
57+
my $polynomial = 0x82f63b78; # CRC-32C
58+
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
59+
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
60+
substr($page,0,4)=$ck;
61+
substr($page,$ps-8,4)=$ck;
62+
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
63+
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
5464
close(FILE) || die "Unable to close $file";
5565
EOF
5666

@@ -97,10 +107,21 @@ SELECT COUNT(*) FROM bug16720368;
97107

98108
# Uncorrupt the FIL_PAGE_OFFSET.
99109
perl;
110+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
100111
my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
101112
open(FILE, "+<$file") || die "Unable to open $file";
102-
# Uncorrupt FIL_PAGE_OFFSET.
103-
print FILE pack("H*","deadbeef00000000") || die "Unable to write $file";
113+
binmode FILE;
114+
my $ps= $ENV{PAGE_SIZE};
115+
my $page;
116+
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
117+
substr($page,4,4)=pack("N",0);
118+
my $polynomial = 0x82f63b78; # CRC-32C
119+
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
120+
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
121+
substr($page,0,4)=$ck;
122+
substr($page,$ps-8,4)=$ck;
123+
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
124+
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
104125
close(FILE) || die "Unable to close $file";
105126
EOF
106127

mysql-test/suite/innodb/t/doublewrite.test

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ set global innodb_buf_flush_list_now = 1;
7373

7474
perl;
7575
use IO::Handle;
76+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
77+
my $polynomial = 0x82f63b78; # CRC-32C
78+
7679
my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd";
7780
my $page_size = $ENV{INNODB_PAGE_SIZE};
7881
my $page;
@@ -102,9 +105,12 @@ for (my $d = $d1; $d < $d2 + 64; $d++)
102105
$badflags |= ($flags & 15 << 6) << 7; # PAGE_SSIZE
103106

104107
substr ($_, 54, 4) = pack("N", $badflags);
105-
# Replace the innodb_checksum_algorithm=none checksum
106-
substr ($_, 0, 4) = pack("N", 0xdeadbeef);
107-
substr ($_, $page_size - 8, 4) = pack("N", 0xdeadbeef);
108+
# Replace the innodb_checksum_algorithm=crc32 checksum
109+
my $ck= pack("N",
110+
mycrc32(substr($_, 4, 22), 0, $polynomial) ^
111+
mycrc32(substr($_, 38, $page_size - 38 - 8), 0, $polynomial));
112+
substr ($_, 0, 4) = $ck;
113+
substr ($_, $page_size - 8, 4) = $ck;
108114
syswrite(FILE, $_, $page_size)==$page_size||die;
109115
close(FILE);
110116
exit 0;

mysql-test/suite/innodb/t/log_corruption.test

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,55 +33,60 @@ EOF
3333
--let $dirs= --innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir
3434

3535
perl;
36+
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
3637
# Create a dummy system tablespace file using the default innodb_page_size=16k
3738
die unless open OUT, ">", "$ENV{bugdir}/ibdata1";
3839
binmode OUT;
3940

41+
# We calculate innodb_checksum_algorithm=crc32 for the pages.
42+
# The following bytes are excluded:
43+
# bytes 0..3 (the checksum is stored there)
44+
# bytes 26..37 (encryption key version, post-encryption checksum, tablespace id)
45+
# bytes $page_size-8..$page_size-1 (checksum, LSB of FIL_PAGE_LSN)
46+
my $polynomial = 0x82f63b78; # CRC-32C
47+
4048
# Tablespace header page with valid FSP_SIZE=768 pages.
4149
# Also, write a dummy FSEG_MAGIC_N at offset 60 to keep fseg_inode_try_get()
4250
# happy when fseg_n_reserved_pages() is following an invalid pointer
4351
# from the all-zero change buffer header page (page 3).
44-
print OUT pack("Nx[42]Nx[10]Nx[16312]Nx[4]",
45-
0xdeadbeef, # checksum
46-
768, # FSP_PAGE_SIZE
47-
97937874, # FSEG_MAGIC_N
48-
0xdeadbeef); # checksum
52+
## FIL_PAGE_OFFSET
53+
my $head = pack("Nx[18]", 0);
54+
## FSP_PAGE_SIZE, # FSEG_MAGIC_N
55+
my $body = pack("x[8]Nx[10]Nx[16312]", 768, 97937874);
56+
my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
57+
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
4958
# Dummy pages 1..6.
5059
print OUT chr(0) x (6 * 16384);
51-
# Dictionary header page.
52-
print OUT pack("NNx[62]Nx[8]Nx[16290]Nx[4]",
53-
0xdeadbeef, # checksum
54-
7, # FIL_PAGE_OFFSET
55-
8, # DICT_HDR_TABLES
56-
9, # DICT_HDR_INDEXES
57-
0xdeadbeef); # checksum
60+
# Dictionary header page (page 7).
61+
## FIL_PAGE_OFFSET
62+
$head = pack("Nx[18]", 7);
63+
## DICT_HDR_TABLES,DICT_HDR_INDEXES
64+
$body = pack("x[32]Nx[8]Nx[16290]", 8, 9);
65+
$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
66+
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
5867

5968
# Empty SYS_TABLES page (page 8).
60-
print OUT pack("NNNNx[8]nx[12]nnx[31]Cx[20]",
61-
0xdeadbeef, # checksum
62-
8, # FIL_PAGE_OFFSET
63-
~0, ~0, # FIL_PAGE_PREV, FIL_PAGE_NEXT
64-
17855, # FIL_PAGE_TYPE == FIL_PAGE_INDEX
65-
2, # PAGE_N_DIR_SLOTS
66-
124, # PAGE_HEAP_TOP
67-
1); # PAGE_INDEX_ID == DICT_TABLES_ID
68-
print OUT pack("nxnn", 0x801, 3, 116), "infimum";
69-
print OUT pack("xnxnxx", 0x901, 0x803), "supremum";
70-
print OUT pack("x[16248]nnNx[4]", 116, 101, 0xdeadbeef);
69+
## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
70+
$head = pack("NNNx[8]n", 8, ~0, ~0, 17855);
71+
## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_TABLES_ID
72+
$body = pack("nnx[31]Cx[20]", 2, 124, 1);
73+
$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
74+
$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
75+
$body .= pack("x[16248]nn", 116, 101);
76+
$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
77+
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
7178

7279
# Empty SYS_INDEXES page (page 9).
73-
print OUT pack("NNNNx[8]nx[12]nnx[31]Cx[20]",
74-
0xdeadbeef, # checksum
75-
9, # FIL_PAGE_OFFSET
76-
~0, ~0, # FIL_PAGE_PREV, FIL_PAGE_NEXT
77-
17855, # FIL_PAGE_TYPE == FIL_PAGE_INDEX
78-
2, # PAGE_N_DIR_SLOTS
79-
124, # PAGE_HEAP_TOP
80-
3); # PAGE_INDEX_ID == DICT_INDEXES_ID
81-
82-
print OUT pack("nxnn", 0x801, 3, 116), "infimum";
83-
print OUT pack("xnxnxx", 0x901, 0x803), "supremum";
84-
print OUT pack("x[16248]nnNx[4]", 116, 101, 0xdeadbeef);
80+
## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
81+
$head = pack("NNNx[8]n", 9, ~0, ~0, 17855);
82+
## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_INDEXES_ID
83+
$body = pack("nnx[31]Cx[20]", 2, 124, 3);
84+
$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
85+
$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
86+
$body .= pack("x[16248]nn", 116, 101);
87+
$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
88+
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
89+
8590
print OUT chr(0) x (759 * 16384);
8691
close OUT or die;
8792

mysql-test/suite/innodb/t/row_format_redundant.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ TRUNCATE TABLE t3;
9292
--source include/shutdown_mysqld.inc
9393
--perl
9494
use strict;
95+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
9596
my $ps= $ENV{INNODB_PAGE_SIZE};
9697
my $file= "$ENV{bugdir}/ibdata1";
9798
open(FILE, "+<", $file) || die "Unable to open $file\n";
@@ -120,8 +121,11 @@ for (my $offset= 0x65; $offset;
120121
$start= $end & 0x7f;
121122
}
122123
}
123-
substr($page,0,4)=pack("N",0xdeadbeef);
124-
substr($page,$ps-8,4)=pack("N",0xdeadbeef);
124+
my $polynomial = 0x82f63b78; # CRC-32C
125+
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
126+
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
127+
substr($page,0,4)=$ck;
128+
substr($page,$ps-8,4)=$ck;
125129
sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
126130
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
127131
close(FILE) || die "Unable to close $file\n";

mysql-test/suite/innodb/t/table_flags.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9;
5252
--source include/shutdown_mysqld.inc
5353
--perl
5454
use strict;
55+
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
5556
my $ps= $ENV{INNODB_PAGE_SIZE};
5657
my $file= "$ENV{bugdir}/ibdata1";
5758
open(FILE, "+<", $file) || die "Unable to open $file\n";
@@ -127,8 +128,11 @@ for (my $offset= 0x65; $offset;
127128
}
128129
print ")\n";
129130
}
130-
substr($page,0,4)=pack("N",0xdeadbeef);
131-
substr($page,$ps-8,4)=pack("N",0xdeadbeef);
131+
my $polynomial = 0x82f63b78; # CRC-32C
132+
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
133+
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
134+
substr($page,0,4)=$ck;
135+
substr($page,$ps-8,4)=$ck;
132136
sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
133137
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
134138
close(FILE) || die "Unable to close $file\n";

mysql-test/suite/mariabackup/huge_lsn.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ let MYSQLD_DATADIR=`select @@datadir`;
1111
--source include/shutdown_mysqld.inc
1212

1313
perl;
14+
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
1415
my $file= "$ENV{MYSQLD_DATADIR}/ibdata1";
1516
open(FILE, "+<", $file) or die "Unable to open $file\n";
1617
binmode FILE;
1718
my $ps= $ENV{INNODB_PAGE_SIZE};
1819
my $page;
1920
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
2021
substr($page,26,8) = pack("NN", 4096, ~1024);
21-
substr($page,0,4)=pack("N",0xdeadbeef);
22-
substr($page,$ps-8,4)=pack("N",0xdeadbeef);
22+
my $polynomial = 0x82f63b78; # CRC-32C
23+
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
24+
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
25+
substr($page,0,4)=$ck;
26+
substr($page,$ps-8,4)=$ck;
2327
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
2428
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
2529
close(FILE) || die "Unable to close $file\n";

0 commit comments

Comments
 (0)