Commit 8a3e2970 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-13575 On failure, Mariabackup --backup --safe-slave-backup may forget to...

MDEV-13575 On failure, Mariabackup --backup --safe-slave-backup may forget to START SLAVE SQL_THREAD

backup_release(): New function, refactored from backup_finish().
Release some resources that may have been acquired by backup_startup()
and should be released even after a failed operation.

xtrabackup_backup_low(): Refactored from xtrabackup_backup_func().

xtrabackup_backup_func(): Always call backup_release() after calling
backup_start().
parent 72ac85cd
...@@ -1342,8 +1342,8 @@ backup_files(const char *from, bool prep_mode) ...@@ -1342,8 +1342,8 @@ backup_files(const char *from, bool prep_mode)
return(ret); return(ret);
} }
bool /** Start --backup */
backup_start() bool backup_start()
{ {
if (!opt_no_lock) { if (!opt_no_lock) {
if (opt_safe_slave_backup) { if (opt_safe_slave_backup) {
...@@ -1418,9 +1418,8 @@ backup_start() ...@@ -1418,9 +1418,8 @@ backup_start()
return(true); return(true);
} }
/** Release resources after backup_start() */
bool void backup_release()
backup_finish()
{ {
/* release all locks */ /* release all locks */
if (!opt_no_lock) { if (!opt_no_lock) {
...@@ -1435,7 +1434,11 @@ backup_finish() ...@@ -1435,7 +1434,11 @@ backup_finish()
xb_mysql_query(mysql_connection, xb_mysql_query(mysql_connection,
"START SLAVE SQL_THREAD", false); "START SLAVE SQL_THREAD", false);
} }
}
/** Finish after backup_start() and backup_release() */
bool backup_finish()
{
/* Copy buffer pool dump or LRU dump */ /* Copy buffer pool dump or LRU dump */
if (!opt_rsync) { if (!opt_rsync) {
if (buffer_pool_filename && file_exists(buffer_pool_filename)) { if (buffer_pool_filename && file_exists(buffer_pool_filename)) {
......
...@@ -31,10 +31,12 @@ copy_file(ds_ctxt_t *datasink, ...@@ -31,10 +31,12 @@ copy_file(ds_ctxt_t *datasink,
const char *dst_file_path, const char *dst_file_path,
uint thread_n); uint thread_n);
bool /** Start --backup */
backup_start(); bool backup_start();
bool /** Release resources after backup_start() */
backup_finish(); void backup_release();
/** Finish after backup_start() and backup_release() */
bool backup_finish();
bool bool
apply_log_finish(); apply_log_finish();
bool bool
......
...@@ -3326,6 +3326,74 @@ static void stop_backup_threads() ...@@ -3326,6 +3326,74 @@ static void stop_backup_threads()
} }
} }
/** Implement the core of --backup
@return whether the operation succeeded */
static
bool
xtrabackup_backup_low()
{
/* read the latest checkpoint lsn */
{
ulint max_cp_field;
log_mutex_enter();
if (recv_find_max_checkpoint(&max_cp_field) == DB_SUCCESS
&& log_sys->log.format != 0) {
metadata_to_lsn = mach_read_from_8(
log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN);
msg("xtrabackup: The latest check point"
" (for incremental): '" LSN_PF "'\n",
metadata_to_lsn);
} else {
metadata_to_lsn = 0;
msg("xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
}
log_mutex_exit();
}
stop_backup_threads();
if (!dst_log_file || xtrabackup_copy_logfile(COPY_LAST)) {
return false;
}
if (ds_close(dst_log_file)) {
dst_log_file = NULL;
return false;
}
dst_log_file = NULL;
if(!xtrabackup_incremental) {
strcpy(metadata_type, "full-backuped");
metadata_from_lsn = 0;
} else {
strcpy(metadata_type, "incremental");
metadata_from_lsn = incremental_lsn;
}
metadata_last_lsn = log_copy_scanned_lsn;
if (!xtrabackup_stream_metadata(ds_meta)) {
msg("xtrabackup: Error: failed to stream metadata.\n");
return false;
}
if (xtrabackup_extra_lsndir) {
char filename[FN_REFLEN];
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
XTRABACKUP_METADATA_FILENAME);
if (!xtrabackup_write_metadata(filename)) {
msg("xtrabackup: Error: failed to write metadata "
"to '%s'.\n", filename);
return false;
}
}
return true;
}
/** Implement --backup /** Implement --backup
@return whether the operation succeeded */ @return whether the operation succeeded */
static static
...@@ -3333,7 +3401,6 @@ bool ...@@ -3333,7 +3401,6 @@ bool
xtrabackup_backup_func() xtrabackup_backup_func()
{ {
MY_STAT stat_info; MY_STAT stat_info;
lsn_t latest_cp;
uint i; uint i;
uint count; uint count;
pthread_mutex_t count_mutex; pthread_mutex_t count_mutex;
...@@ -3733,70 +3800,19 @@ xtrabackup_backup_func() ...@@ -3733,70 +3800,19 @@ xtrabackup_backup_func()
} }
} }
if (!backup_start()) { bool ok = backup_start();
goto fail;
}
/* read the latest checkpoint lsn */
{
ulint max_cp_field;
log_mutex_enter();
if (recv_find_max_checkpoint(&max_cp_field) == DB_SUCCESS
&& log_sys->log.format != 0) {
latest_cp = mach_read_from_8(log_sys->checkpoint_buf +
LOG_CHECKPOINT_LSN);
msg("xtrabackup: The latest check point"
" (for incremental): '" LSN_PF "'\n", latest_cp);
} else {
latest_cp = 0;
msg("xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
}
log_mutex_exit();
}
stop_backup_threads();
if (!dst_log_file || xtrabackup_copy_logfile(COPY_LAST)) {
goto fail;
}
if (ds_close(dst_log_file)) { if (ok) {
dst_log_file = NULL; ok = xtrabackup_backup_low();
goto fail;
}
dst_log_file = NULL;
if(!xtrabackup_incremental) { backup_release();
strcpy(metadata_type, "full-backuped");
metadata_from_lsn = 0;
} else {
strcpy(metadata_type, "incremental");
metadata_from_lsn = incremental_lsn;
}
metadata_to_lsn = latest_cp;
metadata_last_lsn = log_copy_scanned_lsn;
if (!xtrabackup_stream_metadata(ds_meta)) { if (ok) {
msg("xtrabackup: Error: failed to stream metadata.\n"); backup_finish();
goto fail;
}
if (xtrabackup_extra_lsndir) {
char filename[FN_REFLEN];
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
XTRABACKUP_METADATA_FILENAME);
if (!xtrabackup_write_metadata(filename)) {
msg("xtrabackup: Error: failed to write metadata "
"to '%s'.\n", filename);
goto fail;
} }
} }
if (!backup_finish()) { if (!ok) {
goto fail; goto fail;
} }
...@@ -3809,10 +3825,10 @@ xtrabackup_backup_func() ...@@ -3809,10 +3825,10 @@ xtrabackup_backup_func()
xb_data_files_close(); xb_data_files_close();
/* Make sure that the latest checkpoint was included */ /* Make sure that the latest checkpoint was included */
if (latest_cp > log_copy_scanned_lsn) { if (metadata_to_lsn > log_copy_scanned_lsn) {
msg("xtrabackup: error: failed to copy enough redo log (" msg("xtrabackup: error: failed to copy enough redo log ("
"LSN=" LSN_PF "; checkpoint LSN=" LSN_PF ").\n", "LSN=" LSN_PF "; checkpoint LSN=" LSN_PF ").\n",
log_copy_scanned_lsn, latest_cp); log_copy_scanned_lsn, metadata_to_lsn);
goto fail; goto fail;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment