From 942604029e2b25ad8d6b3612df8aa74b708ceda1 Mon Sep 17 00:00:00 2001 From: Aibek Bukabayev Date: Tue, 27 Aug 2024 08:00:52 +0000 Subject: [PATCH] PXB-3334 Code cleanups in reduced lock feature removed argument `prep_handle_ddls` from all using functions, using xtrabackup_prepare instead --- storage/innobase/fil/fil0fil.cc | 36 ++++++++----------- storage/innobase/include/fil0fil.h | 5 +-- storage/innobase/include/xb0xb.h | 1 + storage/innobase/srv/srv0start.cc | 2 +- .../innobase/xtrabackup/src/ddl_tracker.cc | 2 +- storage/innobase/xtrabackup/src/xtrabackup.cc | 30 ++++++++-------- storage/innobase/xtrabackup/src/xtrabackup.h | 4 +-- 7 files changed, 36 insertions(+), 44 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 86fe2362aa5..ea8bffe9979 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -526,8 +526,7 @@ class Tablespace_dirs { @param[in] only_undo if true, only the undo tablespaces are discovered @return DB_SUCCESS if all goes well */ - [[nodiscard]] dberr_t scan(bool populate_fil_cache, bool is_prep_handle_ddls, - bool only_undo); + [[nodiscard]] dberr_t scan(bool populate_fil_cache, bool only_undo); /** Clear all the tablespace file data but leave the list of scanned directories in place. */ @@ -686,7 +685,7 @@ class Tablespace_dirs { @param[in] thread_id Thread ID @param[out] result false in case of failure */ void open_ibd(const Const_iter &start, const Const_iter &end, - size_t thread_id, bool &result, bool is_prep_handle_ddls); + size_t thread_id, bool &result); private: /** Directories scanned and the files discovered under them. */ @@ -1716,9 +1715,8 @@ class Fil_system { @param[in] only_undo if true, only the undo tablespaces are discovered @return DB_SUCCESS on success, other codes on errors */ - dberr_t scan(bool populate_fil_cache, bool is_prep_handle_ddls, - bool only_undo) { - return (m_dirs.scan(populate_fil_cache, is_prep_handle_ddls, only_undo)); + dberr_t scan(bool populate_fil_cache, bool only_undo) { + return (m_dirs.scan(populate_fil_cache, only_undo)); } /** Open all known tablespaces. */ @@ -11636,8 +11634,7 @@ std::tuple fil_open_for_xtrabackup( @param[in] thread_id Thread ID @param[in,out] result result of the open */ void Tablespace_dirs::open_ibd(const Const_iter &start, const Const_iter &end, - size_t thread_id, bool &result, - bool is_prep_handle_ddls) { + size_t thread_id, bool &result) { if (!result) return; for (auto it = start; it != end; ++it) { @@ -11649,9 +11646,10 @@ void Tablespace_dirs::open_ibd(const Const_iter &start, const Const_iter &end, continue; } - /* when processing ddl files on prepare phase we should load data files - without first page validation */ - if (is_prep_handle_ddls) { + /* when LOCK_DDL_REDUCED while processing ddl files on prepare phase + we should load data files without first page validation */ + if (xtrabackup_prepare && opt_lock_ddl == LOCK_DDL_REDUCED && + !xtrabackup_incremental) { dberr_t err = fil_open_for_prepare(phy_filename); if (err != DB_SUCCESS) { result = false; @@ -11954,8 +11952,7 @@ void Tablespace_dirs::set_scan_dirs(const std::string &in_directories) { @param[in] only_undo if true, only the undo tablespaces are discovered @return DB_SUCCESS if all goes well */ -dberr_t Tablespace_dirs::scan(bool populate_fil_cache, bool is_prep_handle_ddls, - bool only_undo) { +dberr_t Tablespace_dirs::scan(bool populate_fil_cache, bool only_undo) { Scanned_files ibd_files; Scanned_files undo_files; uint16_t count = 0; @@ -12073,12 +12070,10 @@ dberr_t Tablespace_dirs::scan(bool populate_fil_cache, bool is_prep_handle_ddls, if (err == DB_SUCCESS && populate_fil_cache && !only_undo) { bool result = true; - std::function - open = std::bind(&Tablespace_dirs::open_ibd, this, _1, _2, _3, _4, _5); + std::function + open = std::bind(&Tablespace_dirs::open_ibd, this, _1, _2, _3, _4); - par_for(PFS_NOT_INSTRUMENTED, ibd_files, n_threads, open, result, - is_prep_handle_ddls); + par_for(PFS_NOT_INSTRUMENTED, ibd_files, n_threads, open, result); if (!result) err = DB_FAIL; } @@ -12101,9 +12096,8 @@ void fil_set_scan_dirs(const std::string &directories) { @param[in] only_undo if true, only the undo tablespaces are discovered @return DB_SUCCESS if all goes well */ -dberr_t fil_scan_for_tablespaces(bool populate_fil_cache, - bool is_prep_handle_ddls, bool only_undo) { - return (fil_system->scan(populate_fil_cache, is_prep_handle_ddls, only_undo)); +dberr_t fil_scan_for_tablespaces(bool populate_fil_cache, bool only_undo) { + return (fil_system->scan(populate_fil_cache, only_undo)); } /** Open all known tablespaces. */ diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index e4de7073f0c..5c777baaa01 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -2253,12 +2253,9 @@ void fil_set_scan_dirs(const std::string &directories); /** Discover tablespaces by reading the header from .ibd files. @param[in] populate_fil_cache Whether to load tablespaces into fil cache -@param[in] is_prep_handle_ddls Whether loading tablespaces on prepare phase - to handle the ddls @param[in] only_undo if true, only the undo tablespaces are discovered @return DB_SUCCESS if all goes well */ -dberr_t fil_scan_for_tablespaces(bool populate_fil_cache, - bool is_prep_handle_ddls, bool only_undo); +dberr_t fil_scan_for_tablespaces(bool populate_fil_cache, bool only_undo); /** Open the tablespace and also get the tablespace filenames, space_id must already be known. diff --git a/storage/innobase/include/xb0xb.h b/storage/innobase/include/xb0xb.h index 0bfe7cb874c..472dce0ba71 100644 --- a/storage/innobase/include/xb0xb.h +++ b/storage/innobase/include/xb0xb.h @@ -27,6 +27,7 @@ extern bool innodb_checksum_algorithm_specified; extern bool opt_lock_ddl_per_table; extern bool redo_catchup_completed; +extern bool xtrabackup_prepare; extern bool opt_page_tracking; extern char *xtrabackup_incremental; extern lsn_t incremental_start_checkpoint_lsn; diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 15aaf4d77c4..a885490ab5a 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1792,7 +1792,7 @@ dberr_t srv_start(bool create_new_db IF_XB(, lsn_t to_lsn)) { return (srv_init_abort(err)); } - err = fil_scan_for_tablespaces(false, false, false); + err = fil_scan_for_tablespaces(false, false); if (err != DB_SUCCESS) { return (srv_init_abort(err)); diff --git a/storage/innobase/xtrabackup/src/ddl_tracker.cc b/storage/innobase/xtrabackup/src/ddl_tracker.cc index 5c071169bd3..3dab29bb1a0 100644 --- a/storage/innobase/xtrabackup/src/ddl_tracker.cc +++ b/storage/innobase/xtrabackup/src/ddl_tracker.cc @@ -411,7 +411,7 @@ std::tuple ddl_tracker_t::handle_undo_ddls() { undo_spaces_deinit(); undo_spaces_init(); - xb_scan_for_tablespaces(false, true); + xb_scan_for_tablespaces(true); // Generates the after_lock_undo list srv_undo_tablespaces_init(false, true); diff --git a/storage/innobase/xtrabackup/src/xtrabackup.cc b/storage/innobase/xtrabackup/src/xtrabackup.cc index 3a1d80871bb..89bedfdb0a3 100644 --- a/storage/innobase/xtrabackup/src/xtrabackup.cc +++ b/storage/innobase/xtrabackup/src/xtrabackup.cc @@ -2478,7 +2478,7 @@ static bool innodb_init_param(void) { return (true); } -void xb_scan_for_tablespaces(bool is_prep_handle_ddls, bool only_undo) { +void xb_scan_for_tablespaces(bool only_undo) { /* This is the default directory for IBD and IBU files. Put it first in the list of known directories. */ fil_set_scan_dir(MySQL_datadir_path.path()); @@ -2497,8 +2497,7 @@ void xb_scan_for_tablespaces(bool is_prep_handle_ddls, bool only_undo) { --innodb-undo-directory also. */ fil_set_scan_dir(Fil_path::remove_quotes(MySQL_undo_path), true); - if (fil_scan_for_tablespaces(true, is_prep_handle_ddls, only_undo) != - DB_SUCCESS) { + if (fil_scan_for_tablespaces(true, only_undo) != DB_SUCCESS) { exit(EXIT_FAILURE); } } @@ -3591,7 +3590,7 @@ static bool xb_fil_io_init(void) /**************************************************************************** Populates the tablespace memory cache by scanning for and opening data files. @returns DB_SUCCESS or error code.*/ -static dberr_t xb_load_tablespaces(bool is_prep_handle_ddls) +static dberr_t xb_load_tablespaces() /*=====================*/ { dberr_t err; @@ -3630,7 +3629,7 @@ static dberr_t xb_load_tablespaces(bool is_prep_handle_ddls) } xb::info() << "Generating a list of tablespaces"; - xb_scan_for_tablespaces(is_prep_handle_ddls, false); + xb_scan_for_tablespaces(false); /* Add separate undo tablespaces to fil_system */ @@ -3641,9 +3640,10 @@ static dberr_t xb_load_tablespaces(bool is_prep_handle_ddls) for (auto tablespace : Tablespace_map::instance().external_files()) { if (tablespace.type != Tablespace_map::TABLESPACE) continue; - /* when processing ddl files on prepare phase we should load data files - without first page validation */ - if (is_prep_handle_ddls) { + /* when LOCK_DDL_REDUCED while processing ddl files on prepare phase + we should load data files without first page validation */ + if (xtrabackup_prepare && opt_lock_ddl == LOCK_DDL_REDUCED && + !xtrabackup_incremental) { dberr_t err = fil_open_for_prepare(tablespace.file_name); if (err != DB_SUCCESS) { return (err); @@ -3662,7 +3662,7 @@ static dberr_t xb_load_tablespaces(bool is_prep_handle_ddls) Initialize the tablespace memory cache and populate it by scanning for and opening data files. @returns DB_SUCCESS or error code.*/ -ulint xb_data_files_init(bool is_prep_handle_ddls) +ulint xb_data_files_init() /*====================*/ { os_create_block_cache(); @@ -3673,7 +3673,7 @@ ulint xb_data_files_init(bool is_prep_handle_ddls) undo_spaces_init(); - return (xb_load_tablespaces(is_prep_handle_ddls)); + return (xb_load_tablespaces()); } /************************************************************************ @@ -4384,7 +4384,7 @@ void xtrabackup_backup_func(void) { Tablespace_map::instance().scan(mysql_connection); /* Populate fil_system with tablespaces to copy */ - dberr_t err = xb_load_tablespaces(false); + dberr_t err = xb_load_tablespaces(); if (err != DB_SUCCESS) { xb::error() << "xb_load_tablespaces() failed with error code " << err; exit(EXIT_FAILURE); @@ -5686,7 +5686,7 @@ static bool prepare_handle_ren_files( std::string ren_path = entry.path; Fil_path::normalize(ren_path); - // trim .ibd.ren + // trim .ren source_space_id = atoi(ren_file_name.substr(0, ren_file_name.length() - EXT_REN.length()) .c_str()); @@ -5822,7 +5822,7 @@ static bool prepare_handle_del_files( std::string del_file = entry.path; space_id_t space_id; - // trim .ibd.del + // trim .del space_id = atoi(del_file_name.substr(0, del_file_name.length() - EXT_DEL.length()) .c_str()); @@ -7041,7 +7041,7 @@ static void xtrabackup_prepare_func(int argc, char **argv) { /* Handle `RENAME/DELETE` DDL files produced by DDL tracking during backup */ - err = xb_data_files_init(true); + err = xb_data_files_init(); if (err != DB_SUCCESS) { xb::error() << "xb_data_files_init() failed " << "with error code " << err; @@ -7105,7 +7105,7 @@ static void xtrabackup_prepare_func(int argc, char **argv) { if (xtrabackup_incremental) { Tablespace_map::instance().deserialize(xtrabackup_incremental_dir); - err = xb_data_files_init(false); + err = xb_data_files_init(); if (err != DB_SUCCESS) { xb::error() << "xb_data_files_init() failed " << "with error code " << err; diff --git a/storage/innobase/xtrabackup/src/xtrabackup.h b/storage/innobase/xtrabackup/src/xtrabackup.h index 6d427775fdd..4a0a1337d1c 100644 --- a/storage/innobase/xtrabackup/src/xtrabackup.h +++ b/storage/innobase/xtrabackup/src/xtrabackup.h @@ -255,7 +255,7 @@ bool xtrabackup_copy_datafile(fil_node_t *node, uint thread_n, /************************************************************************ Initialize the tablespace memory cache and populate it by scanning for and opening data files */ -ulint xb_data_files_init(bool is_prep_handle_ddls); +ulint xb_data_files_init(); /************************************************************************ Destroy the tablespace memory cache. */ @@ -343,5 +343,5 @@ bool xb_process_datadir(const char *path, /*!