From 8f3d109c1806a162c98d9cc15b1ce94cad6279a0 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 27 May 2014 22:47:13 -0700 Subject: [PATCH] raft: rename log.isOk to log.matchTerm --- raft/log.go | 4 ++-- raft/raft.go | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/raft/log.go b/raft/log.go index b02ba12b3..4411acfe9 100644 --- a/raft/log.go +++ b/raft/log.go @@ -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 } diff --git a/raft/raft.go b/raft/raft.go index 1875b42f0..030751323 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -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()})