Skip to content

Commit

Permalink
refactor(backup): remove 'policy' from backup file's path
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyifan27 committed Dec 25, 2020
1 parent 1d88c1d commit 36c650c
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 757 deletions.
81 changes: 22 additions & 59 deletions src/common/backup_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,123 +29,86 @@ const int32_t cold_backup_constant::PROGRESS_FINISHED = 1000;

namespace cold_backup {

std::string get_policy_path(const std::string &root, const std::string &policy_name)
std::string get_backup_path(const std::string &root, int64_t backup_id)
{
std::stringstream ss;
ss << root << "/" << policy_name;
return ss.str();
return root + "/" + std::to_string(backup_id);
}

std::string
get_backup_path(const std::string &root, const std::string &policy_name, int64_t backup_id)
std::string get_backup_info_file(const std::string &root, int64_t backup_id)
{
std::stringstream ss;
ss << get_policy_path(root, policy_name) << "/" << backup_id;
return ss.str();
}

std::string get_app_backup_path(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id)
{
std::stringstream ss;
ss << get_backup_path(root, policy_name, backup_id) << "/" << app_name << "_" << app_id;
return ss.str();
return get_backup_path(root, backup_id) + "/" + cold_backup_constant::BACKUP_INFO;
}

std::string get_replica_backup_path(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id)
{
std::stringstream ss;
ss << get_policy_path(root, policy_name) << "/" << backup_id << "/" << app_name << "_"
<< pid.get_app_id() << "/" << pid.get_partition_index();
return ss.str();
std::string str_app = app_name + "_" + std::to_string(pid.get_app_id());
return get_backup_path(root, backup_id) + "/" + str_app + "/" +
std::to_string(pid.get_partition_index());
}

std::string get_app_meta_backup_path(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id)
{
std::stringstream ss;
ss << get_policy_path(root, policy_name) << "/" << backup_id << "/" << app_name << "_" << app_id
<< "/meta";
return ss.str();
std::string str_app = app_name + "_" + std::to_string(app_id);
return get_backup_path(root, backup_id) + "/" + str_app + "/meta";
}

std::string get_app_metadata_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id)
{
std::stringstream ss;
ss << get_app_meta_backup_path(root, policy_name, app_name, app_id, backup_id) << "/"
<< cold_backup_constant::APP_METADATA;
return ss.str();
return get_app_meta_backup_path(root, app_name, app_id, backup_id) + "/" +
cold_backup_constant::APP_METADATA;
}

std::string get_app_backup_status_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id)
{
std::stringstream ss;
ss << get_app_meta_backup_path(root, policy_name, app_name, app_id, backup_id) << "/"
<< cold_backup_constant::APP_BACKUP_STATUS;
return ss.str();
return get_app_meta_backup_path(root, app_name, app_id, backup_id) + "/" +
cold_backup_constant::APP_BACKUP_STATUS;
}

std::string get_current_chkpt_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id)
{
std::stringstream ss;
ss << get_replica_backup_path(root, policy_name, app_name, pid, backup_id) << "/"
<< cold_backup_constant::CURRENT_CHECKPOINT;
return ss.str();
return get_replica_backup_path(root, app_name, pid, backup_id) + "/" +
cold_backup_constant::CURRENT_CHECKPOINT;
}

std::string get_remote_chkpt_dirname()
{
// here using server address as suffix of remote_chkpt_dirname
rpc_address local_address = dsn_primary_address();
std::stringstream ss;
ss << "chkpt_" << local_address.ipv4_str() << "_" << local_address.port();
return ss.str();
std::string local_address = dsn_primary_address().ipv4_str();
std::string port = std::to_string(dsn_primary_address().port());
return "chkpt_" + local_address + "_" + port;
}

std::string get_remote_chkpt_dir(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id)
{
std::stringstream ss;
ss << get_replica_backup_path(root, policy_name, app_name, pid, backup_id) << "/"
<< get_remote_chkpt_dirname();
return ss.str();
return get_replica_backup_path(root, app_name, pid, backup_id) + "/" +
get_remote_chkpt_dirname();
}

