placement

package
v4.0.0-rc Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareRegionFit

func CompareRegionFit(a, b *RegionFit) int

CompareRegionFit determines the superiority of 2 fits. It returns 1 when the first fit result is better.

func MatchLabelConstraints

func MatchLabelConstraints(store *core.StoreInfo, constraints []LabelConstraint) bool

MatchLabelConstraints checks if a store matches label constraints list.

Types

type LabelConstraint

type LabelConstraint struct {
	Key    string            `json:"key,omitempty"`
	Op     LabelConstraintOp `json:"op,omitempty"`
	Values []string          `json:"values,omitempty"`
}

LabelConstraint is used to filter store when trying to place peer of a region.

func (*LabelConstraint) MatchStore

func (c *LabelConstraint) MatchStore(store *core.StoreInfo) bool

MatchStore checks if a store matches the constraint.

type LabelConstraintOp

type LabelConstraintOp string

LabelConstraintOp defines how a LabelConstraint matches a store. It can be one of 'in', 'notIn', 'exists', or 'notExists'.

const (
	// In restricts the store label value should in the value list.
	// If label does not exist, `in` is always false.
	In LabelConstraintOp = "in"
	// NotIn restricts the store label value should not in the value list.
	// If label does not exist, `notIn` is always true.
	NotIn LabelConstraintOp = "notIn"
	// Exists restricts the store should have the label.
	Exists LabelConstraintOp = "exists"
	// NotExists restricts the store should not have the label.
	NotExists LabelConstraintOp = "notExists"
)

type PeerRoleType

type PeerRoleType string

PeerRoleType is the expected peer type of the placement rule.

const (
	// Voter can either match a leader peer or follower peer
	Voter PeerRoleType = "voter"
	// Leader matches a leader.
	Leader PeerRoleType = "leader"
	// Follower matches a follower.
	Follower PeerRoleType = "follower"
	// Learner matches a learner.
	Learner PeerRoleType = "learner"
)

type RegionFit

type RegionFit struct {
	RuleFits    []*RuleFit
	OrphanPeers []*metapb.Peer
}

RegionFit is the result of fitting a region's peers to rule list. All peers are divided into corresponding rules according to the matching rules, and the remaining Peers are placed in the OrphanPeers list.

func FitRegion

func FitRegion(stores core.StoreSetInformer, region *core.RegionInfo, rules []*Rule) *RegionFit

FitRegion tries to fit peers of a region to the rules.

func (*RegionFit) GetRuleFit

func (f *RegionFit) GetRuleFit(peerID uint64) *RuleFit

GetRuleFit returns the RuleFit that contains the peer.

func (*RegionFit) IsSatisfied

func (f *RegionFit) IsSatisfied() bool

IsSatisfied returns if the rules are properly satisfied. It means all Rules are fulfilled and there is no orphan peers.

type Rule

type Rule struct {
	GroupID          string            `json:"group_id"`                    // mark the source that add the rule
	ID               string            `json:"id"`                          // unique ID within a group
	Index            int               `json:"index,omitempty"`             // rule apply order in a group, rule with less ID is applied first when indexes are equal
	Override         bool              `json:"override,omitempty"`          // when it is true, all rules with less indexes are disabled
	StartKey         []byte            `json:"-"`                           // range start key
	StartKeyHex      string            `json:"start_key"`                   // hex format start key, for marshal/unmarshal
	EndKey           []byte            `json:"-"`                           // range end key
	EndKeyHex        string            `json:"end_key"`                     // hex format end key, for marshal/unmarshal
	Role             PeerRoleType      `json:"role"`                        // expected role of the peers
	Count            int               `json:"count"`                       // expected count of the peers
	LabelConstraints []LabelConstraint `json:"label_constraints,omitempty"` // used to select stores to place peers
	LocationLabels   []string          `json:"location_labels,omitempty"`   // used to make peers isolated physically
}

Rule is the placement rule that can be checked against a region. When applying rules (apply means schedule regions to match selected rules), the apply order is defined by the tuple [GroupID, Index, ID].

func (Rule) Key

func (r Rule) Key() [2]string

Key returns (groupID, ID) as the global unique key of a rule.

func (Rule) StoreKey

func (r Rule) StoreKey() string

StoreKey returns the rule's key for persistent store.

func (Rule) String

func (r Rule) String() string

type RuleFit

type RuleFit struct {
	Rule *Rule
	// Peers of the Region that are divided to this Rule.
	Peers []*metapb.Peer
	// PeersWithDifferentRole is subset of `Peers`. It contains all Peers that have
	// different Role from configuration (the Role can be migrated to target role
	// by scheduling).
	PeersWithDifferentRole []*metapb.Peer
	// IsolationLevel indicates at which level of labeling these Peers are
	// isolated. A larger value indicates a higher isolation level.
	IsolationLevel int
}

RuleFit is the result of fitting status of a Rule.

func (*RuleFit) IsSatisfied

func (f *RuleFit) IsSatisfied() bool

IsSatisfied returns if the rule is properly satisfied.

type RuleManager

type RuleManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RuleManager is responsible for the lifecycle of all placement Rules. It is threadsafe.

func NewRuleManager

func NewRuleManager(store *core.Storage) *RuleManager

NewRuleManager creates a RuleManager instance.

func (*RuleManager) DeleteRule

func (m *RuleManager) DeleteRule(group, id string) error

DeleteRule removes a Rule.

func (*RuleManager) FitRegion

func (m *RuleManager) FitRegion(stores core.StoreSetInformer, region *core.RegionInfo) *RegionFit

FitRegion fits a region to the rules it matches.

func (*RuleManager) GetAllRules

func (m *RuleManager) GetAllRules() []*Rule

GetAllRules returns sorted all rules.

func (*RuleManager) GetRule

func (m *RuleManager) GetRule(group, id string) *Rule

GetRule returns the Rule with the same (group, id).

func (*RuleManager) GetRulesByGroup

func (m *RuleManager) GetRulesByGroup(group string) []*Rule

GetRulesByGroup returns sorted rules of a group.

func (*RuleManager) GetRulesByKey

func (m *RuleManager) GetRulesByKey(key []byte) []*Rule

GetRulesByKey returns sorted rules that affects a key.

func (*RuleManager) GetRulesForApplyRegion

func (m *RuleManager) GetRulesForApplyRegion(region *core.RegionInfo) []*Rule

GetRulesForApplyRegion returns the rules list that should be applied to a region.

func (*RuleManager) GetSplitKeys

func (m *RuleManager) GetSplitKeys(start, end []byte) [][]byte

GetSplitKeys returns all split keys in the range (start, end).

func (*RuleManager) Initialize

func (m *RuleManager) Initialize(maxReplica int, locationLabels []string) error

Initialize loads rules from storage. If Placement Rules feature is never enabled, it creates default rule that is compatible with previous configuration.

func (*RuleManager) SetRule

func (m *RuleManager) SetRule(rule *Rule) error

SetRule inserts or updates a Rule.

Jump to

Keyboard shortcuts

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