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

*: add engine filter to exclude special stores #2426

Merged
merged 10 commits into from
May 22, 2020
46 changes: 44 additions & 2 deletions server/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,41 @@ func (f *ruleFitFilter) Target(opt opt.Options, store *core.StoreInfo) bool {
return placement.CompareRegionFit(f.oldFit, newFit) <= 0
}

type engineFilter struct {
scope string
constraint placement.LabelConstraint
}

// NewEngineFilter creates a filter that filters store for special engine.
func NewEngineFilter(scope string, allowUses ...string) Filter {
Copy link
Member

@HunDunDM HunDunDM May 18, 2020

Choose a reason for hiding this comment

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

Can constraint.Values be specified directly in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have adds some comments.

var values []string
for _, v := range allEngineLabels {
if slice.NoneOf(allowUses, func(i int) bool { return allowUses[i] == v }) {
values = append(values, v)
}
}
return &engineFilter{
scope: scope,
constraint: placement.LabelConstraint{Key: "engine", Op: "in", Values: values},
}
}

func (f *engineFilter) Scope() string {
return f.scope
}

func (f *engineFilter) Type() string {
return "engine-filter"
}

func (f *engineFilter) Source(opt opt.Options, store *core.StoreInfo) bool {
return !f.constraint.MatchStore(store)
}

func (f *engineFilter) Target(opt opt.Options, store *core.StoreInfo) bool {
return !f.constraint.MatchStore(store)
}

type specialUseFilter struct {
scope string
constraint placement.LabelConstraint
Expand All @@ -558,7 +593,7 @@ func NewSpecialUseFilter(scope string, allowUses ...string) Filter {
}
return &specialUseFilter{
scope: scope,
constraint: placement.LabelConstraint{Key: specialUseKey, Op: "in", Values: values},
constraint: placement.LabelConstraint{Key: SpecialUseKey, Op: "in", Values: values},
}
}

Expand All @@ -582,11 +617,18 @@ func (f *specialUseFilter) Target(opt opt.Options, store *core.StoreInfo) bool {
}

const (
specialUseKey = "specialUse"
// SpecialUseKey is the label used to indicate special use storage.
SpecialUseKey = "specialUse"
// SpecialUseHotRegion is the hot region value of special use label
SpecialUseHotRegion = "hotRegion"
// SpecialUseReserved is the reserved value of special use label
SpecialUseReserved = "reserved"

// EngineKey is the label key used to indicate engine.
EngineKey = "engine"
// EngineTiFlash is the tiflash value of the engine label.
EngineTiFlash = "tiflash"
)

var allSpecialUses = []string{SpecialUseHotRegion, SpecialUseReserved}
var allEngineLabels = []string{EngineTiFlash}
1 change: 1 addition & 0 deletions server/schedule/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NewRegionScatterer(cluster opt.Cluster) *RegionScatterer {
cluster: cluster,
filters: []filter.Filter{
filter.StoreStateFilter{ActionScope: regionScatterName},
filter.NewEngineFilter(regionScatterName),
},
selected: newSelectedStores(),
}
Expand Down
10 changes: 7 additions & 3 deletions server/schedulers/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ var _ = Suite(&testScatterRegionSuite{})
type testScatterRegionSuite struct{}

func (s *testScatterRegionSuite) TestSixStores(c *C) {
s.scatter(c, 6, 4)
s.scatter(c, 6, 4, false)
s.scatter(c, 6, 4, true)
}

func (s *testScatterRegionSuite) TestFiveStores(c *C) {
s.scatter(c, 5, 5)
s.scatter(c, 5, 5, false)
s.scatter(c, 5, 5, true)
}

func (s *testScatterRegionSuite) checkOperator(op *operator.Operator, c *C) {
Expand All @@ -209,14 +211,16 @@ func (s *testScatterRegionSuite) checkOperator(op *operator.Operator, c *C) {
}
}

func (s *testScatterRegionSuite) scatter(c *C, numStores, numRegions uint64) {
func (s *testScatterRegionSuite) scatter(c *C, numStores, numRegions uint64, useRules bool) {
opt := mockoption.NewScheduleOptions()
tc := mockcluster.NewCluster(opt)

// Add stores 1~6.
for i := uint64(1); i <= numStores; i++ {
tc.AddRegionStore(i, 0)
}
tc.AddLabelsStore(numStores+1, 0, map[string]string{"engine": "tiflash"})
tc.EnablePlacementRules = useRules

// Add regions 1~4.
seq := newSequencer(3)
Expand Down
2 changes: 2 additions & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func checkBootstrapRequest(clusterID uint64, req *pdpb.BootstrapRequest) error {
return nil
}

// isTiFlashStore used to judge flash store.
// FIXME: remove the hack way
func isTiFlashStore(store *metapb.Store) bool {
for _, l := range store.GetLabels() {
if l.GetKey() == "engine" && l.GetValue() == "tiflash" {
Expand Down