raft: add Entry.isConfig

release-2.0
Xiang Li 2014-06-19 15:56:47 -07:00 committed by Yicheng Qin
parent 3817661f82
commit f387e3e27d
2 changed files with 6 additions and 2 deletions

View File

@ -13,6 +13,10 @@ type Entry struct {
Data []byte
}
func (e *Entry) isConfig() bool {
return e.Type == AddNode || e.Type == RemoveNode
}
type log struct {
ents []Entry
committed int

View File

@ -227,7 +227,7 @@ func (sm *stateMachine) becomeLeader() {
sm.state = stateLeader
for _, e := range sm.log.ents[sm.log.committed:] {
if e.Type == AddNode || e.Type == RemoveNode {
if e.isConfig() {
sm.pendingConf = true
}
}
@ -270,7 +270,7 @@ func (sm *stateMachine) Step(m Message) (ok bool) {
switch sm.lead {
case sm.id:
e := m.Entries[0]
if e.Type == AddNode || e.Type == RemoveNode {
if e.isConfig() {
if sm.pendingConf {
return false
}