Browse Source

raft: add Node.Next

Blake Mizerany 11 years ago
parent
commit
6e0a668455
2 changed files with 11 additions and 2 deletions
  1. 8 0
      raft/node.go
  2. 3 2
      raft/raft.go

+ 8 - 0
raft/node.go

@@ -29,3 +29,11 @@ func (n *Node) Step(m Message) {
 	defer n.lk.Unlock()
 	n.sm.Step(m)
 }
+
+// Next advances the commit index and returns any new
+// commitable entries.
+func (n *Node) Next() []Entry {
+	n.lk.Lock()
+	defer n.lk.Unlock()
+	return n.sm.nextEnts()
+}

+ 3 - 2
raft/raft.go

@@ -191,12 +191,13 @@ func (sm *stateMachine) theN() int {
 	return -1
 }
 
-func (sm *stateMachine) maybeAdvanceCommit() int {
+func (sm *stateMachine) nextEnts() (ents []Entry) {
 	ci := sm.theN()
 	if ci > sm.commit {
+		ents = sm.log[sm.commit+1:ci]
 		sm.commit = ci
 	}
-	return sm.commit
+	return ents
 }
 
 func (sm *stateMachine) reset() {