raft: add Entry.isConfig
parent
3817661f82
commit
f387e3e27d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue