Documentation ¶
Index ¶
- func CompareRegionFit(a, b *RegionFit) int
- func MatchLabelConstraints(store *core.StoreInfo, constraints []LabelConstraint) bool
- type LabelConstraint
- type LabelConstraintOp
- type PeerRoleType
- type RegionFit
- type Rule
- type RuleFit
- type RuleManager
- func (m *RuleManager) DeleteRule(group, id string) error
- func (m *RuleManager) FitRegion(stores core.StoreSetInformer, region *core.RegionInfo) *RegionFit
- func (m *RuleManager) GetAllRules() []*Rule
- func (m *RuleManager) GetRule(group, id string) *Rule
- func (m *RuleManager) GetRulesByGroup(group string) []*Rule
- func (m *RuleManager) GetRulesByKey(key []byte) []*Rule
- func (m *RuleManager) GetRulesForApplyRegion(region *core.RegionInfo) []*Rule
- func (m *RuleManager) GetSplitKeys(start, end []byte) [][]byte
- func (m *RuleManager) Initialize(maxReplica int, locationLabels []string) error
- func (m *RuleManager) SetRule(rule *Rule) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareRegionFit ¶
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 ¶
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 ¶
GetRuleFit returns the RuleFit that contains the peer.
func (*RegionFit) IsSatisfied ¶
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].
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 // IsolationScore indicates at which level of labeling these Peers are // isolated. A larger value is better. IsolationScore float64 }
RuleFit is the result of fitting status of a Rule.
func (*RuleFit) IsSatisfied ¶
IsSatisfied returns if the rule is properly satisfied.
type RuleManager ¶
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.