summaryrefslogtreecommitdiff
path: root/mysql-test/suite/encryption/t/corrupted_during_recovery.test
blob: f838ea04c28622bb2871ac003081e2ba70912a1f (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--source include/have_innodb.inc
--source include/have_file_key_management_plugin.inc

--disable_query_log
call mtr.add_suppression("InnoDB: Plugin initialization aborted");
call mtr.add_suppression("Plugin 'InnoDB' init function returned error");
call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
call mtr.add_suppression("InnoDB: Database page corruption on disk or a failed read of file '.*test.t1\\.ibd' page");
call mtr.add_suppression("InnoDB: Failed to read page [123] from file '.*test.t1\\.ibd': Table is compressed or encrypted but uncompress or decrypt failed");
call mtr.add_suppression("InnoDB: The page \\[page id: space=\\d+, page number=3\\] in file '.*test.t1\\.ibd' cannot be decrypted");
call mtr.add_suppression("InnoDB: Table in tablespace \\d+ encrypted. However key management plugin or used key_version \\d+ is not found or used encryption algorithm or method does not match. Can't continue opening the table.");
--enable_query_log

let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
CREATE TABLE t1(a BIGINT PRIMARY KEY) ENGINE=InnoDB, ENCRYPTED=YES;
INSERT INTO t1 VALUES(1);
# Force a redo log checkpoint.
let $restart_noprint=2;
--source include/restart_mysqld.inc
--source ../../suite/innodb/include/no_checkpoint_start.inc
CREATE TABLE t2(a BIGINT PRIMARY KEY) ENGINE=InnoDB, ENCRYPTED=YES;
INSERT INTO t1 VALUES(2);
SET GLOBAL innodb_flush_log_at_trx_commit=1;
INSERT INTO t2 VALUES(2);

--let CLEANUP_IF_CHECKPOINT=DROP TABLE t1,t2;
--source ../../suite/innodb/include/no_checkpoint_end.inc

--echo # Corrupt the pages

perl;
my $ps = $ENV{INNODB_PAGE_SIZE};

my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
open(FILE, "+<$file") || die "Unable to open $file";
binmode FILE;
my $offset = ($ENV{INNODB_CHECKSUM_ALGORITHM} =~ /full_crc32/) ? 26 : 0;
seek (FILE, $ENV{INNODB_PAGE_SIZE} * 3 + $offset, SEEK_SET) or die "seek";
print FILE "junk";
close FILE or die "close";

$file = "$ENV{MYSQLD_DATADIR}/test/t2.ibd";
open(FILE, "+<$file") || die "Unable to open $file";
binmode FILE;
# Corrupt pages 1 to 3. MLOG_INIT_FILE_PAGE2 should protect us!
# Unfortunately, we are not immune to page 0 corruption.
seek (FILE, $ps, SEEK_SET) or die "seek";
print FILE chr(0xff) x ($ps * 3);
close FILE or die "close";
EOF

--source include/start_mysqld.inc
--error ER_UNKNOWN_STORAGE_ENGINE
SELECT * FROM t1;
--disable_query_log
call mtr.add_suppression("InnoDB: Encrypted page \\[page id: space=[1-9][0-9]*, page number=3\\] in file .*test.t[1].ibd looks corrupted; key_version=");
call mtr.add_suppression("Table .*t1.* is corrupted. Please drop the table and recreate.");
--enable_query_log
let $restart_parameters=--innodb_force_recovery=1 --skip-innodb-buffer-pool-load-at-startup;
--source include/restart_mysqld.inc

--error ER_TABLE_CORRUPT
SELECT * FROM t1;
SELECT * FROM t2;
CHECK TABLE t2;

DROP TABLE t1, t2;