Skip to content

Commit

Permalink
region_scatterer: fix the bug that could generate schedule with too f…
Browse files Browse the repository at this point in the history
…ew peers

close tikv#4565

Signed-off-by: HunDunDM <hundundm@gmail.com>
  • Loading branch information
HunDunDM authored and ti-chi-bot committed Jan 14, 2022
1 parent f57fa77 commit f229e75
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/schedule/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ func (r *RegionScatterer) scatterRegion(region *core.RegionInfo, group string) *
scatterWithSameEngine(peers, ctx)
}

// If the number of target peers is too small, change it back to the original.
if peers := region.GetPeers(); len(peers) != len(targetPeers) {
targetPeers = make(map[uint64]*metapb.Peer, len(peers))
for _, peer := range peers {
targetPeers[peer.GetStoreId()] = peer
}
}

if isSameDistribution(region, targetPeers, targetLeader) {
scatterCounter.WithLabelValues("unnecessary", "").Inc()
r.Put(targetPeers, targetLeader, group)
Expand Down

0 comments on commit f229e75

Please sign in to comment.