Просмотр исходного кода

raft: minor updates and clean up in log.go

- remove redundant test case in log_test.go
- fix test case comment ('equal or larger')
- lastnewi after matching index and term
Gyu-Ho Lee 9 лет назад
Родитель
Сommit
881a120453
2 измененных файлов с 2 добавлено и 3 удалено
  1. 1 1
      raft/log.go
  2. 1 2
      raft/log_test.go

+ 1 - 1
raft/log.go

@@ -74,8 +74,8 @@ func (l *raftLog) String() string {
 // maybeAppend returns (0, false) if the entries cannot be appended. Otherwise,
 // it returns (last index of new entries, true).
 func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry) (lastnewi uint64, ok bool) {
-	lastnewi = index + uint64(len(ents))
 	if l.matchTerm(index, logTerm) {
+		lastnewi = index + uint64(len(ents))
 		ci := l.findConflict(ents)
 		switch {
 		case ci == 0:

+ 1 - 2
raft/log_test.go

@@ -29,7 +29,6 @@ func TestFindConflict(t *testing.T) {
 	}{
 		// no conflict, empty ent
 		{[]pb.Entry{}, 0},
-		{[]pb.Entry{}, 0},
 		// no conflict
 		{[]pb.Entry{{Index: 1, Term: 1}, {Index: 2, Term: 2}, {Index: 3, Term: 3}}, 0},
 		{[]pb.Entry{{Index: 2, Term: 2}, {Index: 3, Term: 3}}, 0},
@@ -73,7 +72,7 @@ func TestIsUpToDate(t *testing.T) {
 		{raftLog.lastIndex() - 1, 2, false},
 		{raftLog.lastIndex(), 2, false},
 		{raftLog.lastIndex() + 1, 2, false},
-		// equal term, lager lastIndex wins
+		// equal term, equal or lager lastIndex wins
 		{raftLog.lastIndex() - 1, 3, false},
 		{raftLog.lastIndex(), 3, true},
 		{raftLog.lastIndex() + 1, 3, true},