Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
126933: raft: pre-size progress maps r=nvanbenschoten a=nvanbenschoten

Drive-by cleanup to pre-size the progress maps when constructing raft `Status` and `SparseStatus` structs.

Epic: None
Release note: None

Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
craig[bot] and nvanbenschoten committed Jul 10, 2024
2 parents b73328d + 1697b3b commit 0639ffb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/raft/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func withProgress(r *raft, visitor func(id pb.PeerID, typ ProgressType, pr track
}

func getProgressCopy(r *raft) map[pb.PeerID]tracker.Progress {
m := make(map[pb.PeerID]tracker.Progress)
m := make(map[pb.PeerID]tracker.Progress, len(r.trk.Progress))
r.trk.Visit(func(id pb.PeerID, pr *tracker.Progress) {
p := *pr
p.Inflights = pr.Inflights.Clone()
Expand Down Expand Up @@ -107,7 +107,7 @@ func getSparseStatus(r *raft) SparseStatus {
BasicStatus: getBasicStatus(r),
}
if status.RaftState == StateLeader {
status.Progress = map[pb.PeerID]tracker.Progress{}
status.Progress = make(map[pb.PeerID]tracker.Progress, len(r.trk.Progress))
withProgress(r, func(id pb.PeerID, _ ProgressType, pr tracker.Progress) {
status.Progress[id] = pr
})
Expand Down

0 comments on commit 0639ffb

Please sign in to comment.