raft: remove unused raftLog.at function

release-2.0
Yicheng Qin 2014-11-24 23:51:34 -08:00
parent 2c06a1d815
commit 1d01c8aa2d
2 changed files with 1 additions and 40 deletions

View File

@ -123,7 +123,7 @@ func (l *raftLog) append(after uint64, ents ...pb.Entry) uint64 {
func (l *raftLog) findConflict(from uint64, ents []pb.Entry) uint64 {
// TODO(xiangli): validate the index of ents
for i, ne := range ents {
if oe := l.at(from + uint64(i)); oe == nil || oe.Term != ne.Term {
if !l.matchTerm(from+uint64(i), ne.Term) {
return from + uint64(i)
}
}
@ -254,14 +254,6 @@ func (l *raftLog) restore(s pb.Snapshot) {
l.unstableEnts = nil
}
func (l *raftLog) at(i uint64) *pb.Entry {
ents := l.slice(i, i+1)
if len(ents) == 0 {
return nil
}
return &ents[0]
}
// slice returns a slice of log entries from lo through hi-1, inclusive.
func (l *raftLog) slice(lo uint64, hi uint64) []pb.Entry {
if lo >= hi {

View File

@ -549,37 +549,6 @@ func TestIsOutOfBounds(t *testing.T) {
}
}
func TestAt(t *testing.T) {
var i uint64
offset := uint64(100)
num := uint64(100)
storage := NewMemoryStorage()
storage.ApplySnapshot(pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: offset}})
l := newLog(storage)
for i = 1; i < num; i++ {
l.append(offset+i-1, pb.Entry{Index: i, Term: i})
}
tests := []struct {
index uint64
w *pb.Entry
}{
{offset - 1, nil},
{offset, nil},
{offset + num/2, &pb.Entry{Index: num / 2, Term: num / 2}},
{offset + num - 1, &pb.Entry{Index: num - 1, Term: num - 1}},
{offset + num, nil},
}
for i, tt := range tests {
g := l.at(tt.index)
if !reflect.DeepEqual(g, tt.w) {
t.Errorf("#%d: at = %v, want %v", i, g, tt.w)
}
}
}
func TestTerm(t *testing.T) {
var i uint64
offset := uint64(100)