mariadb/mysql-test/suite/innodb_zip/t/innochecksum_3.test
Jan Lindström 34eef269eb MDEV-11939: innochecksum mistakes a file for an encrypted one (page 0 invalid)
Always read full page 0 to determine does tablespace contain
encryption metadata. Tablespaces that are page compressed or
page compressed and encrypted do not compare checksum as
it does not exists. For encrypted tables use checksum
verification written for encrypted tables and normal tables
use normal method.

buf_page_is_checksum_valid_crc32
buf_page_is_checksum_valid_innodb
buf_page_is_checksum_valid_none
        Modify Innochecksum logging to file to avoid compilation
	warnings.

fil0crypt.cc fil0crypt.h
        Modify to be able to use in innochecksum compilation and
        move fil_space_verify_crypt_checksum to end of the file.
        Add innochecksum logging to file.

univ.i
        Add innochecksum strict_verify, log_file and cur_page_num
        variables as extern.

page_zip_verify_checksum
        Add innochecksum logging to file and remove unnecessary code.

innochecksum.cc
        Lot of changes most notable able to read encryption
        metadata from page 0 of the tablespace.

Added test case where we corrupt intentionally
FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION (encryption key version)
FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION+4 (post encryption checksum)
FIL_DATA+10 (data)
2017-08-08 09:41:09 +03:00

406 lines
15 KiB
Text

