Skip to content

Commit

Permalink
sort once
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed May 28, 2024
1 parent 5056578 commit b26849f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (r *RegionInfo) GetRef() int32 {

// NewRegionInfo creates RegionInfo with region's meta and leader peer.
func NewRegionInfo(region *metapb.Region, leader *metapb.Peer, opts ...RegionCreateOption) *RegionInfo {
sort.Sort(peerSlice(region.GetPeers()))
regionInfo := &RegionInfo{
meta: region,
leader: leader,
Expand Down Expand Up @@ -151,9 +152,6 @@ func classifyVoterAndLearner(region *RegionInfo) {
region.witnesses = append(region.witnesses, p)
}
}
sort.Sort(peerSlice(region.learners))
sort.Sort(peerSlice(region.voters))
sort.Sort(peerSlice(region.witnesses))
}

// peersEqualTo returns true when the peers are not changed, which may caused by: the region leader not changed,
Expand Down Expand Up @@ -219,6 +217,7 @@ func RegionFromHeartbeat(heartbeat RegionHeartbeatRequest, flowRoundDivisor int)
if heartbeat.GetApproximateSize() > 0 && regionSize < EmptyRegionApproximateSize {
regionSize = EmptyRegionApproximateSize
}
sort.Sort(peerSlice(heartbeat.GetRegion().GetPeers()))

region := &RegionInfo{
term: heartbeat.GetTerm(),
Expand Down

0 comments on commit b26849f

Please sign in to comment.