Skip to content

Commit

Permalink
modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
aybek committed Feb 15, 2024
1 parent 756795d commit 0d2fa13
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 77 deletions.
27 changes: 15 additions & 12 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11593,7 +11593,6 @@ void Tablespace_dirs::open_ibd(const Const_iter &start, const Const_iter &end,
size_t thread_id, bool &result) {
if (!result) return;

uint8_t max_attempt_retries = (opt_lock_ddl == LOCK_DDL_REDUCED) ? 10 : 1;
for (auto it = start; it != end; ++it) {
const std::string filename = it->second;
const auto &files = m_dirs[it->first];
Expand All @@ -11606,17 +11605,19 @@ void Tablespace_dirs::open_ibd(const Const_iter &start, const Const_iter &end,
/* cannot use auto [err, space_id] = fil_open_for_xtrabackup() as space_id
is unused here and we get unused variable error during compilation */
dberr_t err;
uint8_t attempts = 0;
while (attempts < max_attempt_retries) {
attempts++;
std::tie(err, std::ignore) = fil_open_for_xtrabackup(
phy_filename, filename.substr(0, filename.length() - 4));
/* PXB-2275 - Allow DB_INVALID_ENCRYPTION_META as we will test it in the
end of the backup */
if (err == DB_SUCCESS || err == DB_INVALID_ENCRYPTION_META) break;

if (attempts == max_attempt_retries) result = false;
}
std::tie(err, std::ignore) = fil_open_for_xtrabackup(
phy_filename, filename.substr(0, filename.length() - 4));

/* Allow deleted tables between disovery and file open when
LOCK_DDL_REDUCED, they will be handled by ddl_tracker */
if (err == DB_CANNOT_OPEN_FILE && opt_lock_ddl == LOCK_DDL_REDUCED) {
ddl_tracker->add_missing_table(phy_filename);
} else
/* PXB-2275 - Allow DB_INVALID_ENCRYPTION_META as we will test it in
the end of the backup */
if (err != DB_SUCCESS && err != DB_INVALID_ENCRYPTION_META) {
result = false;
}
}
}

Expand Down Expand Up @@ -11999,6 +12000,8 @@ dberr_t Tablespace_dirs::scan(bool populate_fil_cache) {
err = DB_SUCCESS;
}

debug_sync_point("xtrabackup_suspend_between_file_discovery_and_open");

if (err == DB_SUCCESS && populate_fil_cache) {
bool result = true;
std::function<void(const Const_iter &, const Const_iter &, size_t, bool &)>
Expand Down
62 changes: 56 additions & 6 deletions storage/innobase/xtrabackup/src/ddl_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ void ddl_tracker_t::add_table(const space_id_t &space_id, std::string name) {
tables_in_backup[space_id] = name;
}

void ddl_tracker_t::add_missing_table(std::string path) {
Fil_path::normalize(path);
if (Fil_path::has_prefix(path, Fil_path::DOT_SLASH)) {
path.erase(0, 2);
}
missing_tables.insert(path);
}

bool ddl_tracker_t::is_missing_table(const std::string &name) {
if (missing_tables.count(name)) {
return true;
}
return false;
}

/* ======== Data copying thread context ======== */

typedef struct {
Expand Down Expand Up @@ -167,6 +182,16 @@ static void data_copy_thread_func(copy_thread_ctxt_t *ctxt) {
my_thread_end();
}

/* returns .del or .ren file name starting with space_id
like schema/spaceid.ibd.del
*/
std::string ddl_tracker_t::convert_file_name(space_id_t space_id,
std::string file_name,
std::string ext) {
auto sep_pos = file_name.find_last_of(Fil_path::SEPARATOR);
return file_name.substr(0, sep_pos + 1) + std::to_string(space_id) + ext;
}

void ddl_tracker_t::handle_ddl_operations() {
xb::info() << "DDL tracking : handling DDL operations";

Expand Down Expand Up @@ -197,7 +222,9 @@ void ddl_tracker_t::handle_ddl_operations() {
for (auto &table : recopy_tables) {
if (tables_in_backup.find(table) != tables_in_backup.end()) {
if (renames.find(table) != renames.end()) {
backup_file_printf((renames[table].first + ".del").c_str(), "%s", "");
backup_file_printf(
convert_file_name(table, renames[table].first, ".ibd.del").c_str(),
"%s", "");
}
string name = tables_in_backup[table];
new_tables[table] = name;
Expand All @@ -216,7 +243,15 @@ void ddl_tracker_t::handle_ddl_operations() {
new_tables.erase(table.first);
continue;
}
backup_file_printf((table.second + ".del").c_str(), "%s", "");

/* Table not in the backup, nothing to drop, skip drop*/
if (tables_in_backup.find(table.first) == tables_in_backup.end()) {
continue;
}

backup_file_printf(
convert_file_name(table.first, table.second, ".ibd.del").c_str(), "%s",
"");
}

for (auto &table : renames) {
Expand All @@ -226,13 +261,28 @@ void ddl_tracker_t::handle_ddl_operations() {
if (check_if_skip_table(table.second.first.c_str())) {
continue;
}
/* renamed new table. update new table entry to renamed table name */
if (new_tables.find(table.first) != new_tables.end()) {
/* renamed new table. update new table entry to renamed table name
or if table is missing and renamed, add the renamed table to the new_table
list. for example: 1. t1.ibd is discovered
2. t1.ibd renamed to t2.ibd
3. t2.ibd is opened and loaded to cache to copy
4. t1.ibd is missing now
so we should add t2.ibd to new_tables and skip .ren file so that we don't
try to rename t1.ibd to t2.idb where t1.ibd is missing */
if (new_tables.find(table.first) != new_tables.end() ||
is_missing_table(table.second.first)) {
new_tables[table.first] = table.second.second;
continue;
}
backup_file_printf((table.second.first + ".ren").c_str(), "%s",
table.second.second.c_str());

/* Table not in the backup, nothing to rename, skip rename*/
if (tables_in_backup.find(table.first) == tables_in_backup.end()) {
continue;
}

backup_file_printf(
convert_file_name(table.first, table.second.first, ".ibd.ren").c_str(),
"%s", table.second.second.c_str());
}

fil_close_all_files();
Expand Down
10 changes: 10 additions & 0 deletions storage/innobase/xtrabackup/src/ddl_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ddl_tracker_t {
space_id_to_name_t drops;
/* For DDL operation found in redo log, */
std::unordered_map<space_id_t, std::pair<std::string, std::string>> renames;
/** Tables that have been deleted between discovery and file open */
std::unordered_set<std::string> missing_tables;

public:
/** Add a new table in the DDL tracker table list.
Expand All @@ -52,5 +54,13 @@ class ddl_tracker_t {
ulint len, lsn_t start_lsn);
/** Function responsible to generate files based on DDL operations */
void handle_ddl_operations();
/** Note that a table has been deleted between disovery and file open
@param[in] path missing table name with path. */
void add_missing_table(std::string path);
/** Check if table is in missing list
@param[in] name tablespace name */
bool is_missing_table(const std::string &name);
std::string convert_file_name(space_id_t space_id, std::string file_name,
std::string ext);
};
#endif // DDL_TRACKER_H
Loading

0 comments on commit 0d2fa13

Please sign in to comment.