|
@@ -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 {
|