raft: extract 'tracker' package

Mechanically extract `progressTracker`, `Progress`, and `inflights`
to their own package named `tracker`. Add lots of comments in the
progress, and take the opportunity to rename and clarify various
fields.
This commit is contained in:
Tobias Schottdorf
2019-06-08 19:41:24 +02:00
parent 6953ccc135
commit f9c2d00fb3
17 changed files with 1065 additions and 919 deletions

View File

@@ -29,11 +29,11 @@ func TestMsgAppFlowControlFull(t *testing.T) {
r.becomeCandidate()
r.becomeLeader()
pr2 := r.prs.prs[2]
pr2 := r.prs.Progress[2]
// force the progress to be in replicate state
pr2.becomeReplicate()
pr2.BecomeReplicate()
// fill in the inflights window
for i := 0; i < r.prs.maxInflight; i++ {
for i := 0; i < r.prs.MaxInflight; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}})
ms := r.readMessages()
if len(ms) != 1 {
@@ -42,8 +42,8 @@ func TestMsgAppFlowControlFull(t *testing.T) {
}
// ensure 1
if !pr2.ins.full() {
t.Fatalf("inflights.full = %t, want %t", pr2.ins.full(), true)
if !pr2.Inflights.Full() {
t.Fatalf("inflights.full = %t, want %t", pr2.Inflights.Full(), true)
}
// ensure 2
@@ -65,18 +65,18 @@ func TestMsgAppFlowControlMoveForward(t *testing.T) {
r.becomeCandidate()
r.becomeLeader()
pr2 := r.prs.prs[2]
pr2 := r.prs.Progress[2]
// force the progress to be in replicate state
pr2.becomeReplicate()
pr2.BecomeReplicate()
// fill in the inflights window
for i := 0; i < r.prs.maxInflight; i++ {
for i := 0; i < r.prs.MaxInflight; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}})
r.readMessages()
}
// 1 is noop, 2 is the first proposal we just sent.
// so we start with 2.
for tt := 2; tt < r.prs.maxInflight; tt++ {
for tt := 2; tt < r.prs.MaxInflight; tt++ {
// move forward the window
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgAppResp, Index: uint64(tt)})
r.readMessages()
@@ -89,15 +89,15 @@ func TestMsgAppFlowControlMoveForward(t *testing.T) {
}
// ensure 1
if !pr2.ins.full() {
t.Fatalf("inflights.full = %t, want %t", pr2.ins.full(), true)
if !pr2.Inflights.Full() {
t.Fatalf("inflights.full = %t, want %t", pr2.Inflights.Full(), true)
}
// ensure 2
for i := 0; i < tt; i++ {
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgAppResp, Index: uint64(i)})
if !pr2.ins.full() {
t.Fatalf("#%d: inflights.full = %t, want %t", tt, pr2.ins.full(), true)
if !pr2.Inflights.Full() {
t.Fatalf("#%d: inflights.full = %t, want %t", tt, pr2.Inflights.Full(), true)
}
}
}
@@ -110,26 +110,26 @@ func TestMsgAppFlowControlRecvHeartbeat(t *testing.T) {
r.becomeCandidate()
r.becomeLeader()
pr2 := r.prs.prs[2]
pr2 := r.prs.Progress[2]
// force the progress to be in replicate state
pr2.becomeReplicate()
pr2.BecomeReplicate()
// fill in the inflights window
for i := 0; i < r.prs.maxInflight; i++ {
for i := 0; i < r.prs.MaxInflight; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}})
r.readMessages()
}
for tt := 1; tt < 5; tt++ {
if !pr2.ins.full() {
t.Fatalf("#%d: inflights.full = %t, want %t", tt, pr2.ins.full(), true)
if !pr2.Inflights.Full() {
t.Fatalf("#%d: inflights.full = %t, want %t", tt, pr2.Inflights.Full(), true)
}
// recv tt msgHeartbeatResp and expect one free slot
for i := 0; i < tt; i++ {
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgHeartbeatResp})
r.readMessages()
if pr2.ins.full() {
t.Fatalf("#%d.%d: inflights.full = %t, want %t", tt, i, pr2.ins.full(), false)
if pr2.Inflights.Full() {
t.Fatalf("#%d.%d: inflights.full = %t, want %t", tt, i, pr2.Inflights.Full(), false)
}
}