raft: rename log.isOk to log.matchTerm

This commit is contained in:
Xiang Li 2014-05-27 22:47:13 -07:00 committed by Yicheng Qin
parent 4c609ec59c
commit 8f3d109c18
2 changed files with 3 additions and 7 deletions

View File

@ -20,7 +20,7 @@ func newLog() *log {
}
func (l *log) maybeAppend(index, logTerm int, ents ...Entry) bool {
if l.isOk(index, logTerm) {
if l.matchTerm(index, logTerm) {
l.append(index, ents...)
return true
}
@ -58,7 +58,7 @@ func (l *log) isUpToDate(i, term int) bool {
return term > e.Term || (term == e.Term && i >= l.len())
}
func (l *log) isOk(i, term int) bool {
func (l *log) matchTerm(i, term int) bool {
if i > l.len() {
return false
}

View File

@ -132,10 +132,6 @@ func (sm *stateMachine) poll(addr int, v bool) (granted int) {
return granted
}
func (sm *stateMachine) isLogOk(i, term int) bool {
return sm.log.isOk(i, term)
}
// send persists state to stable storage and then sends to its mailbox
func (sm *stateMachine) send(m Message) {
m.From = sm.addr
@ -276,7 +272,7 @@ func (sm *stateMachine) Step(m Message) {
}
handleAppendEntries := func() {
if sm.isLogOk(m.Index, m.LogTerm) {
if sm.log.matchTerm(m.Index, m.LogTerm) {
sm.log.commit = m.Commit
sm.log.append(m.Index, m.Entries...)
sm.send(Message{To: m.From, Type: msgAppResp, Index: sm.li()})