raft: clean up

release-2.0
Xiang Li 2014-11-25 16:21:50 -08:00
parent 9bd1786fe4
commit 8de98d4903
4 changed files with 25 additions and 27 deletions

View File

@ -83,7 +83,7 @@ func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry
switch { switch {
case ci == 0: case ci == 0:
case ci <= l.committed: case ci <= l.committed:
log.Panicf("conflict(%d) with committed entry [committed(%d)]", ci, l.committed) log.Panicf("entry %d conflict with committed entry [committed(%d)]", ci, l.committed)
default: default:
l.append(ci-1, ents[ci-from:]...) l.append(ci-1, ents[ci-from:]...)
} }
@ -95,7 +95,7 @@ func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry
func (l *raftLog) append(after uint64, ents ...pb.Entry) uint64 { func (l *raftLog) append(after uint64, ents ...pb.Entry) uint64 {
if after < l.committed { if after < l.committed {
log.Panicf("after(%d) out of range [committed(%d)]", after, l.committed) log.Panicf("after(%d) is out of range [committed(%d)]", after, l.committed)
} }
if after < l.unstable { if after < l.unstable {
// The log is being truncated to before our current unstable // The log is being truncated to before our current unstable
@ -289,17 +289,3 @@ func (l *raftLog) isOutOfBounds(i uint64) bool {
} }
return false return false
} }
func min(a, b uint64) uint64 {
if a > b {
return b
}
return a
}
func max(a, b uint64) uint64 {
if a > b {
return a
}
return b
}

View File

@ -100,13 +100,6 @@ func (pr *progress) String() string {
return fmt.Sprintf("n=%d m=%d", pr.next, pr.match) return fmt.Sprintf("n=%d m=%d", pr.next, pr.match)
} }
// uint64Slice implements sort interface
type uint64Slice []uint64
func (p uint64Slice) Len() int { return len(p) }
func (p uint64Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
type raft struct { type raft struct {
pb.HardState pb.HardState
@ -452,9 +445,7 @@ func (r *raft) handleSnapshot(m pb.Message) {
} }
} }
func (r *raft) resetPendingConf() { func (r *raft) resetPendingConf() { r.pendingConf = false }
r.pendingConf = false
}
func (r *raft) addNode(id uint64) { func (r *raft) addNode(id uint64) {
r.setProgress(id, 0, r.raftLog.lastIndex()+1) r.setProgress(id, 0, r.raftLog.lastIndex()+1)

View File

@ -158,7 +158,7 @@ func (ms *MemoryStorage) Compact(i uint64, cs *pb.ConfState, data []byte) error
return ErrCompacted return ErrCompacted
} }
if i > offset+uint64(len(ms.ents))-1 { if i > offset+uint64(len(ms.ents))-1 {
log.Panicf("compact %d out of bound lastindex(%d)", i, offset+uint64(len(ms.ents))-1) log.Panicf("compact %d is out of bound lastindex(%d)", i, offset+uint64(len(ms.ents))-1)
} }
i -= offset i -= offset
ents := make([]pb.Entry, 1, 1+uint64(len(ms.ents))-i) ents := make([]pb.Entry, 1, 1+uint64(len(ms.ents))-i)

View File

@ -23,6 +23,27 @@ import (
pb "github.com/coreos/etcd/raft/raftpb" pb "github.com/coreos/etcd/raft/raftpb"
) )
// uint64Slice implements sort interface
type uint64Slice []uint64
func (p uint64Slice) Len() int { return len(p) }
func (p uint64Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func min(a, b uint64) uint64 {
if a > b {
return b
}
return a
}
func max(a, b uint64) uint64 {
if a > b {
return a
}
return b
}
// DescribeMessage returns a concise human-readable description of a // DescribeMessage returns a concise human-readable description of a
// Message for debugging. // Message for debugging.
func DescribeMessage(m pb.Message) string { func DescribeMessage(m pb.Message) string {