raft: refine raftLog.term

release-2.0
Yicheng Qin 2014-11-24 23:27:57 -08:00
parent 7fcaca6d18
commit 0d200baf72
1 changed files with 9 additions and 10 deletions

View File

@ -195,23 +195,22 @@ func (l *raftLog) lastTerm() uint64 {
}
func (l *raftLog) term(i uint64) uint64 {
if i >= l.unstable+uint64(len(l.unstableEnts)) {
switch {
case i > l.lastIndex():
return 0
}
if i < l.unstable {
case i < l.unstable:
t, err := l.storage.Term(i)
if err == nil {
switch err {
case nil:
return t
}
if err == ErrCompacted {
case ErrCompacted:
return 0
} else {
default:
panic(err) // TODO(bdarnell)
}
default:
return l.unstableEnts[i-l.unstable].Term
}
return l.unstableEnts[i-l.unstable].Term
}
func (l *raftLog) entries(i uint64) []pb.Entry {