mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: Make MsgAppRes ack only the last index in MsgApp
As explained in #1366, the leader will fail to transmit the missed logs if the leader receives a hearbeat response from a follower that is not yet matched in the leader. In other words, there are append responses that do not explicitly reject an append but implied a gap. This commit is based on @xiangli-cmu's idea. We should only acknowledge upto the index of logs in the append message. This way responses to heartbeats would never interfer with the log synchronization because their log index is always 0. Fixes #1366
This commit is contained in:
parent
051ad7585f
commit
233617bea2
@ -380,7 +380,11 @@ func (r *raft) Step(m pb.Message) error {
|
||||
|
||||
func (r *raft) handleAppendEntries(m pb.Message) {
|
||||
if r.raftLog.maybeAppend(m.Index, m.LogTerm, m.Commit, m.Entries...) {
|
||||
r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.lastIndex()})
|
||||
mlastIndex := m.Index
|
||||
if len(m.Entries) != 0 {
|
||||
mlastIndex = m.Entries[len(m.Entries)-1].Index
|
||||
}
|
||||
r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: mlastIndex})
|
||||
} else {
|
||||
r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: m.Index, Reject: true})
|
||||
}
|
||||
@ -428,6 +432,9 @@ func stepLeader(r *raft, m pb.Message) {
|
||||
r.appendEntry(e)
|
||||
r.bcastAppend()
|
||||
case pb.MsgAppResp:
|
||||
if m.Index == 0 {
|
||||
return
|
||||
}
|
||||
if m.Reject {
|
||||
if r.prs[m.From].maybeDecrTo(m.Index) {
|
||||
r.sendAppend(m.From)
|
||||
|
Loading…
x
Reference in New Issue
Block a user