#************************************************************
# WL6045:Improve Innochecksum
#************************************************************
--source include/innodb_page_size_small.inc
--source include/no_valgrind_without_big.inc
# Embedded server does not support crashing.
--source include/not_embedded.inc
# Avoid CrashReporter popup on Mac.
--source include/not_crashrep.inc
--echo # Set the environmental variables
let MYSQLD_BASEDIR= `SELECT @@basedir`;
let MYSQLD_DATADIR= `SELECT @@datadir`;
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/my_restart.err;
call mtr.add_suppression("InnoDB: Unable to read tablespace .* page no .* into the buffer pool after 100 attempts");
call mtr.add_suppression("InnoDB: innodb_checksum_algorithm is set to.*");
--echo [1]: Further Test are for rewrite checksum (innodb|crc32|none) for all ibd file & start the server.
CREATE TABLE tab1 (pk INTEGER NOT NULL PRIMARY KEY,
linestring_key GEOMETRY NOT NULL,
linestring_nokey GEOMETRY NOT NULL)
ENGINE=InnoDB ;
INSERT INTO tab1 (pk, linestring_key, linestring_nokey)
VALUES (1, ST_GeomFromText('POINT(10 10) '), ST_GeomFromText('POINT(10 10) '));
CREATE INDEX linestring_index ON tab1(linestring_nokey(5));
ALTER TABLE tab1 ADD KEY (linestring_key(5));
--echo # create a compressed table
CREATE TABLE tab2(col_1 CHAR (255) ,
col_2 VARCHAR (255), col_3 longtext,
col_4 longtext,col_5 longtext,
col_6 longtext , col_7 int )
engine = innodb row_format=compressed key_block_size=4;
CREATE INDEX idx1 ON tab2(col_3(10));
CREATE INDEX idx2 ON tab2(col_4(10));
CREATE INDEX idx3 ON tab2(col_5(10));
# load the with repeat function
SET @col_1 = repeat('a', 5);
SET @col_2 = repeat('b', 20);
SET @col_3 = repeat('c', 100);
SET @col_4 = repeat('d', 100);
SET @col_5 = repeat('e', 100);
SET @col_6 = repeat('f', 100);
# insert 5 records
let $i = 5;
while ($i) {
eval INSERT INTO tab2(col_1,col_2,col_3,col_4,col_5,col_6,col_7)
VALUES (@col_1,@col_2,@col_3,@col_4,@cl_5,@col_6,$i);
dec $i;
}
--disable_result_log
SELECT * FROM tab2 ORDER BY col_7;
--echo # stop the server
--source include/shutdown_mysqld.inc
--echo [1(a)]: Rewrite into new checksum=InnoDB for all *.ibd file and ibdata1
--exec $INNOCHECKSUM --write=InnoDB $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM --write=InnoDB $MYSQLD_DATADIR/test/tab2.ibd
--exec $INNOCHECKSUM --write=InnoDB $MYSQLD_DATADIR/ibdata1
perl;
foreach (glob("$ENV{MYSQLD_DATADIR}/*/*.ibd")) {
system("$ENV{INNOCHECKSUM} --no-check --write=InnoDB $_")
}
EOF
--echo : start the server with innodb_checksum_algorithm=strict_innodb
--let $restart_parameters= --innodb_checksum_algorithm=strict_innodb
--source include/start_mysqld.inc
INSERT INTO tab1 (pk, linestring_key, linestring_nokey)
VALUES (2, ST_GeomFromText('LINESTRING(10 10,20 20,30 30)'), ST_GeomFromText('LINESTRING(10 10,20 20,30 30)'));
# load the with repeat function
SET @col_1 = repeat('a', 5);
SET @col_2 = repeat('b', 20);
SET @col_3 = repeat('c', 100);
SET @col_4 = repeat('d', 100);
SET @col_5 = repeat('e', 100);
SET @col_6 = repeat('f', 100);
# check the table status is GOOD with DML
let $i = 6;
eval INSERT INTO tab2(col_1,col_2,col_3,col_4,col_5,col_6,col_7)
VALUES (@col_1,@col_2,@col_3,@col_4,@cl_5,@col_6,$i);
-- disable_result_log
SELECT pk,ST_AsText(linestring_key),ST_AsText(linestring_nokey)
FROM tab1 ORDER BY pk;
-- disable_result_log
SELECT * FROM tab2 ORDER BY col_7;
--echo # stop the server
--source include/shutdown_mysqld.inc
--echo [1(b)]: Rewrite into new checksum=crc32 for all *.ibd file and ibdata1
--exec $INNOCHECKSUM --write=CRC32 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM --write=CRC32 $MYSQLD_DATADIR/test/tab2.ibd
--exec $INNOCHECKSUM --write=CRC32 $MYSQLD_DATADIR/ibdata1
perl;
foreach (glob("$ENV{MYSQLD_DATADIR}/*/*.ibd")) {
system("$ENV{INNOCHECKSUM} --no-check --write=crc32 $_")
}
EOF
--echo # start the server with innodb_checksum_algorithm=strict_crc32
--let $restart_parameters= --innodb_checksum_algorithm=strict_crc32
--source include/start_mysqld.inc
# check the table status is GOOD with DML
INSERT INTO tab1 (pk, linestring_key, linestring_nokey)
VALUES (3, ST_GeomFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))'),
ST_GeomFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))'));
# load the with repeat function
SET @col_1 = repeat('g', 5);
SET @col_2 = repeat('h', 20);
SET @col_3 = repeat('i', 100);
SET @col_4 = repeat('j', 100);
SET @col_5 = repeat('k', 100);
SET @col_6 = repeat('l', 100);
# check the table status is GOOD with DML
let $i = 7;
eval INSERT INTO tab2(col_1,col_2,col_3,col_4,col_5,col_6,col_7)
VALUES (@col_1,@col_2,@col_3,@col_4,@cl_5,@col_6,$i);
# check the records from table
-- disable_result_log
SELECT pk,ST_AsText(linestring_key),ST_AsText(linestring_nokey)
FROM tab1 ORDER BY pk;
-- disable_result_log
SELECT * FROM tab2 ORDER BY col_7;
--echo # stop the server
--source include/shutdown_mysqld.inc
--echo [1(c)]: Rewrite into new checksum=none for all *.ibd file and ibdata1
--exec $INNOCHECKSUM --write=none $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM --write=none $MYSQLD_DATADIR/test/tab2.ibd
--exec $INNOCHECKSUM --write=none $MYSQLD_DATADIR/ibdata1
perl;
foreach (glob("$ENV{MYSQLD_DATADIR}/undo*")) {
system("$ENV{INNOCHECKSUM} --no-check --write=NONE $_")
}
foreach (glob("$ENV{MYSQLD_DATADIR}/*/*.ibd")) {
system("$ENV{INNOCHECKSUM} --no-check --write=NONE $_")
}
EOF
--let $restart_parameters= --innodb_checksum_algorithm=strict_none
--source include/start_mysqld.inc
--let $restart_parameters=
# check the table status is GOOD with DML
INSERT INTO tab1 (pk, linestring_key, linestring_nokey)
VALUES (4, ST_GeomFromText('MULTIPOINT(0 0,5 5,10 10,20 20) '), ST_GeomFromText('MULTIPOINT(0 0,5 5,10 10,20 20) '));
# load the with repeat function
SET @col_1 = repeat('m', 5);
SET @col_2 = repeat('n', 20);
SET @col_3 = repeat('o', 100);
SET @col_4 = repeat('p', 100);
SET @col_5 = repeat('q', 100);
SET @col_6 = repeat('r', 100);
# check the table status is GOOD with DML
let $i = 8;
eval INSERT INTO tab2(col_1,col_2,col_3,col_4,col_5,col_6,col_7)
VALUES (@col_1,@col_2,@col_3,@col_4,@cl_5,@col_6,$i);
# check the records from table
-- disable_result_log
SELECT pk,ST_AsText(linestring_key),ST_AsText(linestring_nokey)
FROM tab1 ORDER BY pk;
--disable_result_log
SELECT * FROM tab2 ORDER BY col_7;
--enable_result_log
--echo # stop the server
--source include/shutdown_mysqld.inc
--echo [2]: Check the page type summary with shortform for tab1.ibd
--replace_regex /File.*.ibd/File::tab1.ibd/ /[0-9]+/#/
--exec $INNOCHECKSUM -S $MYSQLD_DATADIR/test/tab1.ibd 2>$MYSQLTEST_VARDIR/tmp/page_summary_short.txt
--echo [3]: Check the page type summary with longform for tab1.ibd
--replace_regex /File.*.ibd/File::tab1.ibd/ /[0-9]+/#/
--exec $INNOCHECKSUM --page-type-summary $MYSQLD_DATADIR/test/tab1.ibd 2>$MYSQLTEST_VARDIR/tmp/page_summary_long.txt
--remove_file $MYSQLTEST_VARDIR/tmp/page_summary_short.txt
--remove_file $MYSQLTEST_VARDIR/tmp/page_summary_long.txt
--echo [4]: Page type dump for with longform for tab1.ibd
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--exec $INNOCHECKSUM --page-type-dump $MYSQLTEST_VARDIR/tmp/dump.txt $MYSQLD_DATADIR/test/tab1.ibd
perl;
use strict;
use warnings;
use File::Copy;
my $dir = $ENV{'MYSQLTEST_VARDIR'};
opendir(DIR, $dir) or die $!;
my $file= 'dump.txt';
# open file in write mode
open IN_FILE,"<", "$dir/tmp/$file" or die $!;
open OUT_FILE, ">", "$dir/tmp/innochecksum_3_tempfile" or die $!;
while(<IN_FILE>)
{
# Replace the intergers to # and complete file path to file name only.
$_=~ s/Filename.+/Filename::tab1.ibd/g;
$_=~ s/\d+/#/g;
print OUT_FILE $_;
}
close(IN_FILE);
close(OUT_FILE);
# move the new content from tmp file to the orginal file.
move ("$dir/tmp/innochecksum_3_tempfile", "$dir/tmp/$file");
closedir(DIR);
EOF
--echo # Print the contents stored in dump.txt
cat_file $MYSQLTEST_VARDIR/tmp/dump.txt;
--remove_file $MYSQLTEST_VARDIR/tmp/dump.txt
--echo # Variables used by page type dump for ibdata1
--exec $INNOCHECKSUM -v --page-type-dump $MYSQLTEST_VARDIR/tmp/dump.txt $MYSQLD_DATADIR/ibdata1 > $MYSQLTEST_VARDIR/tmp/page_verbose_summary.txt
--file_exists $MYSQLTEST_VARDIR/tmp/dump.txt
--remove_file $MYSQLTEST_VARDIR/tmp/dump.txt
perl;
use strict;
use warnings;
use File::Copy;
my $dir = $ENV{'MYSQLTEST_VARDIR'};
opendir(DIR, $dir) or die $!;
my $file= 'page_verbose_summary.txt';
# open file in write mode
open IN_FILE,"<", "$dir/tmp/$file" or die $!;
open OUT_FILE, ">", "$dir/tmp/innochecksum_3_tempfile" or die $!;
while(<IN_FILE>)
{
# Replace complete file path to file name only.
$_=~ s/$dir/MYSQLTEST_VARDIR/;
# Remove debug option, which is not in all builds
next if (/debug/);
print OUT_FILE $_;
}
close(IN_FILE);
close(OUT_FILE);
# move the new content from tmp file to the orginal file.
move ("$dir/tmp/innochecksum_3_tempfile", "$dir/tmp/$file");
closedir(DIR);
EOF
cat_file $MYSQLTEST_VARDIR/tmp/page_verbose_summary.txt;
--remove_file $MYSQLTEST_VARDIR/tmp/page_verbose_summary.txt
--echo [5]: Page type dump for with shortform for tab1.ibd
--exec $INNOCHECKSUM -D $MYSQLTEST_VARDIR/tmp/dump.txt $MYSQLD_DATADIR/test/tab1.ibd
perl;
use strict;
use warnings;
use File::Copy;
my $dir = $ENV{'MYSQLTEST_VARDIR'};
opendir(DIR, $dir) or die $!;
my $file= 'dump.txt';
# open file in write mode
open IN_FILE,"<", "$dir/tmp/$file" or die $!;
open OUT_FILE, ">", "$dir/tmp/innochecksum_3_tempfile" or die $!;
while(<IN_FILE>)
{
# Replace the intergers to # and complete file path to file name only.
$_=~ s/Filename.+/Filename::tab1.ibd/g;
$_=~ s/\d+/#/g;
print OUT_FILE $_;
}
close(IN_FILE);
close(OUT_FILE);
# move the new content from tmp file to the orginal file.
move ("$dir/tmp/innochecksum_3_tempfile", "$dir/tmp/$file");
closedir(DIR);
EOF
# Print the contents stored in dump.txt
cat_file $MYSQLTEST_VARDIR/tmp/dump.txt;
--remove_file $MYSQLTEST_VARDIR/tmp/dump.txt
--echo [6]: check the valid lower bound values for option
--echo # allow-mismatches,page,start-page,end-page
--exec $INNOCHECKSUM --allow-mismatches=0 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM -a 0 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM --page=0 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM -p 0 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM --start-page=0 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM -s 0 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM --end-page=0 $MYSQLD_DATADIR/test/tab1.ibd
--exec $INNOCHECKSUM -e 0 $MYSQLD_DATADIR/test/tab1.ibd
#
# These produce now errors
#
#--echo [7]: check the negative values for option
#--echo # allow-mismatches,page,start-page,end-page.
#--echo # They will reset to zero for negative values.
#--echo # check the invalid lower bound values
#--exec $INNOCHECKSUM --allow-mismatches=-1 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM -a -1 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM --page=-1 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM -p -1 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM --start-page=-1 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM -s -1 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM --end-page=-1 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM -e -1 $MYSQLD_DATADIR/test/tab1.ibd
#
#--echo [8]: check the valid upper bound values for
#--echo # both short and long options "allow-mismatches" and "end-page"
#
#--exec $INNOCHECKSUM --allow-mismatches=18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM -a 18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM --end-page=18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd
#--exec $INNOCHECKSUM -e 18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd
--echo [9]: check the both short and long options "page" and "start-page" when
--echo # seek value is larger than file size.
--error 1
--exec $INNOCHECKSUM --page=18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Error: Unable to seek to necessary offset: Invalid argument;
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM -p 18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Error: Unable to seek to necessary offset: Invalid argument;
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM --start-page=18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Error: Unable to seek to necessary offset: Invalid argument;
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM -s 18446744073709551615 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Error: Unable to seek to necessary offset: Invalid argument;
--source include/search_pattern_in_file.inc
--echo [34]: check the invalid upper bound values for options, allow-mismatches, end-page, start-page and page.
--echo # innochecksum will fail with error code: 1
--error 1
--exec $INNOCHECKSUM --allow-mismatches=18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM -a 18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM --end-page=18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM -e 18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM --page=18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM -p 18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM --start-page=18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--error 1
--exec $INNOCHECKSUM -s 18446744073709551616 $MYSQLD_DATADIR/test/tab1.ibd 2> $SEARCH_FILE
let SEARCH_PATTERN= Incorrect unsigned integer value: '18446744073709551616';
--source include/search_pattern_in_file.inc
--remove_file $SEARCH_FILE
# Cleanup
--source include/start_mysqld.inc
DROP TABLE tab1,tab2;