std::string get_remote_chkpt_meta_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id)
{
std::stringstream ss;
ss << get_remote_chkpt_dir(root, policy_name, app_name, pid, backup_id) << "/"
<< cold_backup_constant::BACKUP_METADATA;
return ss.str();
return get_remote_chkpt_dir(root, app_name, pid, backup_id) + "/" +
cold_backup_constant::BACKUP_METADATA;
}

} // namespace cold_backup
Expand Down
71 changes: 24 additions & 47 deletions src/common/backup_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ namespace cold_backup {

// The directory structure on block service
//
// <root>/<policy_name>/<backup_id>/<appname_appid>/meta/app_metadata
// /meta/app_backup_status
// /partition_1/checkpoint@ip:port/***.sst
// /partition_1/checkpoint@ip:port/CURRENT
// /partition_1/checkpoint@ip:port/backup_metadata
// /partition_1/current_checkpoint
// <root>/<policy_name>/<backup_id>/<appname_appid>/meta/app_metadata
// /meta/app_backup_status
// /partition_1/checkpoint@ip:port/***.sst
// /partition_1/checkpoint@ip:port/CURRENT
// /partition_1/checkpoint@ip:port/backup_metadata
// /partition_1/current_checkpoint
// <root>/<policy_name>/<backup_id>/backup_info
// <root>/<backup_id>/<appname_appid>/meta/app_metadata
// /meta/app_backup_status
// /partition_1/checkpoint@ip:port/***.sst
// /partition_1/checkpoint@ip:port/CURRENT
// /partition_1/checkpoint@ip:port/backup_metadata
// /partition_1/current_checkpoint
// <root>/<backup_id>/<appname_appid>/meta/app_metadata
// /meta/app_backup_status
// /partition_1/checkpoint@ip:port/***.sst
// /partition_1/checkpoint@ip:port/CURRENT
// /partition_1/checkpoint@ip:port/backup_metadata
// /partition_1/current_checkpoint
// <root>/<backup_id>/backup_info
//

//
Expand All @@ -72,39 +72,22 @@ namespace cold_backup {
// 5, backup_info : recording the information of this backup
//

// compose the path for policy on block service
// input:
// -- root: the prefix of path
// return:
// the path: <root>/<policy_name>
std::string get_policy_path(const std::string &root, const std::string &policy_name);

// compose the path for app on block service
// input:
// -- root: the prefix of path
// return:
// the path: <root>/<policy_name>/<backup_id>
std::string
get_backup_path(const std::string &root, const std::string &policy_name, int64_t backup_id);
// the path: <root>/<backup_id>
std::string get_backup_path(const std::string &root, int64_t backup_id);

// compose the path for app on block service
// input:
// -- root: the prefix of path
// return:
// the path: <root>/<policy_name>/<backup_id>/<appname_appid>
std::string get_app_backup_path(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id);
// return: <root>/<backup_id>/backup_info
std::string get_backup_info_file(const std::string &root, int64_t backup_id);

// compose the path for replica on block service
// input:
// -- root: the prefix of the path
// return:
// the path: <root>/<policy_name>/<backup_id>/<appname_appid>/<partition_index>
// the path: <root>/<backup_id>/<appname_appid>/<partition_index>
std::string get_replica_backup_path(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id);
Expand All @@ -113,9 +96,8 @@ std::string get_replica_backup_path(const std::string &root,
// input:
// -- root: the prefix of the path
// return:
// the path: <root>/<policy_name>/<backup_id>/<appname_appid>/meta
// the path: <root>/<backup_id>/<appname_appid>/meta
std::string get_app_meta_backup_path(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id);
Expand All @@ -125,9 +107,8 @@ std::string get_app_meta_backup_path(const std::string &root,
// -- prefix: the prefix of AP
// return:
// the AP of app meta data file:
// <root>/<policy_name>/<backup_id>/<appname_appid>/meta/app_metadata
// <root>/<backup_id>/<appname_appid>/meta/app_metadata
std::string get_app_metadata_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id);
Expand All @@ -137,9 +118,8 @@ std::string get_app_metadata_file(const std::string &root,
// -- prefix: the prefix of AP
// return:
// the AP of flag-file, which represent whether the app have finished backup:
// <root>/<policy_name>/<backup_id>/<appname_appid>/meta/app_backup_status
// <root>/<backup_id>/<appname_appid>/meta/app_backup_status
std::string get_app_backup_status_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
int32_t app_id,
int64_t backup_id);
Expand All @@ -150,9 +130,8 @@ std::string get_app_backup_status_file(const std::string &root,
// -- pid: gpid of replica
// return:
// the AP of current checkpoint file:
// <root>/<policy_name>/<backup_id>/<appname_appid>/<partition_index>/current_checkpoint
// <root>/<backup_id>/<appname_appid>/<partition_index>/current_checkpoint
std::string get_current_chkpt_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id);
Expand All @@ -168,9 +147,8 @@ std::string get_remote_chkpt_dirname();
// -- pid: gpid of replcia
// return:
// the AP of the checkpoint dir:
// <root>/<policy_name>/<backup_id>/<appname_appid>/<partition_index>/checkpoint@<ip:port>
// <root>/<backup_id>/<appname_appid>/<partition_index>/checkpoint@<ip:port>
std::string get_remote_chkpt_dir(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id);
Expand All @@ -181,9 +159,8 @@ std::string get_remote_chkpt_dir(const std::string &root,
// -- pid: gpid of replcia
// return:
// the AP of the checkpoint file metadata:
// <root>/<policy_name>/<backup_id>/<appname_appid>/<partition_index>/checkpoint@<ip:port>/backup_metadata
// <root>/<backup_id>/<appname_appid>/<partition_index>/checkpoint@<ip:port>/backup_metadata
std::string get_remote_chkpt_meta_file(const std::string &root,
const std::string &policy_name,
const std::string &app_name,
gpid pid,
int64_t backup_id);
Expand Down
Loading

0 comments on commit 36c650c

Please sign in to comment.