diff --git a/raft/raft.go b/raft/raft.go index 7a3ca2ee9..b37f961be 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -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") diff --git a/raft/raft_test.go b/raft/raft_test.go index 8916ee997..57cb37129 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -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}