Skip to content

Commit 48d5e61

Browse files
craig[bot]arulajmani
craig[bot]
andcommitted
Merge #131708
131708: raft: misc cleanups r=iskettenah a=arulajmani Pulls out the first 3 commits from #131668. See individual commits for details. Co-authored-by: Arul Ajmani <[email protected]>
2 parents 6b41cf6 + 86a7423 commit 48d5e61

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

Diff for: pkg/raft/raft.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ type raft struct {
350350
//
351351
// Messages in this list may target other nodes or may target this node.
352352
//
353-
// Messages in this list have the type MsgAppResp, MsgVoteResp, or
354-
// MsgPreVoteResp. See the comment in raft.send for details.
353+
// Messages in this list have the type MsgAppResp, MsgVoteResp,
354+
// MsgPreVoteResp, or MsgFortifyLeaderResp. See the comment in raft.send for
355+
// details.
355356
msgsAfterAppend []pb.Message
356357

357358
// the leader id

Diff for: pkg/raft/tracker/fortificationtracker.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ func MakeFortificationTracker(
4747

4848
// FortificationEnabled returns whether the raft fortification protocol is
4949
// enabled or not.
50-
func (st *FortificationTracker) FortificationEnabled() bool {
51-
return st.storeLiveness.SupportFromEnabled()
50+
func (ft *FortificationTracker) FortificationEnabled() bool {
51+
return ft.storeLiveness.SupportFromEnabled()
5252
}
5353

54-
// RecordFortification records that the node with the given id supported this
55-
// Raft instance until the supplied timestamp.
56-
func (st *FortificationTracker) RecordFortification(id pb.PeerID, epoch pb.Epoch) {
54+
// RecordFortification records fortification of the given peer for the supplied
55+
// epoch.
56+
func (ft *FortificationTracker) RecordFortification(id pb.PeerID, epoch pb.Epoch) {
5757
// The supported epoch should never regress. Guard against out of order
5858
// delivery of fortify responses by using max.
59-
st.fortification[id] = max(st.fortification[id], epoch)
59+
ft.fortification[id] = max(ft.fortification[id], epoch)
6060
}
6161

6262
// Reset clears out any previously tracked fortification.
63-
func (st *FortificationTracker) Reset() {
64-
clear(st.fortification)
65-
// TODO(arul): when we introduce st.LeadSupportUntil we need to make sure it
63+
func (ft *FortificationTracker) Reset() {
64+
clear(ft.fortification)
65+
// TODO(arul): when we introduce ft.LeadSupportUntil we need to make sure it
6666
// isn't reset here, because we don't want it to regress when a leader steps
6767
// down.
6868
}
@@ -71,15 +71,15 @@ func (st *FortificationTracker) Reset() {
7171
// If the follower's store doesn't support the leader's store in the store
7272
// liveness fabric, then both isSupported and isFortified will be false.
7373
// If isFortified is true, it implies that isSupported is also true.
74-
func (st *FortificationTracker) IsFortifiedBy(id pb.PeerID) (isFortified bool, isSupported bool) {
75-
supportEpoch, curExp := st.storeLiveness.SupportFrom(id)
76-
if st.storeLiveness.SupportExpired(curExp) {
74+
func (ft *FortificationTracker) IsFortifiedBy(id pb.PeerID) (isFortified bool, isSupported bool) {
75+
supportEpoch, curExp := ft.storeLiveness.SupportFrom(id)
76+
if ft.storeLiveness.SupportExpired(curExp) {
7777
return false, false
7878
}
7979

8080
// At this point we know that the follower's store is providing support
8181
// at the store liveness fabric.
82-
fortificationEpoch, exist := st.fortification[id]
82+
fortificationEpoch, exist := ft.fortification[id]
8383
if !exist {
8484
// We don't know that the follower is fortified.
8585
return false, true
@@ -96,12 +96,12 @@ func (st *FortificationTracker) IsFortifiedBy(id pb.PeerID) (isFortified bool, i
9696
// LeadSupportUntil returns the timestamp until which the leader is guaranteed
9797
// fortification until based on the fortification being tracked for it by its
9898
// peers.
99-
func (st *FortificationTracker) LeadSupportUntil() hlc.Timestamp {
99+
func (ft *FortificationTracker) LeadSupportUntil() hlc.Timestamp {
100100
// TODO(arul): avoid this map allocation as we're calling LeadSupportUntil
101101
// from hot paths.
102102
supportExpMap := make(map[pb.PeerID]hlc.Timestamp)
103-
for id, supportEpoch := range st.fortification {
104-
curEpoch, curExp := st.storeLiveness.SupportFrom(id)
103+
for id, supportEpoch := range ft.fortification {
104+
curEpoch, curExp := ft.storeLiveness.SupportFrom(id)
105105
// NB: We can't assert that supportEpoch <= curEpoch because there may be a
106106
// race between a successful MsgFortifyLeaderResp and the store liveness
107107
// heartbeat response that lets the leader know the follower's store is
@@ -111,28 +111,28 @@ func (st *FortificationTracker) LeadSupportUntil() hlc.Timestamp {
111111
supportExpMap[id] = curExp
112112
}
113113
}
114-
return st.config.Voters.LeadSupportExpiration(supportExpMap)
114+
return ft.config.Voters.LeadSupportExpiration(supportExpMap)
115115
}
116116

117117
// QuorumActive returns whether the leader is currently supported by a quorum or
118118
// not.
119-
func (st *FortificationTracker) QuorumActive() bool {
120-
return !st.storeLiveness.SupportExpired(st.LeadSupportUntil())
119+
func (ft *FortificationTracker) QuorumActive() bool {
120+
return !ft.storeLiveness.SupportExpired(ft.LeadSupportUntil())
121121
}
122122

123-
func (st *FortificationTracker) String() string {
124-
if len(st.fortification) == 0 {
123+
func (ft *FortificationTracker) String() string {
124+
if len(ft.fortification) == 0 {
125125
return "empty"
126126
}
127127
// Print the map in sorted order as we assert on its output in tests.
128-
ids := make([]pb.PeerID, 0, len(st.fortification))
129-
for id := range st.fortification {
128+
ids := make([]pb.PeerID, 0, len(ft.fortification))
129+
for id := range ft.fortification {
130130
ids = append(ids, id)
131131
}
132132
slices.Sort(ids)
133133
var buf strings.Builder
134134
for _, id := range ids {
135-
fmt.Fprintf(&buf, "%d : %d\n", id, st.fortification[id])
135+
fmt.Fprintf(&buf, "%d : %d\n", id, ft.fortification[id])
136136
}
137137
return buf.String()
138138
}

Diff for: pkg/raft/tracker/fortificationtracker_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestIsFortifiedBy(t *testing.T) {
195195
ids: []pb.PeerID{1},
196196
// No support recorded at the store liveness fabric.
197197
storeLiveness: makeMockStoreLiveness(map[pb.PeerID]mockLivenessEntry{}),
198-
setup: func(supportTracker *FortificationTracker) {
198+
setup: func(fortificationTracker *FortificationTracker) {
199199
// No support recorded.
200200
},
201201
expSupported: false,
@@ -204,7 +204,7 @@ func TestIsFortifiedBy(t *testing.T) {
204204
{
205205
ids: []pb.PeerID{1},
206206
storeLiveness: mockLivenessOnePeer,
207-
setup: func(supportTracker *FortificationTracker) {
207+
setup: func(fortificationTracker *FortificationTracker) {
208208
// No support recorded.
209209
},
210210
expSupported: true,
@@ -213,44 +213,44 @@ func TestIsFortifiedBy(t *testing.T) {
213213
{
214214
ids: []pb.PeerID{2},
215215
storeLiveness: mockLivenessOnePeer,
216-
setup: func(supportTracker *FortificationTracker) {
216+
setup: func(fortificationTracker *FortificationTracker) {
217217
// Support recorded for a different follower than the one in
218218
// storeLiveness.
219-
supportTracker.RecordFortification(2, 10)
219+
fortificationTracker.RecordFortification(2, 10)
220220
},
221221
expSupported: true,
222222
expFortified: false,
223223
},
224224
{
225225
ids: []pb.PeerID{1},
226226
storeLiveness: mockLivenessOnePeer,
227-
setup: func(supportTracker *FortificationTracker) {
227+
setup: func(fortificationTracker *FortificationTracker) {
228228
// Support recorded for an expired epoch.
229-
supportTracker.RecordFortification(1, 9)
229+
fortificationTracker.RecordFortification(1, 9)
230230
},
231231
expSupported: true,
232232
expFortified: false,
233233
},
234234
{
235235
ids: []pb.PeerID{1},
236236
storeLiveness: mockLivenessOnePeer,
237-
setup: func(supportTracker *FortificationTracker) {
237+
setup: func(fortificationTracker *FortificationTracker) {
238238
// Record support at newer epochs than what are present in
239239
// StoreLiveness.
240240
//
241241
// NB: This is possible if there is a race between store liveness
242242
// heartbeats updates and fortification responses.
243-
supportTracker.RecordFortification(1, 11)
243+
fortificationTracker.RecordFortification(1, 11)
244244
},
245245
expSupported: true,
246246
expFortified: false,
247247
},
248248
{
249249
ids: []pb.PeerID{1},
250250
storeLiveness: mockLivenessOnePeer,
251-
setup: func(supportTracker *FortificationTracker) {
251+
setup: func(fortificationTracker *FortificationTracker) {
252252
// Record support at the same epoch as the storeLiveness.
253-
supportTracker.RecordFortification(1, 10)
253+
fortificationTracker.RecordFortification(1, 10)
254254
},
255255
expSupported: true,
256256
expFortified: true,
@@ -262,10 +262,10 @@ func TestIsFortifiedBy(t *testing.T) {
262262
for _, id := range tc.ids {
263263
cfg.Voters[0][id] = struct{}{}
264264
}
265-
supportTracker := MakeFortificationTracker(&cfg, tc.storeLiveness)
265+
fortificationTracker := MakeFortificationTracker(&cfg, tc.storeLiveness)
266266

267-
tc.setup(&supportTracker)
268-
isFortified, isSupported := supportTracker.IsFortifiedBy(1)
267+
tc.setup(&fortificationTracker)
268+
isFortified, isSupported := fortificationTracker.IsFortifiedBy(1)
269269
require.Equal(t, tc.expSupported, isSupported)
270270
require.Equal(t, tc.expFortified, isFortified)
271271
}

0 commit comments

Comments
 (0)