Browse Source

raft: minor cleanup in comments

Jonathan Boulle 11 years ago
parent
commit
b99633207c
2 changed files with 12 additions and 11 deletions
  1. 7 6
      raft/raft.go
  2. 5 5
      raft/raft_test.go

+ 7 - 6
raft/raft.go

@@ -173,7 +173,7 @@ func (r *raft) poll(id uint64, v bool) (granted int) {
 // send persists state to stable storage and then sends to its mailbox.
 // send persists state to stable storage and then sends to its mailbox.
 func (r *raft) send(m pb.Message) {
 func (r *raft) send(m pb.Message) {
 	m.From = r.id
 	m.From = r.id
-	// do not attach term to msgProp
+	// do not attach term to MsgProp
 	// proposals are a way to forward to the leader and
 	// proposals are a way to forward to the leader and
 	// should be treated as local message.
 	// should be treated as local message.
 	if m.Type != pb.MsgProp {
 	if m.Type != pb.MsgProp {
@@ -200,7 +200,7 @@ func (r *raft) sendAppend(to uint64) {
 	r.send(m)
 	r.send(m)
 }
 }
 
 
-// sendHeartbeat sends an empty msgApp
+// sendHeartbeat sends an empty MsgApp
 func (r *raft) sendHeartbeat(to uint64) {
 func (r *raft) sendHeartbeat(to uint64) {
 	m := pb.Message{
 	m := pb.Message{
 		To:   to,
 		To:   to,
@@ -209,7 +209,8 @@ func (r *raft) sendHeartbeat(to uint64) {
 	r.send(m)
 	r.send(m)
 }
 }
 
 
-// bcastAppend sends RRPC, with entries to all peers that are not up-to-date according to r.mis.
+// bcastAppend sends RRPC, with entries to all peers that are not up-to-date
+// according to the progress recorded in r.prs.
 func (r *raft) bcastAppend() {
 func (r *raft) bcastAppend() {
 	for i := range r.prs {
 	for i := range r.prs {
 		if i == r.id {
 		if i == r.id {
@@ -268,7 +269,7 @@ func (r *raft) appendEntry(e pb.Entry) {
 	r.maybeCommit()
 	r.maybeCommit()
 }
 }
 
 
-// tickElection is ran by followers and candidates after r.electionTimeout.
+// tickElection is run by followers and candidates after r.electionTimeout.
 func (r *raft) tickElection() {
 func (r *raft) tickElection() {
 	if !r.promotable() {
 	if !r.promotable() {
 		r.elapsed = 0
 		r.elapsed = 0
@@ -281,7 +282,7 @@ func (r *raft) tickElection() {
 	}
 	}
 }
 }
 
 
-// tickHeartbeat is ran by leaders to send a msgBeat after r.heartbeatTimeout.
+// tickHeartbeat is run by leaders to send a MsgBeat after r.heartbeatTimeout.
 func (r *raft) tickHeartbeat() {
 func (r *raft) tickHeartbeat() {
 	r.elapsed++
 	r.elapsed++
 	if r.elapsed > r.heartbeatTimeout {
 	if r.elapsed > r.heartbeatTimeout {
@@ -408,7 +409,7 @@ func stepLeader(r *raft, m pb.Message) {
 		r.bcastHeartbeat()
 		r.bcastHeartbeat()
 	case pb.MsgProp:
 	case pb.MsgProp:
 		if len(m.Entries) != 1 {
 		if len(m.Entries) != 1 {
-			panic("unexpected length(entries) of a msgProp")
+			panic("unexpected length(entries) of a MsgProp")
 		}
 		}
 		e := m.Entries[0]
 		e := m.Entries[0]
 		if e.Type == pb.EntryConfChange {
 		if e.Type == pb.EntryConfChange {

+ 5 - 5
raft/raft_test.go

@@ -335,7 +335,7 @@ func TestCandidateConcede(t *testing.T) {
 	tt.recover()
 	tt.recover()
 
 
 	data := []byte("force follower")
 	data := []byte("force follower")
-	// send a proposal to 2 to flush out a msgApp to 0
+	// send a proposal to 2 to flush out a MsgApp to 0
 	tt.send(pb.Message{From: 3, To: 3, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
 	tt.send(pb.Message{From: 3, To: 3, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
 
 
 	a := tt.peers[1].(*raft)
 	a := tt.peers[1].(*raft)
@@ -893,7 +893,7 @@ func TestLeaderAppResp(t *testing.T) {
 }
 }
 
 
 // When the leader receives a heartbeat tick, it should
 // When the leader receives a heartbeat tick, it should
-// send a msgApp with m.Index = 0, m.LogTerm=0 and empty entries.
+// send a MsgApp with m.Index = 0, m.LogTerm=0 and empty entries.
 func TestBcastBeat(t *testing.T) {
 func TestBcastBeat(t *testing.T) {
 	offset := uint64(1000)
 	offset := uint64(1000)
 	// make a state machine with log.offset = 1000
 	// make a state machine with log.offset = 1000
@@ -915,7 +915,7 @@ func TestBcastBeat(t *testing.T) {
 	sm.Step(pb.Message{Type: pb.MsgBeat})
 	sm.Step(pb.Message{Type: pb.MsgBeat})
 	msgs := sm.readMessages()
 	msgs := sm.readMessages()
 	if len(msgs) != 2 {
 	if len(msgs) != 2 {
-		t.Fatalf("len(msgs) = %v, want 1", len(msgs))
+		t.Fatalf("len(msgs) = %v, want 2", len(msgs))
 	}
 	}
 	tomap := map[uint64]bool{2: true, 3: true}
 	tomap := map[uint64]bool{2: true, 3: true}
 	for i, m := range msgs {
 	for i, m := range msgs {
@@ -939,14 +939,14 @@ func TestBcastBeat(t *testing.T) {
 	}
 	}
 }
 }
 
 
-// tests the output of the statemachine when receiving msgBeat
+// tests the output of the statemachine when receiving MsgBeat
 func TestRecvMsgBeat(t *testing.T) {
 func TestRecvMsgBeat(t *testing.T) {
 	tests := []struct {
 	tests := []struct {
 		state StateType
 		state StateType
 		wMsg  int
 		wMsg  int
 	}{
 	}{
 		{StateLeader, 2},
 		{StateLeader, 2},
-		// candidate and follower should ignore msgBeat
+		// candidate and follower should ignore MsgBeat
 		{StateCandidate, 0},
 		{StateCandidate, 0},
 		{StateFollower, 0},
 		{StateFollower, 0},
 	}
 	}