raft: add reportUnreachable

This commit is contained in:
Xiang Li
2015-02-04 14:41:14 -08:00
committed by Yicheng Qin
parent ba7215d7a8
commit 2af33fd494
8 changed files with 101 additions and 19 deletions

View File

@@ -119,6 +119,8 @@ type Node interface {
ApplyConfChange(cc pb.ConfChange) *pb.ConfState
// Status returns the current status of the raft state machine.
Status() Status
// Report reports the given node is not reachable for the last send.
ReportUnreachable(id uint64)
// Stop performs any necessary termination of the Node
Stop()
}
@@ -270,7 +272,7 @@ func (n *node) run(r *raft) {
m.From = r.id
r.Step(m)
case m := <-n.recvc:
// filter out response message from unknow From.
// filter out response message from unknown From.
if _, ok := r.prs[m.From]; ok || !IsResponseMsg(m) {
r.Step(m) // raft never returns an error
}
@@ -418,6 +420,13 @@ func (n *node) Status() Status {
return <-c
}
func (n *node) ReportUnreachable(id uint64) {
select {
case n.recvc <- pb.Message{Type: pb.MsgUnreachable, From: id}:
case <-n.done:
}
}
func newReady(r *raft, prevSoftSt *SoftState, prevHardSt pb.HardState) Ready {
rd := Ready{
Entries: r.raftLog.unstableEntries(),