Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyOperator(mc *mockcluster.Cluster, op *Operator)
- func ApplyOperatorStep(region *core.RegionInfo, op *Operator) *core.RegionInfo
- func CheckOperatorValid(op *Operator) bool
- func DistinctScore(labels []string, stores []*core.StoreInfo, other *core.StoreInfo) float64
- func FilterSource(opt Options, store *core.StoreInfo, filters []Filter) bool
- func FilterTarget(opt Options, store *core.StoreInfo, filters []Filter) bool
- func IsSchedulerRegistered(name string) bool
- func RegisterScheduler(name string, createFn CreateSchedulerFunc)
- type AddLearner
- type AddLightLearner
- type AddLightPeer
- type AddPeer
- type BalanceSelector
- type Bucket
- type Cluster
- type CreateSchedulerFunc
- type Filter
- func NewCacheFilter(scope string, cache *cache.TTLUint64) Filter
- func NewDistinctScoreFilter(scope string, labels []string, stores []*core.StoreInfo, ...) Filter
- func NewExcludedFilter(scope string, sources, targets map[uint64]struct{}) Filter
- func NewHealthFilter(scope string) Filter
- func NewNamespaceFilter(scope string, classifier namespace.Classifier, namespace string) Filter
- func NewOverloadFilter(scope string) Filter
- func NewPendingPeerCountFilter(scope string) Filter
- func NewSnapshotCountFilter(scope string) Filter
- func NewStateFilter(scope string) Filter
- func NewStorageThresholdFilter(scope string) Filter
- type HeartbeatStreams
- type MergeChecker
- type MergeRegion
- type NamespaceChecker
- type OpInfluence
- type Operator
- func CreateAddLearnerOperator(desc string, cluster Cluster, region *core.RegionInfo, peerID uint64, ...) *Operator
- func CreateAddPeerOperator(desc string, cluster Cluster, region *core.RegionInfo, peerID uint64, ...) *Operator
- func CreateMergeRegionOperator(desc string, cluster Cluster, source *core.RegionInfo, target *core.RegionInfo, ...) ([]*Operator, error)
- func CreateMoveLeaderOperator(desc string, cluster Cluster, region *core.RegionInfo, kind OperatorKind, ...) (*Operator, error)
- func CreateMovePeerOperator(desc string, cluster Cluster, region *core.RegionInfo, kind OperatorKind, ...) (*Operator, error)
- func CreateMoveRegionOperator(desc string, cluster Cluster, region *core.RegionInfo, kind OperatorKind, ...) (*Operator, error)
- func CreatePromoteLearnerOperator(desc string, region *core.RegionInfo, peer *metapb.Peer) *Operator
- func CreateRemovePeerOperator(desc string, cluster Cluster, kind OperatorKind, region *core.RegionInfo, ...) (*Operator, error)
- func CreateScatterRegionOperator(desc string, cluster Cluster, origin *core.RegionInfo, ...) *Operator
- func CreateSplitRegionOperator(desc string, region *core.RegionInfo, kind OperatorKind, policy string) *Operator
- func CreateTransferLeaderOperator(desc string, region *core.RegionInfo, sourceStoreID uint64, ...) *Operator
- func NewOperator(desc string, regionID uint64, regionEpoch *metapb.RegionEpoch, ...) *Operator
- func (o *Operator) AttachKind(kind OperatorKind)
- func (o *Operator) Check(region *core.RegionInfo) OperatorStep
- func (o *Operator) Desc() string
- func (o *Operator) ElapsedTime() time.Duration
- func (o *Operator) GetPriorityLevel() core.PriorityLevel
- func (o *Operator) History() []OperatorHistory
- func (o *Operator) IsFinish() bool
- func (o *Operator) IsTimeout() bool
- func (o *Operator) Kind() OperatorKind
- func (o *Operator) Len() int
- func (o *Operator) MarshalJSON() ([]byte, error)
- func (o *Operator) RegionEpoch() *metapb.RegionEpoch
- func (o *Operator) RegionID() uint64
- func (o *Operator) RunningTime() time.Duration
- func (o *Operator) SetDesc(desc string)
- func (o *Operator) SetPriorityLevel(level core.PriorityLevel)
- func (o *Operator) Step(i int) OperatorStep
- func (o *Operator) String() string
- func (o *Operator) TotalInfluence(opInfluence OpInfluence, region *core.RegionInfo)
- func (o *Operator) UnfinishedInfluence(opInfluence OpInfluence, region *core.RegionInfo)
- type OperatorController
- func (oc *OperatorController) AddOperator(ops ...*Operator) bool
- func (oc *OperatorController) AddWaitingOperator(ops ...*Operator) bool
- func (oc *OperatorController) Dispatch(region *core.RegionInfo, source string)
- func (oc *OperatorController) GetAllStoresLimit() map[uint64]float64
- func (oc *OperatorController) GetHistory(start time.Time) []OperatorHistory
- func (oc *OperatorController) GetOpInfluence(cluster Cluster) OpInfluence
- func (oc *OperatorController) GetOperator(regionID uint64) *Operator
- func (oc *OperatorController) GetOperatorStatus(id uint64) *OperatorWithStatus
- func (oc *OperatorController) GetOperators() []*Operator
- func (oc *OperatorController) GetWaitingOperators() []*Operator
- func (oc *OperatorController) OperatorCount(mask OperatorKind) uint64
- func (oc *OperatorController) PromoteWaitingOperator()
- func (oc *OperatorController) PruneHistory()
- func (oc *OperatorController) PushOperators()
- func (oc *OperatorController) RemoveOperator(op *Operator) (found bool)
- func (oc *OperatorController) RemoveStoreLimit(storeID uint64)
- func (oc *OperatorController) SendScheduleCommand(region *core.RegionInfo, step OperatorStep, source string)
- func (oc *OperatorController) SetAllStoresLimit(rate float64)
- func (oc *OperatorController) SetOperator(op *Operator)
- func (oc *OperatorController) SetStoreLimit(storeID uint64, rate float64)
- type OperatorHistory
- type OperatorKind
- type OperatorRecords
- type OperatorStep
- type OperatorWithStatus
- type Options
- type PromoteLearner
- type RandBuckets
- type RandomSelector
- type RangeCluster
- func (r *RangeCluster) GetAverageRegionSize() int64
- func (r *RangeCluster) GetFollowerStores(region *core.RegionInfo) []*core.StoreInfo
- func (r *RangeCluster) GetLeaderStore(region *core.RegionInfo) *core.StoreInfo
- func (r *RangeCluster) GetRegionStores(region *core.RegionInfo) []*core.StoreInfo
- func (r *RangeCluster) GetStore(id uint64) *core.StoreInfo
- func (r *RangeCluster) GetStores() []*core.StoreInfo
- func (r *RangeCluster) GetTolerantSizeRatio() float64
- func (r *RangeCluster) RandFollowerRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo
- func (r *RangeCluster) RandLeaderRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo
- func (r *RangeCluster) SetTolerantSizeRatio(ratio float64)
- type RegionScatterer
- type RegionSetInformer
- type RemovePeer
- type ReplicaChecker
- type ReplicaSelector
- type Scheduler
- type SplitRegion
- type StoreInfluence
- type StoreStateFilter
- type TransferLeader
- type WaitingOperator
- type WaitingOperatorStatus
Constants ¶
const ( // LeaderOperatorWaitTime is the duration that when a leader operator lives // longer than it, the operator will be considered timeout. LeaderOperatorWaitTime = 10 * time.Second // RegionOperatorWaitTime is the duration that when a region operator lives // longer than it, the operator will be considered timeout. RegionOperatorWaitTime = 10 * time.Minute // RegionInfluence represents the influence of a operator step, which is used by ratelimit. RegionInfluence int64 = 1000 )
const ( DispatchFromHeartBeat = "heartbeat" DispatchFromNotifierQueue = "active push" DispatchFromCreate = "create" )
The source of dispatched region.
const ( // RejectLeader is the label property type that suggests a store should not // have any region leaders. RejectLeader = "reject-leader" )
Variables ¶
var ( // PushOperatorTickInterval is the interval try to push the operator. PushOperatorTickInterval = 500 * time.Millisecond // StoreBalanceBaseTime represents the base time of balance rate. StoreBalanceBaseTime float64 = 60 )
var PriorityWeight = []float64{1.0, 4.0, 9.0}
PriorityWeight is used to represent the weight of different priorities of operators.
Functions ¶
func ApplyOperator ¶
func ApplyOperator(mc *mockcluster.Cluster, op *Operator)
ApplyOperator applies operator. Only for test purpose.
func ApplyOperatorStep ¶
func ApplyOperatorStep(region *core.RegionInfo, op *Operator) *core.RegionInfo
ApplyOperatorStep applies operator step. Only for test purpose.
func CheckOperatorValid ¶
CheckOperatorValid checks if the operator is valid.
func DistinctScore ¶
DistinctScore returns the score that the other is distinct from the stores. A higher score means the other store is more different from the existed stores.
func FilterSource ¶
FilterSource checks if store can pass all Filters as source store.
func FilterTarget ¶
FilterTarget checks if store can pass all Filters as target store.
func IsSchedulerRegistered ¶
IsSchedulerRegistered check where the named scheduler type is registered.
func RegisterScheduler ¶
func RegisterScheduler(name string, createFn CreateSchedulerFunc)
RegisterScheduler binds a scheduler creator. It should be called in init() func of a package.
Types ¶
type AddLearner ¶
type AddLearner struct {
ToStore, PeerID uint64
}
AddLearner is an OperatorStep that adds a region learner peer.
func (AddLearner) Influence ¶
func (al AddLearner) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (AddLearner) IsFinish ¶
func (al AddLearner) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (AddLearner) String ¶
func (al AddLearner) String() string
type AddLightLearner ¶
type AddLightLearner struct {
ToStore, PeerID uint64
}
AddLightLearner is an OperatorStep that adds a region learner peer without considering the influence.
func (AddLightLearner) Influence ¶
func (al AddLightLearner) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (AddLightLearner) IsFinish ¶
func (al AddLightLearner) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (AddLightLearner) String ¶
func (al AddLightLearner) String() string
type AddLightPeer ¶
type AddLightPeer struct {
ToStore, PeerID uint64
}
AddLightPeer is an OperatorStep that adds a region peer without considering the influence.
func (AddLightPeer) Influence ¶
func (ap AddLightPeer) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (AddLightPeer) IsFinish ¶
func (ap AddLightPeer) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (AddLightPeer) String ¶
func (ap AddLightPeer) String() string
type AddPeer ¶
type AddPeer struct {
ToStore, PeerID uint64
}
AddPeer is an OperatorStep that adds a region peer.
func (AddPeer) Influence ¶
func (ap AddPeer) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
type BalanceSelector ¶
type BalanceSelector struct {
// contains filtered or unexported fields
}
BalanceSelector selects source/target from store candidates based on their resource scores.
func NewBalanceSelector ¶
func NewBalanceSelector(kind core.ResourceKind, filters []Filter) *BalanceSelector
NewBalanceSelector creates a BalanceSelector instance.
func (*BalanceSelector) SelectSource ¶
SelectSource selects the store that can pass all filters and has the minimal resource score.
func (*BalanceSelector) SelectTarget ¶
func (s *BalanceSelector) SelectTarget(opt Options, stores []*core.StoreInfo, filters ...Filter) *core.StoreInfo
SelectTarget selects the store that can pass all filters and has the maximal resource score.
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket is used to maintain the operators created by a specific scheduler.
type Cluster ¶
type Cluster interface { RegionSetInformer GetStores() []*core.StoreInfo GetStore(id uint64) *core.StoreInfo GetRegionStores(region *core.RegionInfo) []*core.StoreInfo GetFollowerStores(region *core.RegionInfo) []*core.StoreInfo GetLeaderStore(region *core.RegionInfo) *core.StoreInfo BlockStore(id uint64) error UnblockStore(id uint64) AttachOverloadStatus(id uint64, f func() bool) IsRegionHot(id uint64) bool RegionWriteStats() []*statistics.RegionStat RegionReadStats() []*statistics.RegionStat RandHotRegionFromStore(store uint64, kind statistics.FlowKind) *core.RegionInfo // get config methods GetOpt() namespace.ScheduleOptions Options // TODO: it should be removed. Schedulers don't need to know anything // about peers. AllocPeer(storeID uint64) (*metapb.Peer, error) }
Cluster provides an overview of a cluster's regions distribution.
type CreateSchedulerFunc ¶
type CreateSchedulerFunc func(opController *OperatorController, args []string) (Scheduler, error)
CreateSchedulerFunc is for creating scheduler.
type Filter ¶
type Filter interface { // Scope is used to indicate where the filter will act on. Scope() string Type() string // Return true if the store should not be used as a source store. FilterSource(opt Options, store *core.StoreInfo) bool // Return true if the store should not be used as a target store. FilterTarget(opt Options, store *core.StoreInfo) bool }
Filter is an interface to filter source and target store.
func NewCacheFilter ¶
NewCacheFilter creates a Filter that filters all stores that are in the cache.
func NewDistinctScoreFilter ¶
func NewDistinctScoreFilter(scope string, labels []string, stores []*core.StoreInfo, source *core.StoreInfo) Filter
NewDistinctScoreFilter creates a filter that filters all stores that have lower distinct score than specified store.
func NewExcludedFilter ¶
NewExcludedFilter creates a Filter that filters all specified stores.
func NewHealthFilter ¶
NewHealthFilter creates a Filter that filters all stores that are Busy or Down.
func NewNamespaceFilter ¶
func NewNamespaceFilter(scope string, classifier namespace.Classifier, namespace string) Filter
NewNamespaceFilter creates a Filter that filters all stores that are not belong to a namespace.
func NewOverloadFilter ¶
NewOverloadFilter creates a Filter that filters all stores that are overloaded from balance.
func NewPendingPeerCountFilter ¶
NewPendingPeerCountFilter creates a Filter that filters all stores that are currently handling too many pending peers.
func NewSnapshotCountFilter ¶
NewSnapshotCountFilter creates a Filter that filters all stores that are currently handling too many snapshots.
func NewStateFilter ¶
NewStateFilter creates a Filter that filters all stores that are not UP.
func NewStorageThresholdFilter ¶
NewStorageThresholdFilter creates a Filter that filters all stores that are almost full.
type HeartbeatStreams ¶
type HeartbeatStreams interface {
SendMsg(region *core.RegionInfo, msg *pdpb.RegionHeartbeatResponse)
}
HeartbeatStreams is an interface of async region heartbeat.
type MergeChecker ¶
type MergeChecker struct {
// contains filtered or unexported fields
}
MergeChecker ensures region to merge with adjacent region when size is small
func NewMergeChecker ¶
func NewMergeChecker(cluster Cluster, classifier namespace.Classifier) *MergeChecker
NewMergeChecker creates a merge checker.
func (*MergeChecker) Check ¶
func (m *MergeChecker) Check(region *core.RegionInfo) []*Operator
Check verifies a region's replicas, creating an Operator if need.
func (*MergeChecker) RecordRegionSplit ¶
func (m *MergeChecker) RecordRegionSplit(regionID uint64)
RecordRegionSplit put the recently splitted region into cache. MergeChecker will skip check it for a while.
type MergeRegion ¶
type MergeRegion struct { FromRegion *metapb.Region ToRegion *metapb.Region // there are two regions involved in merge process, // so to keep them from other scheduler, // both of them should add MerRegion operatorStep. // But actually, TiKV just needs the region want to be merged to get the merge request, // thus use a IsPassive mark to indicate that // this region doesn't need to send merge request to TiKV. IsPassive bool }
MergeRegion is an OperatorStep that merge two regions.
func (MergeRegion) Influence ¶
func (mr MergeRegion) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (MergeRegion) IsFinish ¶
func (mr MergeRegion) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (MergeRegion) String ¶
func (mr MergeRegion) String() string
type NamespaceChecker ¶
type NamespaceChecker struct {
// contains filtered or unexported fields
}
NamespaceChecker ensures region to go to the right place.
func NewNamespaceChecker ¶
func NewNamespaceChecker(cluster Cluster, classifier namespace.Classifier) *NamespaceChecker
NewNamespaceChecker creates a namespace checker.
func (*NamespaceChecker) Check ¶
func (n *NamespaceChecker) Check(region *core.RegionInfo) *Operator
Check verifies a region's namespace, creating an Operator if need.
func (*NamespaceChecker) SelectBestPeerToRelocate ¶
func (n *NamespaceChecker) SelectBestPeerToRelocate(region *core.RegionInfo, targets []*core.StoreInfo) *metapb.Peer
SelectBestPeerToRelocate return a new peer that to be used to move a region
func (*NamespaceChecker) SelectBestStoreToRelocate ¶
func (n *NamespaceChecker) SelectBestStoreToRelocate(region *core.RegionInfo, targets []*core.StoreInfo) uint64
SelectBestStoreToRelocate randomly returns the store to relocate
type OpInfluence ¶
type OpInfluence struct {
// contains filtered or unexported fields
}
OpInfluence records the influence of the cluster.
func NewTotalOpInfluence ¶
func NewTotalOpInfluence(operators []*Operator, cluster Cluster) OpInfluence
NewTotalOpInfluence creates a OpInfluence.
func NewUnfinishedOpInfluence ¶
func NewUnfinishedOpInfluence(operators []*Operator, cluster Cluster) OpInfluence
NewUnfinishedOpInfluence creates a OpInfluence.
func (OpInfluence) GetStoreInfluence ¶
func (m OpInfluence) GetStoreInfluence(id uint64) *StoreInfluence
GetStoreInfluence get storeInfluence of specific store.
type Operator ¶
type Operator struct {
// contains filtered or unexported fields
}
Operator contains execution steps generated by scheduler.
func CreateAddLearnerOperator ¶
func CreateAddLearnerOperator(desc string, cluster Cluster, region *core.RegionInfo, peerID uint64, toStoreID uint64, kind OperatorKind) *Operator
CreateAddLearnerOperator creates an operator that adds a new learner.
func CreateAddPeerOperator ¶
func CreateAddPeerOperator(desc string, cluster Cluster, region *core.RegionInfo, peerID uint64, toStoreID uint64, kind OperatorKind) *Operator
CreateAddPeerOperator creates an operator that adds a new peer.
func CreateMergeRegionOperator ¶
func CreateMergeRegionOperator(desc string, cluster Cluster, source *core.RegionInfo, target *core.RegionInfo, kind OperatorKind) ([]*Operator, error)
CreateMergeRegionOperator creates an operator that merge two region into one.
func CreateMoveLeaderOperator ¶
func CreateMoveLeaderOperator(desc string, cluster Cluster, region *core.RegionInfo, kind OperatorKind, oldStore, newStore uint64, peerID uint64) (*Operator, error)
CreateMoveLeaderOperator creates an operator that replaces an old leader with a new leader.
func CreateMovePeerOperator ¶
func CreateMovePeerOperator(desc string, cluster Cluster, region *core.RegionInfo, kind OperatorKind, oldStore, newStore uint64, peerID uint64) (*Operator, error)
CreateMovePeerOperator creates an operator that replaces an old peer with a new peer.
func CreateMoveRegionOperator ¶
func CreateMoveRegionOperator(desc string, cluster Cluster, region *core.RegionInfo, kind OperatorKind, storeIDs map[uint64]struct{}) (*Operator, error)
CreateMoveRegionOperator creates an operator that moves a region to specified stores.
func CreatePromoteLearnerOperator ¶
func CreatePromoteLearnerOperator(desc string, region *core.RegionInfo, peer *metapb.Peer) *Operator
CreatePromoteLearnerOperator creates an operator that promotes a learner.
func CreateRemovePeerOperator ¶
func CreateRemovePeerOperator(desc string, cluster Cluster, kind OperatorKind, region *core.RegionInfo, storeID uint64) (*Operator, error)
CreateRemovePeerOperator creates an operator that removes a peer from region.
func CreateScatterRegionOperator ¶
func CreateScatterRegionOperator(desc string, cluster Cluster, origin *core.RegionInfo, replacedPeers, targetPeers []*metapb.Peer) *Operator
CreateScatterRegionOperator creates an operator that scatters the specified region.
func CreateSplitRegionOperator ¶
func CreateSplitRegionOperator(desc string, region *core.RegionInfo, kind OperatorKind, policy string) *Operator
CreateSplitRegionOperator creates an operator that splits a region.
func CreateTransferLeaderOperator ¶
func CreateTransferLeaderOperator(desc string, region *core.RegionInfo, sourceStoreID uint64, targetStoreID uint64, kind OperatorKind) *Operator
CreateTransferLeaderOperator creates an operator that transfers the leader from a source store to a target store.
func NewOperator ¶
func NewOperator(desc string, regionID uint64, regionEpoch *metapb.RegionEpoch, kind OperatorKind, steps ...OperatorStep) *Operator
NewOperator creates a new operator.
func (*Operator) AttachKind ¶
func (o *Operator) AttachKind(kind OperatorKind)
AttachKind attaches an operator kind for the operator.
func (*Operator) Check ¶
func (o *Operator) Check(region *core.RegionInfo) OperatorStep
Check checks if current step is finished, returns next step to take action. It's safe to be called by multiple goroutine concurrently.
func (*Operator) ElapsedTime ¶
ElapsedTime returns duration since it was created.
func (*Operator) GetPriorityLevel ¶
func (o *Operator) GetPriorityLevel() core.PriorityLevel
GetPriorityLevel gets the priority level.
func (*Operator) History ¶
func (o *Operator) History() []OperatorHistory
History transfers the operator's steps to operator histories.
func (*Operator) IsTimeout ¶
IsTimeout checks the operator's create time and determines if it is timeout.
func (*Operator) MarshalJSON ¶
MarshalJSON serializes custom types to JSON.
func (*Operator) RegionEpoch ¶
func (o *Operator) RegionEpoch() *metapb.RegionEpoch
RegionEpoch returns the region's epoch that is attached to the operator.
func (*Operator) RunningTime ¶
RunningTime returns duration since it was promoted.
func (*Operator) SetPriorityLevel ¶
func (o *Operator) SetPriorityLevel(level core.PriorityLevel)
SetPriorityLevel sets the priority level for operator.
func (*Operator) TotalInfluence ¶
func (o *Operator) TotalInfluence(opInfluence OpInfluence, region *core.RegionInfo)
TotalInfluence calculates the store difference which whole operator steps make.
func (*Operator) UnfinishedInfluence ¶
func (o *Operator) UnfinishedInfluence(opInfluence OpInfluence, region *core.RegionInfo)
UnfinishedInfluence calculates the store difference which unfinished operator steps make.
type OperatorController ¶
OperatorController is used to limit the speed of scheduling.
func NewOperatorController ¶
func NewOperatorController(cluster Cluster, hbStreams HeartbeatStreams) *OperatorController
NewOperatorController creates a OperatorController.
func (*OperatorController) AddOperator ¶
func (oc *OperatorController) AddOperator(ops ...*Operator) bool
AddOperator adds operators to the running operators.
func (*OperatorController) AddWaitingOperator ¶
func (oc *OperatorController) AddWaitingOperator(ops ...*Operator) bool
AddWaitingOperator adds operators to waiting operators.
func (*OperatorController) Dispatch ¶
func (oc *OperatorController) Dispatch(region *core.RegionInfo, source string)
Dispatch is used to dispatch the operator of a region.
func (*OperatorController) GetAllStoresLimit ¶
func (oc *OperatorController) GetAllStoresLimit() map[uint64]float64
GetAllStoresLimit is used to get limit of all stores.
func (*OperatorController) GetHistory ¶
func (oc *OperatorController) GetHistory(start time.Time) []OperatorHistory
GetHistory gets operators' history.
func (*OperatorController) GetOpInfluence ¶
func (oc *OperatorController) GetOpInfluence(cluster Cluster) OpInfluence
GetOpInfluence gets OpInfluence.
func (*OperatorController) GetOperator ¶
func (oc *OperatorController) GetOperator(regionID uint64) *Operator
GetOperator gets a operator from the given region.
func (*OperatorController) GetOperatorStatus ¶
func (oc *OperatorController) GetOperatorStatus(id uint64) *OperatorWithStatus
GetOperatorStatus gets the operator and its status with the specify id.
func (*OperatorController) GetOperators ¶
func (oc *OperatorController) GetOperators() []*Operator
GetOperators gets operators from the running operators.
func (*OperatorController) GetWaitingOperators ¶
func (oc *OperatorController) GetWaitingOperators() []*Operator
GetWaitingOperators gets operators from the waiting operators.
func (*OperatorController) OperatorCount ¶
func (oc *OperatorController) OperatorCount(mask OperatorKind) uint64
OperatorCount gets the count of operators filtered by mask.
func (*OperatorController) PromoteWaitingOperator ¶
func (oc *OperatorController) PromoteWaitingOperator()
PromoteWaitingOperator promotes operators from waiting operators.
func (*OperatorController) PruneHistory ¶
func (oc *OperatorController) PruneHistory()
PruneHistory prunes a part of operators' history.
func (*OperatorController) PushOperators ¶
func (oc *OperatorController) PushOperators()
PushOperators periodically pushes the unfinished operator to the executor(TiKV).
func (*OperatorController) RemoveOperator ¶
func (oc *OperatorController) RemoveOperator(op *Operator) (found bool)
RemoveOperator removes a operator from the running operators.
func (*OperatorController) RemoveStoreLimit ¶
func (oc *OperatorController) RemoveStoreLimit(storeID uint64)
RemoveStoreLimit removes the store limit for a given store ID.
func (*OperatorController) SendScheduleCommand ¶
func (oc *OperatorController) SendScheduleCommand(region *core.RegionInfo, step OperatorStep, source string)
SendScheduleCommand sends a command to the region.
func (*OperatorController) SetAllStoresLimit ¶
func (oc *OperatorController) SetAllStoresLimit(rate float64)
SetAllStoresLimit is used to set limit of all stores.
func (*OperatorController) SetOperator ¶
func (oc *OperatorController) SetOperator(op *Operator)
SetOperator is only used for test.
func (*OperatorController) SetStoreLimit ¶
func (oc *OperatorController) SetStoreLimit(storeID uint64, rate float64)
SetStoreLimit is used to set the limit of a store.
type OperatorHistory ¶
type OperatorHistory struct { FinishTime time.Time From, To uint64 Kind core.ResourceKind }
OperatorHistory is used to log and visualize completed operators.
type OperatorKind ¶
type OperatorKind uint32
OperatorKind is a bit field to identify operator types.
const ( OpLeader OperatorKind = 1 << iota // Include leader transfer. OpRegion // Include peer movement. OpAdmin // Initiated by admin. OpHotRegion // Initiated by hot region scheduler. OpAdjacent // Initiated by adjacent region scheduler. OpReplica // Initiated by replica checkers. OpBalance // Initiated by balancers. OpMerge // Initiated by merge checkers or merge schedulers. OpRange // Initiated by range scheduler. )
Flags for operators.
func ParseOperatorKind ¶
func ParseOperatorKind(str string) (OperatorKind, error)
ParseOperatorKind converts string (flag name list concat by ',') to OperatorKind.
func (OperatorKind) String ¶
func (k OperatorKind) String() string
type OperatorRecords ¶
type OperatorRecords struct {
// contains filtered or unexported fields
}
OperatorRecords remains the operator and its status for a while.
func NewOperatorRecords ¶
func NewOperatorRecords() *OperatorRecords
NewOperatorRecords returns a OperatorRecords.
func (*OperatorRecords) Get ¶
func (o *OperatorRecords) Get(id uint64) *OperatorWithStatus
Get gets the operator and its status.
func (*OperatorRecords) Put ¶
func (o *OperatorRecords) Put(op *Operator, status pdpb.OperatorStatus)
Put puts the operator and its status.
type OperatorStep ¶
type OperatorStep interface { fmt.Stringer IsFinish(region *core.RegionInfo) bool Influence(opInfluence OpInfluence, region *core.RegionInfo) }
OperatorStep describes the basic scheduling steps that can not be subdivided.
func CreateAddLightPeerSteps ¶
func CreateAddLightPeerSteps(newStore uint64, peerID uint64, cluster Cluster) []OperatorStep
CreateAddLightPeerSteps creates an OperatorStep list that add a new peer without considering the influence.
func CreateAddPeerSteps ¶
func CreateAddPeerSteps(newStore uint64, peerID uint64, cluster Cluster) []OperatorStep
CreateAddPeerSteps creates an OperatorStep list that add a new peer.
type OperatorWithStatus ¶
type OperatorWithStatus struct { Op *Operator Status pdpb.OperatorStatus }
OperatorWithStatus records the operator and its status.
func (*OperatorWithStatus) MarshalJSON ¶
func (o *OperatorWithStatus) MarshalJSON() ([]byte, error)
MarshalJSON returns the status of operator as a JSON string
type Options ¶
type Options interface { GetLeaderScheduleLimit() uint64 GetRegionScheduleLimit() uint64 GetReplicaScheduleLimit() uint64 GetMergeScheduleLimit() uint64 GetHotRegionScheduleLimit() uint64 // store limit GetStoreBalanceRate() float64 GetMaxSnapshotCount() uint64 GetMaxPendingPeerCount() uint64 GetMaxStoreDownTime() time.Duration GetMaxMergeRegionSize() uint64 GetMaxMergeRegionKeys() uint64 GetSplitMergeInterval() time.Duration GetEnableOneWayMerge() bool GetMaxReplicas() int GetLocationLabels() []string GetStrictlyMatchLabel() bool GetHotRegionCacheHitsThreshold() int GetTolerantSizeRatio() float64 GetLowSpaceRatio() float64 GetHighSpaceRatio() float64 GetSchedulerMaxWaitingOperator() uint64 IsRaftLearnerEnabled() bool IsRemoveDownReplicaEnabled() bool IsReplaceOfflineReplicaEnabled() bool IsMakeUpReplicaEnabled() bool IsRemoveExtraReplicaEnabled() bool IsLocationReplacementEnabled() bool IsNamespaceRelocationEnabled() bool CheckLabelProperty(typ string, labels []*metapb.StoreLabel) bool }
Options for schedulers.
type PromoteLearner ¶
type PromoteLearner struct {
ToStore, PeerID uint64
}
PromoteLearner is an OperatorStep that promotes a region learner peer to normal voter.
func (PromoteLearner) Influence ¶
func (pl PromoteLearner) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (PromoteLearner) IsFinish ¶
func (pl PromoteLearner) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (PromoteLearner) String ¶
func (pl PromoteLearner) String() string
type RandBuckets ¶
type RandBuckets struct {
// contains filtered or unexported fields
}
RandBuckets is an implementation of waiting operators
func (*RandBuckets) GetOperator ¶
func (b *RandBuckets) GetOperator() []*Operator
GetOperator gets an operator from the random buckets.
func (*RandBuckets) ListOperator ¶
func (b *RandBuckets) ListOperator() []*Operator
ListOperator lists all operator in the random buckets.
func (*RandBuckets) PutOperator ¶
func (b *RandBuckets) PutOperator(op *Operator)
PutOperator puts an operator into the random buckets.
type RandomSelector ¶
type RandomSelector struct {
// contains filtered or unexported fields
}
RandomSelector selects source/target store randomly.
func NewRandomSelector ¶
func NewRandomSelector(filters []Filter) *RandomSelector
NewRandomSelector creates a RandomSelector instance.
func (*RandomSelector) SelectSource ¶
SelectSource randomly selects a source store from those can pass all filters.
func (*RandomSelector) SelectTarget ¶
func (s *RandomSelector) SelectTarget(opt Options, stores []*core.StoreInfo, filters ...Filter) *core.StoreInfo
SelectTarget randomly selects a target store from those can pass all filters.
type RangeCluster ¶
type RangeCluster struct { Cluster // contains filtered or unexported fields }
RangeCluster isolates the cluster by range.
func GenRangeCluster ¶
func GenRangeCluster(cluster Cluster, startKey, endKey []byte) *RangeCluster
GenRangeCluster gets a range cluster by specifying start key and end key. The cluster can only know the regions within [startKey, endKey].
func (*RangeCluster) GetAverageRegionSize ¶
func (r *RangeCluster) GetAverageRegionSize() int64
GetAverageRegionSize returns the average region approximate size.
func (*RangeCluster) GetFollowerStores ¶
func (r *RangeCluster) GetFollowerStores(region *core.RegionInfo) []*core.StoreInfo
GetFollowerStores returns all stores that contains the region's follower peer.
func (*RangeCluster) GetLeaderStore ¶
func (r *RangeCluster) GetLeaderStore(region *core.RegionInfo) *core.StoreInfo
GetLeaderStore returns all stores that contains the region's leader peer.
func (*RangeCluster) GetRegionStores ¶
func (r *RangeCluster) GetRegionStores(region *core.RegionInfo) []*core.StoreInfo
GetRegionStores returns all stores that contains the region's peer.
func (*RangeCluster) GetStore ¶
func (r *RangeCluster) GetStore(id uint64) *core.StoreInfo
GetStore searches for a store by ID.
func (*RangeCluster) GetStores ¶
func (r *RangeCluster) GetStores() []*core.StoreInfo
GetStores returns all Stores in the cluster.
func (*RangeCluster) GetTolerantSizeRatio ¶
func (r *RangeCluster) GetTolerantSizeRatio() float64
GetTolerantSizeRatio gets the tolerant size ratio.
func (*RangeCluster) RandFollowerRegion ¶
func (r *RangeCluster) RandFollowerRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo
RandFollowerRegion returns a random region that has a follower on the store.
func (*RangeCluster) RandLeaderRegion ¶
func (r *RangeCluster) RandLeaderRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo
RandLeaderRegion returns a random region that has leader on the store.
func (*RangeCluster) SetTolerantSizeRatio ¶
func (r *RangeCluster) SetTolerantSizeRatio(ratio float64)
SetTolerantSizeRatio sets the tolerant size ratio.
type RegionScatterer ¶
type RegionScatterer struct {
// contains filtered or unexported fields
}
RegionScatterer scatters regions.
func NewRegionScatterer ¶
func NewRegionScatterer(cluster Cluster, classifier namespace.Classifier) *RegionScatterer
NewRegionScatterer creates a region scatterer. RegionScatter is used for the `Lightning`, it will scatter the specified regions before import data.
func (*RegionScatterer) Scatter ¶
func (r *RegionScatterer) Scatter(region *core.RegionInfo) (*Operator, error)
Scatter relocates the region.
type RegionSetInformer ¶
type RegionSetInformer interface { RandFollowerRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo RandLeaderRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo RandPendingRegion(storeID uint64, opts ...core.RegionOption) *core.RegionInfo GetAverageRegionSize() int64 GetStoreRegionCount(storeID uint64) int GetRegion(id uint64) *core.RegionInfo GetAdjacentRegions(region *core.RegionInfo) (*core.RegionInfo, *core.RegionInfo) ScanRegions(startKey []byte, limit int) []*core.RegionInfo }
RegionSetInformer provides access to a shared informer of regions. TODO: move to core package
type RemovePeer ¶
type RemovePeer struct {
FromStore uint64
}
RemovePeer is an OperatorStep that removes a region peer.
func (RemovePeer) Influence ¶
func (rp RemovePeer) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (RemovePeer) IsFinish ¶
func (rp RemovePeer) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (RemovePeer) String ¶
func (rp RemovePeer) String() string
type ReplicaChecker ¶
type ReplicaChecker struct {
// contains filtered or unexported fields
}
ReplicaChecker ensures region has the best replicas. Including the following: Replica number management. Unhealth replica management, mainly used for disaster recovery of TiKV. Location management, mainly used for cross data center deployment.
func NewReplicaChecker ¶
func NewReplicaChecker(cluster Cluster, classifier namespace.Classifier, n ...string) *ReplicaChecker
NewReplicaChecker creates a replica checker.
func (*ReplicaChecker) Check ¶
func (r *ReplicaChecker) Check(region *core.RegionInfo) *Operator
Check verifies a region's replicas, creating an Operator if need.
func (*ReplicaChecker) SelectBestReplacementStore ¶
func (r *ReplicaChecker) SelectBestReplacementStore(region *core.RegionInfo, oldPeer *metapb.Peer, filters ...Filter) (uint64, float64)
SelectBestReplacementStore returns a store id that to be used to replace the old peer and distinct score.
type ReplicaSelector ¶
type ReplicaSelector struct {
// contains filtered or unexported fields
}
ReplicaSelector selects source/target store candidates based on their distinct scores based on a region's peer stores.
func NewReplicaSelector ¶
func NewReplicaSelector(regionStores []*core.StoreInfo, labels []string, filters ...Filter) *ReplicaSelector
NewReplicaSelector creates a ReplicaSelector instance.
func (*ReplicaSelector) SelectSource ¶
SelectSource selects the store that can pass all filters and has the minimal distinct score.
func (*ReplicaSelector) SelectTarget ¶
func (s *ReplicaSelector) SelectTarget(opt Options, stores []*core.StoreInfo, filters ...Filter) *core.StoreInfo
SelectTarget selects the store that can pass all filters and has the maximal distinct score.
type Scheduler ¶
type Scheduler interface { GetName() string // GetType should in accordance with the name passing to schedule.RegisterScheduler() GetType() string GetMinInterval() time.Duration GetNextInterval(interval time.Duration) time.Duration Prepare(cluster Cluster) error Cleanup(cluster Cluster) Schedule(cluster Cluster) []*Operator IsScheduleAllowed(cluster Cluster) bool }
Scheduler is an interface to schedule resources.
func CreateScheduler ¶
func CreateScheduler(name string, opController *OperatorController, args ...string) (Scheduler, error)
CreateScheduler creates a scheduler with registered creator func.
type SplitRegion ¶
type SplitRegion struct {
StartKey, EndKey []byte
Policy pdpb.CheckPolicy
}
SplitRegion is an OperatorStep that splits a region.
func (SplitRegion) Influence ¶
func (sr SplitRegion) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (SplitRegion) IsFinish ¶
func (sr SplitRegion) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (SplitRegion) String ¶
func (sr SplitRegion) String() string
type StoreInfluence ¶
type StoreInfluence struct { RegionSize int64 RegionCount int64 LeaderSize int64 LeaderCount int64 StepCost int64 }
StoreInfluence records influences that pending operators will make.
func (StoreInfluence) ResourceSize ¶
func (s StoreInfluence) ResourceSize(kind core.ResourceKind) int64
ResourceSize returns delta size of leader/region by influence.
type StoreStateFilter ¶
type StoreStateFilter struct { ActionScope string // Set true if the schedule involves any transfer leader operation. TransferLeader bool // Set true if the schedule involves any move region operation. MoveRegion bool }
StoreStateFilter is used to determine whether a store can be selected as the source or target of the schedule based on the store's state.
func (StoreStateFilter) FilterSource ¶
func (f StoreStateFilter) FilterSource(opt Options, store *core.StoreInfo) bool
FilterSource returns true when the store cannot be selected as the schedule source.
func (StoreStateFilter) FilterTarget ¶
func (f StoreStateFilter) FilterTarget(opt Options, store *core.StoreInfo) bool
FilterTarget returns true when the store cannot be selected as the schedule target.
func (StoreStateFilter) Scope ¶
func (f StoreStateFilter) Scope() string
Scope returns the scheduler or the checker which the filter acts on.
func (StoreStateFilter) Type ¶
func (f StoreStateFilter) Type() string
Type returns the type of the Filter.
type TransferLeader ¶
type TransferLeader struct {
FromStore, ToStore uint64
}
TransferLeader is an OperatorStep that transfers a region's leader.
func (TransferLeader) Influence ¶
func (tl TransferLeader) Influence(opInfluence OpInfluence, region *core.RegionInfo)
Influence calculates the store difference that current step makes.
func (TransferLeader) IsFinish ¶
func (tl TransferLeader) IsFinish(region *core.RegionInfo) bool
IsFinish checks if current step is finished.
func (TransferLeader) String ¶
func (tl TransferLeader) String() string
type WaitingOperator ¶
type WaitingOperator interface { PutOperator(op *Operator) GetOperator() []*Operator ListOperator() []*Operator }
WaitingOperator is an interface of waiting operators.
type WaitingOperatorStatus ¶
type WaitingOperatorStatus struct {
// contains filtered or unexported fields
}
WaitingOperatorStatus is used to limit the count of each kind of operators.
func NewWaitingOperatorStatus ¶
func NewWaitingOperatorStatus() *WaitingOperatorStatus
NewWaitingOperatorStatus creates a new WaitingOperatorStatus.