Skip to content

Commit 680ca15

Browse files
committed
MDEV-28446 mariabackup prepare fails for incrementals if a new schema is created after full backup is taken
When "mariabackup --target-dir=$basedir --incremental-dir=$incremental_dir" is running and is moving a new table file (e.g. `db1/t1.new`) from the incremental directory to the base directory, it needs to verify that the base backup database directory (e.g. `$basedir/db1`) really exists (or create it otherwise). The table `db1/t1` can come from a new database `db1` which was created during the base mariabackup execution time. In such case the directory `db1` exists only in the incremental directory, but does not exist in the base directory.
1 parent f354e45 commit 680ca15

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

extra/mariabackup/xtrabackup.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5441,11 +5441,23 @@ static ibool prepare_handle_new_files(const char *data_home_dir,
54415441
const char *file_name, void *arg)
54425442
{
54435443
const char *dest_dir = static_cast<const char *>(arg);
5444-
std::string src_path = std::string(data_home_dir) + '/' + std::string(db_name) + '/' + file_name;
5444+
std::string src_path = std::string(data_home_dir) + '/' + std::string(db_name) + '/';
54455445
/* Copy "*.new" files from incremental to base dir for incremental backup */
54465446
std::string dest_path=
54475447
dest_dir ? std::string(dest_dir) + '/' + std::string(db_name) +
5448-
'/' + file_name : src_path;
5448+
'/' : src_path;
5449+
5450+
/*
5451+
A CREATE DATABASE could have happened during the base mariabackup run.
5452+
In case if the current table file (e.g. `t1.new`) is from such
5453+
a new database, the database directory may not exist yet in
5454+
the base backup directory. Let's make sure to check if the directory
5455+
exists (and create if needed).
5456+
*/
5457+
if (!directory_exists(dest_path.c_str(), true/*create if not exists*/))
5458+
return FALSE;
5459+
src_path+= file_name;
5460+
dest_path+= file_name;
54495461

54505462
size_t index = dest_path.find(".new");
54515463
DBUG_ASSERT(index != std::string::npos);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
call mtr.add_suppression("InnoDB: New log files created");
2+
#
3+
# Start of 10.2 tests
4+
#
5+
#
6+
# MDEV-28446 mariabackup prepare fails for incrementals if a new schema is created after full backup is taken
7+
#
8+
CREATE TABLE t1(i INT PRIMARY KEY) ENGINE INNODB;
9+
# Prepare full backup, apply incremental one
10+
# shutdown server
11+
# remove datadir
12+
# xtrabackup move back
13+
# restart server
14+
SELECT COUNT(*) FROM test.t1;
15+
COUNT(*)
16+
0
17+
SELECT COUNT(*) FROM test1.t1;
18+
COUNT(*)
19+
10000
20+
DROP TABLE t1;
21+
DROP DATABASE test1;
22+
#
23+
# End of 10.2 tests
24+
#
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--source include/have_innodb.inc
2+
--source include/have_debug.inc
3+
4+
call mtr.add_suppression("InnoDB: New log files created");
5+
6+
--echo #
7+
--echo # Start of 10.2 tests
8+
--echo #
9+
10+
--echo #
11+
--echo # MDEV-28446 mariabackup prepare fails for incrementals if a new schema is created after full backup is taken
12+
--echo #
13+
14+
--let $basedir=$MYSQLTEST_VARDIR/tmp/backup
15+
--let $incremental_dir=$MYSQLTEST_VARDIR/tmp/backup_inc1
16+
17+
CREATE TABLE t1(i INT PRIMARY KEY) ENGINE INNODB;
18+
19+
--disable_result_log
20+
--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$basedir
21+
--enable_result_log
22+
23+
--let after_load_tablespaces=BEGIN NOT ATOMIC CREATE DATABASE test1; CREATE TABLE test1.t1 ENGINE=INNODB SELECT UUID() from test.seq_1_to_10000; END
24+
25+
--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$incremental_dir --incremental-basedir=$basedir --dbug=+d,mariabackup_events,mariabackup_inject_code
26+
--let after_load_tablespaces=
27+
--disable_result_log
28+
--echo # Prepare full backup, apply incremental one
29+
--exec $XTRABACKUP --apply-log-only --prepare --target-dir=$basedir
30+
--exec $XTRABACKUP --prepare --target-dir=$basedir --incremental-dir=$incremental_dir
31+
--enable_result_log
32+
33+
--let $targetdir=$basedir
34+
--source include/restart_and_restore.inc
35+
--enable_result_log
36+
37+
SELECT COUNT(*) FROM test.t1;
38+
SELECT COUNT(*) FROM test1.t1;
39+
40+
DROP TABLE t1;
41+
DROP DATABASE test1;
42+
--rmdir $basedir
43+
--rmdir $incremental_dir
44+
45+
--echo #
46+
--echo # End of 10.2 tests
47+
--echo #

0 commit comments

Comments
 (0)