diff --git a/raft/log.go b/raft/log.go index 7cb753ec0..3c5266629 100644 --- a/raft/log.go +++ b/raft/log.go @@ -6,23 +6,23 @@ type Entry struct { } type log struct { - ents []Entry - commit int - applied int + ents []Entry + committed int + applied int } func newLog() *log { return &log{ - ents: make([]Entry, 1), - commit: 0, - applied: 0, + ents: make([]Entry, 1), + committed: 0, + applied: 0, } } -func (l *log) maybeAppend(index, logTerm, commit int, ents ...Entry) bool { +func (l *log) maybeAppend(index, logTerm, committed int, ents ...Entry) bool { if l.matchTerm(index, logTerm) { l.append(index, ents...) - l.commit = commit + l.committed = committed return true } return false @@ -64,8 +64,8 @@ func (l *log) matchTerm(i, term int) bool { } func (l *log) maybeCommit(maxIndex, term int) bool { - if maxIndex > l.commit && l.term(maxIndex) == term { - l.commit = maxIndex + if maxIndex > l.committed && l.term(maxIndex) == term { + l.committed = maxIndex return true } return false @@ -74,9 +74,9 @@ func (l *log) maybeCommit(maxIndex, term int) bool { // nextEnts returns all the avaliable entries for execution. // all the returned entries will be marked as applied. func (l *log) nextEnts() (ents []Entry) { - if l.commit > l.applied { - ents = l.ents[l.applied+1 : l.commit+1] - l.applied = l.commit + if l.committed > l.applied { + ents = l.ents[l.applied+1 : l.committed+1] + l.applied = l.committed } return ents } diff --git a/raft/raft.go b/raft/raft.go index 801f2be22..9c5744bae 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -152,7 +152,7 @@ func (sm *stateMachine) sendAppend() { m.Index = in.next - 1 m.LogTerm = sm.log.term(in.next - 1) m.Entries = sm.log.entries(in.next) - m.Commit = sm.log.commit + m.Commit = sm.log.committed sm.send(m) } } diff --git a/raft/raft_test.go b/raft/raft_test.go index 864946173..f8d1eaa11 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -58,8 +58,8 @@ func TestLeaderElection(t *testing.T) { func TestLogReplication(t *testing.T) { tests := []struct { *network - msgs []Message - wcommit int + msgs []Message + wcommitted int }{ { newNetwork(nil, nil, nil), @@ -92,8 +92,8 @@ func TestLogReplication(t *testing.T) { for j, ism := range tt.ss { sm := ism.(*nsm) - if sm.log.commit != tt.wcommit { - t.Errorf("#%d.%d: commit = %d, want %d", i, j, sm.log.commit, tt.wcommit) + if sm.log.committed != tt.wcommitted { + t.Errorf("#%d.%d: committed = %d, want %d", i, j, sm.log.committed, tt.wcommitted) } ents := sm.nextEnts() @@ -327,8 +327,8 @@ func TestCommit(t *testing.T) { } sm := &stateMachine{log: &log{ents: tt.logs}, ins: ins, k: len(ins), term: tt.smTerm} sm.maybeCommit() - if g := sm.log.commit; g != tt.w { - t.Errorf("#%d: commit = %d, want %d", i, g, tt.w) + if g := sm.log.committed; g != tt.w { + t.Errorf("#%d: committed = %d, want %d", i, g, tt.w) } } }