filter

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BalanceLeader is the filter type for balance leader.
	BalanceLeader scope = iota
	// BalanceRegion is the filter type for balance region.
	BalanceRegion
	// BalanceHotRegion is the filter type for hot region.
	BalanceHotRegion
	// BalanceWitness is the filter type for balance witness.
	BalanceWitness
	// Label is the filter type for replica.
	Label

	// EvictLeader is the filter type for evict leader.
	EvictLeader
	// RegionScatter is the filter type for scatter region.
	RegionScatter
	// ReplicaChecker is the filter type for replica.
	ReplicaChecker
	// RuleChecker is the filter type for rule.
	RuleChecker

	// GrantHotLeader is the filter type for grant hot leader.
	GrantHotLeader
	// ShuffleHotRegion is the filter type for shuffle hot region.
	ShuffleHotRegion
	// ShuffleRegion is the filter type for shuffle region.
	ShuffleRegion
	// RandomMerge is the filter type for random merge.
	RandomMerge
)
View Source
const (
	// 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"
)

Variables

View Source
var (

	// NotSpecialEngines is used to filter the special engine.
	NotSpecialEngines = placement.LabelConstraint{Key: core.EngineKey, Op: placement.NotIn, Values: allSpecialEngines}
)

Functions

func IsRegionHealthy

func IsRegionHealthy(region *core.RegionInfo) bool

IsRegionHealthy checks if a region is healthy for scheduling. It requires the region does not have any down or pending peers.

func IsRegionHealthyAllowPending

func IsRegionHealthyAllowPending(region *core.RegionInfo) bool

IsRegionHealthyAllowPending checks if a region is healthy for scheduling. Differs from IsRegionHealthy, it allows the region to have pending peers.

func IsRegionReplicated

func IsRegionReplicated(cluster regionHealthCluster, region *core.RegionInfo) bool

IsRegionReplicated checks if a region is fully replicated. When placement rules is enabled, its peers should fit corresponding rules. When placement rules is disabled, it should have enough replicas and no any learner peer.

func ReplicatedRegion

func ReplicatedRegion(cluster regionHealthCluster) func(*core.RegionInfo) bool

ReplicatedRegion returns a function that checks if a region is fully replicated.

func SelectOneRegion

func SelectOneRegion(regions []*core.RegionInfo, collector *plan.Collector, filters ...RegionFilter) *core.RegionInfo

SelectOneRegion selects one region that be selected from the list.

func SelectRegions

func SelectRegions(regions []*core.RegionInfo, filters ...RegionFilter) []*core.RegionInfo

SelectRegions selects regions that be selected from the list.

func SelectSourceStores

func SelectSourceStores(stores []*core.StoreInfo, filters []Filter, conf config.Config, collector *plan.Collector,
	counter *Counter) []*core.StoreInfo

SelectSourceStores selects stores that be selected as source store from the list.

func SelectTargetStores

func SelectTargetStores(stores []*core.StoreInfo, filters []Filter, conf config.Config, collector *plan.Collector,
	counter *Counter) []*core.StoreInfo

SelectTargetStores selects stores that be selected as target store from the list.

func SelectUnavailableTargetStores

func SelectUnavailableTargetStores(stores []*core.StoreInfo, filters []Filter, conf config.Config,
	collector *plan.Collector, counter *Counter) []*core.StoreInfo

SelectUnavailableTargetStores selects unavailable stores that can't be selected as target store from the list.

func Target

func Target(conf config.Config, store *core.StoreInfo, filters []Filter) bool

Target checks if store can pass all Filters as target store.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter records the filter counter.

func NewCounter

func NewCounter(scope string) *Counter

NewCounter creates a Counter.

func (*Counter) Flush

func (c *Counter) Flush()

Flush flushes the counter to the metrics.

type Filter

type Filter interface {
	// Scope is used to indicate where the filter will act on.
	Scope() string
	Type() filterType
	// Source Return plan.Status to show whether be filtered as source
	Source(conf config.Config, store *core.StoreInfo) *plan.Status
	// Target Return plan.Status to show whether be filtered as target
	Target(conf config.Config, store *core.StoreInfo) *plan.Status
}

Filter is an interface to filter source and target store.

func NewEngineFilter

func NewEngineFilter(scope string, constraint placement.LabelConstraint) Filter

NewEngineFilter creates a filter that only keeps allowedEngines.

func NewExcludedFilter

func NewExcludedFilter(scope string, sources, targets map[uint64]struct{}) Filter

NewExcludedFilter creates a Filter that filters all specified stores.

func NewIsolationFilter

