Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

split: parent replica create child replica #291

Merged
merged 22 commits into from
Aug 21, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/dist/replication/lib/replica_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,25 +2270,24 @@ std::string replica_stub::get_replica_dir(const char *app_type,
{
std::string gpid_str = fmt::format("{}.{}", id.to_string(), app_type);
std::string replica_dir;
bool is_dir_confict = false;
bool is_dir_exist = false;
for (const std::string &data_dir : _options.data_dirs) {
std::string dir = utils::filesystem::path_combine(data_dir, gpid_str);
if (utils::filesystem::directory_exists(dir) && parent_dir == "") {
if (is_dir_confict) {
dassert(
false, "replica dir conflict: %s <--> %s", dir.c_str(), replica_dir.c_str());
}
replica_dir = dir;
is_dir_confict = true;
}

// if creating child replica during partition split, we should gurantee child replica and
// parent replica share the same data dir
// parent_dir = <dir>/<gpid>.<app_type>, check if parent_dir's <dir> is euqal to <data_dir>
hycdong marked this conversation as resolved.
Show resolved Hide resolved
if (parent_dir.substr(0, data_dir.size() + 1) == data_dir + "/") {
if (parent_dir != "" && parent_dir.substr(0, data_dir.size() + 1) == data_dir + "/") {
hycdong marked this conversation as resolved.
Show resolved Hide resolved
replica_dir = dir;
_fs_manager.add_replica(id, replica_dir);
break;
return replica_dir;
}
if (utils::filesystem::directory_exists(dir) && parent_dir == "") {
if (is_dir_exist) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有明白这个循环的意思, 可以加下注释吗?

Copy link
Contributor Author

@hycdong hycdong Aug 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数的意思是得到replica存储数据的data_dir,若不存在则为其分配data_dir, _options.data_dirs是在https://github.com/XiaoMi/rdsn/blob/master/src/dist/replication/common/replication_common.cpp#L131 定义的,这个循环中还会检查data_dir是否冲突,因为一个replica只能分配一个data_dir,这个函数我没有改动逻辑,只是重构一下

dassert(
false, "replica dir conflict: %s <--> %s", dir.c_str(), replica_dir.c_str());
}
replica_dir = dir;
is_dir_exist = true;
}
}
if (replica_dir.empty() && create_new) {
Expand Down