mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: remove unused raftLog.at function
This commit is contained in:
parent
2c06a1d815
commit
1d01c8aa2d
10
raft/log.go
10
raft/log.go
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user