| 1 |
--source include/have_innodb.inc |
| 2 |
--source include/have_debug.inc |
| 3 |
--source include/not_embedded.inc |
| 4 |
--source include/have_file_key_management_plugin.inc |
| 5 |
call mtr.add_suppression("InnoDB: Encrypted page \\[page id: space=[1-9][0-9]*, page number=3\\] in file .*test.t[12]\\.ibd looks corrupted"); |
| 6 |
call mtr.add_suppression("InnoDB: Unable to apply log to corrupted page "); |
| 7 |
call mtr.add_suppression("InnoDB: Plugin initialization aborted"); |
| 8 |
call mtr.add_suppression("Plugin 'InnoDB' init function returned error"); |
| 9 |
call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed"); |
| 10 |
|
| 11 |
let INNODB_PAGE_SIZE=`select @@innodb_page_size`; |
| 12 |
let MYSQLD_DATADIR=`select @@datadir`; |
| 13 |
let ALGO=`select @@innodb_checksum_algorithm`; |
| 14 |
|
| 15 |
create table t1 (f1 int primary key, f2 blob)page_compressed=1 engine=innodb encrypted=yes stats_persistent=0; |
| 16 |
create table t2(f1 int primary key, f2 blob)engine=innodb encrypted=yes stats_persistent=0; |
| 17 |
create table t3(f1 int primary key, f2 blob)page_compressed=1 engine=innodb encrypted=no stats_persistent=0; |
| 18 |
|
| 19 |
start transaction; |
| 20 |
insert into t1 values(1, repeat('#',12)); |
| 21 |
insert into t1 values(2, repeat('+',12)); |
| 22 |
insert into t1 values(3, repeat('/',12)); |
| 23 |
insert into t1 values(4, repeat('-',12)); |
| 24 |
insert into t1 values(5, repeat('.',12)); |
| 25 |
insert into t2 select * from t1; |
| 26 |
insert into t3 select * from t1; |
| 27 |
commit work; |
| 28 |
|
| 29 |
# Slow shutdown and restart to make sure ibuf merge is finished |
| 30 |
SET GLOBAL innodb_fast_shutdown = 0; |
| 31 |
let $shutdown_timeout=; |
| 32 |
let $restart_parameters=--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0; |
| 33 |
--source include/restart_mysqld.inc |
| 34 |
--source ../../suite/innodb/include/no_checkpoint_start.inc |
| 35 |
|
| 36 |
select space into @t1_space_id from information_schema.innodb_sys_tablespaces where name='test/t1'; |
| 37 |
select space into @t2_space_id from information_schema.innodb_sys_tablespaces where name='test/t2'; |
| 38 |
select space into @t3_space_id from information_schema.innodb_sys_tablespaces where name='test/t3'; |
| 39 |
|
| 40 |
begin; |
| 41 |
insert into t1 values (6, repeat('%', 400)); |
| 42 |
insert into t2 values (6, repeat('%', 400)); |
| 43 |
insert into t3 values (6, repeat('%', 400)); |
| 44 |
|
| 45 |
# Copy the t1.ibd, t2.ibd, t3.ibd file |
| 46 |
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup_1; |
| 47 |
--disable_result_log |
| 48 |
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --skip-innodb-log-checkpoint-now --target-dir=$targetdir; |
| 49 |
--enable_result_log |
| 50 |
|
| 51 |
echo # xtrabackup prepare; |
| 52 |
--disable_result_log |
| 53 |
exec $XTRABACKUP --prepare --target-dir=$targetdir; |
| 54 |
|
| 55 |
set global innodb_saved_page_number_debug = 3; |
| 56 |
set global innodb_fil_make_page_dirty_debug = @t1_space_id; |
| 57 |
|
| 58 |
set global innodb_saved_page_number_debug = 3; |
| 59 |
set global innodb_fil_make_page_dirty_debug = @t2_space_id; |
| 60 |
|
| 61 |
set global innodb_saved_page_number_debug = 3; |
| 62 |
set global innodb_fil_make_page_dirty_debug = @t3_space_id; |
| 63 |
|
| 64 |
set global innodb_buf_flush_list_now = 1; |
| 65 |
--let CLEANUP_IF_CHECKPOINT=drop table t1, t2, t3, unexpected_checkpoint; |
| 66 |
--source ../../suite/innodb/include/no_checkpoint_end.inc |
| 67 |
# Corrupt the page 3 in t1.ibd, t2.ibd file |
| 68 |
perl; |
| 69 |
use IO::Handle; |
| 70 |
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl"; |
| 71 |
my $polynomial = 0x82f63b78; # CRC-32C |
| 72 |
my $algo = $ENV{ALGO}; |
| 73 |
die "Unsupported innodb_checksum_algorithm=$algo\n" unless $algo =~ /crc32/; |
| 74 |
|
| 75 |
my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd"; |
| 76 |
my $page_size = $ENV{INNODB_PAGE_SIZE}; |
| 77 |
my $page; |
| 78 |
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl"; |
| 79 |
open(FILE, "+<", $fname) or die; |
| 80 |
sysseek(FILE, 3*$page_size, 0); |
| 81 |
sysread(FILE, $page, $page_size)==$page_size||die "Unable to read $name\n"; |
| 82 |
sysseek(FILE, 3*$page_size, 0)||die "Unable to seek $fname\n"; |
| 83 |
my $corrupted = $page; |
| 84 |
# Set FIL_PAGE_LSN to the maximum |
| 85 |
substr($corrupted, 16, 8) = chr(255) x 8; |
| 86 |
substr($corrupted, $page_size - 8, 8) = chr(255) x 8; |
| 87 |
if ($algo =~ /full_crc32/) |
| 88 |
{ |
| 89 |
my $ck = mycrc32(substr($corrupted, 0, $page_size - 4), 0, $polynomial); |
| 90 |
substr($corrupted, $page_size - 4, 4) = pack("N", $ck); |
| 91 |
} |
| 92 |
else |
| 93 |
{ |
| 94 |
# Replace the innodb_checksum_algorithm=crc32 checksum |
| 95 |
my $ck= pack("N", |
| 96 |
mycrc32(substr($corrupted, 4, 22), 0, $polynomial) ^ |
| 97 |
mycrc32(substr($corrupted_, 38, $page_size - 38 - 8), 0, |
| 98 |
$polynomial)); |
| 99 |
substr ($corrupted, 0, 4) = $ck; |
| 100 |
substr ($corrupted, $page_size - 8, 4) = $ck; |
| 101 |
} |
| 102 |
syswrite(FILE, $corrupted); |
| 103 |
close FILE; |
| 104 |
|
| 105 |
# Zero the complete page |
| 106 |
my $fname= "$ENV{'MYSQLD_DATADIR'}test/t2.ibd"; |
| 107 |
open(FILE, "+<", $fname) or die; |
| 108 |
FILE->autoflush(1); |
| 109 |
binmode FILE; |
| 110 |
sysseek(FILE, 3*$page_size, 0); |
| 111 |
print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'}); |
| 112 |
close FILE; |
| 113 |
|
| 114 |
# Zero the complete page |
| 115 |
my $fname= "$ENV{'MYSQLD_DATADIR'}test/t3.ibd"; |
| 116 |
open(FILE, "+<", $fname) or die; |
| 117 |
FILE->autoflush(1); |
| 118 |
binmode FILE; |
| 119 |
sysseek(FILE, 3*$page_size, 0); |
| 120 |
print FILE chr(0) x ($ENV{'INNODB_PAGE_SIZE'}); |
| 121 |
close FILE; |
| 122 |
EOF |
| 123 |
|
| 124 |
# Successful recover from doublewrite buffer |
| 125 |
let $restart_parameters=; |
| 126 |
--source include/start_mysqld.inc |
| 127 |
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; |
| 128 |
let SEARCH_PATTERN=InnoDB: Recovered page \\[page id: space=[1-9][0-9]*, page number=3\\]; |
| 129 |
--source include/search_pattern_in_file.inc |
| 130 |
|
| 131 |
check table t1; |
| 132 |
check table t2; |
| 133 |
check table t3; |
| 134 |
select f1, f2 from t1; |
| 135 |
select f1, f2 from t2; |
| 136 |
select f1, f2 from t3; |
| 137 |
|
| 138 |
SET GLOBAL innodb_fast_shutdown = 0; |
| 139 |
let $shutdown_timeout=; |
| 140 |
let $restart_parameters=--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0; |
| 141 |
--source ../../mariabackup/include/restart_and_restore.inc |
| 142 |
--source ../../suite/innodb/include/no_checkpoint_start.inc |
| 143 |
select space into @t1_space_id from information_schema.innodb_sys_tablespaces where name='test/t1'; |
| 144 |
|
| 145 |
begin; |
| 146 |
insert into t1 values (6, repeat('%', 400)); |
| 147 |
|
| 148 |
set global innodb_saved_page_number_debug = 3; |
| 149 |
set global innodb_fil_make_page_dirty_debug = @t1_space_id; |
| 150 |
|
| 151 |
set global innodb_buf_flush_list_now = 1; |
| 152 |
--let CLEANUP_IF_CHECKPOINT=drop table t1, unexpected_checkpoint; |
| 153 |
--source ../../suite/innodb/include/no_checkpoint_end.inc |
| 154 |
|
| 155 |
--echo # Corrupt the page 3 in t1.ibd file |
| 156 |
--echo # Assign the maximum value to lsn in doublewrite buffer page |
| 157 |
perl; |
| 158 |
use IO::Handle; |
| 159 |
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl"; |
| 160 |
my $polynomial = 0x82f63b78; # CRC-32C |
| 161 |
my $algo = $ENV{ALGO}; |
| 162 |
die "Unsupported innodb_checksum_algorithm=$algo\n" unless $algo =~ /crc32/; |
| 163 |
|
| 164 |
my $fname= "$ENV{'MYSQLD_DATADIR'}test/t1.ibd"; |
| 165 |
my $page_size = $ENV{INNODB_PAGE_SIZE}; |
| 166 |
my $page; |
| 167 |
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl"; |
| 168 |
open(FILE, "+<", $fname) or die; |
| 169 |
sysseek(FILE, 3*$page_size, 0); |
| 170 |
sysread(FILE, $page, $page_size)==$page_size||die "Unable to read $name\n"; |
| 171 |
sysseek(FILE, 3*$page_size, 0)||die "Unable to seek $fname\n"; |
| 172 |
my $corrupted = $page; |
| 173 |
# Set FIL_PAGE_LSN to the maximum |
| 174 |
substr($corrupted, 16, 8) = chr(255) x 8; |
| 175 |
substr($corrupted, $page_size - 8, 8) = chr(255) x 8; |
| 176 |
if ($algo =~ /full_crc32/) |
| 177 |
{ |
| 178 |
my $ck = mycrc32(substr($corrupted, 0, $page_size - 4), 0, $polynomial); |
| 179 |
substr($corrupted, $page_size - 4, 4) = pack("N", $ck); |
| 180 |
} |
| 181 |
else |
| 182 |
{ |
| 183 |
# Replace the innodb_checksum_algorithm=crc32 checksum |
| 184 |
my $ck= pack("N", |
| 185 |
mycrc32(substr($corrupted, 4, 22), 0, $polynomial) ^ |
| 186 |
mycrc32(substr($corrupted_, 38, $page_size - 38 - 8), 0, |
| 187 |
$polynomial)); |
| 188 |
substr ($corrupted, 0, 4) = $ck; |
| 189 |
substr ($corrupted, $page_size - 8, 4) = $ck; |
| 190 |
} |
| 191 |
syswrite(FILE, $corrupted); |
| 192 |
close FILE; |
| 193 |
|
| 194 |
# Change the page lsn to maximum value |
| 195 |
open(FILE, "+<", "$ENV{MYSQLD_DATADIR}ibdata1")||die "cannot open ibdata1\n"; |
| 196 |
sysseek(FILE, 6 * $page_size - 190, 0)||die "Unable to seek ibdata1\n"; |
| 197 |
sysread(FILE, $_, 12) == 12||die "Unable to read TRX_SYS\n"; |
| 198 |
my($magic,$d1,$d2)=unpack "NNN", $_; |
| 199 |
die "magic=$magic, $d1, $d2\n" unless $magic == 536853855 && $d2 >= $d1 + 64; |
| 200 |
sysseek(FILE, $d1 * $page_size, 0)||die "Unable to seek ibdata1\n"; |
| 201 |
# Find the page in the doublewrite buffer |
| 202 |
for (my $d = $d1; $d < $d2 + 64; $d++) |
| 203 |
{ |
| 204 |
sysread(FILE, $_, $page_size)==$page_size||die "Cannot read doublewrite\n"; |
| 205 |
next unless $_ eq $page; |
| 206 |
sysseek(FILE, $d * $page_size, 0)||die "Unable to seek ibdata1\n"; |
| 207 |
substr($_, 16, 8) = chr(255) x 8; |
| 208 |
if ($algo =~ /full_crc32/) |
| 209 |
{ |
| 210 |
my $ck = mycrc32(substr($_, 0, $page_size - 4), 0, $polynomial); |
| 211 |
substr($_, $page_size - 4, 4) = pack("N", $ck); |
| 212 |
} |
| 213 |
else |
| 214 |
{ |
| 215 |
# Replace the innodb_checksum_algorithm=crc32 checksum |
| 216 |
my $ck= pack("N", |
| 217 |
mycrc32(substr($_, 4, 22), 0, $polynomial) ^ |
| 218 |
mycrc32(substr($_, 38, $page_size - 38 - 8), 0, |
| 219 |
$polynomial)); |
| 220 |
substr ($_, 0, 4) = $ck; |
| 221 |
substr ($_, $page_size - 8, 4) = $ck; |
| 222 |
} |
| 223 |
syswrite(FILE, $_, $page_size)==$page_size||die; |
| 224 |
close(FILE); |
| 225 |
exit 0; |
| 226 |
} |
| 227 |
die "Did not find the page in the doublewrite buffer ($d1,$d2)\n"; |
| 228 |
EOF |
| 229 |
|
| 230 |
let $restart_parameters=; |
| 231 |
--source include/start_mysqld.inc |
| 232 |
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; |
| 233 |
let SEARCH_PATTERN=InnoDB: Encrypted page \\[page id: space=[1-9]*, page number=3\\] in file .*test.t1.ibd looks corrupted; |
| 234 |
--source include/search_pattern_in_file.inc |
| 235 |
|
| 236 |
--error ER_UNKNOWN_STORAGE_ENGINE |
| 237 |
select * from t1; |
| 238 |
|
| 239 |
--source ../../mariabackup/include/restart_and_restore.inc |
| 240 |
select * from t1; |
| 241 |
drop table t3, t2, t1; |