Skip to content

Commit

Permalink
rename leader strategy to leader policy
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Jan 3, 2020
1 parent ea974c9 commit 3373788
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 75 deletions.
4 changes: 2 additions & 2 deletions conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ region-schedule-limit = 2048
replica-schedule-limit = 64
merge-schedule-limit = 8
hot-region-schedule-limit = 4
## There are some strategics supported: ["count", "size"], default: "count"
# leader-schedule-strategy = "count"
## There are some policies supported: ["count", "size"], default: "count"
# leader-schedule-policy = "count"
## When the score difference between the leader or Region of the two stores is
## less than specified multiple times of the Region size, it is considered in balance by PD.
## If it equals 0.0, PD will automatically adjust it.
Expand Down
12 changes: 6 additions & 6 deletions pkg/mock/mockoption/mockoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
defaultSchedulerMaxWaitingOperator = 3
defaultHotRegionCacheHitsThreshold = 3
defaultStrictlyMatchLabel = true
defaultLeaderScheduleStrategy = "count"
defaultLeaderSchedulePolicy = "count"
defaultEnablePlacementRules = false
defaultKeyType = "table"
)
Expand Down Expand Up @@ -83,7 +83,7 @@ type ScheduleOptions struct {
DisableMakeUpReplica bool
DisableRemoveExtraReplica bool
DisableLocationReplacement bool
LeaderScheduleStrategy string
LeaderSchedulePolicy string
LabelProperties map[string][]*metapb.StoreLabel
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func NewScheduleOptions() *ScheduleOptions {
mso.EnableMakeUpReplica = true
mso.EnableRemoveExtraReplica = true
mso.EnableLocationReplacement = true
mso.LeaderScheduleStrategy = defaultLeaderScheduleStrategy
mso.LeaderSchedulePolicy = defaultLeaderSchedulePolicy
mso.KeyType = defaultKeyType
return mso
}
Expand Down Expand Up @@ -270,9 +270,9 @@ func (mso *ScheduleOptions) IsDebugMetricsEnabled() bool {
return mso.EnableDebugMetrics
}

// GetLeaderScheduleStrategy is to get leader schedule strategy.
func (mso *ScheduleOptions) GetLeaderScheduleStrategy() core.ScheduleStrategy {
return core.StringToScheduleStrategy(mso.LeaderScheduleStrategy)
// GetLeaderSchedulePolicy is to get leader schedule policy.
func (mso *ScheduleOptions) GetLeaderSchedulePolicy() core.SchedulePolicy {
return core.StringToSchedulePolicy(mso.LeaderSchedulePolicy)
}

// GetKeyType is to get key type.
Expand Down
2 changes: 1 addition & 1 deletion server/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func newStoreInfo(opt *config.ScheduleConfig, store *core.StoreInfo) *StoreInfo
UsedSize: typeutil.ByteSize(store.GetUsedSize()),
LeaderCount: store.GetLeaderCount(),
LeaderWeight: store.GetLeaderWeight(),
LeaderScore: store.LeaderScore(core.StringToScheduleStrategy(opt.LeaderScheduleStrategy), 0),
LeaderScore: store.LeaderScore(core.StringToSchedulePolicy(opt.LeaderSchedulePolicy), 0),
LeaderSize: store.GetLeaderSize(),
RegionCount: store.GetRegionCount(),
RegionWeight: store.GetRegionWeight(),
Expand Down
6 changes: 3 additions & 3 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,9 @@ func (c *RaftCluster) IsRemoveDownReplicaEnabled() bool {
return c.opt.IsRemoveDownReplicaEnabled()
}

// GetLeaderScheduleStrategy is to get leader schedule strategy.
func (c *RaftCluster) GetLeaderScheduleStrategy() core.ScheduleStrategy {
return c.opt.GetLeaderScheduleStrategy()
// GetLeaderSchedulePolicy is to get leader schedule policy.
func (c *RaftCluster) GetLeaderSchedulePolicy() core.SchedulePolicy {
return c.opt.GetLeaderSchedulePolicy()
}

// GetKeyType is to get key type.
Expand Down
12 changes: 6 additions & 6 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ type ScheduleConfig struct {
MaxStoreDownTime typeutil.Duration `toml:"max-store-down-time" json:"max-store-down-time"`
// LeaderScheduleLimit is the max coexist leader schedules.
LeaderScheduleLimit uint64 `toml:"leader-schedule-limit" json:"leader-schedule-limit"`
// LeaderScheduleStrategy is the option to balance leader, there are some strategics supported: ["count", "size"], default: "count"
LeaderScheduleStrategy string `toml:"leader-schedule-strategy" json:"leader-schedule-strategy"`
// LeaderSchedulePolicy is the option to balance leader, there are some policies supported: ["count", "size"], default: "count"
LeaderSchedulePolicy string `toml:"leader-schedule-policy" json:"leader-schedule-policy"`
// RegionScheduleLimit is the max coexist region schedules.
RegionScheduleLimit uint64 `toml:"region-schedule-limit" json:"region-schedule-limit"`
// ReplicaScheduleLimit is the max coexist replica schedules.
Expand Down Expand Up @@ -590,7 +590,7 @@ func (c *ScheduleConfig) Clone() *ScheduleConfig {
PatrolRegionInterval: c.PatrolRegionInterval,
MaxStoreDownTime: c.MaxStoreDownTime,
LeaderScheduleLimit: c.LeaderScheduleLimit,
LeaderScheduleStrategy: c.LeaderScheduleStrategy,
LeaderSchedulePolicy: c.LeaderSchedulePolicy,
RegionScheduleLimit: c.RegionScheduleLimit,
ReplicaScheduleLimit: c.ReplicaScheduleLimit,
MergeScheduleLimit: c.MergeScheduleLimit,
Expand Down Expand Up @@ -642,7 +642,7 @@ const (
// hot region.
defaultHotRegionCacheHitsThreshold = 3
defaultSchedulerMaxWaitingOperator = 3
defaultLeaderScheduleStrategy = "count"
defaultLeaderSchedulePolicy = "count"
defaultStoreLimitMode = "manual"
)

Expand Down Expand Up @@ -686,8 +686,8 @@ func (c *ScheduleConfig) adjust(meta *configMetaData) error {
if !meta.IsDefined("scheduler-max-waiting-operator") {
adjustUint64(&c.SchedulerMaxWaitingOperator, defaultSchedulerMaxWaitingOperator)
}
if !meta.IsDefined("leader-schedule-strategy") {
adjustString(&c.LeaderScheduleStrategy, defaultLeaderScheduleStrategy)
if !meta.IsDefined("leader-schedule-policy") {
adjustString(&c.LeaderSchedulePolicy, defaultLeaderSchedulePolicy)
}
if !meta.IsDefined("store-limit-mode") {
adjustString(&c.StoreLimitMode, defaultStoreLimitMode)
Expand Down
6 changes: 3 additions & 3 deletions server/config/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ func (o *ScheduleOption) GetSchedulerMaxWaitingOperator() uint64 {
return o.Load().SchedulerMaxWaitingOperator
}

// GetLeaderScheduleStrategy is to get leader schedule strategy.
func (o *ScheduleOption) GetLeaderScheduleStrategy() core.ScheduleStrategy {
return core.StringToScheduleStrategy(o.Load().LeaderScheduleStrategy)
// GetLeaderSchedulePolicy is to get leader schedule policy.
func (o *ScheduleOption) GetLeaderSchedulePolicy() core.SchedulePolicy {
return core.StringToSchedulePolicy(o.Load().LeaderSchedulePolicy)
}

// GetKeyType is to get key type.
Expand Down
24 changes: 12 additions & 12 deletions server/core/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ const (
HighPriority
)

// ScheduleKind distinguishes resources and schedule strategy.
// ScheduleKind distinguishes resources and schedule policy.
type ScheduleKind struct {
Resource ResourceKind
Strategy ScheduleStrategy
Policy SchedulePolicy
}

// NewScheduleKind creates a schedule kind with resource kind and schedule strategy.
func NewScheduleKind(Resource ResourceKind, Strategy ScheduleStrategy) ScheduleKind {
// NewScheduleKind creates a schedule kind with resource kind and schedule policy.
func NewScheduleKind(Resource ResourceKind, Policy SchedulePolicy) ScheduleKind {
return ScheduleKind{
Resource: Resource,
Strategy: Strategy,
Policy: Policy,
}
}

Expand All @@ -58,17 +58,17 @@ func (k ResourceKind) String() string {
}
}

// ScheduleStrategy distinguishes different kinds of schedule strategy
type ScheduleStrategy int
// SchedulePolicy distinguishes different kinds of schedule policies.
type SchedulePolicy int

const (
// ByCount indicates that balance by count
ByCount ScheduleStrategy = iota
ByCount SchedulePolicy = iota
// BySize indicates that balance by size
BySize
)

func (k ScheduleStrategy) String() string {
func (k SchedulePolicy) String() string {
switch k {
case ByCount:
return "count"
Expand All @@ -79,15 +79,15 @@ func (k ScheduleStrategy) String() string {
}
}

// StringToScheduleStrategy creates a schedule strategy with string.
func StringToScheduleStrategy(input string) ScheduleStrategy {
// StringToSchedulePolicy creates a schedule policy with string.
func StringToSchedulePolicy(input string) SchedulePolicy {
switch input {
case BySize.String():
return BySize
case ByCount.String():
return ByCount
default:
panic("invalid schedule strategy: " + input)
panic("invalid schedule policy: " + input)
}
}

Expand Down
6 changes: 3 additions & 3 deletions server/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ const minWeight = 1e-6
const maxScore = 1024 * 1024 * 1024

// LeaderScore returns the store's leader score.
func (s *StoreInfo) LeaderScore(strategy ScheduleStrategy, delta int64) float64 {
switch strategy {
func (s *StoreInfo) LeaderScore(policy SchedulePolicy, delta int64) float64 {
switch policy {
case BySize:
return float64(s.GetLeaderSize()+delta) / math.Max(s.GetLeaderWeight(), minWeight)
case ByCount:
Expand Down Expand Up @@ -357,7 +357,7 @@ func (s *StoreInfo) ResourceSize(kind ResourceKind) int64 {
func (s *StoreInfo) ResourceScore(scheduleKind ScheduleKind, highSpaceRatio, lowSpaceRatio float64, delta int64) float64 {
switch scheduleKind.Resource {
case LeaderKind:
return s.LeaderScore(scheduleKind.Strategy, delta)
return s.LeaderScore(scheduleKind.Policy, delta)
case RegionKind:
return s.RegionScore(highSpaceRatio, lowSpaceRatio, delta)
default:
Expand Down
4 changes: 2 additions & 2 deletions server/schedule/checker/merge_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func (m *MergeChecker) allowMerge(region *core.RegionInfo, adjacent *core.Region
if m.cluster.IsPlacementRulesEnabled() && len(m.ruleManager.GetSplitKeys(start, end)) > 0 {
return false
}
strategy := m.cluster.GetKeyType()
switch strategy {
policy := m.cluster.GetKeyType()
switch policy {
case core.Table:
if m.cluster.IsCrossTableMergeEnabled() {
return true
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/operator/influence.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type StoreInfluence struct {
func (s StoreInfluence) ResourceProperty(kind core.ScheduleKind) int64 {
switch kind.Resource {
case core.LeaderKind:
switch kind.Strategy {
switch kind.Policy {
case core.ByCount:
return s.LeaderCount
case core.BySize:
Expand Down
6 changes: 3 additions & 3 deletions server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,12 @@ func (oc *OperatorController) GetAllStoresLimit() map[uint64]*StoreLimit {
return limits
}

// GetLeaderScheduleStrategy is to get leader schedule strategy
func (oc *OperatorController) GetLeaderScheduleStrategy() core.ScheduleStrategy {
// GetLeaderSchedulePolicy is to get leader schedule policy.
func (oc *OperatorController) GetLeaderSchedulePolicy() core.SchedulePolicy {
if oc.cluster == nil {
return core.ByCount
}
return oc.cluster.GetLeaderScheduleStrategy()
return oc.cluster.GetLeaderSchedulePolicy()
}

// RemoveStoreLimit removes the store limit for a given store ID.
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/opt/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Options interface {
IsRemoveExtraReplicaEnabled() bool
IsLocationReplacementEnabled() bool
IsDebugMetricsEnabled() bool
GetLeaderScheduleStrategy() core.ScheduleStrategy
GetLeaderSchedulePolicy() core.SchedulePolicy
GetKeyType() core.KeyType

RemoveScheduler(name string) error
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *BalanceSelector) SelectTarget(opt opt.Options, stores []*core.StoreInfo

func (s *BalanceSelector) updateConfig(opt opt.Options) {
if s.kind.Resource == core.LeaderKind {
s.kind.Strategy = opt.GetLeaderScheduleStrategy()
s.kind.Policy = opt.GetLeaderSchedulePolicy()
}
}

Expand Down
8 changes: 4 additions & 4 deletions server/schedule/selector/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func (s *testSelectorSuite) TestScheduleConfig(c *C) {

kinds := []core.ScheduleKind{{
Resource: core.RegionKind,
Strategy: core.ByCount,
Policy: core.ByCount,
}, {
Resource: core.RegionKind,
Strategy: core.BySize,
Policy: core.BySize,
}}

for _, kind := range kinds {
Expand All @@ -80,7 +80,7 @@ func (s *testSelectorSuite) TestScheduleConfig(c *C) {

selector := NewBalanceSelector(core.ScheduleKind{
Resource: core.LeaderKind,
Strategy: core.ByCount,
Policy: core.ByCount,
}, filters)
stores := []*core.StoreInfo{
core.NewStoreInfoWithSizeCount(1, 2, 20, 10, 25),
Expand All @@ -89,6 +89,6 @@ func (s *testSelectorSuite) TestScheduleConfig(c *C) {
core.NewStoreInfoWithSizeCount(4, 2, 20, 10, 1),
}
testScheduleConfig(selector, stores, 2, 3)
s.tc.LeaderScheduleStrategy = core.BySize.String()
s.tc.LeaderSchedulePolicy = core.BySize.String()
testScheduleConfig(selector, stores, 1, 4)
}
12 changes: 6 additions & 6 deletions server/schedulers/balance_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ func (l *balanceLeaderScheduler) IsScheduleAllowed(cluster opt.Cluster) bool {
func (l *balanceLeaderScheduler) Schedule(cluster opt.Cluster) []*operator.Operator {
schedulerCounter.WithLabelValues(l.GetName(), "schedule").Inc()

leaderScheduleStrategy := l.opController.GetLeaderScheduleStrategy()
leaderSchedulePolicy := l.opController.GetLeaderSchedulePolicy()
stores := cluster.GetStores()
sources := filter.SelectSourceStores(stores, l.filters, cluster)
targets := filter.SelectTargetStores(stores, l.filters, cluster)
sort.Slice(sources, func(i, j int) bool {
return sources[i].LeaderScore(leaderScheduleStrategy, 0) > sources[j].LeaderScore(leaderScheduleStrategy, 0)
return sources[i].LeaderScore(leaderSchedulePolicy, 0) > sources[j].LeaderScore(leaderSchedulePolicy, 0)
})
sort.Slice(targets, func(i, j int) bool {
return targets[i].LeaderScore(leaderScheduleStrategy, 0) < targets[j].LeaderScore(leaderScheduleStrategy, 0)
return targets[i].LeaderScore(leaderSchedulePolicy, 0) < targets[j].LeaderScore(leaderSchedulePolicy, 0)
})

for i := 0; i < len(sources) || i < len(targets); i++ {
Expand Down Expand Up @@ -190,9 +190,9 @@ func (l *balanceLeaderScheduler) transferLeaderOut(cluster opt.Cluster, source *
}
targets := cluster.GetFollowerStores(region)
targets = filter.SelectTargetStores(targets, l.filters, cluster)
leaderScheduleStrategy := l.opController.GetLeaderScheduleStrategy()
leaderSchedulePolicy := l.opController.GetLeaderSchedulePolicy()
sort.Slice(targets, func(i, j int) bool {
return targets[i].LeaderScore(leaderScheduleStrategy, 0) < targets[j].LeaderScore(leaderScheduleStrategy, 0)
return targets[i].LeaderScore(leaderSchedulePolicy, 0) < targets[j].LeaderScore(leaderSchedulePolicy, 0)
})
for _, target := range targets {
if op := l.createOperator(cluster, region, source, target); len(op) > 0 {
Expand Down Expand Up @@ -244,7 +244,7 @@ func (l *balanceLeaderScheduler) createOperator(cluster opt.Cluster, region *cor
targetID := target.GetID()

opInfluence := l.opController.GetOpInfluence(cluster)
kind := core.NewScheduleKind(core.LeaderKind, cluster.GetLeaderScheduleStrategy())
kind := core.NewScheduleKind(core.LeaderKind, cluster.GetLeaderSchedulePolicy())
if !shouldBalance(cluster, source, target, region, kind, opInfluence, l.GetName()) {
schedulerCounter.WithLabelValues(l.GetName(), "skip").Inc()
return nil
Expand Down
Loading

0 comments on commit 3373788

Please sign in to comment.