Commit df51dc28 authored by Marko Mäkelä's avatar Marko Mäkelä

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
parent e8b6c150
...@@ -19,9 +19,26 @@ sub convert_to_mariadb_101 ...@@ -19,9 +19,26 @@ sub convert_to_mariadb_101
{ {
warn "$file: changing $flags to $badflags\n"; warn "$file: changing $flags to $badflags\n";
substr ($_, 54, 4) = pack("N", $badflags); substr ($_, 54, 4) = pack("N", $badflags);
# Replace the innodb_checksum_algorithm=none checksum # Compute and replace the innodb_checksum_algorithm=crc32 checksum
substr ($_, 0, 4) = pack("N", 0xdeadbeef); my $polynomial = 0x82f63b78; # CRC-32C
substr ($_, $page_size - 8, 4) = pack("N", 0xdeadbeef); if ($page_size == 1024)
{
# ROW_FORMAT=COMPRESSED
substr($_,0,4)=pack("N",
mycrc32(substr($_, 4, 12), 0, $polynomial) ^
mycrc32(substr($_, 24, 2), 0, $polynomial) ^
mycrc32(substr($_, 34, $page_size - 34), 0,
$polynomial));
}
else
{
my $ck=pack("N",
mycrc32(substr($_, 4, 22), 0, $polynomial) ^
mycrc32(substr($_, 38, $page_size - 38 - 8), 0,
$polynomial));
substr($_, 0, 4) = $ck;
substr ($_, $page_size - 8, 4) = $ck;
}
syswrite(FILE, $_, $page_size)==$page_size||die "Unable to write $file\n"; syswrite(FILE, $_, $page_size)==$page_size||die "Unable to write $file\n";
} }
close(FILE); close(FILE);
......
...@@ -12,7 +12,7 @@ connection default; ...@@ -12,7 +12,7 @@ connection default;
# Cleanly shutdown mysqld # Cleanly shutdown mysqld
disconnect con1; disconnect con1;
# Corrupt FIL_PAGE_OFFSET in bug16720368.ibd, # Corrupt FIL_PAGE_OFFSET in bug16720368.ibd,
# and update the checksum to the "don't care" value. # and recompute innodb_checksum_algorithm=crc32
# Restart mysqld # Restart mysqld
# This will succeed after a clean shutdown, due to # This will succeed after a clean shutdown, due to
# fil_open_single_table_tablespace(check_space_id=FALSE). # fil_open_single_table_tablespace(check_space_id=FALSE).
......
...@@ -42,6 +42,7 @@ perl; ...@@ -42,6 +42,7 @@ perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl"; do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test", "ti"); ib_discard_tablespaces("test", "ti");
ib_restore_tablespaces("test", "ti"); ib_restore_tablespaces("test", "ti");
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl"; do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
my $ps = $ENV{INNODB_PAGE_SIZE}; my $ps = $ENV{INNODB_PAGE_SIZE};
my $dd = $ENV{MYSQLD_DATADIR}; my $dd = $ENV{MYSQLD_DATADIR};
...@@ -62,6 +63,7 @@ INSERT INTO ti VALUES(1); ...@@ -62,6 +63,7 @@ INSERT INTO ti VALUES(1);
--source include/kill_mysqld.inc --source include/kill_mysqld.inc
perl; perl;
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl"; do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
my $ps = $ENV{INNODB_PAGE_SIZE}; my $ps = $ENV{INNODB_PAGE_SIZE};
my $dd = $ENV{MYSQLD_DATADIR}; my $dd = $ENV{MYSQLD_DATADIR};
...@@ -81,6 +83,7 @@ CHECK TABLE tr,tc,td,tz,tdd,tp,ti; ...@@ -81,6 +83,7 @@ CHECK TABLE tr,tc,td,tz,tdd,tp,ti;
--source include/shutdown_mysqld.inc --source include/shutdown_mysqld.inc
perl; perl;
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl"; do "$ENV{MTR_SUITE_DIR}/include/ibd_convert.pl";
my $ps = $ENV{INNODB_PAGE_SIZE}; my $ps = $ENV{INNODB_PAGE_SIZE};
my $dd = $ENV{MYSQLD_DATADIR}; my $dd = $ENV{MYSQLD_DATADIR};
......
...@@ -44,13 +44,23 @@ connection default; ...@@ -44,13 +44,23 @@ connection default;
disconnect con1; disconnect con1;
-- echo # Corrupt FIL_PAGE_OFFSET in bug16720368.ibd, -- echo # Corrupt FIL_PAGE_OFFSET in bug16720368.ibd,
-- echo # and update the checksum to the "don't care" value. -- echo # and recompute innodb_checksum_algorithm=crc32
perl; perl;
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd"; my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
open(FILE, "+<$file") || die "Unable to open $file"; open(FILE, "+<$file") || die "Unable to open $file";
print FILE pack("H*","deadbeefc001cafe") || die "Unable to write $file"; binmode FILE;
seek(FILE, $ENV{PAGE_SIZE}-8, 0) || die "Unable to seek $file"; my $ps= $ENV{PAGE_SIZE};
print FILE pack("H*","deadbeef") || die "Unable to write $file"; my $page;
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
substr($page,4,4)=pack("N",0xc001cafe);
my $polynomial = 0x82f63b78; # CRC-32C
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
substr($page,0,4)=$ck;
substr($page,$ps-8,4)=$ck;
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
close(FILE) || die "Unable to close $file"; close(FILE) || die "Unable to close $file";
EOF EOF
...@@ -97,10 +107,21 @@ SELECT COUNT(*) FROM bug16720368; ...@@ -97,10 +107,21 @@ SELECT COUNT(*) FROM bug16720368;
# Uncorrupt the FIL_PAGE_OFFSET. # Uncorrupt the FIL_PAGE_OFFSET.
perl; perl;
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd"; my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
open(FILE, "+<$file") || die "Unable to open $file"; open(FILE, "+<$file") || die "Unable to open $file";
# Uncorrupt FIL_PAGE_OFFSET. binmode FILE;
print FILE pack("H*","deadbeef00000000") || die "Unable to write $file"; my $ps= $ENV{PAGE_SIZE};
my $page;
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
substr($page,4,4)=pack("N",0);
my $polynomial = 0x82f63b78; # CRC-32C
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
substr($page,0,4)=$ck;
substr($page,$ps-8,4)=$ck;
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
close(FILE) || die "Unable to close $file"; close(FILE) || die "Unable to close $file";
EOF EOF
......
...@@ -73,6 +73,9 @@ set global innodb_buf_flush_list_now = 1; ...@@ -73,6 +73,9 @@ set global innodb_buf_flush_list_now = 1;
perl; perl;
use IO::Handle; use IO::Handle;
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
my $polynomial = 0x82f63b78; # CRC-32C
my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd"; my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd";
my $page_size = $ENV{INNODB_PAGE_SIZE}; my $page_size = $ENV{INNODB_PAGE_SIZE};
my $page; my $page;
...@@ -102,9 +105,12 @@ for (my $d = $d1; $d < $d2 + 64; $d++) ...@@ -102,9 +105,12 @@ for (my $d = $d1; $d < $d2 + 64; $d++)
$badflags |= ($flags & 15 << 6) << 7; # PAGE_SSIZE $badflags |= ($flags & 15 << 6) << 7; # PAGE_SSIZE
substr ($_, 54, 4) = pack("N", $badflags); substr ($_, 54, 4) = pack("N", $badflags);
# Replace the innodb_checksum_algorithm=none checksum # Replace the innodb_checksum_algorithm=crc32 checksum
substr ($_, 0, 4) = pack("N", 0xdeadbeef); my $ck= pack("N",
substr ($_, $page_size - 8, 4) = pack("N", 0xdeadbeef); mycrc32(substr($_, 4, 22), 0, $polynomial) ^
mycrc32(substr($_, 38, $page_size - 38 - 8), 0, $polynomial));
substr ($_, 0, 4) = $ck;
substr ($_, $page_size - 8, 4) = $ck;
syswrite(FILE, $_, $page_size)==$page_size||die; syswrite(FILE, $_, $page_size)==$page_size||die;
close(FILE); close(FILE);
exit 0; exit 0;
......
...@@ -33,55 +33,60 @@ EOF ...@@ -33,55 +33,60 @@ EOF
--let $dirs= --innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir --let $dirs= --innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir
perl; perl;
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
# Create a dummy system tablespace file using the default innodb_page_size=16k # Create a dummy system tablespace file using the default innodb_page_size=16k
die unless open OUT, ">", "$ENV{bugdir}/ibdata1"; die unless open OUT, ">", "$ENV{bugdir}/ibdata1";
binmode OUT; binmode OUT;
# We calculate innodb_checksum_algorithm=crc32 for the pages.
# The following bytes are excluded:
# bytes 0..3 (the checksum is stored there)
# bytes 26..37 (encryption key version, post-encryption checksum, tablespace id)
# bytes $page_size-8..$page_size-1 (checksum, LSB of FIL_PAGE_LSN)
my $polynomial = 0x82f63b78; # CRC-32C
# Tablespace header page with valid FSP_SIZE=768 pages. # Tablespace header page with valid FSP_SIZE=768 pages.
# Also, write a dummy FSEG_MAGIC_N at offset 60 to keep fseg_inode_try_get() # Also, write a dummy FSEG_MAGIC_N at offset 60 to keep fseg_inode_try_get()
# happy when fseg_n_reserved_pages() is following an invalid pointer # happy when fseg_n_reserved_pages() is following an invalid pointer
# from the all-zero change buffer header page (page 3). # from the all-zero change buffer header page (page 3).
print OUT pack("Nx[42]Nx[10]Nx[16312]Nx[4]", ## FIL_PAGE_OFFSET
0xdeadbeef, # checksum my $head = pack("Nx[18]", 0);
768, # FSP_PAGE_SIZE ## FSP_PAGE_SIZE, # FSEG_MAGIC_N
97937874, # FSEG_MAGIC_N my $body = pack("x[8]Nx[10]Nx[16312]", 768, 97937874);
0xdeadbeef); # checksum my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
# Dummy pages 1..6. # Dummy pages 1..6.
print OUT chr(0) x (6 * 16384); print OUT chr(0) x (6 * 16384);
# Dictionary header page. # Dictionary header page (page 7).
print OUT pack("NNx[62]Nx[8]Nx[16290]Nx[4]", ## FIL_PAGE_OFFSET
0xdeadbeef, # checksum $head = pack("Nx[18]", 7);
7, # FIL_PAGE_OFFSET ## DICT_HDR_TABLES,DICT_HDR_INDEXES
8, # DICT_HDR_TABLES $body = pack("x[32]Nx[8]Nx[16290]", 8, 9);
9, # DICT_HDR_INDEXES $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
0xdeadbeef); # checksum print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
# Empty SYS_TABLES page (page 8). # Empty SYS_TABLES page (page 8).
print OUT pack("NNNNx[8]nx[12]nnx[31]Cx[20]", ## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
0xdeadbeef, # checksum $head = pack("NNNx[8]n", 8, ~0, ~0, 17855);
8, # FIL_PAGE_OFFSET ## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_TABLES_ID
~0, ~0, # FIL_PAGE_PREV, FIL_PAGE_NEXT $body = pack("nnx[31]Cx[20]", 2, 124, 1);
17855, # FIL_PAGE_TYPE == FIL_PAGE_INDEX $body .= pack("nxnn", 0x801, 3, 116) . "infimum";
2, # PAGE_N_DIR_SLOTS $body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
124, # PAGE_HEAP_TOP $body .= pack("x[16248]nn", 116, 101);
1); # PAGE_INDEX_ID == DICT_TABLES_ID $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
print OUT pack("nxnn", 0x801, 3, 116), "infimum"; print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
print OUT pack("xnxnxx", 0x901, 0x803), "supremum";
print OUT pack("x[16248]nnNx[4]", 116, 101, 0xdeadbeef);
# Empty SYS_INDEXES page (page 9). # Empty SYS_INDEXES page (page 9).
print OUT pack("NNNNx[8]nx[12]nnx[31]Cx[20]", ## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
0xdeadbeef, # checksum $head = pack("NNNx[8]n", 9, ~0, ~0, 17855);
9, # FIL_PAGE_OFFSET ## PAGE_N_DIR_SLOTS, PAGE_HEAP_TOP, PAGE_INDEX_ID == DICT_INDEXES_ID
~0, ~0, # FIL_PAGE_PREV, FIL_PAGE_NEXT $body = pack("nnx[31]Cx[20]", 2, 124, 3);
17855, # FIL_PAGE_TYPE == FIL_PAGE_INDEX $body .= pack("nxnn", 0x801, 3, 116) . "infimum";
2, # PAGE_N_DIR_SLOTS $body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
124, # PAGE_HEAP_TOP $body .= pack("x[16248]nn", 116, 101);
3); # PAGE_INDEX_ID == DICT_INDEXES_ID $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);
print OUT pack("nxnn", 0x801, 3, 116), "infimum";
print OUT pack("xnxnxx", 0x901, 0x803), "supremum";
print OUT pack("x[16248]nnNx[4]", 116, 101, 0xdeadbeef);
print OUT chr(0) x (759 * 16384); print OUT chr(0) x (759 * 16384);
close OUT or die; close OUT or die;
......
...@@ -92,6 +92,7 @@ TRUNCATE TABLE t3; ...@@ -92,6 +92,7 @@ TRUNCATE TABLE t3;
--source include/shutdown_mysqld.inc --source include/shutdown_mysqld.inc
--perl --perl
use strict; use strict;
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
my $ps= $ENV{INNODB_PAGE_SIZE}; my $ps= $ENV{INNODB_PAGE_SIZE};
my $file= "$ENV{bugdir}/ibdata1"; my $file= "$ENV{bugdir}/ibdata1";
open(FILE, "+<", $file) || die "Unable to open $file\n"; open(FILE, "+<", $file) || die "Unable to open $file\n";
...@@ -120,8 +121,11 @@ for (my $offset= 0x65; $offset; ...@@ -120,8 +121,11 @@ for (my $offset= 0x65; $offset;
$start= $end & 0x7f; $start= $end & 0x7f;
} }
} }
substr($page,0,4)=pack("N",0xdeadbeef); my $polynomial = 0x82f63b78; # CRC-32C
substr($page,$ps-8,4)=pack("N",0xdeadbeef); my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
substr($page,0,4)=$ck;
substr($page,$ps-8,4)=$ck;
sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file"; sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n"; syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
close(FILE) || die "Unable to close $file\n"; close(FILE) || die "Unable to close $file\n";
......
...@@ -52,6 +52,7 @@ PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9; ...@@ -52,6 +52,7 @@ PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9;
--source include/shutdown_mysqld.inc --source include/shutdown_mysqld.inc
--perl --perl
use strict; use strict;
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
my $ps= $ENV{INNODB_PAGE_SIZE}; my $ps= $ENV{INNODB_PAGE_SIZE};
my $file= "$ENV{bugdir}/ibdata1"; my $file= "$ENV{bugdir}/ibdata1";
open(FILE, "+<", $file) || die "Unable to open $file\n"; open(FILE, "+<", $file) || die "Unable to open $file\n";
...@@ -127,8 +128,11 @@ for (my $offset= 0x65; $offset; ...@@ -127,8 +128,11 @@ for (my $offset= 0x65; $offset;
} }
print ")\n"; print ")\n";
} }
substr($page,0,4)=pack("N",0xdeadbeef); my $polynomial = 0x82f63b78; # CRC-32C
substr($page,$ps-8,4)=pack("N",0xdeadbeef); my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
substr($page,0,4)=$ck;
substr($page,$ps-8,4)=$ck;
sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file"; sysseek(FILE, $sys_tables_root*$ps, 0) || die "Unable to seek $file";
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n"; syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
close(FILE) || die "Unable to close $file\n"; close(FILE) || die "Unable to close $file\n";
......
...@@ -11,6 +11,7 @@ let MYSQLD_DATADIR=`select @@datadir`; ...@@ -11,6 +11,7 @@ let MYSQLD_DATADIR=`select @@datadir`;
--source include/shutdown_mysqld.inc --source include/shutdown_mysqld.inc
perl; perl;
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
my $file= "$ENV{MYSQLD_DATADIR}/ibdata1"; my $file= "$ENV{MYSQLD_DATADIR}/ibdata1";
open(FILE, "+<", $file) or die "Unable to open $file\n"; open(FILE, "+<", $file) or die "Unable to open $file\n";
binmode FILE; binmode FILE;
...@@ -18,8 +19,11 @@ my $ps= $ENV{INNODB_PAGE_SIZE}; ...@@ -18,8 +19,11 @@ my $ps= $ENV{INNODB_PAGE_SIZE};
my $page; my $page;
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps; die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
substr($page,26,8) = pack("NN", 4096, ~1024); substr($page,26,8) = pack("NN", 4096, ~1024);
substr($page,0,4)=pack("N",0xdeadbeef); my $polynomial = 0x82f63b78; # CRC-32C
substr($page,$ps-8,4)=pack("N",0xdeadbeef); my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
substr($page,0,4)=$ck;
substr($page,$ps-8,4)=$ck;
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n"; sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n"; syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
close(FILE) || die "Unable to close $file\n"; close(FILE) || die "Unable to close $file\n";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment