Skip to content

Commit

Permalink
MDEV-33980 mariadb-backup --backup is missing retry logic for undo ta…
Browse files Browse the repository at this point in the history
…blespaces

- This is a merge of commit f378e76
from 10.4 to 10.5.
  • Loading branch information
Thirunarayanan committed May 6, 2024
1 parent b88c20c commit 9b2bf09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
8 changes: 0 additions & 8 deletions storage/innobase/os/os0file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4264,15 +4264,7 @@ bool fil_node_t::read_page0()
}
aligned_free(page);

DBUG_EXECUTE_IF("undo_space_read_fail",
if (space_id == srv_undo_space_id_start) {
goto wrong_space_id;
});

if (UNIV_UNLIKELY(space_id != space->id)) {
#ifndef DBUG_OFF
wrong_space_id:
#endif
ib::error() << "Expected tablespace id " << space->id
<< " but found " << space_id
<< " in the file " << name;
Expand Down
28 changes: 13 additions & 15 deletions storage/innobase/srv/srv0start.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i)
char undo_name[sizeof "innodb_undo000"];
ulint space_id= 0;
ulint fsp_flags= 0;
ulint n_retries= 5;

if (create)
{
Expand All @@ -506,7 +505,6 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i)
}
}

undo_retry:
pfs_os_file_t fh= os_file_create(innodb_data_file_key, name, OS_FILE_OPEN |
OS_FILE_ON_ERROR_NO_EXIT |
OS_FILE_ON_ERROR_SILENT,
Expand All @@ -516,22 +514,33 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i)
if (!success)
return 0;

ulint n_retries = 5;
os_offset_t size= os_file_get_size(fh);
ut_a(size != os_offset_t(-1));

if (!create)
{
page_t *page= static_cast<byte*>(aligned_malloc(srv_page_size,
srv_page_size));
undo_retry:
if (os_file_read(IORequestRead, fh, page, 0, srv_page_size) !=
DB_SUCCESS)
{
err_exit:
if (n_retries && srv_operation == SRV_OPERATION_BACKUP)
{
sql_print_information("InnoDB: Retrying to read undo "
"tablespace %s", name);
n_retries--;
goto undo_retry;
}
ib::error() << "Unable to read first page of file " << name;
aligned_free(page);
return ULINT_UNDEFINED;
}

DBUG_EXECUTE_IF("undo_space_read_fail", goto err_exit;);

uint32_t id= mach_read_from_4(FIL_PAGE_SPACE_ID + page);
if (id == 0 || id >= SRV_SPACE_ID_UPPER_BOUND ||
memcmp_aligned<2>(FIL_PAGE_SPACE_ID + page,
Expand Down Expand Up @@ -576,7 +585,7 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i)
space->set_sizes(SRV_UNDO_TABLESPACE_SIZE_IN_PAGES);
space->size= file->size= uint32_t(size >> srv_page_size_shift);
}
else if (!(success = file->read_page0()))
else if (!file->read_page0())
{
os_file_close(file->handle);
file->handle= OS_FILE_CLOSED;
Expand All @@ -585,18 +594,7 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i)
}

mutex_exit(&fil_system.mutex);

if (!success && n_retries &&
srv_operation == SRV_OPERATION_BACKUP)
{
sql_print_information("InnoDB: Retrying to read undo "
"tablespace %s", undo_name);
fil_space_free(space_id, false);
n_retries--;
goto undo_retry;
}

return success ? space_id : ULINT_UNDEFINED;
return space_id;
}

/** Check if undo tablespaces and redo log files exist before creating a
Expand Down

0 comments on commit 9b2bf09

Please sign in to comment.