From 4b4dbb23eac79040b39173693a53124183108317 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 7 Jun 2024 20:24:39 +0530 Subject: [PATCH] MDEV-34169 Don't allow innodb_open_files to be lesser than number of non-user tablespace. fil_space_t::try_to_close(): Don't try to close the tablespace which is acquired by the caller of the function Added the suppression message in open_files_limit test case --- mysql-test/suite/innodb/r/open_files_limit.result | 1 + mysql-test/suite/innodb/t/open_files_limit.test | 1 + storage/innobase/fil/fil0fil.cc | 12 +++++++----- storage/innobase/include/fil0fil.h | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/innodb/r/open_files_limit.result b/mysql-test/suite/innodb/r/open_files_limit.result index f2f63376495..1c66bab7533 100644 --- a/mysql-test/suite/innodb/r/open_files_limit.result +++ b/mysql-test/suite/innodb/r/open_files_limit.result @@ -1,4 +1,5 @@ call mtr.add_suppression("\\[Warning\\] InnoDB: innodb_open_files=.* is not greater than the number of system tablespace files, temporary tablespace files, innodb_undo_tablespaces=.*"); +call mtr.add_suppression("\\[Warning\\] InnoDB: innodb_open_files=.* is exceeded \\(.* files stay open\\)"); FOUND 1 /\[Warning\] InnoDB: innodb_open_files=.* is not greater than the number of system tablespace files, temporary tablespace files, innodb_undo_tablespaces=.*/ in mysqld.1.err CREATE TABLE t1(f1 INT NOT NULL)ENGINE=InnoDB; DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/open_files_limit.test b/mysql-test/suite/innodb/t/open_files_limit.test index ea7383150a8..c10f62f3333 100644 --- a/mysql-test/suite/innodb/t/open_files_limit.test +++ b/mysql-test/suite/innodb/t/open_files_limit.test @@ -1,6 +1,7 @@ --source include/have_innodb.inc --source include/not_embedded.inc call mtr.add_suppression("\\[Warning\\] InnoDB: innodb_open_files=.* is not greater than the number of system tablespace files, temporary tablespace files, innodb_undo_tablespaces=.*"); +call mtr.add_suppression("\\[Warning\\] InnoDB: innodb_open_files=.* is exceeded \\(.* files stay open\\)"); let SEARCH_PATTERN= \[Warning\] InnoDB: innodb_open_files=.* is not greater than the number of system tablespace files, temporary tablespace files, innodb_undo_tablespaces=.*; let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err; --source include/search_pattern_in_file.inc diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 88c1115969a..ba4fbc49204 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -66,9 +66,10 @@ inline bool fil_is_user_tablespace_id(ulint space_id) } /** Try to close a file to adhere to the innodb_open_files limit. +@param ignore_space Ignore the tablespace which is acquired by caller @param print_info whether to diagnose why a file cannot be closed @return whether a file was closed */ -bool fil_space_t::try_to_close(bool print_info) +bool fil_space_t::try_to_close(fil_space_t *ignore_space, bool print_info) { ut_ad(mutex_own(&fil_system.mutex)); for (fil_space_t *space= UT_LIST_GET_FIRST(fil_system.space_list); space; @@ -80,7 +81,8 @@ bool fil_space_t::try_to_close(bool print_info) case FIL_TYPE_IMPORT: break; case FIL_TYPE_TABLESPACE: - if (!fil_is_user_tablespace_id(space->id)) + if (space == ignore_space + || !fil_is_user_tablespace_id(space->id)) continue; } @@ -354,7 +356,7 @@ fil_node_t* fil_space_t::add(const char* name, pfs_os_file_t handle, n_pending.fetch_and(~CLOSING, std::memory_order_relaxed); if (++fil_system.n_open >= srv_max_n_open_files) { reacquire(); - try_to_close(true); + try_to_close(this, true); release(); } } @@ -405,7 +407,7 @@ static bool fil_node_open_file_low(fil_node_t *node) /* The following call prints an error message */ if (os_file_get_last_error(true) == EMFILE + 100 && - fil_space_t::try_to_close(true)) + fil_space_t::try_to_close(nullptr, true)) continue; ib::warn() << "Cannot open '" << node->name << "'."; @@ -449,7 +451,7 @@ static bool fil_node_open_file(fil_node_t *node) for (ulint count= 0; fil_system.n_open >= srv_max_n_open_files; count++) { - if (fil_space_t::try_to_close(count > 1)) + if (fil_space_t::try_to_close(nullptr, count > 1)) count= 0; else if (count >= 2) { diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index 1f5589a4a20..059a3456c50 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -590,9 +590,10 @@ private: public: /** Try to close a file to adhere to the innodb_open_files limit. + @param ignore_space Ignore the tablespace which is acquired by caller @param print_info whether to diagnose why a file cannot be closed @return whether a file was closed */ - static bool try_to_close(bool print_info); + static bool try_to_close(fil_space_t *ignore_space, bool print_info); /** Close all tablespace files at shutdown */ static void close_all();