summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thiru@mariadb.com>2019-06-28 18:49:43 +0530
committerThirunarayanan Balathandayuthapani <thiru@mariadb.com>2019-06-28 18:58:52 +0530
commite4a0dbfb4aa77a9d41039f5cd7144d98a6b9baed (patch)
treed2c2344720e5b47345b0aecf642165ec17954f76 /mysql-test
parentf7a4a8719bd59eca27e3e5e467c138853aa63dd5 (diff)
downloadmariadb-git-e4a0dbfb4aa77a9d41039f5cd7144d98a6b9baed.tar.gz
MDEV-19781 Add page id matching check in innochecksum tool
Added the condition in innochecksum tool to check page id mismatch. This could catch the write corruption caused by InnoDB. Added the debug insert inside fil_io() to check whether it writes the page to wrong offset.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/suite/encryption/r/innochecksum.result2
-rw-r--r--mysql-test/suite/encryption/t/innochecksum.test3
-rw-r--r--mysql-test/suite/innodb/r/page_id_innochecksum.result6
-rw-r--r--mysql-test/suite/innodb/t/page_id_innochecksum.test52
4 files changed, 61 insertions, 2 deletions
diff --git a/mysql-test/suite/encryption/r/innochecksum.result b/mysql-test/suite/encryption/r/innochecksum.result
index 6ea54f3d053..2c1279cd232 100644
--- a/mysql-test/suite/encryption/r/innochecksum.result
+++ b/mysql-test/suite/encryption/r/innochecksum.result
@@ -33,7 +33,7 @@ CREATE TABLE t6 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ENGINE=InnoDB;
# Run innochecksum on t2
# Run innochecksum on t3
# Run innochecksum on t6
-# no encryption corrupting the field should not have effect
+# Space ID mismatch
# Restore the original tables
# Corrupt FIL_DATA+10 (data)
# Run innochecksum on t2
diff --git a/mysql-test/suite/encryption/t/innochecksum.test b/mysql-test/suite/encryption/t/innochecksum.test
index f1c1b65d418..47da8525130 100644
--- a/mysql-test/suite/encryption/t/innochecksum.test
+++ b/mysql-test/suite/encryption/t/innochecksum.test
@@ -206,7 +206,8 @@ EOF
--exec $INNOCHECKSUM $t3_IBD
--echo # Run innochecksum on t6
---echo # no encryption corrupting the field should not have effect
+--echo # Space ID mismatch
+--error 1
--exec $INNOCHECKSUM $t6_IBD
--enable_result_log
diff --git a/mysql-test/suite/innodb/r/page_id_innochecksum.result b/mysql-test/suite/innodb/r/page_id_innochecksum.result
new file mode 100644
index 00000000000..e2c13442fe6
--- /dev/null
+++ b/mysql-test/suite/innodb/r/page_id_innochecksum.result
@@ -0,0 +1,6 @@
+# Set the environmental variables
+create table t1(f1 int not null)engine=innodb;
+insert into t1 values(1), (2), (3);
+# Change the page offset
+FOUND 1 /page id mismatch/ in result.log
+drop table t1;
diff --git a/mysql-test/suite/innodb/t/page_id_innochecksum.test b/mysql-test/suite/innodb/t/page_id_innochecksum.test
new file mode 100644
index 00000000000..5bd8a58fcd5
--- /dev/null
+++ b/mysql-test/suite/innodb/t/page_id_innochecksum.test
@@ -0,0 +1,52 @@
+--source include/have_innodb.inc
+--echo # Set the environmental variables
+let MYSQLD_BASEDIR= `SELECT @@basedir`;
+let MYSQLD_DATADIR= `SELECT @@datadir`;
+let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
+
+create table t1(f1 int not null)engine=innodb;
+insert into t1 values(1), (2), (3);
+let $resultlog=$MYSQLTEST_VARDIR/tmp/result.log;
+
+--source include/shutdown_mysqld.inc
+--echo # Change the page offset
+perl;
+use strict;
+use warnings;
+use Fcntl qw(:DEFAULT :seek);
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+
+my $page_size = $ENV{INNODB_PAGE_SIZE};
+
+sysopen IBD_FILE, "$ENV{MYSQLD_DATADIR}/test/t1.ibd", O_RDWR
+|| die "Cannot open t1.ibd\n";
+sysread(IBD_FILE, $_, 38) || die "Cannot read t1.ibd\n";
+my $space = unpack("x[34]N", $_);
+sysseek(IBD_FILE, $page_size * 3, SEEK_SET) || die "Cannot seek t1.ibd\n";
+
+my $head = pack("Nx[18]", 4); # better to have a valid page number
+my $body = chr(0) x ($page_size - 38 - 8);
+
+# Calculate innodb_checksum_algorithm=crc32 for the unencrypted page.
+# 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
+my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+
+my $page= pack("N",$ck).$head.pack("NNN",1,$ck,$space).$body.pack("Nx[4]",$ck);
+die unless syswrite(IBD_FILE, $page, $page_size) == $page_size;
+close IBD_FILE;
+EOF
+
+--error 1
+exec $INNOCHECKSUM -C crc32 -l $resultlog $MYSQLD_DATADIR/test/t1.ibd;
+
+let SEARCH_FILE = $MYSQLTEST_VARDIR/tmp/result.log;
+let SEARCH_PATTERN=page id mismatch;
+--source include/search_pattern_in_file.inc
+
+--remove_file $resultlog
+--source include/start_mysqld.inc
+drop table t1;