Skip to content

Commit 017bdda

Browse files
committed
tracker: rename the paused probes flow field
Signed-off-by: Pavel Kalinnikov <[email protected]>
1 parent c38c1b7 commit 017bdda

File tree

5 files changed

+56
-51
lines changed

5 files changed

+56
-51
lines changed

raft.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ func stepLeader(r *raft, m pb.Message) error {
15271527
}
15281528
case pb.MsgHeartbeatResp:
15291529
pr.RecentActive = true
1530-
pr.MsgAppFlowPaused = false
1530+
pr.PauseMsgAppProbes(false)
15311531
r.maybeSendAppend(m.From, pr)
15321532

15331533
if r.readOnly.option != ReadOnlySafe || len(m.Context) == 0 {
@@ -1561,7 +1561,7 @@ func stepLeader(r *raft, m pb.Message) error {
15611561
// If snapshot finish, wait for the MsgAppResp from the remote node before sending
15621562
// out the next MsgApp.
15631563
// If snapshot failure, wait for a heartbeat interval before next try
1564-
pr.MsgAppFlowPaused = true
1564+
pr.PauseMsgAppProbes(true)
15651565
case pb.MsgUnreachable:
15661566
// During optimistic replication, if the remote becomes unreachable,
15671567
// there is huge probability that a MsgApp is lost.
@@ -1598,7 +1598,7 @@ func stepLeader(r *raft, m pb.Message) error {
15981598
r.sendTimeoutNow(leadTransferee)
15991599
r.logger.Infof("%x sends MsgTimeoutNow to %x immediately as %x already has up-to-date log", r.id, leadTransferee, leadTransferee)
16001600
} else {
1601-
pr.MsgAppFlowPaused = false
1601+
pr.PauseMsgAppProbes(false)
16021602
r.maybeSendAppend(leadTransferee, pr)
16031603
}
16041604
}

raft_snap_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func TestSnapshotFailure(t *testing.T) {
8383
if sm.trk.Progress[2].Next != 1 {
8484
t.Fatalf("Next = %d, want 1", sm.trk.Progress[2].Next)
8585
}
86-
if !sm.trk.Progress[2].MsgAppFlowPaused {
87-
t.Errorf("MsgAppFlowPaused = %v, want true", sm.trk.Progress[2].MsgAppFlowPaused)
86+
if !sm.trk.Progress[2].MsgAppProbesPaused {
87+
t.Errorf("msgAppProbesPaused = %v, want true", sm.trk.Progress[2].MsgAppProbesPaused)
8888
}
8989
}
9090

@@ -106,8 +106,8 @@ func TestSnapshotSucceed(t *testing.T) {
106106
if sm.trk.Progress[2].Next != 12 {
107107
t.Fatalf("Next = %d, want 12", sm.trk.Progress[2].Next)
108108
}
109-
if !sm.trk.Progress[2].MsgAppFlowPaused {
110-
t.Errorf("MsgAppFlowPaused = %v, want true", sm.trk.Progress[2].MsgAppFlowPaused)
109+
if !sm.trk.Progress[2].MsgAppProbesPaused {
110+
t.Errorf("MsgAppProbesPaused = %v, want true", sm.trk.Progress[2].MsgAppProbesPaused)
111111
}
112112
}
113113

raft_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,21 @@ func TestProgressResumeByHeartbeatResp(t *testing.T) {
128128
r.becomeCandidate()
129129
r.becomeLeader()
130130

131-
r.trk.Progress[2].MsgAppFlowPaused = true
131+
r.trk.Progress[2].PauseMsgAppProbes(true)
132132

133133
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgBeat})
134-
if !r.trk.Progress[2].MsgAppFlowPaused {
135-
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppFlowPaused)
134+
if !r.trk.Progress[2].MsgAppProbesPaused {
135+
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppProbesPaused)
136136
}
137137

138138
r.trk.Progress[2].BecomeReplicate()
139-
if r.trk.Progress[2].MsgAppFlowPaused {
140-
t.Errorf("paused = %v, want false", r.trk.Progress[2].MsgAppFlowPaused)
139+
if r.trk.Progress[2].MsgAppProbesPaused {
140+
t.Errorf("paused = %v, want false", r.trk.Progress[2].MsgAppProbesPaused)
141141
}
142-
r.trk.Progress[2].MsgAppFlowPaused = true
142+
r.trk.Progress[2].PauseMsgAppProbes(true)
143143
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgHeartbeatResp})
144-
if !r.trk.Progress[2].MsgAppFlowPaused {
145-
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppFlowPaused)
144+
if !r.trk.Progress[2].MsgAppProbesPaused {
145+
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppProbesPaused)
146146
}
147147
}
148148

