Browse Source

Merge pull request #11073 from Wine93/typo

raft: fixed some typos
Xiang Li 6 years ago
parent
commit
7e9a26eb6d
3 changed files with 9 additions and 9 deletions
  1. 5 5
      raft/log_test.go
  2. 2 2
      raft/raft.go
  3. 2 2
      raft/storage_test.go

+ 5 - 5
raft/log_test.go

@@ -265,7 +265,7 @@ func TestLogMaybeAppend(t *testing.T) {
 					t.Fatalf("unexpected error %v", err)
 					t.Fatalf("unexpected error %v", err)
 				}
 				}
 				if !reflect.DeepEqual(tt.ents, gents) {
 				if !reflect.DeepEqual(tt.ents, gents) {
-					t.Errorf("%d: appended entries = %v, want %v", i, gents, tt.ents)
+					t.Errorf("#%d: appended entries = %v, want %v", i, gents, tt.ents)
 				}
 				}
 			}
 			}
 		}()
 		}()
@@ -426,7 +426,7 @@ func TestUnstableEnts(t *testing.T) {
 
 
 		ents := raftLog.unstableEntries()
 		ents := raftLog.unstableEntries()
 		if l := len(ents); l > 0 {
 		if l := len(ents); l > 0 {
-			raftLog.stableTo(ents[l-1].Index, ents[l-i].Term)
+			raftLog.stableTo(ents[l-1].Index, ents[l-1].Term)
 		}
 		}
 		if !reflect.DeepEqual(ents, tt.wents) {
 		if !reflect.DeepEqual(ents, tt.wents) {
 			t.Errorf("#%d: unstableEnts = %+v, want %+v", i, ents, tt.wents)
 			t.Errorf("#%d: unstableEnts = %+v, want %+v", i, ents, tt.wents)
@@ -671,13 +671,13 @@ func TestIsOutOfBounds(t *testing.T) {
 			}()
 			}()
 			err := l.mustCheckOutOfBounds(tt.lo, tt.hi)
 			err := l.mustCheckOutOfBounds(tt.lo, tt.hi)
 			if tt.wpanic {
 			if tt.wpanic {
-				t.Errorf("%d: panic = %v, want %v", i, false, true)
+				t.Errorf("#%d: panic = %v, want %v", i, false, true)
 			}
 			}
 			if tt.wErrCompacted && err != ErrCompacted {
 			if tt.wErrCompacted && err != ErrCompacted {
-				t.Errorf("%d: err = %v, want %v", i, err, ErrCompacted)
+				t.Errorf("#%d: err = %v, want %v", i, err, ErrCompacted)
 			}
 			}
 			if !tt.wErrCompacted && err != nil {
 			if !tt.wErrCompacted && err != nil {
-				t.Errorf("%d: unexpected err %v", i, err)
+				t.Errorf("#%d: unexpected err %v", i, err)
 			}
 			}
 		}()
 		}()
 	}
 	}

+ 2 - 2
raft/raft.go

@@ -367,7 +367,7 @@ func newRaft(c *Config) *raft {
 	}
 	}
 	assertConfStatesEquivalent(r.logger, cs, r.switchToConfig(cfg, prs))
 	assertConfStatesEquivalent(r.logger, cs, r.switchToConfig(cfg, prs))
 
 
-	if !isHardStateEqual(hs, emptyState) {
+	if !IsEmptyHardState(hs) {
 		r.loadState(hs)
 		r.loadState(hs)
 	}
 	}
 	if c.Applied > 0 {
 	if c.Applied > 0 {
@@ -1099,7 +1099,7 @@ func stepLeader(r *raft, m pb.Message) error {
 			case ReadOnlyLeaseBased:
 			case ReadOnlyLeaseBased:
 				ri := r.raftLog.committed
 				ri := r.raftLog.committed
 				if m.From == None || m.From == r.id { // from local member
 				if m.From == None || m.From == r.id { // from local member
-					r.readStates = append(r.readStates, ReadState{Index: r.raftLog.committed, RequestCtx: m.Entries[0].Data})
+					r.readStates = append(r.readStates, ReadState{Index: ri, RequestCtx: m.Entries[0].Data})
 				} else {
 				} else {
 					r.send(pb.Message{To: m.From, Type: pb.MsgReadIndexResp, Index: ri, Entries: m.Entries})
 					r.send(pb.Message{To: m.From, Type: pb.MsgReadIndexResp, Index: ri, Entries: m.Entries})
 				}
 				}

+ 2 - 2
raft/storage_test.go

@@ -106,7 +106,7 @@ func TestStorageLastIndex(t *testing.T) {
 		t.Errorf("err = %v, want nil", err)
 		t.Errorf("err = %v, want nil", err)
 	}
 	}
 	if last != 5 {
 	if last != 5 {
-		t.Errorf("term = %d, want %d", last, 5)
+		t.Errorf("last = %d, want %d", last, 5)
 	}
 	}
 
 
 	s.Append([]pb.Entry{{Index: 6, Term: 5}})
 	s.Append([]pb.Entry{{Index: 6, Term: 5}})
@@ -115,7 +115,7 @@ func TestStorageLastIndex(t *testing.T) {
 		t.Errorf("err = %v, want nil", err)
 		t.Errorf("err = %v, want nil", err)
 	}
 	}
 	if last != 6 {
 	if last != 6 {
-		t.Errorf("last = %d, want %d", last, 5)
+		t.Errorf("last = %d, want %d", last, 6)
 	}
 	}
 }
 }