Browse Source

raft: add Entry.isConfig

Xiang Li 11 years ago
parent
commit
f387e3e27d
2 changed files with 6 additions and 2 deletions
  1. 4 0
      raft/log.go
  2. 2 2
      raft/raft.go

+ 4 - 0
raft/log.go

@@ -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

+ 2 - 2
raft/raft.go

@@ -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
 				}