-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
schedule: revise region_scatter distribution for multi groups #3422
Changes from 5 commits
eb3e66f
37ceec2
5e2e2ae
0b9e93d
a11927f
4dfa057
c6d532d
344ceb5
aaaca9a
3dc64fe
5f1e4c1
47b1f43
86ab658
b13b1e6
e91faed
6b33f0a
3eb838b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,23 @@ func (s *selectedStores) newFilters(scope, group string) []filter.Filter { | |
return []filter.Filter{filter.NewExcludedFilter(scope, nil, cloned)} | ||
} | ||
|
||
func (s *selectedStores) storeTotalCount(storeID uint64) uint64 { | ||
groups := s.groupDistribution.GetAllID() | ||
totalCount := uint64(0) | ||
for _, group := range groups { | ||
storeDistribution, ok := s.getGroupDistribution(group) | ||
if !ok { | ||
continue | ||
} | ||
count, ok := storeDistribution[storeID] | ||
if !ok { | ||
continue | ||
} | ||
totalCount += count | ||
} | ||
return totalCount | ||
} | ||
|
||
// RegionScatterer scatters regions. | ||
type RegionScatterer struct { | ||
ctx context.Context | ||
|
@@ -307,15 +324,29 @@ func (r *RegionScatterer) scatterRegion(region *core.RegionInfo, group string) * | |
|
||
scatterWithSameEngine := func(peers []*metapb.Peer, context engineContext) { | ||
stores := r.collectAvailableStores(group, region, context) | ||
maxStoreTotalCount := uint64(0) | ||
minStoreTotalCount := uint64(math.MaxUint64) | ||
for _, store := range r.cluster.GetStores() { | ||
count := context.selectedPeer.storeTotalCount(store.GetID()) | ||
if count > maxStoreTotalCount { | ||
maxStoreTotalCount = count | ||
} | ||
if count < minStoreTotalCount { | ||
minStoreTotalCount = count | ||
} | ||
} | ||
for _, peer := range peers { | ||
if len(stores) == 0 { | ||
context.selectedPeer.reset() | ||
stores = r.collectAvailableStores(group, region, context) | ||
} | ||
if context.selectedPeer.put(peer.GetStoreId(), group) { | ||
delete(stores, peer.GetStoreId()) | ||
targetPeers[peer.GetStoreId()] = peer | ||
continue | ||
storeCount := context.selectedPeer.storeTotalCount(peer.GetStoreId()) | ||
if storeCount < maxStoreTotalCount || storeCount == minStoreTotalCount { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the storeCounts are all the same( maxStoreTotalCount == minStoreTotalCount), we can pick this store as candidate. |
||
if context.selectedPeer.put(peer.GetStoreId(), group) { | ||
delete(stores, peer.GetStoreId()) | ||
targetPeers[peer.GetStoreId()] = peer | ||
continue | ||
} | ||
} | ||
newPeer := r.selectPeerToReplace(group, stores, region, peer, context) | ||
if newPeer == nil { | ||
|
@@ -419,17 +450,28 @@ func (r *RegionScatterer) collectAvailableStores(group string, region *core.Regi | |
// selectAvailableLeaderStores select the target leader store from the candidates. The candidates would be collected by | ||
// the existed peers store depended on the leader counts in the group level. | ||
func (r *RegionScatterer) selectAvailableLeaderStores(group string, peers map[uint64]*metapb.Peer, context engineContext) uint64 { | ||
maxStoreTotalCount := uint64(0) | ||
for _, store := range r.cluster.GetStores() { | ||
count := r.ordinaryEngine.selectedLeader.storeTotalCount(store.GetID()) | ||
if count > maxStoreTotalCount { | ||
maxStoreTotalCount = count | ||
} | ||
} | ||
minStoreGroupLeader := uint64(math.MaxUint64) | ||
id := uint64(0) | ||
targetLeader := uint64(0) | ||
for storeID := range peers { | ||
if targetLeader == 0 { | ||
targetLeader = storeID | ||
} | ||
if context.selectedLeader.storeTotalCount(storeID) >= maxStoreTotalCount { | ||
continue | ||
} | ||
storeGroupLeaderCount := context.selectedLeader.get(storeID, group) | ||
if minStoreGroupLeader > storeGroupLeaderCount { | ||
minStoreGroupLeader = storeGroupLeaderCount | ||
id = storeID | ||
targetLeader = storeID | ||
} | ||
} | ||
if id != 0 { | ||
context.selectedLeader.put(id, group) | ||
} | ||
return id | ||
context.selectedLeader.put(targetLeader, group) | ||
return targetLeader | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is a little bit confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.