Skip to content

Commit 8a3e297

Browse files
committed
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().
1 parent 72ac85c commit 8a3e297

File tree

3 files changed

+91
-70
lines changed

3 files changed

+91
-70
lines changed

extra/mariabackup/backup_copy.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,8 @@ backup_files(const char *from, bool prep_mode)
13421342
return(ret);
13431343
}
13441344

1345-
bool
1346-
backup_start()
1345+
/** Start --backup */
1346+
bool backup_start()
13471347
{
13481348
if (!opt_no_lock) {
13491349
if (opt_safe_slave_backup) {
@@ -1418,9 +1418,8 @@ backup_start()
14181418
return(true);
14191419
}
14201420

1421-
1422-
bool
1423-
backup_finish()
1421+
/** Release resources after backup_start() */
1422+
void backup_release()
14241423
{
14251424
/* release all locks */
14261425
if (!opt_no_lock) {
@@ -1435,7 +1434,11 @@ backup_finish()
14351434
xb_mysql_query(mysql_connection,
14361435
"START SLAVE SQL_THREAD", false);
14371436
}
1437+
}
14381438

1439+
/** Finish after backup_start() and backup_release() */
1440+
bool backup_finish()
1441+
{
14391442
/* Copy buffer pool dump or LRU dump */
14401443
if (!opt_rsync) {
14411444
if (buffer_pool_filename && file_exists(buffer_pool_filename)) {

extra/mariabackup/backup_copy.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ copy_file(ds_ctxt_t *datasink,
3131
const char *dst_file_path,
3232
uint thread_n);
3333

34-
bool
35-
backup_start();
36-
bool
37-
backup_finish();
34+
/** Start --backup */
35+
bool backup_start();
36+
/** Release resources after backup_start() */
37+
void backup_release();
38+
/** Finish after backup_start() and backup_release() */
39+
bool backup_finish();
3840
bool
3941
apply_log_finish();
4042
bool

extra/mariabackup/xtrabackup.cc

Lines changed: 77 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,14 +3326,81 @@ static void stop_backup_threads()
33263326
}
33273327
}
33283328

3329+
/** Implement the core of --backup
3330+
@return whether the operation succeeded */
3331+
static
3332+
bool
3333+
xtrabackup_backup_low()
3334+
{
3335+
/* read the latest checkpoint lsn */
3336+
{
3337+
ulint max_cp_field;
3338+
3339+
log_mutex_enter();
3340+
3341+
if (recv_find_max_checkpoint(&max_cp_field) == DB_SUCCESS
3342+
&& log_sys->log.format != 0) {
3343+
metadata_to_lsn = mach_read_from_8(
3344+
log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN);
3345+
msg("xtrabackup: The latest check point"
3346+
" (for incremental): '" LSN_PF "'\n",
3347+
metadata_to_lsn);
3348+
} else {
3349+
metadata_to_lsn = 0;
3350+
msg("xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
3351+
}
3352+
log_mutex_exit();
3353+
}
3354+
3355+
stop_backup_threads();
3356+
3357+
if (!dst_log_file || xtrabackup_copy_logfile(COPY_LAST)) {
3358+
return false;
3359+
}
3360+
3361+
if (ds_close(dst_log_file)) {
3362+
dst_log_file = NULL;
3363+
return false;
3364+
}
3365+
3366+
dst_log_file = NULL;
3367+
3368+
if(!xtrabackup_incremental) {
3369+
strcpy(metadata_type, "full-backuped");
3370+
metadata_from_lsn = 0;
3371+
} else {
3372+
strcpy(metadata_type, "incremental");
3373+
metadata_from_lsn = incremental_lsn;
3374+
}
3375+
metadata_last_lsn = log_copy_scanned_lsn;
3376+
3377+
if (!xtrabackup_stream_metadata(ds_meta)) {
3378+
msg("xtrabackup: Error: failed to stream metadata.\n");
3379+
return false;
3380+
}
3381+
if (xtrabackup_extra_lsndir) {
3382+
char filename[FN_REFLEN];
3383+
3384+
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
3385+
XTRABACKUP_METADATA_FILENAME);
3386+
if (!xtrabackup_write_metadata(filename)) {
3387+
msg("xtrabackup: Error: failed to write metadata "
3388+
"to '%s'.\n", filename);
3389+
return false;
3390+
}
3391+
3392+
}
3393+
3394+
return true;
3395+
}
3396+
33293397
/** Implement --backup
33303398
@return whether the operation succeeded */
33313399
static
33323400
bool
33333401
xtrabackup_backup_func()
33343402
{
33353403
MY_STAT stat_info;
3336-
lsn_t latest_cp;
33373404
uint i;
33383405
uint count;
33393406
pthread_mutex_t count_mutex;
@@ -3733,70 +3800,19 @@ xtrabackup_backup_func()
37333800
}
37343801
}
37353802

3736-
if (!backup_start()) {
3737-
goto fail;
3738-
}
3739-
3740-
/* read the latest checkpoint lsn */
3741-
{
3742-
ulint max_cp_field;
3743-
3744-
log_mutex_enter();
3745-
3746-
if (recv_find_max_checkpoint(&max_cp_field) == DB_SUCCESS
3747-
&& log_sys->log.format != 0) {
3748-
latest_cp = mach_read_from_8(log_sys->checkpoint_buf +
3749-
LOG_CHECKPOINT_LSN);
3750-
msg("xtrabackup: The latest check point"
3751-
" (for incremental): '" LSN_PF "'\n", latest_cp);
3752-
} else {
3753-
latest_cp = 0;
3754-
msg("xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
3755-
}
3756-
log_mutex_exit();
3757-
}
3758-
3759-
stop_backup_threads();
3760-
3761-
if (!dst_log_file || xtrabackup_copy_logfile(COPY_LAST)) {
3762-
goto fail;
3763-
}
3803+
bool ok = backup_start();
37643804

3765-
if (ds_close(dst_log_file)) {
3766-
dst_log_file = NULL;
3767-
goto fail;
3768-
}
3769-
3770-
dst_log_file = NULL;
3805+
if (ok) {
3806+
ok = xtrabackup_backup_low();
37713807

3772-
if(!xtrabackup_incremental) {
3773-
strcpy(metadata_type, "full-backuped");
3774-
metadata_from_lsn = 0;
3775-
} else {
3776-
strcpy(metadata_type, "incremental");
3777-
metadata_from_lsn = incremental_lsn;
3778-
}
3779-
metadata_to_lsn = latest_cp;
3780-
metadata_last_lsn = log_copy_scanned_lsn;
3808+
backup_release();
37813809

3782-
if (!xtrabackup_stream_metadata(ds_meta)) {
3783-
msg("xtrabackup: Error: failed to stream metadata.\n");
3784-
goto fail;
3785-
}
3786-
if (xtrabackup_extra_lsndir) {
3787-
char filename[FN_REFLEN];
3788-
3789-
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
3790-
XTRABACKUP_METADATA_FILENAME);
3791-
if (!xtrabackup_write_metadata(filename)) {
3792-
msg("xtrabackup: Error: failed to write metadata "
3793-
"to '%s'.\n", filename);
3794-
goto fail;
3810+
if (ok) {
3811+
backup_finish();
37953812
}
3796-
37973813
}
37983814

3799-
if (!backup_finish()) {
3815+
if (!ok) {
38003816
goto fail;
38013817
}
38023818

@@ -3809,10 +3825,10 @@ xtrabackup_backup_func()
38093825
xb_data_files_close();
38103826

38113827
/* Make sure that the latest checkpoint was included */
3812-
if (latest_cp > log_copy_scanned_lsn) {
3828+
if (metadata_to_lsn > log_copy_scanned_lsn) {
38133829
msg("xtrabackup: error: failed to copy enough redo log ("
38143830
"LSN=" LSN_PF "; checkpoint LSN=" LSN_PF ").\n",
3815-
log_copy_scanned_lsn, latest_cp);
3831+
log_copy_scanned_lsn, metadata_to_lsn);
38163832
goto fail;
38173833
}
38183834

0 commit comments

Comments
 (0)