From b793feb1d68c181f1073a15241b4e9833f84745b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 22 May 2024 16:54:33 +0300 Subject: [PATCH] MDEV-34216 Possible corruption when shrinking the system tablespace on innodb_fast_shutdown=0 This bug was found related to MDEV-34212. Some InnoDB tests, most notably innodb.table_flags,64k would occasionally fail. I am able to reproduce this locally on a MemorySanitizer build, sporadically. The following is a minimal .test file for reproducing this: --source include/have_innodb.inc SELECT @@innodb_page_size; and the .opt file: --innodb-undo-tablespaces=0 --innodb-page-size=64k --innodb-buffer-pool-size=20m This bug was revealed due to the recent commit 466ae1cf81f54b729058357bb19c4cf3982e1367 which set innodb_fast_shutdown=0 during server bootstrap in our regression test driver. Due to the bug, a write of undo page 50 in the system tablespace was discarded in buf_page_t::flush(). A subsequent InnoDB startup failed because an old version of that page would point to a freed undo log page 300. mtr_t::commit_shrink(): Only invoke fil_space_t::set_create_lsn() on undo tablespaces, which will be fully reinitialized or created from the scratch. On the system tablespace, we must only adjust the file size, to avoid writing pages that are beyond the end of the tablespace. Thanks to Thirunarayanan Balathandayuthapani for providing this fix. --- storage/innobase/mtr/mtr0mtr.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc index 90a2007a48d..8db52ac1f47 100644 --- a/storage/innobase/mtr/mtr0mtr.cc +++ b/storage/innobase/mtr/mtr0mtr.cc @@ -583,8 +583,9 @@ void mtr_t::commit_shrink(fil_space_t &space, uint32_t size) if (space.id == TRX_SYS_SPACE) srv_sys_space.set_last_file_size(file->size); + else + space.set_create_lsn(m_commit_lsn); - space.set_create_lsn(m_commit_lsn); mysql_mutex_unlock(&fil_system.mutex); space.clear_freed_ranges();