Browse Source

raft: remove unused raftLog.at function

Yicheng Qin 11 years ago
parent
commit
1d01c8aa2d
2 changed files with 1 additions and 40 deletions
  1. 1 9
      raft/log.go
  2. 0 31
      raft/log_test.go

+ 1 - 9
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 {
 func (l *raftLog) findConflict(from uint64, ents []pb.Entry) uint64 {
 	// TODO(xiangli): validate the index of ents
 	// TODO(xiangli): validate the index of ents
 	for i, ne := range 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)
 			return from + uint64(i)
 		}
 		}
 	}
 	}
@@ -254,14 +254,6 @@ func (l *raftLog) restore(s pb.Snapshot) {
 	l.unstableEnts = nil
 	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.
 // slice returns a slice of log entries from lo through hi-1, inclusive.
 func (l *raftLog) slice(lo uint64, hi uint64) []pb.Entry {
 func (l *raftLog) slice(lo uint64, hi uint64) []pb.Entry {
 	if lo >= hi {
 	if lo >= hi {

+ 0 - 31
raft/log_test.go

@@ -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) {
 func TestTerm(t *testing.T) {
 	var i uint64
 	var i uint64
 	offset := uint64(100)
 	offset := uint64(100)