filter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SpecialUseKey is the label used to indicate special use storage.
	SpecialUseKey = "specialUse"
	// SpecialUseHotResource is the hot resource value of special use label
	SpecialUseHotResource = "hotResource"
	// 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"
)

Variables

This section is empty.

Functions

func SelectSourceContainers

func SelectSourceContainers(containers []*core.CachedContainer, filters []Filter, opt *config.PersistOptions) []*core.CachedContainer

SelectSourceContainers selects containers that be selected as source container from the list.

func SelectTargetContainers

func SelectTargetContainers(containers []*core.CachedContainer, filters []Filter, opt *config.PersistOptions) []*core.CachedContainer

SelectTargetContainers selects containers that be selected as target container from the list.

func Source

func Source(opt *config.PersistOptions, container *core.CachedContainer, filters []Filter) bool

Source checks if container can pass all Filters as source container.

func Target

func Target(opt *config.PersistOptions, container *core.CachedContainer, filters []Filter) bool

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

Types

type ContainerCandidates

type ContainerCandidates struct {
	Containers []*core.CachedContainer
}

ContainerCandidates wraps container list and provide utilities to select source or target container to schedule.

func NewCandidates

func NewCandidates(containers []*core.CachedContainer) *ContainerCandidates

NewCandidates creates ContainerCandidates with container list.

func (*ContainerCandidates) FilterSource

func (c *ContainerCandidates) FilterSource(opt *config.PersistOptions, filters ...Filter) *ContainerCandidates

FilterSource keeps containers that can pass all source filters.

func (*ContainerCandidates) FilterTarget

func (c *ContainerCandidates) FilterTarget(opt *config.PersistOptions, filters ...Filter) *ContainerCandidates

FilterTarget keeps containers that can pass all target filters.

func (*ContainerCandidates) PickFirst

func (c *ContainerCandidates) PickFirst() *core.CachedContainer

PickFirst returns the first container in candidate list.

func (*ContainerCandidates) RandomPick

func (c *ContainerCandidates) RandomPick() *core.CachedContainer

RandomPick returns a random container from the list.

func (*ContainerCandidates) Reverse

Reverse reverses the candidate container list.

func (*ContainerCandidates) Shuffle

Shuffle reorders all candidates randomly.

func (*ContainerCandidates) Sort

Sort sorts container list by given comparer in ascending order.

func (*ContainerCandidates) Top

Top keeps all containers that have the same priority with the first container. The container list should be sorted before calling Top.

type ContainerComparer

type ContainerComparer func(a, b *core.CachedContainer) int

ContainerComparer compares 2 containers. Often used for ContainerCandidates to sort candidate containers.

func IsolationComparer

func IsolationComparer(locationLabels []string, resourceContainers []*core.CachedContainer) ContainerComparer

IsolationComparer creates a ContainerComparer to sort container by isolation score.

func ResourceScoreComparer

func ResourceScoreComparer(opt *config.PersistOptions) ContainerComparer

ResourceScoreComparer creates a ContainerComparer to sort container by resource score.

type ContainerStateFilter

type ContainerStateFilter struct {
	ActionScope string
	// Set true if the schedule involves any transfer leader operation.
	TransferLeader bool
	// Set true if the schedule involves any move resource operation.
	MoveResource bool
	// Set true if allows temporary states.
	AllowTemporaryStates bool
	// Reason is used to distinguish the reason of container state filter
	Reason string
}

ContainerStateFilter is used to determine whether a container can be selected as the source or target of the schedule based on the container's state.

func (*ContainerStateFilter) Scope

func (f *ContainerStateFilter) Scope() string

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

func (*ContainerStateFilter) Source

func (f *ContainerStateFilter) Source(opts *config.PersistOptions, container *core.CachedContainer) bool

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

func (*ContainerStateFilter) Target

func (f *ContainerStateFilter) Target(opts *config.PersistOptions, container *core.CachedContainer) bool

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

func (*ContainerStateFilter) Type

func (f *ContainerStateFilter) Type() string

Type returns the type of the Filter.

type Filter

type Filter interface {
	// Scope is used to indicate where the filter will act on.
	Scope() string
	Type() string
	// Return true if the container can be used as a source container.
	Source(opt *config.PersistOptions, container *core.CachedContainer) bool
	// Return true if the container can be used as a target container.
	Target(opt *config.PersistOptions, container *core.CachedContainer) bool
}

Filter is an interface to filter source and target container.

func NewEngineFilter

func NewEngineFilter(scope string, allowedEngines ...string) 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 containers.

func NewIsolationFilter

func NewIsolationFilter(scope, isolationLevel string, locationLabels []string, resourceContainers []*core.CachedContainer) Filter

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

func NewLabelConstaintFilter

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

NewLabelConstaintFilter creates a filter that selects containers satisfy the constraints.

func NewLocationImprover

func NewLocationImprover(scope string, labels []string, containers []*core.CachedContainer, source *core.CachedContainer) Filter

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

func NewLocationSafeguard

func NewLocationSafeguard(scope string, labels []string, containers []*core.CachedContainer, source *core.CachedContainer) Filter

NewLocationSafeguard creates a filter that filters all containers that have lower distinct score than specified container.

func NewOrdinaryEngineFilter

func NewOrdinaryEngineFilter(scope string) Filter

NewOrdinaryEngineFilter creates a filter that only keeps ordinary engine containers.

func NewPlacementLeaderSafeguard

func NewPlacementLeaderSafeguard(scope string, cluster opt.Cluster, res *core.CachedResource, sourceContainer *core.CachedContainer, factory func() metadata.Resource) 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 sourceContainer.

func NewPlacementSafeguard

func NewPlacementSafeguard(scope string, cluster opt.Cluster, res *core.CachedResource, sourceContainer *core.CachedContainer, factory func() metadata.Resource) Filter

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

func NewSpecialUseFilter

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

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

func NewStorageThresholdFilter

func NewStorageThresholdFilter(scope string) Filter

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

type ResourceFitter

type ResourceFitter interface {
	FitResource(*core.CachedResource) *placement.ResourceFit
}

ResourceFitter is the interface that can fit a resource against placement rules.

Jump to

Keyboard shortcuts

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