mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: leader updates its own match; tries to commit after a prop
This commit is contained in:
parent
6fa74b0e33
commit
c32d34166e
@ -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")
|
||||
|
@ -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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user