From 5a58935cb9939c1ca389e7112d1b288ea1b038d5 Mon Sep 17 00:00:00 2001 From: mariadb-DebarunBanerjee Date: Fri, 5 Jan 2024 12:20:37 +0530 Subject: [PATCH] MDEV-33101 Server crashes when starting the server with innodb-force-recovery=6 and enabling the innodb_truncate_temporary_tablespace_now variable The issue is introduced by "MDEV-28699: Shrink temporary tablespaces without restart". SRV_FORCE_NO_LOG_REDO forces server to read only mode and we don't initialize temporary tablespace in read only mode. solution: innodb_truncate_temporary_tablespace_now should be no-op in read only mode. --- mysql-test/suite/innodb/r/read_only_recovery.result | 5 +++++ mysql-test/suite/innodb/r/temp_truncate.result | 8 ++++++++ mysql-test/suite/innodb/t/read_only_recovery.test | 3 +++ mysql-test/suite/innodb/t/temp_truncate.test | 10 ++++++++++ storage/innobase/handler/ha_innodb.cc | 3 ++- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/read_only_recovery.result b/mysql-test/suite/innodb/r/read_only_recovery.result index 2cde58189d5..78815e563f7 100644 --- a/mysql-test/suite/innodb/r/read_only_recovery.result +++ b/mysql-test/suite/innodb/r/read_only_recovery.result @@ -29,6 +29,9 @@ UPDATE t SET a=3 WHERE a=1; # Starting with MariaDB 10.2, innodb_read_only implies READ UNCOMMITTED. # In earlier versions, this would return the last committed version # (empty table)! +SHOW VARIABLES LIKE "innodb_read_only"; +Variable_name Value +innodb_read_only ON SELECT * FROM t; a 3 @@ -39,6 +42,8 @@ a SET GLOBAL innodb_max_purge_lag_wait=0; INSERT INTO mysql.innodb_index_stats SELECT * FROM mysql.innodb_index_stats LIMIT 0; +Test Temp tablespace truncate in read only mode +SET GLOBAL innodb_truncate_temporary_tablespace_now=1; # restart SELECT * FROM t; a diff --git a/mysql-test/suite/innodb/r/temp_truncate.result b/mysql-test/suite/innodb/r/temp_truncate.result index 65129927d7b..2b241feb044 100644 --- a/mysql-test/suite/innodb/r/temp_truncate.result +++ b/mysql-test/suite/innodb/r/temp_truncate.result @@ -1,3 +1,11 @@ +# MDEV-33101 Server crashes when starting the server with +# innodb-force-recovery=6 and enabling the +# innodb_truncate_temporary_tablespace_now variable +# restart: --innodb-force-recovery=6 +SHOW VARIABLES LIKE "innodb_read_only"; +Variable_name Value +innodb_read_only ON +SET GLOBAL innodb_truncate_temporary_tablespace_now=1; # restart CREATE TEMPORARY TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL)ENGINE=InnoDB; diff --git a/mysql-test/suite/innodb/t/read_only_recovery.test b/mysql-test/suite/innodb/t/read_only_recovery.test index d011b3aa5e3..75e9c530017 100644 --- a/mysql-test/suite/innodb/t/read_only_recovery.test +++ b/mysql-test/suite/innodb/t/read_only_recovery.test @@ -35,12 +35,15 @@ UPDATE t SET a=3 WHERE a=1; --echo # Starting with MariaDB 10.2, innodb_read_only implies READ UNCOMMITTED. --echo # In earlier versions, this would return the last committed version --echo # (empty table)! +SHOW VARIABLES LIKE "innodb_read_only"; SELECT * FROM t; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SELECT * FROM t; SET GLOBAL innodb_max_purge_lag_wait=0; INSERT INTO mysql.innodb_index_stats SELECT * FROM mysql.innodb_index_stats LIMIT 0; +--echo Test Temp tablespace truncate in read only mode +SET GLOBAL innodb_truncate_temporary_tablespace_now=1; --let $restart_parameters= --source include/restart_mysqld.inc SELECT * FROM t; diff --git a/mysql-test/suite/innodb/t/temp_truncate.test b/mysql-test/suite/innodb/t/temp_truncate.test index 1eb35c11a09..aca1715681e 100644 --- a/mysql-test/suite/innodb/t/temp_truncate.test +++ b/mysql-test/suite/innodb/t/temp_truncate.test @@ -1,6 +1,16 @@ --source include/have_innodb.inc --source include/have_sequence.inc +--echo # MDEV-33101 Server crashes when starting the server with +--echo # innodb-force-recovery=6 and enabling the +--echo # innodb_truncate_temporary_tablespace_now variable + +--let $restart_parameters=--innodb-force-recovery=6 +--source include/restart_mysqld.inc +SHOW VARIABLES LIKE "innodb_read_only"; +SET GLOBAL innodb_truncate_temporary_tablespace_now=1; + +--let $restart_parameters= --source include/restart_mysqld.inc CREATE TEMPORARY TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL)ENGINE=InnoDB; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 4164ce336b3..b6f54c97c17 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -18482,7 +18482,8 @@ static void innodb_trunc_temp_space_update(THD*, st_mysql_sys_var*, void*, const void* save) { - if (!*static_cast(save)) + /* Temp tablespace is not initialized in read only mode. */ + if (!*static_cast(save) || srv_read_only_mode) return; mysql_mutex_unlock(&LOCK_global_system_variables); fsp_shrink_temp_space();