Skip to content
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, schedulers: make schedulers aware of placement rules #1999

Merged
merged 6 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/core/region_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ func WithPromoteLearner(peerID uint64) RegionCreateOption {
}

// WithReplacePeerStore replaces a peer's storeID with another ID.
func WithReplacePeerStore(peerID, newStoreID uint64) RegionCreateOption {
func WithReplacePeerStore(oldStoreID, newStoreID uint64) RegionCreateOption {
return func(region *RegionInfo) {
for _, p := range region.GetPeers() {
if p.GetId() == peerID {
if p.GetStoreId() == oldStoreID {
p.StoreId = newStoreID
}
}
Expand Down
24 changes: 12 additions & 12 deletions server/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,23 +531,23 @@ type RegionFitter interface {
}

type ruleFitFilter struct {
scope string
fitter RegionFitter
region *core.RegionInfo
oldFit *placement.RegionFit
oldPeer uint64
scope string
fitter RegionFitter
region *core.RegionInfo
oldFit *placement.RegionFit
oldStore uint64
}

// NewRuleFitFilter creates a filter that ensures after replace a peer with new
// one, the isolation level will not decrease. Its function is the same as
// distinctScoreFilter but used when placement rules is enabled.
func NewRuleFitFilter(scope string, fitter RegionFitter, region *core.RegionInfo, oldPeerID uint64) Filter {
func NewRuleFitFilter(scope string, fitter RegionFitter, region *core.RegionInfo, oldStoreID uint64) Filter {
return &ruleFitFilter{
scope: scope,
fitter: fitter,
region: region,
oldFit: fitter.FitRegion(region),
oldPeer: oldPeerID,
scope: scope,
fitter: fitter,
region: region,
oldFit: fitter.FitRegion(region),
oldStore: oldStoreID,
}
}

Expand All @@ -564,7 +564,7 @@ func (f *ruleFitFilter) Source(opt opt.Options, store *core.StoreInfo) bool {
}

func (f *ruleFitFilter) Target(opt opt.Options, store *core.StoreInfo) bool {
region := f.region.Clone(core.WithReplacePeerStore(f.oldPeer, store.GetID()))
region := f.region.Clone(core.WithReplacePeerStore(f.oldStore, store.GetID()))
newFit := f.fitter.FitRegion(region)
return placement.CompareRegionFit(f.oldFit, newFit) > 0
}
7 changes: 6 additions & 1 deletion server/schedule/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ func (r *RegionScatterer) selectPeerToReplace(stores map[uint64]*core.StoreInfo,
if sourceStore == nil {
log.Error("failed to get the store", zap.Uint64("store-id", storeID))
}
scoreGuard := filter.NewDistinctScoreFilter(r.name, r.cluster.GetLocationLabels(), regionStores, sourceStore)
var scoreGuard filter.Filter
if r.cluster.IsPlacementRulesEnabled() {
scoreGuard = filter.NewRuleFitFilter(r.name, r.cluster, region, oldPeer.GetStoreId())
} else {
scoreGuard = filter.NewDistinctScoreFilter(r.name, r.cluster.GetLocationLabels(), regionStores, sourceStore)
}

candidates := make([]*core.StoreInfo, 0, len(stores))
for _, store := range stores {
Expand Down
8 changes: 6 additions & 2 deletions server/schedulers/adjacent_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,12 @@ func (l *balanceAdjacentRegionScheduler) dispersePeer(cluster opt.Cluster, regio
log.Error("failed to get the source store", zap.Uint64("store-id", leaderStoreID))
return nil
}

scoreGuard := filter.NewDistinctScoreFilter(l.GetName(), cluster.GetLocationLabels(), stores, source)
var scoreGuard filter.Filter
if cluster.IsPlacementRulesEnabled() {
scoreGuard = filter.NewRuleFitFilter(l.GetName(), cluster, region, leaderStoreID)
} else {
scoreGuard = filter.NewDistinctScoreFilter(l.GetName(), cluster.GetLocationLabels(), stores, source)
}
excludeStores := region.GetStoreIds()
for _, storeID := range l.cacheRegions.assignedStoreIds {
if _, ok := excludeStores[storeID]; !ok {
Expand Down
15 changes: 14 additions & 1 deletion server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,23 @@ func (h *balanceHotRegionsScheduler) balanceByPeer(cluster opt.Cluster, storesSt
if srcStore == nil {
log.Error("failed to get the source store", zap.Uint64("store-id", srcStoreID))
}

srcPeer := srcRegion.GetStorePeer(srcStoreID)
if srcPeer == nil {
return nil, nil, nil, Influence{}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need to judge it in hot region rather than other schedulers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use continue to just skip this peer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shafreeck good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lhy1024 because hot region scheduler selects region from stats, which may be out of date. Others do not have this problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lhy1024 For shcedulers that include label related tests (hotWrite and shuffleHot), I have changed them to test twice, the second time run with placement rules enabled.


var scoreGuard filter.Filter
if cluster.IsPlacementRulesEnabled() {
scoreGuard = filter.NewRuleFitFilter(h.GetName(), cluster, srcRegion, srcStoreID)
} else {
scoreGuard = filter.NewDistinctScoreFilter(h.GetName(), cluster.GetLocationLabels(), cluster.GetRegionStores(srcRegion), srcStore)
}

filters := []filter.Filter{
filter.StoreStateFilter{ActionScope: h.GetName(), MoveRegion: true},
filter.NewExcludedFilter(h.GetName(), srcRegion.GetStoreIds(), srcRegion.GetStoreIds()),
filter.NewDistinctScoreFilter(h.GetName(), cluster.GetLocationLabels(), cluster.GetRegionStores(srcRegion), srcStore),
scoreGuard,
}
candidateStoreIDs := make([]uint64, 0, len(stores))
for _, store := range stores {
Expand Down
10 changes: 9 additions & 1 deletion server/schedulers/shuffle_hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ func (s *shuffleHotRegionScheduler) randomSchedule(cluster opt.Cluster, storeSta
if srcStore == nil {
log.Error("failed to get the source store", zap.Uint64("store-id", srcStoreID))
}

var scoreGuard filter.Filter
if cluster.IsPlacementRulesEnabled() {
scoreGuard = filter.NewRuleFitFilter(s.GetName(), cluster, srcRegion, srcStoreID)
} else {
scoreGuard = filter.NewDistinctScoreFilter(s.GetName(), cluster.GetLocationLabels(), cluster.GetRegionStores(srcRegion), srcStore)
}

filters := []filter.Filter{
filter.StoreStateFilter{ActionScope: s.GetName(), MoveRegion: true},
filter.NewExcludedFilter(s.GetName(), srcRegion.GetStoreIds(), srcRegion.GetStoreIds()),
filter.NewDistinctScoreFilter(s.GetName(), cluster.GetLocationLabels(), cluster.GetRegionStores(srcRegion), srcStore),
scoreGuard,
}
stores := cluster.GetStores()
destStoreIDs := make([]uint64, 0, len(stores))
Expand Down