modulepackage
0.0.0-20200506124431-80829ded9c47
Repository: https://github.com/aberic/raft4go.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# Functions
Get 从集群获取数据.
No description provided by the author
NodeList 查看当前集群中节点集合,包括自身.
Put 集群新增数据.
RaftStart 启动且只能启动一次Raft服务
node 自身节点信息
nodes 集群节点信息
timeCheck raft心跳定时检查超时时间
timeout raft心跳定时/超时ms.
No description provided by the author
Status 获取角色状态,0-leader、1-candidate、2-follower
RoleStatusLeader、RoleStatusCandidate、RoleStatusFollower.
# Constants
RoleStatusCandidate candidate.
RoleStatusFollower follower.
RoleStatusLeader leader.
# Structs
data 匹配数据对象.
Log 日志属性.
node 节点信息.
Params 启动参数.
Raft 接收客户端提交的同步内容,被封装在自定义的方法中
也返回客户端期望的同步结果及从其他节点同步过来的信息.
ReqData 请求当前集群指定key数据.
ReqDataList 请求当前集群数据集合.
ReqHeartBeat 用于Leader节点复制日志给其他节点,也作为心跳
prevLogIndex和prevLogTerm表示上一次发送的日志的索引和任期,用于保证收到的日志是连续的.
ReqNodeList 请求当前集群节点集合.
ReqSyncData 用于Leader节点同步数据给其他节点.
reqVote 用于Candidate获取选票.
RespData 应答当前集群指定key数据.
RespDataList 应答当前集群数据集合.
RespHeartBeat 接收者实现逻辑
返回false,如果收到的任期比当前任期小
返回false,如果不包含之前的日志条目(没有匹配prevLogIndex和prevLogTerm)
如果存在index相同但是term不相同的日志,删除从该位置开始所有的日志
追加所有不存在的日志
如果leaderCommit>commitIndex,将commitIndex设置为commitIndex = min(leaderCommit, index of last new entry).
RespNodeList 应答当前集群节点集合.
RespSyncData 接收者实现逻辑
返回false,如果收到的任期比当前任期小
返回false,如果不包含之前的日志条目(没有匹配prevLogIndex和prevLogTerm)
如果存在index相同但是term不相同的日志,删除从该位置开始所有的日志
追加所有不存在的日志
如果leaderCommit>commitIndex,将commitIndex设置为commitIndex = min(leaderCommit, index of last new entry).
接收者的实现逻辑
返回false,如果收到的任期比当前任期小
如果本地状态中votedFor为null或者candidateId,且candidate的日志等于或多余(按照index判断)接收者的日志,则接收者投票给candidate,即返回true.
Server gRPC服务.
UnimplementedRaftServer can be embedded to have forward compatible implementations.
# Interfaces
RaftClient is the client API for Raft service.
RaftServer is the server API for Raft service.