diff --git a/raft/raft.go b/raft/raft.go index 9a5f87814..c8fda32d8 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -95,7 +95,7 @@ type stateMachine struct { // the log log *log - ins []*index + ins []index state stateType @@ -178,9 +178,9 @@ func (sm *stateMachine) reset() { sm.lead = none sm.vote = none sm.votes = make(map[int]bool) - sm.ins = make([]*index, sm.k) + sm.ins = make([]index, sm.k) for i := range sm.ins { - sm.ins[i] = &index{next: sm.log.lastIndex() + 1} + sm.ins[i] = index{next: sm.log.lastIndex() + 1} } } @@ -273,12 +273,11 @@ func (sm *stateMachine) Step(m Message) { case stateLeader: switch m.Type { case msgAppResp: - in := sm.ins[m.From] if m.Index < 0 { - in.decr() + sm.ins[m.From].decr() sm.sendAppend() } else { - in.update(m.Index) + sm.ins[m.From].update(m.Index) if sm.maybeCommit() { sm.sendAppend() } diff --git a/raft/raft_test.go b/raft/raft_test.go index 1619fad68..8592f9a2d 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -331,9 +331,9 @@ func TestCommit(t *testing.T) { } for i, tt := range tests { - ins := make([]*index, len(tt.matches)) + ins := make([]index, len(tt.matches)) for j := 0; j < len(ins); j++ { - ins[j] = &index{tt.matches[j], tt.matches[j] + 1} + ins[j] = index{tt.matches[j], tt.matches[j] + 1} } sm := &stateMachine{log: &log{ents: tt.logs}, ins: ins, k: len(ins), term: tt.smTerm} sm.maybeCommit()