Merge pull request #1049 from unihorn/120

raftLog: enhance check in compact
This commit is contained in:
Yicheng Qin
2014-09-12 11:35:41 -07:00
2 changed files with 24 additions and 10 deletions

View File

@ -152,8 +152,8 @@ func (l *raftLog) maybeCommit(maxIndex, term int64) bool {
// and not greater than the index of the last entry.
// the number of entries after compaction will be returned.
func (l *raftLog) compact(i int64) int64 {
if l.isOutOfBounds(i) {
panic(fmt.Sprintf("compact %d out of bounds [%d:%d]", i, l.offset, l.lastIndex()))
if l.isOutOfAppliedBounds(i) {
panic(fmt.Sprintf("compact %d out of bounds [%d:%d]", i, l.offset, l.applied))
}
l.ents = l.slice(i, l.lastIndex()+1)
l.unstable = max(i+1, l.unstable)
@ -208,6 +208,13 @@ func (l *raftLog) isOutOfBounds(i int64) bool {
return false
}
func (l *raftLog) isOutOfAppliedBounds(i int64) bool {
if i < l.offset || i > l.applied {
return true
}
return false
}
func min(a, b int64) int64 {
if a > b {
return b