raft: rename log.commit to log.committed

This commit is contained in:
Xiang Li 2014-05-28 11:08:32 -07:00 committed by Yicheng Qin
parent 9cd3b2153f
commit 0cdd1b58a4
3 changed files with 20 additions and 20 deletions

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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)
}
}
}