Merge pull request #1523 from jonboulle/raft_stuff

raft: minor cleanup in comments
This commit is contained in:
Jonathan Boulle 2014-10-30 10:01:59 -07:00
commit 9359a57211
2 changed files with 12 additions and 11 deletions

View File

@ -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.
func (r *raft) send(m pb.Message) {
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
// should be treated as local message.
if m.Type != pb.MsgProp {
@ -200,7 +200,7 @@ func (r *raft) sendAppend(to uint64) {
r.send(m)
}
// sendHeartbeat sends an empty msgApp
// sendHeartbeat sends an empty MsgApp
func (r *raft) sendHeartbeat(to uint64) {
m := pb.Message{
To: to,
@ -209,7 +209,8 @@ func (r *raft) sendHeartbeat(to uint64) {
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() {
for i := range r.prs {
if i == r.id {
@ -268,7 +269,7 @@ func (r *raft) appendEntry(e pb.Entry) {
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() {
if !r.promotable() {
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() {
r.elapsed++
if r.elapsed > r.heartbeatTimeout {
@ -408,7 +409,7 @@ func stepLeader(r *raft, m pb.Message) {
r.bcastHeartbeat()
case pb.MsgProp:
if len(m.Entries) != 1 {
panic("unexpected length(entries) of a msgProp")
panic("unexpected length(entries) of a MsgProp")
}
e := m.Entries[0]
if e.Type == pb.EntryConfChange {

View File

@ -335,7 +335,7 @@ func TestCandidateConcede(t *testing.T) {
tt.recover()
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}}})
a := tt.peers[1].(*raft)
@ -893,7 +893,7 @@ func TestLeaderAppResp(t *testing.T) {
}
// 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) {
offset := uint64(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})
msgs := sm.readMessages()
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}
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) {
tests := []struct {
state StateType
wMsg int
}{
{StateLeader, 2},
// candidate and follower should ignore msgBeat
// candidate and follower should ignore MsgBeat
{StateCandidate, 0},
{StateFollower, 0},
}