@@ -2784,8 +2784,8 @@ func TestSendAppendForProgressProbe(t *testing.T) {
27842784
}
27852785
}
27862786

2787-
if !r.trk.Progress[2].MsgAppFlowPaused {
2788-
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppFlowPaused)
2787+
if !r.trk.Progress[2].MsgAppProbesPaused {
2788+
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppProbesPaused)
27892789
}
27902790
for j := 0; j < 10; j++ {
27912791
mustAppendEntry(r, pb.Entry{Data: []byte("somedata")})
@@ -2799,8 +2799,8 @@ func TestSendAppendForProgressProbe(t *testing.T) {
27992799
for j := 0; j < r.heartbeatTimeout; j++ {
28002800
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgBeat})
28012801
}
2802-
if !r.trk.Progress[2].MsgAppFlowPaused {
2803-
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppFlowPaused)
2802+
if !r.trk.Progress[2].MsgAppProbesPaused {
2803+
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppProbesPaused)
28042804
}
28052805

28062806
// consume the heartbeat
@@ -2822,8 +2822,8 @@ func TestSendAppendForProgressProbe(t *testing.T) {
28222822
if msg[0].Index != 0 {
28232823
t.Errorf("index = %d, want %d", msg[0].Index, 0)
28242824
}
2825-
if !r.trk.Progress[2].MsgAppFlowPaused {
2826-
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppFlowPaused)
2825+
if !r.trk.Progress[2].MsgAppProbesPaused {
2826+
t.Errorf("paused = %v, want true", r.trk.Progress[2].MsgAppProbesPaused)
28272827
}
28282828
}
28292829

tracker/progress.go

+18-13
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ type Progress struct {
8787
// This is always true on the leader.
8888
RecentActive bool
8989

90-
// MsgAppFlowPaused is used when the MsgApp flow to a node is throttled. This
91-
// happens in StateProbe, or StateReplicate with saturated Inflights. In both
92-
// cases, we need to continue sending MsgApp once in a while to guarantee
93-
// progress, but we only do so when MsgAppFlowPaused is false (it is reset on
94-
// receiving a heartbeat response), to not overflow the receiver. See
95-
// IsPaused().
96-
MsgAppFlowPaused bool
90+
// MsgAppProbesPaused set to true prevents sending "probe" MsgApp messages to
91+
// this follower. Used in StateProbe, or StateReplicate when all entries are
92+
// in-flight or the in-flight volume exceeds limits. See ShouldSendMsgApp().
93+
//
94+
// TODO(pav-kv): unexport this field. It is used by a few tests, but should be
95+
// replaced by PauseMsgAppProbes() and ShouldSendMsgApp().
96+
MsgAppProbesPaused bool
9797

9898
// Inflights is a sliding window for the inflight messages.
9999
// Each inflight message contains one or more log entries.
@@ -113,7 +113,7 @@ type Progress struct {
113113
IsLearner bool
114114
}
115115

116-
// ResetState moves the Progress into the specified State, resetting MsgAppFlowPaused,
116+
// ResetState moves the Progress into the specified State, resetting MsgAppProbesPaused,
117117
// PendingSnapshot, and Inflights.
118118
func (pr *Progress) ResetState(state StateType) {
119119
pr.PauseMsgAppProbes(false)
@@ -169,7 +169,7 @@ func (pr *Progress) SentEntries(entries int, bytes uint64) {
169169
// PauseMsgAppProbes pauses or unpauses empty MsgApp messages flow, depending on
170170
// the passed-in bool.
171171
func (pr *Progress) PauseMsgAppProbes(pause bool) {
172-
pr.MsgAppFlowPaused = pause
172+
pr.MsgAppProbesPaused = pause
173173
}
174174

175175
// CanSendEntries returns true if the flow control state allows sending at least
@@ -251,12 +251,17 @@ func (pr *Progress) MaybeDecrTo(rejected, matchHint uint64) bool {
251251
// operation, this is false. A throttled node will be contacted less frequently
252252
// until it has reached a state in which it's able to accept a steady stream of
253253
// log entries again.
254+
//
255+
// TODO(pav-kv): this method is deprecated, remove it. It is still used in tests
256+
// and String(), find a way to avoid this. The problem is that the actual flow
257+
// control state depends on the log size and commit index, which are not part of
258+
// this Progress struct - they are passed-in to methods like ShouldSendMsgApp().
254259
func (pr *Progress) IsPaused() bool {
255260
switch pr.State {
256261
case StateProbe:
257-
return pr.MsgAppFlowPaused
262+
return pr.MsgAppProbesPaused
258263
case StateReplicate:
259-
return pr.MsgAppFlowPaused && pr.Inflights.Full()
264+
return pr.MsgAppProbesPaused && pr.Inflights.Full()
260265
case StateSnapshot:
261266
return true
262267
default:
@@ -286,10 +291,10 @@ func (pr *Progress) IsPaused() bool {
286291
func (pr *Progress) ShouldSendMsgApp(last, commit uint64) bool {
287292
switch pr.State {
288293
case StateProbe:
289-
return !pr.MsgAppFlowPaused
294+
return !pr.MsgAppProbesPaused
290295
case StateReplicate:
291296
return pr.CanBumpCommit(commit) ||
292-
pr.Match < last && (!pr.MsgAppFlowPaused || pr.CanSendEntries(last))
297+
pr.Match < last && (!pr.MsgAppProbesPaused || pr.CanSendEntries(last))
293298
case StateSnapshot:
294299
return false
295300
default:

tracker/progress_test.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func TestProgressString(t *testing.T) {
2424
ins := NewInflights(1, 0)
2525
ins.Add(123, 1)
2626
pr := &Progress{
27-
Match: 1,
28-
Next: 2,
29-
State: StateSnapshot,
30-
PendingSnapshot: 123,
31-
RecentActive: false,
32-
MsgAppFlowPaused: true,
33-
IsLearner: true,
34-
Inflights: ins,
27+
Match: 1,
28+
Next: 2,
29+
State: StateSnapshot,
30+
PendingSnapshot: 123,
31+
RecentActive: false,
32+
MsgAppProbesPaused: true,
33+
IsLearner: true,
34+
Inflights: ins,
3535
}
3636
const exp = `StateSnapshot match=1 next=2 learner paused pendingSnap=123 inactive inflight=1[full]`
3737
assert.Equal(t, exp, pr.String())
@@ -53,29 +53,29 @@ func TestProgressIsPaused(t *testing.T) {
5353
}
5454
for i, tt := range tests {
5555
p := &Progress{
56-
State: tt.state,
57-
MsgAppFlowPaused: tt.paused,
58-
Inflights: NewInflights(256, 0),
56+
State: tt.state,
57+
MsgAppProbesPaused: tt.paused,
58+
Inflights: NewInflights(256, 0),
5959
}
6060
assert.Equal(t, tt.w, p.IsPaused(), i)
6161
}
6262
}
6363

64-
// TestProgressResume ensures that MaybeDecrTo resets MsgAppFlowPaused, and
64+
// TestProgressResume ensures that MaybeDecrTo resets MsgAppProbesPaused, and
6565
// MaybeUpdate does not.
6666
//
6767
// TODO(pav-kv): there is little sense in testing these micro-behaviours in the
6868
// struct. We should test the visible behaviour instead.
6969
func TestProgressResume(t *testing.T) {
7070
p := &Progress{
71-
Next: 2,
72-
MsgAppFlowPaused: true,
71+
Next: 2,
72+
MsgAppProbesPaused: true,
7373
}
7474
p.MaybeDecrTo(1, 1)
75-
assert.False(t, p.MsgAppFlowPaused)
76-
p.MsgAppFlowPaused = true
75+
assert.False(t, p.MsgAppProbesPaused)
76+
p.MsgAppProbesPaused = true
7777
p.MaybeUpdate(2)
78-
assert.True(t, p.MsgAppFlowPaused)
78+
assert.True(t, p.MsgAppProbesPaused)
7979
}
8080

8181
func TestProgressBecomeProbe(t *testing.T) {

0 commit comments

Comments
 (0)