raft: leader updates its own match; tries to commit after a prop

This commit is contained in:
Xiang Li 2014-05-28 15:30:01 -07:00 committed by Yicheng Qin
parent 6fa74b0e33
commit c32d34166e
2 changed files with 14 additions and 0 deletions

View File

@ -258,6 +258,8 @@ func (sm *stateMachine) Step(m Message) {
switch sm.lead {
case sm.addr:
sm.log.append(sm.log.lastIndex(), Entry{Term: sm.term, Data: m.Data})
sm.ins[sm.addr].update(sm.log.lastIndex())
sm.log.maybeCommit(sm.log.lastIndex(), sm.term)
sm.bcastAppend()
case none:
panic("msgProp given without leader")

View File

@ -112,6 +112,18 @@ func TestLogReplication(t *testing.T) {
}
}
func TestSingleNodeCommit(t *testing.T) {
tt := newNetwork(nil)
tt.Step(Message{To: 0, Type: msgHup})
tt.Step(Message{To: 0, Type: msgProp, Data: []byte("some data")})
tt.Step(Message{To: 0, Type: msgProp, Data: []byte("some data")})
sm := tt.ss[0].(*nsm)
if sm.log.committed != 2 {
t.Errorf("committed = %d, want %d", sm.log.committed, 2)
}
}
func TestDualingCandidates(t *testing.T) {
a := &nsm{stateMachine{log: defaultLog()}, nil}
c := &nsm{stateMachine{log: defaultLog()}, nil}