Skip to content

Commit

Permalink
unify raft Role and Status
Browse files Browse the repository at this point in the history
  • Loading branch information
kikimo committed Nov 25, 2021
1 parent da5d406 commit eb45dbf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/interface/raftex.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ enum Role {
LEADER = 1, // the leader
FOLLOWER = 2; // following a leader
CANDIDATE = 3; // Has sent AskForVote request
LEARNER = 4; // It is the same with FOLLOWER,
// except it does not participate in leader election
LEARNER = 4; // same with FOLLOWER, except that it does
// not vote in leader election
}

enum Status {
Expand Down
4 changes: 2 additions & 2 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,13 @@ bool RaftPart::prepareElectionRequest(cpp2::AskForVoteRequest& req,
void RaftPart::getState(cpp2::GetStateResponse& resp) {
std::lock_guard<std::mutex> g(raftLock_);
resp.set_term(term_);
resp.set_role(nebula::raftex::cpp2::Role(role_));
resp.set_role(role_);
resp.set_is_leader(role_ == Role::LEADER);
resp.set_error_code(cpp2::ErrorCode::SUCCEEDED);
resp.set_committed_log_id(committedLogId_);
resp.set_last_log_id(lastLogId_);
resp.set_last_log_term(lastLogTerm_);
resp.set_status(nebula::raftex::cpp2::Status(status_));
resp.set_status(status_);
}

typename RaftPart::Role RaftPart::processElectionResponses(
Expand Down
16 changes: 2 additions & 14 deletions src/kvstore/raftex/RaftPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,8 @@ class RaftPart : public std::enable_shared_from_this<RaftPart> {
std::shared_ptr<thrift::ThriftClientManager<cpp2::RaftexServiceAsyncClient>> clientMan,
std::shared_ptr<kvstore::DiskManager> diskMan);

enum class Status {
STARTING = 0, // The part is starting, not ready for service
RUNNING, // The part is running
STOPPED, // The part has been stopped
WAITING_SNAPSHOT // Waiting for the snapshot.
};

enum class Role {
LEADER = 1, // the leader
FOLLOWER, // following a leader
CANDIDATE, // Has sent AskForVote request
LEARNER // It is the same with FOLLOWER,
// except it does not participate in leader election
};
using Status = cpp2::Status;
using Role = cpp2::Role;

const char* idStr() const { return idStr_.c_str(); }

Expand Down

0 comments on commit eb45dbf

Please sign in to comment.