Documentation
¶
Index ¶
- func MatchLabelConstraints(store *core.StoreInfo, constraints []LabelConstraint) bool
- func ValidateFit(fit *RegionFit) bool
- func ValidateRegion(region *core.RegionInfo) bool
- func ValidateStores(stores []*core.StoreInfo) bool
- type GroupBundle
- type LabelConstraint
- type LabelConstraintOp
- type PeerRoleType
- type RegionFit
- type RegionRuleFitCacheManager
- func (manager *RegionRuleFitCacheManager) CheckAndGetCache(region *core.RegionInfo, rules []*Rule, stores []*core.StoreInfo) (bool, *RegionFit)
- func (manager *RegionRuleFitCacheManager) Invalid(regionID uint64)
- func (manager *RegionRuleFitCacheManager) SetCache(region *core.RegionInfo, fit *RegionFit)
- type Rule
- type RuleFit
- type RuleGroup
- type RuleManager
- func (m *RuleManager) Batch(todo []RuleOp) error
- func (m *RuleManager) CheckIsCachedDirectly(regionID uint64) bool
- func (m *RuleManager) DeleteGroupBundle(id string, regex bool) error
- func (m *RuleManager) DeleteRule(group, id string) error
- func (m *RuleManager) DeleteRuleGroup(id string) error
- func (m *RuleManager) FitRegion(storeSet StoreSet, region *core.RegionInfo) (fit *RegionFit)
- func (m *RuleManager) GetAllGroupBundles() []GroupBundle
- func (m *RuleManager) GetAllRules() []*Rule
- func (m *RuleManager) GetGroupBundle(id string) (b GroupBundle)
- func (m *RuleManager) GetRule(group, id string) *Rule
- func (m *RuleManager) GetRuleGroup(id string) *RuleGroup
- func (m *RuleManager) GetRuleGroups() []*RuleGroup
- func (m *RuleManager) GetRulesByGroup(group string) []*Rule
- func (m *RuleManager) GetRulesByKey(key []byte) []*Rule
- func (m *RuleManager) GetRulesForApplyRange(start, end []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) InvalidCache(regionID uint64)
- func (m *RuleManager) IsInitialized() bool
- func (m *RuleManager) IsRegionFitCached(storeSet StoreSet, region *core.RegionInfo) bool
- func (m *RuleManager) SetAllGroupBundles(groups []GroupBundle, override bool) error
- func (m *RuleManager) SetGroupBundle(group GroupBundle) error
- func (m *RuleManager) SetKeyType(h string) *RuleManager
- func (m *RuleManager) SetPlaceholderRegionFitCache(region *core.RegionInfo)
- func (m *RuleManager) SetRegionFitCache(region *core.RegionInfo, fit *RegionFit)
- func (m *RuleManager) SetRule(rule *Rule) error
- func (m *RuleManager) SetRuleGroup(group *RuleGroup) error
- func (m *RuleManager) SetRules(rules []*Rule) error
- type RuleOp
- type RuleOpType
- type StoreSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchLabelConstraints ¶
func MatchLabelConstraints(store *core.StoreInfo, constraints []LabelConstraint) bool
MatchLabelConstraints checks if a store matches label constraints list.
func ValidateFit ¶
ValidateFit checks whether regionFit is valid
func ValidateRegion ¶
func ValidateRegion(region *core.RegionInfo) bool
ValidateRegion checks whether region is healthy
func ValidateStores ¶
ValidateStores checks whether store isn't offline, unhealthy and disconnected. Only Up store should be cached in RegionFitCache
Types ¶
type GroupBundle ¶
type GroupBundle struct { ID string `json:"group_id"` Index int `json:"group_index"` Override bool `json:"group_override"` Rules []*Rule `json:"rules"` }
GroupBundle represents a rule group and all rules belong to the group. NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
func (GroupBundle) String ¶
func (g GroupBundle) String() string
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" )
func (PeerRoleType) MetaPeerRole ¶
func (s PeerRoleType) MetaPeerRole() metapb.PeerRole
MetaPeerRole converts placement.PeerRoleType to metapb.PeerRole.
type RegionFit ¶
type RegionFit struct { RuleFits []*RuleFit `json:"rule-fits"` OrphanPeers []*metapb.Peer `json:"orphan-peers"` // contains filtered or unexported fields }
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 (*RegionFit) GetRegionStores ¶
GetRegionStores returns region's stores
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 RegionRuleFitCacheManager ¶
type RegionRuleFitCacheManager struct {
// contains filtered or unexported fields
}
RegionRuleFitCacheManager stores each region's RegionFit Result and involving variables only when the RegionFit result is satisfied with its rules RegionRuleFitCacheManager caches RegionFit result for each region only when: 1. region have no down peers 2. RegionFit is satisfied RegionRuleFitCacheManager will invalid the cache for the region only when: 1. region peer topology is changed 2. region have down peers 3. region leader is changed 4. any involved rule is changed 5. stores topology is changed 6. any store label is changed 7. any store state is changed
func NewRegionRuleFitCacheManager ¶
func NewRegionRuleFitCacheManager() *RegionRuleFitCacheManager
NewRegionRuleFitCacheManager returns RegionRuleFitCacheManager
func (*RegionRuleFitCacheManager) CheckAndGetCache ¶
func (manager *RegionRuleFitCacheManager) CheckAndGetCache(region *core.RegionInfo, rules []*Rule, stores []*core.StoreInfo) (bool, *RegionFit)
CheckAndGetCache checks whether the region and rules are changed for the stored cache If the check pass, it will return the cache
func (*RegionRuleFitCacheManager) Invalid ¶
func (manager *RegionRuleFitCacheManager) Invalid(regionID uint64)
Invalid cache by regionID
func (*RegionRuleFitCacheManager) SetCache ¶
func (manager *RegionRuleFitCacheManager) SetCache(region *core.RegionInfo, fit *RegionFit)
SetCache stores RegionFit cache
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 IsWitness bool `json:"is_witness"` // when it is true, it means the role is also a witness 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 IsolationLevel string `json:"isolation_level,omitempty"` // used to isolate replicas explicitly and forcibly Version uint64 `json:"version,omitempty"` // only set at runtime, add 1 each time rules updated, begin from 0. CreateTimestamp uint64 `json:"create_timestamp,omitempty"` // only set at runtime, recorded rule create timestamp // contains filtered or unexported fields }
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 [GroupIndex, GroupID, Index, ID].
NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
type RuleFit ¶
type RuleFit struct { Rule *Rule `json:"rule"` // Peers of the Region that are divided to this Rule. Peers []*metapb.Peer `json:"peers"` // 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 `json:"peers-different-role"` // IsolationScore indicates at which level of labeling these Peers are // isolated. A larger value is better. IsolationScore float64 `json:"isolation-score"` WitnessScore int `json:"witness-score"` // contains filtered or unexported fields }
RuleFit is the result of fitting status of a Rule.
func (*RuleFit) IsSatisfied ¶
IsSatisfied returns if the rule is properly satisfied.
type RuleGroup ¶
type RuleGroup struct { ID string `json:"id,omitempty"` Index int `json:"index,omitempty"` Override bool `json:"override,omitempty"` }
RuleGroup defines properties of a rule group. NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
type RuleManager ¶
RuleManager is responsible for the lifecycle of all placement Rules. It is thread safe.
func NewRuleManager ¶
func NewRuleManager(storage endpoint.RuleStorage, storeSetInformer core.StoreSetInformer, conf config.Config) *RuleManager
NewRuleManager creates a RuleManager instance.
func (*RuleManager) Batch ¶
func (m *RuleManager) Batch(todo []RuleOp) error
Batch executes a series of actions at once.
func (*RuleManager) CheckIsCachedDirectly ¶
func (m *RuleManager) CheckIsCachedDirectly(regionID uint64) bool
CheckIsCachedDirectly returns whether the region's fit is cached Only used for testing
func (*RuleManager) DeleteGroupBundle ¶
func (m *RuleManager) DeleteGroupBundle(id string, regex bool) error
DeleteGroupBundle removes a Group and all rules belong to it. If `regex` is true, `id` is a regexp expression.
func (*RuleManager) DeleteRule ¶
func (m *RuleManager) DeleteRule(group, id string) error
DeleteRule removes a Rule.
func (*RuleManager) DeleteRuleGroup ¶
func (m *RuleManager) DeleteRuleGroup(id string) error
DeleteRuleGroup removes a RuleGroup.
func (*RuleManager) FitRegion ¶
func (m *RuleManager) FitRegion(storeSet StoreSet, region *core.RegionInfo) (fit *RegionFit)
FitRegion fits a region to the rules it matches.
func (*RuleManager) GetAllGroupBundles ¶
func (m *RuleManager) GetAllGroupBundles() []GroupBundle
GetAllGroupBundles returns all rules and groups configuration. Rules are grouped by groups.
func (*RuleManager) GetAllRules ¶
func (m *RuleManager) GetAllRules() []*Rule
GetAllRules returns sorted all rules.
func (*RuleManager) GetGroupBundle ¶
func (m *RuleManager) GetGroupBundle(id string) (b GroupBundle)
GetGroupBundle returns a group and all rules belong to it.
func (*RuleManager) GetRule ¶
func (m *RuleManager) GetRule(group, id string) *Rule
GetRule returns the Rule with the same (group, id).
func (*RuleManager) GetRuleGroup ¶
func (m *RuleManager) GetRuleGroup(id string) *RuleGroup
GetRuleGroup returns a RuleGroup configuration.
func (*RuleManager) GetRuleGroups ¶
func (m *RuleManager) GetRuleGroups() []*RuleGroup
GetRuleGroups returns all RuleGroup configuration.
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) GetRulesForApplyRange ¶
func (m *RuleManager) GetRulesForApplyRange(start, end []byte) []*Rule
GetRulesForApplyRange returns the rules list that should be applied to a range.
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) InvalidCache ¶
func (m *RuleManager) InvalidCache(regionID uint64)
InvalidCache invalids the cache.
func (*RuleManager) IsInitialized ¶
func (m *RuleManager) IsInitialized() bool
IsInitialized returns whether the rule manager is initialized.
func (*RuleManager) IsRegionFitCached ¶
func (m *RuleManager) IsRegionFitCached(storeSet StoreSet, region *core.RegionInfo) bool
IsRegionFitCached returns whether the RegionFit can be cached.
func (*RuleManager) SetAllGroupBundles ¶
func (m *RuleManager) SetAllGroupBundles(groups []GroupBundle, override bool) error
SetAllGroupBundles resets configuration. If override is true, all old configurations are dropped.
func (*RuleManager) SetGroupBundle ¶
func (m *RuleManager) SetGroupBundle(group GroupBundle) error
SetGroupBundle resets a Group and all rules belong to it. All old rules belong to the Group are dropped.
func (*RuleManager) SetKeyType ¶
func (m *RuleManager) SetKeyType(h string) *RuleManager
SetKeyType will update keyType for adjustRule()
func (*RuleManager) SetPlaceholderRegionFitCache ¶
func (m *RuleManager) SetPlaceholderRegionFitCache(region *core.RegionInfo)
SetPlaceholderRegionFitCache sets a placeholder region fit cache information Only used for testing
func (*RuleManager) SetRegionFitCache ¶
func (m *RuleManager) SetRegionFitCache(region *core.RegionInfo, fit *RegionFit)
SetRegionFitCache sets RegionFitCache
func (*RuleManager) SetRule ¶
func (m *RuleManager) SetRule(rule *Rule) error
SetRule inserts or updates a Rule.
func (*RuleManager) SetRuleGroup ¶
func (m *RuleManager) SetRuleGroup(group *RuleGroup) error
SetRuleGroup updates a RuleGroup.
func (*RuleManager) SetRules ¶
func (m *RuleManager) SetRules(rules []*Rule) error
SetRules inserts or updates lots of Rules at once.
type RuleOp ¶
type RuleOp struct { *Rule // information of the placement rule to add/delete the operation type Action RuleOpType `json:"action"` DeleteByIDPrefix bool `json:"delete_by_id_prefix"` // if action == delete, delete by the prefix of id }
RuleOp is for batching placement rule actions. The action type is distinguished by the field `Action`.
type RuleOpType ¶
type RuleOpType string
RuleOpType indicates the operation type
const ( // RuleOpAdd a placement rule, only need to specify the field *Rule RuleOpAdd RuleOpType = "add" // RuleOpDel a placement rule, only need to specify the field `GroupID`, `ID`, `MatchID` RuleOpDel RuleOpType = "del" )