mirror of
https://github.com/MariaDB/server.git
synced 2025-02-05 13:22:17 +01:00
bb47e575de
The invariant of write-ahead logging is that before any change to a
page is written to the data file, the corresponding log record must
must first have been durably written.
On crash recovery, there were some sloppy checks for this. Let us
implement accurate checks and flag an inconsistency as a hard error,
so that we can avoid further corruption of a corrupted database.
For data extraction from the corrupted database, innodb_force_recovery
can be used.
Before recovery is reading any data pages or invoking
buf_dblwr_t::recover() to recover torn pages from the
doublewrite buffer, InnoDB will have parsed the log until the
final LSN and updated log_sys.lsn to that. So, we can rely on
log_sys.lsn at all times. The doublewrite buffer recovery has been
refactored in such a way that the recv_sys.dblwr.pages may be consulted
while discovering files and their page sizes, but nothing will be
written back to data files before buf_dblwr_t::recover() is invoked.
A section of the test mariabackup.innodb_redo_overwrite
that is parsing some mariadb-backup --backup output has
been removed, because that output "redo log block is overwritten"
would often be missing in a Microsoft Windows environment
as a result of these changes.
recv_max_page_lsn, recv_lsn_checks_on: Remove.
recv_sys_t::validate_checkpoint(): Validate the write-ahead-logging
condition at the end of the recovery.
recv_dblwr_t::validate_page(): Keep track of the maximum LSN
(if we are checking a non-doublewrite copy of a page) but
do not complain LSN being in the future. The doublewrite buffer
is a special case, because it will be read early during recovery.
Besides, starting with commit 762bcb81b5
the dblwr=true copies of pages may legitimately be "too new".
recv_dblwr_t::find_page(): Find a valid page with the smallest
FIL_PAGE_LSN that is in the valid range for recovery.
recv_dblwr_t::restore_first_page(): Replaced by find_page().
Only buf_dblwr_t::recover() will write to data files.
buf_dblwr_t::recover(): Simplify the message output. Do attempt
doublewrite recovery on user page read error. Ignore doublewrite
pages whose FIL_PAGE_LSN is outside the usable bounds. Previously,
we could wrongly recover a too new page from the doublewrite buffer.
It is unlikely that this could have lead to an actual error.
Write back all recovered pages from the doublewrite buffer here,
including for the first page of any tablespace.
buf_page_is_corrupted(): Distinguish the return values
CORRUPTED_FUTURE_LSN and CORRUPTED_OTHER.
buf_page_check_corrupt(): Return the error code DB_CORRUPTION
in case the LSN is in the future.
Datafile::read_first_page(): Handle FSP_SPACE_FLAGS=0xffffffff
in the same way on both 32-bit and 64-bit architectures.
Datafile::read_first_page_flags(): Split from read_first_page().
Take a copy of the first page as a parameter.
recv_sys_t::free_corrupted_page(): Take the file as a parameter
and return whether a message was displayed. This avoids some duplicated
and incomplete error messages.
buf_page_t::read_complete(): Remove some redundant output and always
display the name of the corrupted file. Never return DB_FAIL;
use it only in internal error handling.
IORequest::read_complete(): Assume that buf_page_t::read_complete()
will have reported any error.
fil_space_t::set_corrupted(): Return whether this is the first time
the tablespace had been flagged as corrupted.
Datafile::validate_first_page(), fil_node_open_file_low(),
fil_node_open_file(), fil_space_t::read_page0(),
fil_node_t::read_page0(): Add a parameter for a copy of the
first page, and a parameter to indicate whether the FIL_PAGE_LSN
check should be suppressed. Before buf_dblwr_t::recover() is
invoked, we cannot validate the FIL_PAGE_LSN, but we can trust the
FSP_SPACE_FLAGS and the tablespace ID that may be present in a
potentially too new copy of a page.
Reviewed by: Debarun Banerjee
83 lines
2.2 KiB
Text
83 lines
2.2 KiB
Text
#
|
|
# Test opening a corrupted table.
|
|
#
|
|
# Restarting is not supported under embedded
|
|
-- source include/not_embedded.inc
|
|
# Require InnoDB
|
|
-- source include/have_innodb.inc
|
|
-- source include/not_encrypted.inc
|
|
|
|
--disable_query_log
|
|
call mtr.add_suppression("InnoDB: Table `test`\\.`t1` is corrupted\\. Please drop the table and recreate\\.");
|
|
call mtr.add_suppression("InnoDB: Failed to read page [1-9][0-9]* from file '.*test.t1\\.ibd'");
|
|
call mtr.add_suppression("InnoDB: We detected index corruption in an InnoDB type table");
|
|
call mtr.add_suppression("Index for table 't1' is corrupt; try to repair it");
|
|
call mtr.add_suppression("InnoDB: File '.*test/t1\\.ibd' is corrupted");
|
|
--enable_query_log
|
|
|
|
--echo # Ensure that purge will not crash on the table after we corrupt it.
|
|
SET GLOBAL innodb_fast_shutdown=0;
|
|
|
|
--echo # Create and populate the table to be corrupted
|
|
|
|
set global innodb_file_per_table=ON;
|
|
|
|
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ENGINE=InnoDB;
|
|
INSERT INTO t1 (b) VALUES ('corrupt me');
|
|
--disable_query_log
|
|
--let $i = 10
|
|
while ($i)
|
|
{
|
|
INSERT INTO t1 (b) VALUES (REPEAT('abcdefghijklmnopqrstuvwxyz', 100));
|
|
dec $i;
|
|
}
|
|
--enable_query_log
|
|
INSERT INTO t1 (b) VALUES ('corrupt me');
|
|
|
|
let $MYSQLD_DATADIR=`select @@datadir`;
|
|
let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd;
|
|
|
|
--source include/shutdown_mysqld.inc
|
|
|
|
--echo # Corrupt the table
|
|
|
|
perl;
|
|
use strict;
|
|
use warnings;
|
|
use Fcntl qw(:DEFAULT :seek);
|
|
|
|
my $ibd_file = $ENV{'t1_IBD'};
|
|
|
|
my $chunk;
|
|
my $len;
|
|
|
|
sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file";
|
|
|
|
while ($len = sysread IBD_FILE, $chunk, 1024)
|
|
{
|
|
if ($chunk =~ s/corrupt me/korrupt me/)
|
|
{
|
|
print "Munged a string.\n";
|
|
sysseek IBD_FILE, -$len, SEEK_CUR;
|
|
syswrite IBD_FILE, $chunk, $len;
|
|
}
|
|
}
|
|
|
|
close IBD_FILE;
|
|
EOF
|
|
|
|
--source include/start_mysqld.inc
|
|
|
|
--echo # Now t1 is corrupted but we should not crash
|
|
|
|
--error ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE
|
|
SELECT * FROM t1;
|
|
|
|
--error 126,ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE
|
|
INSERT INTO t1(b) VALUES('abcdef');
|
|
|
|
--error ER_GET_ERRNO,ER_NOT_KEYFILE,ER_INDEX_CORRUPT,ER_NO_SUCH_TABLE_IN_ENGINE
|
|
UPDATE t1 set b = 'deadbeef' where a = 1;
|
|
|
|
--echo # Cleanup, this must be possible
|
|
DROP TABLE t1;
|