mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: rename log.commit to log.committed
This commit is contained in:
parent
9cd3b2153f
commit
0cdd1b58a4
26
raft/log.go
26
raft/log.go
@ -6,23 +6,23 @@ type Entry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type log struct {
|
type log struct {
|
||||||
ents []Entry
|
ents []Entry
|
||||||
commit int
|
committed int
|
||||||
applied int
|
applied int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLog() *log {
|
func newLog() *log {
|
||||||
return &log{
|
return &log{
|
||||||
ents: make([]Entry, 1),
|
ents: make([]Entry, 1),
|
||||||
commit: 0,
|
committed: 0,
|
||||||
applied: 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) {
|
if l.matchTerm(index, logTerm) {
|
||||||
l.append(index, ents...)
|
l.append(index, ents...)
|
||||||
l.commit = commit
|
l.committed = committed
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -64,8 +64,8 @@ func (l *log) matchTerm(i, term int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *log) maybeCommit(maxIndex, term int) bool {
|
func (l *log) maybeCommit(maxIndex, term int) bool {
|
||||||
if maxIndex > l.commit && l.term(maxIndex) == term {
|
if maxIndex > l.committed && l.term(maxIndex) == term {
|
||||||
l.commit = maxIndex
|
l.committed = maxIndex
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -74,9 +74,9 @@ func (l *log) maybeCommit(maxIndex, term int) bool {
|
|||||||
// nextEnts returns all the avaliable entries for execution.
|
// nextEnts returns all the avaliable entries for execution.
|
||||||
// all the returned entries will be marked as applied.
|
// all the returned entries will be marked as applied.
|
||||||
func (l *log) nextEnts() (ents []Entry) {
|
func (l *log) nextEnts() (ents []Entry) {
|
||||||
if l.commit > l.applied {
|
if l.committed > l.applied {
|
||||||
ents = l.ents[l.applied+1 : l.commit+1]
|
ents = l.ents[l.applied+1 : l.committed+1]
|
||||||
l.applied = l.commit
|
l.applied = l.committed
|
||||||
}
|
}
|
||||||
return ents
|
return ents
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ func (sm *stateMachine) sendAppend() {
|
|||||||
m.Index = in.next - 1
|
m.Index = in.next - 1
|
||||||
m.LogTerm = sm.log.term(in.next - 1)
|
m.LogTerm = sm.log.term(in.next - 1)
|
||||||
m.Entries = sm.log.entries(in.next)
|
m.Entries = sm.log.entries(in.next)
|
||||||
m.Commit = sm.log.commit
|
m.Commit = sm.log.committed
|
||||||
sm.send(m)
|
sm.send(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,8 @@ func TestLeaderElection(t *testing.T) {
|
|||||||
func TestLogReplication(t *testing.T) {
|
func TestLogReplication(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
*network
|
*network
|
||||||
msgs []Message
|
msgs []Message
|
||||||
wcommit int
|
wcommitted int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
newNetwork(nil, nil, nil),
|
newNetwork(nil, nil, nil),
|
||||||
@ -92,8 +92,8 @@ func TestLogReplication(t *testing.T) {
|
|||||||
for j, ism := range tt.ss {
|
for j, ism := range tt.ss {
|
||||||
sm := ism.(*nsm)
|
sm := ism.(*nsm)
|
||||||
|
|
||||||
if sm.log.commit != tt.wcommit {
|
if sm.log.committed != tt.wcommitted {
|
||||||
t.Errorf("#%d.%d: commit = %d, want %d", i, j, sm.log.commit, tt.wcommit)
|
t.Errorf("#%d.%d: committed = %d, want %d", i, j, sm.log.committed, tt.wcommitted)
|
||||||
}
|
}
|
||||||
|
|
||||||
ents := sm.nextEnts()
|
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 := &stateMachine{log: &log{ents: tt.logs}, ins: ins, k: len(ins), term: tt.smTerm}
|
||||||
sm.maybeCommit()
|
sm.maybeCommit()
|
||||||
if g := sm.log.commit; g != tt.w {
|
if g := sm.log.committed; g != tt.w {
|
||||||
t.Errorf("#%d: commit = %d, want %d", i, g, tt.w)
|
t.Errorf("#%d: committed = %d, want %d", i, g, tt.w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user