Merge pull request #1761 from xiang90/fix_raft

raft: should not decrease match and next when handling out of order msgAppResp
This commit is contained in:
Xiang Li 2014-11-20 18:12:15 -08:00
commit 66c30f28d6
2 changed files with 34 additions and 2 deletions

View File

@ -59,8 +59,12 @@ type progress struct {
}
func (pr *progress) update(n uint64) {
pr.match = n
pr.next = n + 1
if pr.match < n {
pr.match = n
}
if pr.next < n+1 {
pr.next = n + 1
}
}
func (pr *progress) optimisticUpdate(n uint64) {

View File

@ -47,6 +47,34 @@ func (r *raft) readMessages() []pb.Message {
return msgs
}
func TestProgressUpdate(t *testing.T) {
prevM, prevN := uint64(3), uint64(5)
tests := []struct {
update uint64
wm uint64
wn uint64
}{
{prevM - 1, prevM, prevN}, // do not decrease match, next
{prevM, prevM, prevN}, // do not decrease next
{prevM + 1, prevM + 1, prevN}, // increase match, do not decrease next
{prevM + 2, prevM + 2, prevN + 1}, // increase match, next
}
for i, tt := range tests {
p := &progress{
match: prevM,
next: prevN,
}
p.update(tt.update)
if p.match != tt.wm {
t.Errorf("#%d: match=%d, want %d", i, p.match, tt.wm)
}
if p.next != tt.wn {
t.Errorf("#%d: next=%d, want %d", i, p.next, tt.wn)
}
}
}
func TestProgressMaybeDecr(t *testing.T) {
tests := []struct {
m uint64