func NewIsolationFilter(scope, isolationLevel string, locationLabels []string, regionStores []*core.StoreInfo) Filter

NewIsolationFilter creates a filter that filters out stores with isolationLevel For example, a region has 3 replicas in z1, z2 and z3 individually. With isolationLevel = zone, if the region on z1 is down, we need to filter out z2 and z3 because these two zones already have one of the region's replicas on them. We need to choose a store on z1 or z4 to place the new replica to meet the isolationLevel explicitly and forcibly.

func NewLabelConstraintFilter

func NewLabelConstraintFilter(scope string, constraints []placement.LabelConstraint) Filter

NewLabelConstraintFilter creates a filter that selects stores satisfy the constraints.

func NewLocationImprover

func NewLocationImprover(scope string, labels []string, stores []*core.StoreInfo, source *core.StoreInfo) Filter

NewLocationImprover creates a filter that filters all stores that have lower or equal distinct score than specified store.

func NewLocationSafeguard

func NewLocationSafeguard(scope string, labels []string, stores []*core.StoreInfo, source *core.StoreInfo) Filter

NewLocationSafeguard creates a filter that filters all stores that have lower distinct score than specified store.

func NewPlacementLeaderSafeguard

func NewPlacementLeaderSafeguard(scope string, conf config.Config, cluster *core.BasicCluster, ruleManager *placement.RuleManager, region *core.RegionInfo, sourceStore *core.StoreInfo, allowMoveLeader bool) Filter

NewPlacementLeaderSafeguard creates a filter that ensures after transfer a leader with existed peer, the placement restriction will not become worse. Note that it only worked when PlacementRules enabled otherwise it will always permit the sourceStore.

func NewPlacementSafeguard

func NewPlacementSafeguard(scope string, conf config.Config, cluster *core.BasicCluster, ruleManager *placement.RuleManager,
	region *core.RegionInfo, sourceStore *core.StoreInfo, oldFit *placement.RegionFit) Filter

NewPlacementSafeguard creates a filter that ensures after replace a peer with new peer, the placement restriction will not become worse.

func NewPlacementWitnessSafeguard

func NewPlacementWitnessSafeguard(scope string, conf config.Config, cluster *core.BasicCluster, ruleManager *placement.RuleManager,
	region *core.RegionInfo, sourceStore *core.StoreInfo, oldFit *placement.RegionFit) Filter

NewPlacementWitnessSafeguard creates a filter that ensures after transfer a witness with existed peer, the placement restriction will not become worse. Note that it only worked when PlacementRules enabled otherwise it will always permit the sourceStore.

func NewSpecialUseFilter

func NewSpecialUseFilter(scope string, allowUses ...string) Filter

NewSpecialUseFilter creates a filter that filters out normal stores. By default, all stores that are not marked with a special use will be filtered out. Specify the special use label if you want to include the special stores.

func NewStorageThresholdFilter

func NewStorageThresholdFilter(scope string) Filter

NewStorageThresholdFilter creates a Filter that filters all stores that are almost full.

type RegionFilter

type RegionFilter interface {
	// Return plan.Status show whether be filtered
	Select(region *core.RegionInfo) *plan.Status
}

RegionFilter is an interface to filter region.

func NewRegionDownFilter

func NewRegionDownFilter() RegionFilter

NewRegionDownFilter creates a RegionFilter that filters all regions with down peers.

func NewRegionEmptyFilter

func NewRegionEmptyFilter(cluster regionHealthCluster) RegionFilter

NewRegionEmptyFilter returns creates a RegionFilter that filters all empty regions.

func NewRegionPendingFilter

func NewRegionPendingFilter() RegionFilter

NewRegionPendingFilter creates a RegionFilter that filters all regions with pending peers.

func NewRegionReplicatedFilter

func NewRegionReplicatedFilter(cluster regionHealthCluster) RegionFilter

NewRegionReplicatedFilter creates a RegionFilter that filters all unreplicated regions.

func NewRegionWitnessFilter

func NewRegionWitnessFilter(storeID uint64) RegionFilter

NewRegionWitnessFilter returns creates a RegionFilter that filters regions with witness peer on the specific store.

func NewSnapshotSendFilter

func NewSnapshotSendFilter(stores []*core.StoreInfo, level constant.PriorityLevel) RegionFilter

NewSnapshotSendFilter returns creates a RegionFilter that filters regions with witness peer on the specific store. level should be set as same with the operator priority level.

type RegionReplicatedFilter

type RegionReplicatedFilter struct {
	// contains filtered or unexported fields
}

RegionReplicatedFilter filters all unreplicated regions.

func (*RegionReplicatedFilter) GetFit

