From 2d6c2f22a4f9844db45d66e063fbf9314889eb1b Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Tue, 28 Nov 2023 16:29:04 +0530 Subject: [PATCH] MDEV-32452 InnoDB system tablespace is not shrunk on slow shutdown - During slow shutdown, shrink the system tablespace which was done in commit f9003c73a15d892423845a2df96c8bd73bbe96ca (MDEV-14795) --- .../innodb/r/sys_truncate_shutdown.result | 23 +++++++++ .../r/sys_truncate_shutdown_debug.result | 41 +++++++++++++++ .../suite/innodb/t/sys_truncate_shutdown.opt | 3 ++ .../suite/innodb/t/sys_truncate_shutdown.test | 20 ++++++++ .../innodb/t/sys_truncate_shutdown_debug.opt | 3 ++ .../innodb/t/sys_truncate_shutdown_debug.test | 51 +++++++++++++++++++ storage/innobase/handler/ha_innodb.cc | 5 ++ 7 files changed, 146 insertions(+) create mode 100644 mysql-test/suite/innodb/r/sys_truncate_shutdown.result create mode 100644 mysql-test/suite/innodb/r/sys_truncate_shutdown_debug.result create mode 100644 mysql-test/suite/innodb/t/sys_truncate_shutdown.opt create mode 100644 mysql-test/suite/innodb/t/sys_truncate_shutdown.test create mode 100644 mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.opt create mode 100644 mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.test diff --git a/mysql-test/suite/innodb/r/sys_truncate_shutdown.result b/mysql-test/suite/innodb/r/sys_truncate_shutdown.result new file mode 100644 index 00000000000..ee567a76fb1 --- /dev/null +++ b/mysql-test/suite/innodb/r/sys_truncate_shutdown.result @@ -0,0 +1,23 @@ +SET GLOBAL innodb_fast_shutdown=0; +# restart +SET GLOBAL INNODB_FILE_PER_TABLE= 0; +Warnings: +Warning 1287 '@@innodb_file_per_table' is deprecated and will be removed in a future release +SET UNIQUE_CHECKS=0, FOREIGN_KEY_CHECKS=0; +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, +f3 INT NOT NULL, INDEX(f1), +INDEX(f2), INDEX(f3))ENGINE=InnoDB; +BEGIN; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +COMMIT; +DROP TABLE t1; +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; +NAME FILE_SIZE +innodb_system 70254592 +SET GLOBAL innodb_fast_shutdown=0; +# restart +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; +NAME FILE_SIZE +innodb_system 3145728 diff --git a/mysql-test/suite/innodb/r/sys_truncate_shutdown_debug.result b/mysql-test/suite/innodb/r/sys_truncate_shutdown_debug.result new file mode 100644 index 00000000000..0aad5af9cb6 --- /dev/null +++ b/mysql-test/suite/innodb/r/sys_truncate_shutdown_debug.result @@ -0,0 +1,41 @@ +call mtr.add_suppression("InnoDB: Cannot shrink the system 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"); +SET GLOBAL innodb_fast_shutdown=0; +# restart +SET GLOBAL INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG=2; +SET GLOBAL INNODB_FILE_PER_TABLE= 0; +Warnings: +Warning 1287 '@@innodb_file_per_table' is deprecated and will be removed in a future release +SET UNIQUE_CHECKS=0, FOREIGN_KEY_CHECKS=0; +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, +f3 INT NOT NULL, INDEX(f1), +INDEX(f2), INDEX(f3))ENGINE=InnoDB; +BEGIN; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +COMMIT; +DROP TABLE t1; +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; +NAME FILE_SIZE +innodb_system 540016640 +SET GLOBAL INNODB_FAST_SHUTDOWN=0; +SET GLOBAL DEBUG_DBUG="+d,shrink_buffer_pool_full"; +# restart +FOUND 1 /\[Warning\] InnoDB: Cannot shrink the system tablespace/ in mysqld.1.err +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; +NAME FILE_SIZE +innodb_system 540016640 +SET GLOBAL INNODB_FAST_SHUTDOWN=0; +SET GLOBAL DEBUG_DBUG="+d,mtr_log_max_size"; +# restart +FOUND 1 /\[ERROR\] InnoDB: Cannot shrink the system tablespace/ in mysqld.1.err +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; +NAME FILE_SIZE +innodb_system 540016640 +SET GLOBAL INNODB_FAST_SHUTDOWN=0; +# restart: --debug_dbug=+d,crash_after_sys_truncate +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; +NAME FILE_SIZE +innodb_system 3145728 diff --git a/mysql-test/suite/innodb/t/sys_truncate_shutdown.opt b/mysql-test/suite/innodb/t/sys_truncate_shutdown.opt new file mode 100644 index 00000000000..001feac38fb --- /dev/null +++ b/mysql-test/suite/innodb/t/sys_truncate_shutdown.opt @@ -0,0 +1,3 @@ +--innodb_data_file_path=ibdata1:1M:autoextend +--innodb_sys_tablespaces +--innodb_page_size=4k diff --git a/mysql-test/suite/innodb/t/sys_truncate_shutdown.test b/mysql-test/suite/innodb/t/sys_truncate_shutdown.test new file mode 100644 index 00000000000..0f61049ba5e --- /dev/null +++ b/mysql-test/suite/innodb/t/sys_truncate_shutdown.test @@ -0,0 +1,20 @@ +--source include/have_innodb.inc +--source include/have_sequence.inc +SET GLOBAL innodb_fast_shutdown=0; +--source include/restart_mysqld.inc +SET GLOBAL INNODB_FILE_PER_TABLE= 0; +SET UNIQUE_CHECKS=0, FOREIGN_KEY_CHECKS=0; +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, + f3 INT NOT NULL, INDEX(f1), + INDEX(f2), INDEX(f3))ENGINE=InnoDB; +BEGIN; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +COMMIT; +DROP TABLE t1; +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; + +SET GLOBAL innodb_fast_shutdown=0; +--source include/restart_mysqld.inc +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; diff --git a/mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.opt b/mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.opt new file mode 100644 index 00000000000..001feac38fb --- /dev/null +++ b/mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.opt @@ -0,0 +1,3 @@ +--innodb_data_file_path=ibdata1:1M:autoextend +--innodb_sys_tablespaces +--innodb_page_size=4k diff --git a/mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.test b/mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.test new file mode 100644 index 00000000000..8e8c91e7b47 --- /dev/null +++ b/mysql-test/suite/innodb/t/sys_truncate_shutdown_debug.test @@ -0,0 +1,51 @@ +--source include/have_innodb.inc +--source include/have_sequence.inc +--source include/not_embedded.inc +--source include/have_debug.inc + +call mtr.add_suppression("InnoDB: Cannot shrink the system 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"); + +SET GLOBAL innodb_fast_shutdown=0; +--source include/restart_mysqld.inc +SET GLOBAL INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG=2; +SET GLOBAL INNODB_FILE_PER_TABLE= 0; +SET UNIQUE_CHECKS=0, FOREIGN_KEY_CHECKS=0; +CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, + f3 INT NOT NULL, INDEX(f1), + INDEX(f2), INDEX(f3))ENGINE=InnoDB; +BEGIN; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +INSERT INTO t1 SELECT seq, seq, seq FROM seq_1_to_16384; +COMMIT; +DROP TABLE t1; +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; + +SET GLOBAL INNODB_FAST_SHUTDOWN=0; +SET GLOBAL DEBUG_DBUG="+d,shrink_buffer_pool_full"; +--source include/restart_mysqld.inc + +--let SEARCH_PATTERN= \\[Warning\\] InnoDB: Cannot shrink the system tablespace +let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; +--source include/search_pattern_in_file.inc + +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; + +SET GLOBAL INNODB_FAST_SHUTDOWN=0; +SET GLOBAL DEBUG_DBUG="+d,mtr_log_max_size"; +--source include/restart_mysqld.inc + +--let SEARCH_PATTERN= \\[ERROR\\] InnoDB: Cannot shrink the system tablespace +let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; +--source include/search_pattern_in_file.inc + +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; + +SET GLOBAL INNODB_FAST_SHUTDOWN=0; +# Crash after shrinking the system tablespace +let $restart_parameters=--debug_dbug="+d,crash_after_sys_truncate"; +--source include/restart_mysqld.inc + +SELECT NAME, FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE SPACE = 0; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 4e5a46c1a00..d937c654de5 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -4236,6 +4236,11 @@ innobase_end(handlerton*, ha_panic_function) } } + /* Do system tablespace truncation during slow shutdown */ + if (!srv_fast_shutdown + && srv_operation == SRV_OPERATION_NORMAL) { + fsp_system_tablespace_truncate(); + } innodb_shutdown(); mysql_mutex_destroy(&log_requests.mutex);