Commit 588a6a18 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-12750 Fix crash recovery of key rotation

When MySQL 5.7.9 was merged to MariaDB 10.2.2, an important
debug assertion was omitted from mlog_write_initial_log_record_low().

mlog_write_initial_log_record_low(): Put back the assertion
mtr_t::is_named_space().

fil_crypt_start_encrypting_space(), fil_crypt_rotate_page():
Call mtr_t::set_named_space() before modifying any pages.

fsp_flags_try_adjust(): Call mtr_t::set_named_space(). This additional
breakage was introduced in the merge of MDEV-11623 from 10.1. It was
not caught because of the missing debug assertion in
mlog_write_initial_log_record_low().

Remove some suppressions from the encryption.innodb-redo-badkey test.
parent 63229133
call mtr.add_suppression("InnoDB: Block in space_id .* in file .* encrypted.");
call mtr.add_suppression("Plugin 'file_key_management' .*");
call mtr.add_suppression("Plugin 'file_key_management'");
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: Read operation failed for tablespace .*");
call mtr.add_suppression("InnoDB: Database page corruption on disk or a failed.*");
call mtr.add_suppression("InnoDB: Recovery read page .*");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t2 cannot be decrypted.");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t3 cannot be decrypted.");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t4 cannot be decrypted.");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t1 cannot be decrypted.");
call mtr.add_suppression("InnoDB: Missing MLOG_FILE_NAME or MLOG_FILE_DELETE .*");
call mtr.add_suppression("InnoDB: Plugin initialization aborted .*");
call mtr.add_suppression("InnoDB: ############### CORRUPT LOG RECORD FOUND ##################");
call mtr.add_suppression("InnoDB: The page \[page id: space=[1-9][0-9]*, page number=[0-9]+\] in file test/t[1-4] cannot be decrypted");
call mtr.add_suppression("InnoDB: Plugin initialization aborted");
call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
# Restart mysqld --file-key-management-filename=keys2.txt
# Wait max 10 min for key encryption threads to encrypt all spaces
SET GLOBAL innodb_file_format = `Barracuda`;
......
......@@ -3,20 +3,11 @@
# embedded does not support restart
-- source include/not_embedded.inc
call mtr.add_suppression("InnoDB: Block in space_id .* in file .* encrypted.");
call mtr.add_suppression("Plugin 'file_key_management' .*");
call mtr.add_suppression("Plugin 'file_key_management'");
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: Read operation failed for tablespace .*");
call mtr.add_suppression("InnoDB: Database page corruption on disk or a failed.*");
call mtr.add_suppression("InnoDB: Recovery read page .*");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t2 cannot be decrypted.");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t3 cannot be decrypted.");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t4 cannot be decrypted.");
call mtr.add_suppression("InnoDB: The page \[page id: space=[0-9]+, page number=[0-9]+\] in file test/t1 cannot be decrypted.");
call mtr.add_suppression("InnoDB: Missing MLOG_FILE_NAME or MLOG_FILE_DELETE .*");
call mtr.add_suppression("InnoDB: Plugin initialization aborted .*");
call mtr.add_suppression("InnoDB: ############### CORRUPT LOG RECORD FOUND ##################");
call mtr.add_suppression("InnoDB: The page \[page id: space=[1-9][0-9]*, page number=[0-9]+\] in file test/t[1-4] cannot be decrypted");
call mtr.add_suppression("InnoDB: Plugin initialization aborted");
call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed");
--echo # Restart mysqld --file-key-management-filename=keys2.txt
-- let $restart_parameters=--file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys2.txt
......
......@@ -1004,7 +1004,8 @@ fil_crypt_start_encrypting_space(
do
{
mtr_t mtr;
mtr_start(&mtr);
mtr.start();
mtr.set_named_space(space);
/* 2 - get page 0 */
dberr_t err = DB_SUCCESS;
......@@ -1020,7 +1021,7 @@ fil_crypt_start_encrypting_space(
crypt_data->type = CRYPT_SCHEME_1;
crypt_data->write_page0(space, frame, &mtr);
mtr_commit(&mtr);
mtr.commit();
/* record lsn of update */
lsn_t end_lsn = mtr.commit_lsn();
......@@ -1758,12 +1759,11 @@ fil_crypt_rotate_page(
}
mtr_t mtr;
mtr_start(&mtr);
buf_block_t* block = fil_crypt_get_page_throttle(state,
offset, &mtr,
&sleeptime_ms);
if (block) {
mtr.start();
if (buf_block_t* block = fil_crypt_get_page_throttle(state,
offset, &mtr,
&sleeptime_ms)) {
mtr.set_named_space(space);
bool modified = false;
int needs_scrubbing = BTR_SCRUB_SKIP_PAGE;
......@@ -1804,11 +1804,11 @@ fil_crypt_rotate_page(
BTR_SCRUB_PAGE_ALLOCATION_UNKNOWN);
}
mtr_commit(&mtr);
mtr.commit();
lsn_t end_lsn = mtr.commit_lsn();
if (needs_scrubbing == BTR_SCRUB_PAGE) {
mtr_start(&mtr);
mtr.start();
/*
* refetch page and allocation status
*/
......@@ -1820,6 +1820,7 @@ fil_crypt_rotate_page(
&sleeptime_ms);
if (block) {
mtr.set_named_space(space);
/* get required table/index and index-locks */
needs_scrubbing = btr_scrub_recheck_page(
......@@ -1981,6 +1982,7 @@ fil_crypt_flush_space(
page_id_t(space->id, 0), page_size_t(space->flags),
RW_X_LATCH, NULL, BUF_GET,
__FILE__, __LINE__, &mtr, &err)) {
mtr.set_named_space(space);
crypt_data->write_page0(space, block->frame, &mtr);
}
......
......@@ -4773,7 +4773,7 @@ fsp_flags_try_adjust(ulint space_id, ulint flags)
ut_ad(fsp_flags_is_valid(flags));
mtr_t mtr;
mtr_start(&mtr);
mtr.start();
if (buf_block_t* b = buf_page_get(
page_id_t(space_id, 0), page_size_t(flags),
RW_X_LATCH, &mtr)) {
......@@ -4787,12 +4787,13 @@ fsp_flags_try_adjust(ulint space_id, ulint flags)
<< " to " << ib::hex(flags);
}
if (f != flags) {
mtr.set_named_space(space_id);
mlog_write_ulint(FSP_HEADER_OFFSET
+ FSP_SPACE_FLAGS + b->frame,
flags, MLOG_4BYTES, &mtr);
}
}
mtr_commit(&mtr);
mtr.commit();
}
/** Determine if a matching tablespace exists in the InnoDB tablespace
......
......@@ -76,10 +76,10 @@ mlog_catenate_ulint(
ulint val, /*!< in: value to write */
mlog_id_t type) /*!< in: type of value to write */
{
ut_ad(MLOG_1BYTE == 1);
ut_ad(MLOG_2BYTES == 2);
ut_ad(MLOG_4BYTES == 4);
ut_ad(MLOG_8BYTES == 8);
compile_time_assert(MLOG_1BYTE == 1);
compile_time_assert(MLOG_2BYTES == 2);
compile_time_assert(MLOG_4BYTES == 4);
compile_time_assert(MLOG_8BYTES == 8);
byte* ptr = mtr_buf->push<byte*>(type);
......@@ -182,6 +182,14 @@ mlog_write_initial_log_record_low(
mtr_t* mtr)
{
ut_ad(type <= MLOG_BIGGEST_TYPE || EXTRA_CHECK_MLOG_NUMBER(type));
ut_ad(type == MLOG_FILE_NAME
|| type == MLOG_FILE_DELETE
|| type == MLOG_FILE_CREATE2
|| type == MLOG_FILE_RENAME2
|| type == MLOG_INDEX_LOAD
|| type == MLOG_TRUNCATE
|| type == MLOG_FILE_WRITE_CRYPT_DATA
|| mtr->is_named_space(space_id));
mach_write_to_1(log_ptr, type);
log_ptr++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment