mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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:
commit
66c30f28d6
@ -59,8 +59,12 @@ type progress struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pr *progress) update(n uint64) {
|
func (pr *progress) update(n uint64) {
|
||||||
pr.match = n
|
if pr.match < n {
|
||||||
pr.next = n + 1
|
pr.match = n
|
||||||
|
}
|
||||||
|
if pr.next < n+1 {
|
||||||
|
pr.next = n + 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pr *progress) optimisticUpdate(n uint64) {
|
func (pr *progress) optimisticUpdate(n uint64) {
|
||||||
|
@ -47,6 +47,34 @@ func (r *raft) readMessages() []pb.Message {
|
|||||||
return msgs
|
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) {
|
func TestProgressMaybeDecr(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
m uint64
|
m uint64
|
||||||
|
Loading…
x
Reference in New Issue
Block a user