--source include/have_innodb.inc
--source include/big_test.inc
--source include/not_embedded.inc
call mtr.add_suppression("InnoDB: The change buffer is corrupted");
call mtr.add_suppression("InnoDB: Tablespace size stored in header is 768 pages, but the sum of data file sizes is 384 pages");
call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of file");
--source include/shutdown_mysqld.inc
let bugdir= $MYSQLTEST_VARDIR/tmp/log_upgrade;
--mkdir $bugdir
--let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err
--let $dirs= --innodb-data-home-dir=$bugdir --innodb-log-group-home-dir=$bugdir --innodb-undo-directory=$bugdir

# Test case similar to log_upgrade.test
perl;
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
my $polynomial = 0x82f63b78; # CRC-32C

die unless open OUT, ">", "$ENV{bugdir}/ibdata1";
binmode OUT;

my $head = pack("Nx[18]", 0);
# Add FSP_SPACE_FLAGS as 49152 (10.1.0...10.1.20), page_size = 32k
my $body = pack("x[8]Nx[4]Nx[2]Nx[32696]", 768, 49152, 97937874);
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 change buffer header page (page 3).
die unless seek(OUT, 3 * 32768, 0);
## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT, FIL_PAGE_TYPE
my $head = pack("NNNx[8]n", 3, 0xffffffff, 0xffffffff, 6);
my $body = pack("x[62]nnx[32656]", 2, 50);
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 change buffer root page (page 4).
## FIL_PAGE_OFFSET, FIL_PAGE_PREV, FIL_PAGE_NEXT
my $head = pack("NNNx[10]", 4, 0xffffffff, 0xffffffff);
my $body = chr(0) x 32722;
my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);


# Dictionary header page (page 7).
die unless seek(OUT, 7 * 32768, 0);
$head = pack("Nx[18]", 7);
$body = pack("x[32]Nx[8]Nx[32674]", 8, 9);
$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);

# Empty SYS_TABLES page (page 8).
$head = pack("NNNx[8]n", 8, ~0, ~0, 17855);
$body = pack("nnx[31]Cx[20]", 2, 124, 1);
$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
$body .= pack("x[32632]nn", 116, 101);
$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);

# Empty SYS_INDEXES page (page 9).
$head = pack("NNNx[8]n", 9, ~0, ~0, 17855);
$body = pack("nnx[31]Cx[20]", 2, 124, 3);
$body .= pack("nxnn", 0x801, 3, 116) . "infimum";
$body .= pack("xnxnxx", 0x901, 0x803) . "supremum";
$body .= pack("x[32632]nn", 116, 101);
$ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
print OUT pack("N",$ck).$head.pack("x[12]").$body.pack("Nx[4]",$ck);

die unless seek(OUT, 768 * 16384 - 1, 0);
print OUT chr(0);
close OUT or die;

die unless open OUT, ">", "$ENV{bugdir}/ib_logfile0";
binmode OUT;
$_= pack("Nx[5]nx[5]", 1, 0x1286) . "BogoDB 4.3.2.1" . chr(0) x 478;
print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
# checkpoint page 1 and all-zero checkpoint 2
$_= pack("x[13]nCNNx[484]", 0x1286, 12, 2, 0x80c);
print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
die unless seek(OUT, 0x1FFFFFFFF, 0);
print OUT chr(0);
close OUT or die;
die unless open OUT, ">", "$ENV{bugdir}/ib_logfile1";
binmode OUT;
die unless seek(OUT, 0x800, 0); # the first 2048 bytes are unused!
$_= pack("Nnnx[500]", 0x80000944, 12, 12);
print OUT $_, pack("N", mycrc32($_, 0, $polynomial));
die unless seek(OUT, 0x1FFFFFFFF, 0);
print OUT chr(0);
close OUT or die;
EOF

--let $restart_parameters= $dirs --innodb-force-recovery=5 --innodb-log-file-size=4m --innodb_page_size=32k --innodb_buffer_pool_size=11M
--source include/start_mysqld.inc
SELECT COUNT(*) FROM INFORMATION_SCHEMA.ENGINES
WHERE engine = 'innodb'
AND support IN ('YES', 'DEFAULT', 'ENABLED');
--source include/shutdown_mysqld.inc
--let SEARCH_PATTERN= InnoDB: Upgrading redo log:
--source include/search_pattern_in_file.inc
--let $restart_parameters= $dirs

--remove_files_wildcard $bugdir
--rmdir $bugdir
--let $restart_parameters=
--source include/start_mysqld.inc

--echo # End of 10.5 tests
