Skip to content

Commit

Permalink
[fix][store] Fixup check raft meta as restarting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
rock-git authored and ketor committed Sep 9, 2024
1 parent 9eb2520 commit 9840ecc
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/engine/raft_store_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,13 @@ RaftStoreEnginePtr RaftStoreEngine::GetSelfPtr() {
bool RaftStoreEngine::Init(std::shared_ptr<Config> /*config*/) { return true; }

// Clean region raft directory
static bool CleanRaftDirectory(int64_t region_id, const std::string& raft_path, const std::string& raft_log_path) {
std::string region_raft_path = fmt::format("{}/{}", raft_path, region_id);
if (!Helper::RemoveAllFileOrDirectory(region_raft_path)) {
return false;
}

static bool CleanRaftDirectory(int64_t region_id, const std::string& raft_log_path) {
std::string region_raft_log_path = fmt::format("{}/{}", raft_log_path, region_id);
return Helper::RemoveAllFileOrDirectory(region_raft_log_path);
}

// check region raft complete
static bool IsCompleteRaftNode(int64_t region_id, const std::string& raft_path, const std::string& raft_log_path) {
std::string raft_meta_path = fmt::format("{}/{}/raft_meta/raft_meta", raft_path, region_id);
if (!Helper::IsExistPath(raft_meta_path)) {
DINGO_LOG(WARNING) << fmt::format("[raft.engine][region({})] missing raft_meta file, path: {}.", region_id,
raft_meta_path);
return false;
}

static bool IsCompleteRaftNode(int64_t region_id, const std::string& raft_log_path) {
std::string region_raft_log_path = fmt::format("{}/{}/log_meta", raft_log_path, region_id);
if (!Helper::IsExistPath(region_raft_log_path)) {
DINGO_LOG(WARNING) << fmt::format("[raft.engine][region({})] missing raft log file, path: {}.", region_id,
Expand Down Expand Up @@ -149,17 +137,14 @@ bool RaftStoreEngine::Recover() {
parameter.region_metrics = region_metrics;
parameter.listeners = listener_factory->Build();

auto is_complete = IsCompleteRaftNode(region->Id(), parameter.raft_path, parameter.log_path);
auto is_complete = IsCompleteRaftNode(region->Id(), parameter.log_path);
if (!is_complete) {
DINGO_LOG(INFO) << fmt::format("[raft.engine][region({})] raft node is not complete.", region->Id());
if (!CleanRaftDirectory(region->Id(), parameter.raft_path, parameter.log_path)) {
if (!CleanRaftDirectory(region->Id(), parameter.log_path)) {
DINGO_LOG(WARNING) << fmt::format("[raft.engine][region({})] clean region raft directory failed.",
region->Id());
continue;
}
raft_meta = store::RaftMeta::New(region->Id());
store_raft_meta->UpdateRaftMeta(raft_meta);
parameter.raft_meta = raft_meta;
parameter.is_restart = false;
}

Expand Down

0 comments on commit 9840ecc

Please sign in to comment.