Raft 是一种为了高可理解性而设计的分布式共识算法。系统节点在任意时刻仅处于三种状态之一:Leader、Follower 或 Candidate。整个系统依靠心跳超时机制驱动状态转换与强一致性日志同步。
一、RequestVote RPC 参数定义
protobuf
syntax = "proto3";
package raft;
message RequestVoteArgs {
int64 term = 1; // 候选人的任期号
string candidateId = 2; // 请求选票的候选人标识
int64 lastLogIndex = 3; // 候选人最后一条日志的索引值
int64 lastLogTerm = 4; // 候选人最后一条日志的任期号
}
message RequestVoteReply {
int64 term = 1; // 当前任期号,便于候选人更新自身
bool voteGranted = 2; // 候选人是否赢得此票
}