Skip to content

Commit

Permalink
PXB-3334 Code cleanups in reduced lock feature
Browse files Browse the repository at this point in the history
removed argument `prep_handle_ddls` from all using functions, using xtrabackup_prepare instead
  • Loading branch information
Aibek Bukabayev committed Aug 27, 2024
1 parent 171ab41 commit 9426040
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 44 deletions.
36 changes: 15 additions & 21 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -11636,8 +11634,7 @@ std::tuple<dberr_t, space_id_t> 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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<void(const Const_iter &, const Const_iter &, size_t, bool &,
bool)>
open = std::bind(&Tablespace_dirs::open_ibd, this, _1, _2, _3, _4, _5);
std::function<void(const Const_iter &, const Const_iter &, size_t, bool &)>
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;
}
Expand All @@ -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. */
Expand Down
5 changes: 1 addition & 4 deletions storage/innobase/include/fil0fil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions storage/innobase/include/xb0xb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/srv/srv0start.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/xtrabackup/src/ddl_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ std::tuple<filevec, filevec> 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);
Expand Down
30 changes: 15 additions & 15 deletions storage/innobase/xtrabackup/src/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */

Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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());
}

/************************************************************************
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/xtrabackup/src/xtrabackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -343,5 +343,5 @@ bool xb_process_datadir(const char *path, /*!<in: datadir path */
@param[in] lsn lsn to update */
void update_log_temp_checkpoint(byte *buf, lsn_t lsn);

void xb_scan_for_tablespaces(bool is_prep_handle_ddls, bool only_undo);
void xb_scan_for_tablespaces(bool only_undo);
#endif /* XB_XTRABACKUP_H */

0 comments on commit 9426040

Please sign in to comment.