Skip to content

Commit e1146f0

Browse files
PXB-2724 : Make --move-back work with RocksDB engine
https://perconadev.atlassian.net/browse/PXB-2724 Problem & Fix: -------------- --move-back option hasn't been used when restoring RocksDB files, which always resulted in a copy. Now, the missing check and related move code have been added.
1 parent 2247ae1 commit e1146f0

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

storage/innobase/xtrabackup/src/backup_copy.cc

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ static bool copy_or_move_file(const char *src_file_path,
927927
ds_ctxt_t *datasink = ds_data; /* copy to datadir by default */
928928
bool ret;
929929

930-
/* File is located outsude of the datadir */
930+
/* File is located outside of the datadir */
931931
char external_dir[FN_REFLEN];
932932

933933
if (Fil_path::type_of_path(dst_file_path) == Fil_path::absolute) {
@@ -1302,20 +1302,27 @@ Myrocks_checkpoint::file_list Myrocks_checkpoint::data_files() const {
13021302
return Myrocks_datadir(checkpoint_dir).data_files();
13031303
}
13041304

1305-
static void par_copy_rocksdb_files(const Myrocks_datadir::const_iterator &start,
1306-
const Myrocks_datadir::const_iterator &end,
1307-
size_t thread_n, ds_ctxt_t *ds,
1308-
bool *result) {
1305+
static void par_copy_or_move_rocksdb_files(
1306+
const Myrocks_datadir::const_iterator &start,
1307+
const Myrocks_datadir::const_iterator &end, size_t thread_n, ds_ctxt_t *ds,
1308+
bool *result) {
13091309
for (auto it = start; it != end; it++) {
13101310
if (ends_with(it->path.c_str(), ".qp") ||
13111311
ends_with(it->path.c_str(), ".lz4") ||
13121312
ends_with(it->path.c_str(), ".zst") ||
13131313
ends_with(it->path.c_str(), ".xbcrypt")) {
13141314
continue;
13151315
}
1316-
if (!copy_file(ds, it->path.c_str(), it->rel_path.c_str(), thread_n,
1317-
FILE_PURPOSE_OTHER, it->file_size)) {
1318-
*result = false;
1316+
if (xtrabackup_copy_back) {
1317+
if (!copy_file(ds, it->path.c_str(), it->rel_path.c_str(), thread_n,
1318+
FILE_PURPOSE_OTHER, it->file_size)) {
1319+
*result = false;
1320+
}
1321+
} else {
1322+
if (!move_file(ds, it->path.c_str(), it->rel_path.c_str(), ds->root,
1323+
thread_n, FILE_PURPOSE_OTHER)) {
1324+
*result = false;
1325+
}
13191326
}
13201327
if (!*result) {
13211328
break;
@@ -1885,7 +1892,8 @@ bool copy_incremental_over_full() {
18851892
bool result = true;
18861893
std::function<void(const Myrocks_datadir::const_iterator &,
18871894
const Myrocks_datadir::const_iterator &, size_t)>
1888-
copy = std::bind(&par_copy_rocksdb_files, _1, _2, _3, ds_data, &result);
1895+
copy = std::bind(&par_copy_or_move_rocksdb_files, _1, _2, _3, ds_data,
1896+
&result);
18891897

18901898
par_for(PFS_NOT_INSTRUMENTED, rocksdb.files(), xtrabackup_parallel, copy);
18911899
}
@@ -2385,7 +2393,8 @@ bool copy_back(int argc, char **argv) {
23852393
using std::placeholders::_3;
23862394
std::function<void(const Myrocks_datadir::const_iterator &,
23872395
const Myrocks_datadir::const_iterator &, size_t)>
2388-
copy = std::bind(&par_copy_rocksdb_files, _1, _2, _3, ds_data, &ret);
2396+
copy = std::bind(&par_copy_or_move_rocksdb_files, _1, _2, _3, ds_data,
2397+
&ret);
23892398

23902399
if (rocksdb_wal_dir.empty()) {
23912400
par_for(PFS_NOT_INSTRUMENTED, rocksdb.files("", ""), xtrabackup_parallel,
@@ -2419,7 +2428,8 @@ bool copy_back(int argc, char **argv) {
24192428
using std::placeholders::_3;
24202429
std::function<void(const Myrocks_datadir::const_iterator &,
24212430
const Myrocks_datadir::const_iterator &, size_t)>
2422-
copy = std::bind(&par_copy_rocksdb_files, _1, _2, _3, ds_data, &ret);
2431+
copy = std::bind(&par_copy_or_move_rocksdb_files, _1, _2, _3, ds_data,
2432+
&ret);
24232433

24242434
par_for(PFS_NOT_INSTRUMENTED, rocksdb.wal_files(""), xtrabackup_parallel,
24252435
copy);

storage/innobase/xtrabackup/test/suites/rocksdb/ddl.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ stop_server
115115
rm -rf $mysql_datadir
116116
xtrabackup --move-back --target-dir=$topdir/backup
117117

118+
# Check if RocksDB files have been moved (--move-back).
119+
if ls $topdir/backup/.rocksdb/* 1>/dev/null 2>&1 ; then
120+
die "RocksDB files haven't been moved."
121+
fi
122+
118123
start_server
119124

120125
# Verify backup

0 commit comments

Comments
 (0)