etcd源码分析
nevermoress
https://github.com/nevermoressss/note 我的一些学习笔记
展开
-
etcd 一些机制
checkquorum机制:每隔一段时间,leader节点会尝试连接集群中的节点(发送心跳),如果发现自己可以连接到的节点个数没有超过半数,则主动切换成follower状态。这样在网络分区的情况下,旧的leader节点可以很快的知道自己已经过期了。PreVote优化当follower节点准备发起选举时候,先连接其他节点,并询问它们是否愿意参与选举(其他人是否能正常收到leader节点的信息),当有半数以上节点响应并参与则可以发起新一轮选举。...原创 2020-11-18 11:50:02 · 245 阅读 · 0 评论 -
etcd 源码分析之unstable
unstable对于leader节点:维护了客户端请求对应的entry记录对于follower节点:维护从leader复制来的entrytype unstable struct { // 快照数据,未写入storage的 snapshot *pb.Snapshot // 未写入storage的entry entries []pb.Entry // entries中第一条entry记录的索引值 offset uint64 logger Logger}尝试获取第一和最后// ma原创 2020-11-18 11:49:18 · 333 阅读 · 0 评论 -
etcd 源码分析之storage
MemoryStorage在内存上维护状态信息、快照数据、Entrytype MemoryStorage struct { // Protects access to all fields. Most methods of MemoryStorage are // run on the raft goroutine, but Append() is run on an application // goroutine. sync.Mutex //状态信息(当前任期,当前节点投票给了谁,已原创 2020-11-17 14:38:27 · 292 阅读 · 0 评论 -
etcd 源码分析之raftLog
raftLog管理节点上的日志(数据)type raftLog struct { // memoryStorage实例 storage Storage // unstable 实例 unstable unstable // 已提交的位置 committed uint64 // 已应用的位置 applied uint64 logger Logger // maxNextEntsSize是从对nextEnts的调用返回的消息的最大总数字节大小 maxNextEntsSize原创 2020-11-17 14:38:06 · 197 阅读 · 0 评论 -
etcd 源码分析之raft&config
raft 结构体type raft struct { id uint64 //集群中的标识 Term uint64 //当前任期 Vote uint64 //当前任期投票给了谁 readStates []ReadState // the log raftLog *raftLog //本地log maxMsgSize uint64 //单条消息最大字节 maxUncommittedSize uint64 //最大为commit数量 // TODO(tbg):原创 2020-11-17 14:37:43 · 189 阅读 · 0 评论