GetFit returns the region fit.

func (*RegionReplicatedFilter) Select

func (f *RegionReplicatedFilter) Select(region *core.RegionInfo) *plan.Status

Select returns Ok if the given region satisfy the replication. it will cache the lasted region fit if the region satisfy the replication.

type SnapshotSenderFilter

type SnapshotSenderFilter struct {
	// contains filtered or unexported fields
}

SnapshotSenderFilter filer the region who's leader store reaches the limit.

func (*SnapshotSenderFilter) Select

func (f *SnapshotSenderFilter) Select(region *core.RegionInfo) *plan.Status

Select returns ok if the region leader in the senders.

type StoreCandidates

type StoreCandidates struct {
	Stores []*core.StoreInfo
	// contains filtered or unexported fields
}

StoreCandidates wraps store list and provide utilities to select source or target store to schedule.

func NewCandidates

func NewCandidates(stores []*core.StoreInfo) *StoreCandidates

NewCandidates creates StoreCandidates with store list.

func (*StoreCandidates) FilterSource

func (c *StoreCandidates) FilterSource(conf config.Config, collector *plan.Collector, counter *Counter, filters ...Filter) *StoreCandidates

FilterSource keeps stores that can pass all source filters.

func (*StoreCandidates) FilterTarget

func (c *StoreCandidates) FilterTarget(conf config.Config, collector *plan.Collector, counter *Counter, filters ...Filter) *StoreCandidates

FilterTarget keeps stores that can pass all target filters.

func (*StoreCandidates) KeepTheTopStores

func (c *StoreCandidates) KeepTheTopStores(cmp StoreComparer, asc bool) *StoreCandidates

KeepTheTopStores keeps the slice of the stores in the front order by asc.

func (*StoreCandidates) Len

func (c *StoreCandidates) Len() int

Len returns a length of candidate list.

func (*StoreCandidates) PickAll

func (c *StoreCandidates) PickAll() []*core.StoreInfo

PickAll return all stores in candidate list.

func (*StoreCandidates) PickFirst

func (c *StoreCandidates) PickFirst() *core.StoreInfo

PickFirst returns the first store in candidate list.

func (*StoreCandidates) PickTheTopStore

func (c *StoreCandidates) PickTheTopStore(cmp StoreComparer, asc bool) *core.StoreInfo

PickTheTopStore returns the first store order by asc. It returns the min item when asc is true, returns the max item when asc is false.

func (*StoreCandidates) RandomPick

func (c *StoreCandidates) RandomPick() *core.StoreInfo

RandomPick returns a random store from the list.

func (*StoreCandidates) Shuffle

func (c *StoreCandidates) Shuffle() *StoreCandidates

Shuffle reorders all candidates randomly.

func (*StoreCandidates) Sort

Sort sorts store list by given comparer in ascending order.

type StoreComparer

type StoreComparer func(a, b *core.StoreInfo) int

StoreComparer compares 2 stores. Often used for StoreCandidates to sort candidate stores.

func IsolationComparer

func IsolationComparer(locationLabels []string, regionStores []*core.StoreInfo) StoreComparer

IsolationComparer creates a StoreComparer to sort store by isolation score.

func RegionScoreComparer

func RegionScoreComparer(conf config.Config) StoreComparer

RegionScoreComparer creates a StoreComparer to sort store by region score.

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
	// Set true if the scatter move the region
	ScatterRegion bool
	// Set true if allows failover (through witness)
	AllowFastFailover bool
	// Set true if allows temporary states.
	AllowTemporaryStates bool
	// Set the priority level of the filter, it should be same with the operator level.
	// The priority level can be higher than the operator level in checker,
	// the operator controller should check it again by using the actual operator level.
	// If it checks failed, the operator will be put back to the waiting queue util the limit is available.
	// But the scheduler should keep the same with the operator level.
	OperatorLevel constant.PriorityLevel
	// Reason is used to distinguish the reason of store state filter
	Reason filterType
}

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) Scope

func (f *StoreStateFilter) Scope() string

Scope returns the scheduler or the checker which the filter acts on.

func (*StoreStateFilter) Source

func (f *StoreStateFilter) Source(conf config.Config, store *core.StoreInfo) (status *plan.Status)

Source returns true when the store can be selected as the schedule source.

func (*StoreStateFilter) Target

func (f *StoreStateFilter) Target(conf config.Config, store *core.StoreInfo) (status *plan.Status)

Target returns true when the store can be selected as the schedule target.

func (*StoreStateFilter) Type

func (f *StoreStateFilter) Type() filterType

Type returns the type of the Filter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL