From f73d059d80af7028531a12d76fb37fe4ea01254f Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 8 Dec 2014 15:23:21 -0800 Subject: [PATCH] raft: group configuration related funcs --- raft/raft.go | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/raft/raft.go b/raft/raft.go index 4d7786182..4919de204 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -461,24 +461,6 @@ func (r *raft) handleSnapshot(m pb.Message) { } } -func (r *raft) resetPendingConf() { r.pendingConf = false } - -func (r *raft) addNode(id uint64) { - if _, ok := r.prs[id]; ok { - // Ignore any redundant addNode calls (which can happen because the - // initial bootstrapping entries are applied twice). - return - } - - r.setProgress(id, 0, r.raftLog.lastIndex()+1) - r.pendingConf = false -} - -func (r *raft) removeNode(id uint64) { - r.delProgress(id) - r.pendingConf = false -} - type stepFunc func(r *raft, m pb.Message) func stepLeader(r *raft, m pb.Message) { @@ -626,6 +608,31 @@ func (r *raft) nodes() []uint64 { return nodes } +// promotable indicates whether state machine can be promoted to leader, +// which is true when its own id is in progress list. +func (r *raft) promotable() bool { + _, ok := r.prs[r.id] + return ok +} + +func (r *raft) addNode(id uint64) { + if _, ok := r.prs[id]; ok { + // Ignore any redundant addNode calls (which can happen because the + // initial bootstrapping entries are applied twice). + return + } + + r.setProgress(id, 0, r.raftLog.lastIndex()+1) + r.pendingConf = false +} + +func (r *raft) removeNode(id uint64) { + r.delProgress(id) + r.pendingConf = false +} + +func (r *raft) resetPendingConf() { r.pendingConf = false } + func (r *raft) setProgress(id, match, next uint64) { r.prs[id] = &progress{next: next, match: match} } @@ -634,13 +641,6 @@ func (r *raft) delProgress(id uint64) { delete(r.prs, id) } -// promotable indicates whether state machine can be promoted to leader, -// which is true when its own id is in progress list. -func (r *raft) promotable() bool { - _, ok := r.prs[r.id] - return ok -} - func (r *raft) loadState(state pb.HardState) { if state.Commit < r.raftLog.committed || state.Commit > r.raftLog.lastIndex() { log.Panicf("raft: %x state.commit %d is out of range [%d, %d]", r.id, state.Commit, r.raftLog.committed, r.raftLog.lastIndex())