Skip to content

Commit

Permalink
raft: support learner
Browse files Browse the repository at this point in the history
  • Loading branch information
siddontang committed Nov 10, 2017
1 parent 75c7e62 commit 509c9bc
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 104 deletions.
4 changes: 3 additions & 1 deletion raft/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (n *node) run(r *raft) {
r.Step(m)
case m := <-n.recvc:
// filter out response message from unknown From.
if _, ok := r.prs[m.From]; ok || !IsResponseMsg(m.Type) {
if pr := r.getProgress(m.From); pr != nil || !IsResponseMsg(m.Type) {
r.Step(m) // raft never returns an error
}
case cc := <-n.confc:
Expand All @@ -334,6 +334,8 @@ func (n *node) run(r *raft) {
switch cc.Type {
case pb.ConfChangeAddNode:
r.addNode(cc.NodeID)
case pb.ConfChangeAddLearnerNode:
r.addLearner(cc.NodeID)
case pb.ConfChangeRemoveNode:
// block incoming proposal when local node is
// removed
Expand Down
4 changes: 4 additions & 0 deletions raft/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Progress struct {
// When in ProgressStateSnapshot, leader should have sent out snapshot
// before and stops sending any replication message.
State ProgressStateType

// Paused is used in ProgressStateProbe.
// When Paused is true, raft should pause sending replication message to this peer.
Paused bool
Expand Down Expand Up @@ -76,6 +77,9 @@ type Progress struct {
// be freed by calling inflights.freeTo with the index of the last
// received entry.
ins *inflights

// IsLearner is true if this progress is tracked for a learner.
IsLearner bool
}

func (pr *Progress) resetState(state ProgressStateType) {
Expand Down
Loading

0 comments on commit 509c9bc

Please sign in to comment.