在前面,我们探讨了关于raft的消息类型和协议层的数据结构,今天我们学习一下etcd raft的一些实体消息结构,加油呀 _
type Message struct {
Type MessageType `protobuf:"varint,1,opt,name=type,enum=raftpb.MessageType" json:"type"`
// 消息的接受者
To uint64 `protobuf:"varint,2,opt,name=to" json:"to"`
// 消息的发送者
From uint64 `protobuf:"varint,3,opt,name=from" json:"from"`
// 消息所处的任期
Term uint64 `protobuf:"varint,4,opt,name=term" json:"term"`
// logTerm is generally used for appending Raft logs to followers. For example,
// (type=MsgApp,index=100,logTerm=5) means leader appends entries starting at
// index=101, and the term of entry at index 100 is 5.
// (type=MsgAppResp,reject=true,index=100,logTerm=5) means follower rejects some
// entries from its leader as it already has an entry with term 5 at index 100.
// 消息发出者所保存的日志中的最后一条的任期号,一般选取消息会用到这个
LogTerm uint64 `protobuf:"varint,5,opt,name=logTerm" json:"logTerm"`
// 日志索引号,如果是选举消息MsgVote的话,代表这个是候选人的最后一条日志的索引号,与LogTerm一起代表这个候选者的日志情况,从而决定是否投票
Index uint64 `protobuf:"varint,6,opt,name=index" json:"index"`
// 日志具体内容
Entries []Entry `protobuf:"bytes,7,rep,name=entries" json:"entries"`
// 已经提交的日志的索引号,一般是主节点向其他节点同步日志的提交信息
Commit uint64 `protobuf:"varint,8,opt,name=commit" json:"commit"`
// 一般和MsgSnap合用,用来同步主节点的当前的数据【主要用于日志相差较大的情况,例如新节点加入或者坏节点恢复】
Snapshot Snapshot `protobuf:"bytes,9,opt,name=snapshot" json:"snapshot"`
// 代表目标节点拒绝了当前节点的请求
Reject bool `protobuf:"varint,10,opt,name=reject" json:"reject"`
RejectHint uint64 `protobuf:"varint,11,opt,name=rejectHint" json:"rejectHint"`
// 携带一些其他数据
Context []byte `protobuf:"bytes,12,opt,name=context" json:"context,omitempty"`
}
type Entry struct {
// 当前日志数据的任期号
Term uint64 `protobuf:"varint,2,opt,name=Term" json:"Term"`
// 日志索引号
Index uint64 `protobuf:"varint,3,opt,name=Index" json:"Index"`
// 一般有两类:正常数据和配置更改数据
Type EntryType `protobuf:"varint,1,opt,name=Type,enum=raftpb.EntryType" json:"Type"`
// 具体的数据
Data []byte `protobuf:"bytes,4,opt,name=Data" json:"Data,omitempty"`
}