mirror of
https://github.com/MariaDB/server.git
synced 2025-11-28 17:36:30 +03:00
MariaDB data-at-rest encryption (innodb_encrypt_tables) had repurposed the same unused data field that was repurposed in MySQL 5.7 (and MariaDB 10.2) for the Split Sequence Number (SSN) field of SPATIAL INDEX. Because of this, MariaDB was unable to support encryption on SPATIAL INDEX pages. Furthermore, InnoDB page checksums skipped some bytes, and there are multiple variations and checksum algorithms. By default, InnoDB accepts all variations of all algorithms that ever existed. This unnecessarily weakens the page checksums. We hereby introduce two more innodb_checksum_algorithm variants (full_crc32, strict_full_crc32) that are special in a way: When either setting is active, newly created data files will carry a flag (fil_space_t::full_crc32()) that indicates that all pages of the file will use a full CRC-32C checksum over the entire page contents (excluding the bytes where the checksum is stored, at the very end of the page). Such files will always use that checksum, no matter what the parameter innodb_checksum_algorithm is assigned to. For old files, the old checksum algorithms will continue to be used. The value strict_full_crc32 will be equivalent to strict_crc32 and the value full_crc32 will be equivalent to crc32. ROW_FORMAT=COMPRESSED tables will only use the old format. These tables do not support new features, such as larger innodb_page_size or instant ADD/DROP COLUMN. They may be deprecated in the future. We do not want an unnecessary file format change for them. The new full_crc32() format also cleans up the MariaDB tablespace flags. We will reserve flags to store the page_compressed compression algorithm, and to store the compressed payload length, so that checksum can be computed over the compressed (and possibly encrypted) stream and can be validated without decrypting or decompressing the page. In the full_crc32 format, there no longer are separate before-encryption and after-encryption checksums for pages. The single checksum is computed on the page contents that is written to the file. We do not make the new algorithm the default for two reasons. First, MariaDB 10.4.2 was a beta release, and the default values of parameters should not change after beta. Second, we did not yet implement the full_crc32 format for page_compressed pages. This will be fixed in MDEV-18644. This is joint work with Marko Mäkelä.
202 lines
6.8 KiB
Plaintext
202 lines
6.8 KiB
Plaintext
--source include/have_innodb.inc
|
|
# The embedded server does not support restarting in mysql-test-run.
|
|
-- source include/not_embedded.inc
|
|
-- source include/no_valgrind_without_big.inc
|
|
-- source include/innodb_checksum_algorithm.inc
|
|
|
|
let MYSQLD_DATADIR=`select @@datadir`;
|
|
let PAGE_SIZE=`select @@innodb_page_size`;
|
|
|
|
-- disable_query_log
|
|
call mtr.add_suppression("InnoDB: innodb_force_recovery is on.");
|
|
call mtr.add_suppression("InnoDB: Header page contains inconsistent data in .*bug16720368.ibd");
|
|
call mtr.add_suppression("InnoDB: Checksum mismatch in datafile:.*bug16720368");
|
|
call mtr.add_suppression("InnoDB: Ignoring tablespace for.*bug16720368");
|
|
call mtr.add_suppression("Found 1 prepared XA transactions");
|
|
call mtr.add_suppression("InnoDB: Operating system error.*in a file operation");
|
|
call mtr.add_suppression("InnoDB: \(The error means\|If you are\)");
|
|
call mtr.add_suppression("InnoDB: Ignoring tablespace `test/bug16720368` because it could not be opened");
|
|
call mtr.add_suppression("InnoDB: Tablespace .* was not found at.*bug16735660");
|
|
call mtr.add_suppression("InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace.");
|
|
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.");
|
|
-- enable_query_log
|
|
|
|
-- echo #
|
|
-- echo # Bug#16720368 INNODB CRASHES ON BROKEN #SQL*.IBD FILE AT STARTUP
|
|
-- echo #
|
|
|
|
SET GLOBAL innodb_file_per_table=1;
|
|
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
|
|
|
|
CREATE TABLE bug16720368_1 (a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
|
|
connect (con1,localhost,root);
|
|
CREATE TABLE bug16720368 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
|
|
INSERT INTO bug16720368 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8);
|
|
--source include/wait_all_purged.inc
|
|
|
|
connection default;
|
|
|
|
-- echo # Cleanly shutdown mysqld
|
|
-- source include/shutdown_mysqld.inc
|
|
|
|
disconnect con1;
|
|
|
|
-- echo # Corrupt FIL_PAGE_OFFSET in bug16720368.ibd,
|
|
-- echo # and recompute innodb_checksum_algorithm=crc32
|
|
perl;
|
|
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
|
|
my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
|
|
open(FILE, "+<$file") || die "Unable to open $file";
|
|
binmode FILE;
|
|
my $ps= $ENV{PAGE_SIZE};
|
|
my $page;
|
|
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
|
|
substr($page,4,4)=pack("N",0xc001cafe);
|
|
my $polynomial = 0x82f63b78; # CRC-32C
|
|
my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
|
|
if ($full_crc32)
|
|
{
|
|
my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
|
|
substr($page, $ps-4, 4) = pack("N", $ck);
|
|
}
|
|
else
|
|
{
|
|
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
|
|
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
|
|
substr($page,0,4)=$ck;
|
|
substr($page,$ps-8,4)=$ck;
|
|
}
|
|
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
|
|
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
|
|
close(FILE) || die "Unable to close $file";
|
|
EOF
|
|
|
|
-- echo # Restart mysqld
|
|
-- source include/start_mysqld.inc
|
|
|
|
-- echo # This will succeed after a clean shutdown, due to
|
|
-- echo # fil_open_single_table_tablespace(check_space_id=FALSE).
|
|
SELECT COUNT(*) FROM bug16720368;
|
|
|
|
INSERT INTO bug16720368_1 VALUES(1);
|
|
|
|
--let $shutdown_timeout= 0
|
|
--source include/restart_mysqld.inc
|
|
|
|
-- echo # The table is unaccessible, because after a crash we will
|
|
-- echo # validate the tablespace header.
|
|
--error ER_NO_SUCH_TABLE_IN_ENGINE
|
|
SELECT COUNT(*) FROM bug16720368;
|
|
--error ER_NO_SUCH_TABLE_IN_ENGINE
|
|
INSERT INTO bug16720368 VALUES(0,1);
|
|
|
|
let $restart_parameters = --innodb-force-recovery=3;
|
|
--let $shutdown_timeout= 0
|
|
--source include/restart_mysqld.inc
|
|
|
|
-- echo # The table is readable thanks to innodb-force-recovery.
|
|
SELECT COUNT(*) FROM bug16720368;
|
|
INSERT INTO bug16720368 VALUES(0,1);
|
|
|
|
-- echo # Shut down the server cleanly to hide the corruption.
|
|
let $shutdown_timeout=;
|
|
let $restart_parameters =;
|
|
-- source include/restart_mysqld.inc
|
|
|
|
-- echo # The table is accessible, because after a clean shutdown we will
|
|
-- echo # NOT validate the tablespace header.
|
|
-- echo # We can modify the existing pages, but we cannot allocate or free
|
|
-- echo # any pages, because that would hit the corruption on page 0.
|
|
SELECT COUNT(*) FROM bug16720368;
|
|
|
|
-- echo # Shut down the server to uncorrupt the data.
|
|
-- source include/shutdown_mysqld.inc
|
|
|
|
# Uncorrupt the FIL_PAGE_OFFSET.
|
|
perl;
|
|
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl";
|
|
my $file = "$ENV{MYSQLD_DATADIR}/test/bug16720368.ibd";
|
|
open(FILE, "+<$file") || die "Unable to open $file";
|
|
binmode FILE;
|
|
my $ps= $ENV{PAGE_SIZE};
|
|
my $page;
|
|
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
|
|
substr($page,4,4)=pack("N",0);
|
|
my $polynomial = 0x82f63b78; # CRC-32C
|
|
my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
|
|
if ($full_crc32)
|
|
{
|
|
my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial);
|
|
substr($page, $ps-4, 4) = pack("N", $ck);
|
|
}
|
|
else
|
|
{
|
|
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
|
|
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
|
|
substr($page,0,4)=$ck;
|
|
substr($page,$ps-8,4)=$ck;
|
|
}
|
|
sysseek(FILE, 0, 0) || die "Unable to rewind $file\n";
|
|
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
|
|
close(FILE) || die "Unable to close $file";
|
|
EOF
|
|
|
|
-- echo # Restart the server after uncorrupting the file.
|
|
-- source include/start_mysqld.inc
|
|
|
|
INSERT INTO bug16720368 VALUES(9,1);
|
|
SELECT COUNT(*) FROM bug16720368;
|
|
# A debug assertion would fail in buf_block_align_instance()
|
|
# if we did not uncorrupt the page number first.
|
|
DROP TABLE bug16720368, bug16720368_1;
|
|
|
|
-- echo #
|
|
-- echo # Bug#16735660 ASSERT TABLE2 == NULL, ROLLBACK OF RESURRECTED TXNS,
|
|
-- echo # DICT_TABLE_ADD_TO_CACHE
|
|
-- echo #
|
|
|
|
SET GLOBAL innodb_file_per_table=1;
|
|
|
|
CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES(42);
|
|
|
|
-- connect (con1,localhost,root)
|
|
|
|
CREATE TABLE bug16735660 (a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
|
|
XA START 'x';
|
|
--source ../include/no_checkpoint_start.inc
|
|
INSERT INTO bug16735660 VALUES(1),(2),(3);
|
|
XA END 'x';
|
|
XA PREPARE 'x';
|
|
--connection default
|
|
--let CLEANUP_IF_CHECKPOINT=XA ROLLBACK 'x';DROP TABLE bug16735660;
|
|
--source ../include/no_checkpoint_end.inc
|
|
|
|
-- disconnect con1
|
|
-- move_file $MYSQLD_DATADIR/test/bug16735660.ibd $MYSQLD_DATADIR/bug16735660.omg
|
|
|
|
-- echo # Attempt to start without an *.ibd file.
|
|
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
|
|
--source include/start_mysqld.inc
|
|
|
|
let SEARCH_PATTERN= \[ERROR\] InnoDB: Tablespace [0-9]+ was not found at .*test.bug16735660.ibd;
|
|
-- source include/search_pattern_in_file.inc
|
|
|
|
-- move_file $MYSQLD_DATADIR/bug16735660.omg $MYSQLD_DATADIR/test/bug16735660.ibd
|
|
|
|
-- source include/restart_mysqld.inc
|
|
|
|
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
|
|
SELECT * FROM bug16735660;
|
|
|
|
XA RECOVER;
|
|
XA ROLLBACK 'x';
|
|
|
|
SELECT * FROM bug16735660;
|
|
DROP TABLE bug16735660;
|