Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 authored and ti-chi-bot committed Sep 13, 2021
1 parent 0ef1e7e commit 861f768
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 41 deletions.
5 changes: 0 additions & 5 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ func NewCluster(ctx context.Context, opts *config.PersistOptions) *Cluster {
return clus
}

// GetClusterType returns the cluster type
func (mc *Cluster) GetClusterType() core.ClusterType {
return core.MockCluster
}

// GetOpts returns the cluster configuration.
func (mc *Cluster) GetOpts() *config.PersistOptions {
return mc.PersistOptions
Expand Down
5 changes: 0 additions & 5 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,6 @@ func (c *RaftCluster) SetStorage(s *core.Storage) {
c.storage = s
}

// GetClusterType returns the cluster type
func (c *RaftCluster) GetClusterType() core.ClusterType {
return core.RaftCluster
}

// GetOpts returns cluster's configuration.
func (c *RaftCluster) GetOpts() *config.PersistOptions {
return c.opt
Expand Down
11 changes: 0 additions & 11 deletions server/core/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,3 @@ func StringToKeyType(input string) KeyType {
}
}

// ClusterType means the type of cluster
type ClusterType int

const (
// RaftCluster means the ClusterType of RaftCluster
RaftCluster ClusterType = iota
// RangeCluster means the ClusterType of RangeCluster
RangeCluster
// MockCluster means the ClusterType of MockCluster
MockCluster
)
8 changes: 1 addition & 7 deletions server/schedule/opt/healthy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ func HealthAllowPending(cluster Cluster) func(*core.RegionInfo) bool {

// AllowBalanceEmptyRegion returns a function that checks if a region is an empty region and can be balanced.
func AllowBalanceEmptyRegion(cluster Cluster) func(*core.RegionInfo) bool {
switch cluster.GetClusterType() {
case core.RangeCluster:
// allow empty region to be scheduled in range cluster
return func(region *core.RegionInfo) bool { return true }
default:
return func(region *core.RegionInfo) bool { return IsEmptyRegionAllowBalance(cluster, region) }
}
return func(region *core.RegionInfo) bool { return IsEmptyRegionAllowBalance(cluster, region) }
}

// IsRegionReplicated checks if a region is fully replicated. When placement
Expand Down
1 change: 0 additions & 1 deletion server/schedule/opt/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type Cluster interface {
statistics.RegionStatInformer
statistics.StoreStatInformer

GetClusterType() core.ClusterType
GetOpts() *config.PersistOptions
AllocID() (uint64, error)
FitRegion(*core.RegionInfo) *placement.RegionFit
Expand Down
5 changes: 0 additions & 5 deletions server/schedule/range_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ func GenRangeCluster(cluster opt.Cluster, startKey, endKey []byte) *RangeCluster
}
}

// GetClusterType returns the cluster type
func (r *RangeCluster) GetClusterType() core.ClusterType {
return core.RangeCluster
}

func (r *RangeCluster) updateStoreInfo(s *core.StoreInfo) *core.StoreInfo {
id := s.GetID()

Expand Down
19 changes: 15 additions & 4 deletions server/schedulers/balance_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,34 @@ func (s *balanceRegionScheduler) Schedule(cluster opt.Cluster) []*operator.Opera
return stores[i].RegionScore(opts.GetRegionScoreFormulaVersion(), opts.GetHighSpaceRatio(), opts.GetLowSpaceRatio(), iOp) >
stores[j].RegionScore(opts.GetRegionScoreFormulaVersion(), opts.GetHighSpaceRatio(), opts.GetLowSpaceRatio(), jOp)
})

var allowBalanceEmptyRegion func(*core.RegionInfo) bool

switch cluster.(type) {
case *schedule.RangeCluster:
// allow empty region to be scheduled in range cluster
allowBalanceEmptyRegion = func(region *core.RegionInfo) bool { return true }
default:
allowBalanceEmptyRegion = opt.AllowBalanceEmptyRegion(cluster)
}

for _, plan.source = range stores {
for i := 0; i < balanceRegionRetryLimit; i++ {
schedulerCounter.WithLabelValues(s.GetName(), "total").Inc()
// Priority pick the region that has a pending peer.
// Pending region may means the disk is overload, remove the pending region firstly.
plan.region = cluster.RandPendingRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthAllowPending(cluster), opt.ReplicatedRegion(cluster), opt.AllowBalanceEmptyRegion(cluster))
plan.region = cluster.RandPendingRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthAllowPending(cluster), opt.ReplicatedRegion(cluster), allowBalanceEmptyRegion)
if plan.region == nil {
// Then pick the region that has a follower in the source store.
plan.region = cluster.RandFollowerRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthRegion(cluster), opt.ReplicatedRegion(cluster), opt.AllowBalanceEmptyRegion(cluster))
plan.region = cluster.RandFollowerRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthRegion(cluster), opt.ReplicatedRegion(cluster), allowBalanceEmptyRegion)
}
if plan.region == nil {
// Then pick the region has the leader in the source store.
plan.region = cluster.RandLeaderRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthRegion(cluster), opt.ReplicatedRegion(cluster), opt.AllowBalanceEmptyRegion(cluster))
plan.region = cluster.RandLeaderRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthRegion(cluster), opt.ReplicatedRegion(cluster), allowBalanceEmptyRegion)
}
if plan.region == nil {
// Finally pick learner.
plan.region = cluster.RandLearnerRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthRegion(cluster), opt.ReplicatedRegion(cluster), opt.AllowBalanceEmptyRegion(cluster))
plan.region = cluster.RandLearnerRegion(plan.SourceStoreID(), s.conf.Ranges, opt.HealthRegion(cluster), opt.ReplicatedRegion(cluster), allowBalanceEmptyRegion)
}
if plan.region == nil {
schedulerCounter.WithLabelValues(s.GetName(), "no-region").Inc()
Expand Down
6 changes: 3 additions & 3 deletions server/schedulers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ func (p *balancePlan) getTolerantResource() int64 {

func adjustTolerantRatio(cluster opt.Cluster, kind core.ScheduleKind) float64 {
var tolerantSizeRatio float64
switch cluster.GetClusterType() {
case core.RangeCluster:
switch c := cluster.(type) {
case *schedule.RangeCluster:
// range cluster use a separate configuration
tolerantSizeRatio = cluster.(*schedule.RangeCluster).GetTolerantSizeRatio()
tolerantSizeRatio = c.GetTolerantSizeRatio()
default:
tolerantSizeRatio = cluster.GetOpts().GetTolerantSizeRatio()
}
Expand Down

0 comments on commit 861f768

Please sign in to comment.