Documentation ¶
Index ¶
- Constants
- Variables
- func GroupID(id int64) string
- type Bundle
- func NewBundle(id int64) *Bundle
- func NewBundleFromConstraintsOptions(options *model.PlacementSettings) (*Bundle, error)
- func NewBundleFromOptions(options *model.PlacementSettings) (bundle *Bundle, err error)
- func NewBundleFromSugarOptions(options *model.PlacementSettings) (*Bundle, error)
- func NewFullTableBundles(getter PolicyGetter, tbInfo *model.TableInfo) ([]*Bundle, error)
- func NewPartitionBundle(getter PolicyGetter, def model.PartitionDefinition) (*Bundle, error)
- func NewPartitionListBundles(getter PolicyGetter, defs []model.PartitionDefinition) ([]*Bundle, error)
- func NewTableBundle(getter PolicyGetter, tbInfo *model.TableInfo) (*Bundle, error)
- type Constraint
- type ConstraintCompatibility
- type ConstraintOp
- type Constraints
- type PeerRoleType
- type PolicyGetter
- type Rule
- type RuleGroupConfig
- type TiFlashRule
Constants ¶
const ( // TiFlashRuleGroupID is the rule group id of tiflash TiFlashRuleGroupID = "tiflash" // BundleIDPrefix is the bundle prefix of all rule bundles from TiDB_DDL statements. BundleIDPrefix = "TiDB_DDL_" // PDBundleID is the bundle name of pd, the default bundle for all regions. PDBundleID = "pd" )
const ( // RuleIndexTable is the index for a rule of table. RuleIndexTable = 40 // RuleIndexPartition is the index for a rule of partition. RuleIndexPartition = 80 // RuleIndexTiFlash is the index for a rule of TiFlash. RuleIndexTiFlash = 120 )
const ( // DCLabelKey indicates the key of label which represents the dc for Store. // FIXME: currently we assumes "zone" is the dcLabel key in Store DCLabelKey = "zone" // EngineLabelKey is the label that indicates the backend of store instance: // tikv or tiflash. TiFlash instance will contain a label of 'engine: tiflash'. EngineLabelKey = "engine" // EngineLabelTiFlash is the label value, which a TiFlash instance will have with // a label key of EngineLabelKey. EngineLabelTiFlash = "tiflash" // EngineLabelTiKV is the label value used in some tests. And possibly TiKV will // set the engine label with a value of EngineLabelTiKV. EngineLabelTiKV = "tikv" // EngineLabelTiFlashCompute is for disaggregated tiflash mode, // it's the lable of tiflash_compute nodes. EngineLabelTiFlashCompute = "tiflash_compute" // EngineRoleLabelKey is the label that indicates if the TiFlash instance is a write node. EngineRoleLabelKey = "engine_role" // EngineRoleLabelWrite is for disaggregated tiflash write node. EngineRoleLabelWrite = "write" )
Variables ¶
var ( // ErrInvalidConstraintFormat is from constraint.go. ErrInvalidConstraintFormat = errors.New("label constraint should be in format '{+|-}key=value'") // ErrUnsupportedConstraint is from constraint.go. ErrUnsupportedConstraint = errors.New("unsupported label constraint") // ErrConflictingConstraints is from constraints.go. ErrConflictingConstraints = errors.New("conflicting label constraints") // ErrInvalidConstraintsMapcnt is from rule.go. ErrInvalidConstraintsMapcnt = errors.New("label constraints in map syntax have invalid replicas") // ErrInvalidConstraintsFormat is from rule.go. ErrInvalidConstraintsFormat = errors.New("invalid label constraints format") // ErrInvalidSurvivalPreferenceFormat is from rule.go. ErrInvalidSurvivalPreferenceFormat = errors.New("survival preference format should be in format [xxx=yyy, ...]") // ErrInvalidConstraintsRelicas is from rule.go. ErrInvalidConstraintsRelicas = errors.New("label constraints with invalid REPLICAS") // ErrInvalidBundleID is from bundle.go. ErrInvalidBundleID = errors.New("invalid bundle ID") // ErrInvalidBundleIDFormat is from bundle.go. ErrInvalidBundleIDFormat = errors.New("invalid bundle ID format") // ErrLeaderReplicasMustOne is from bundle.go. ErrLeaderReplicasMustOne = errors.New("REPLICAS must be 1 if ROLE=leader") // ErrMissingRoleField is from bundle.go. ErrMissingRoleField = errors.New("the ROLE field is not specified") // ErrNoRulesToDrop is from bundle.go. ErrNoRulesToDrop = errors.New("no rule of such role to drop") // ErrInvalidPlacementOptions is from bundle.go. ErrInvalidPlacementOptions = errors.New("invalid placement option") // ErrInvalidConstraintsMappingWrongSeparator is wrong separator in mapping. ErrInvalidConstraintsMappingWrongSeparator = errors.New("mappings use a colon and space (“: ”) to mark each key/value pair") // ErrInvalidConstraintsMappingNoColonFound is no colon found in mapping. ErrInvalidConstraintsMappingNoColonFound = errors.New("no colon found") )
Functions ¶
Types ¶
type Bundle ¶
type Bundle struct { ID string `json:"group_id"` Index int `json:"group_index"` Override bool `json:"group_override"` Rules []*Rule `json:"rules"` }
Bundle is a group of all rules and configurations. It is used to support rule cache.
func NewBundle ¶
NewBundle will create a bundle with the provided ID. Note that you should never pass negative id.
func NewBundleFromConstraintsOptions ¶
func NewBundleFromConstraintsOptions(options *model.PlacementSettings) (*Bundle, error)
NewBundleFromConstraintsOptions will transform constraints options into the bundle.
func NewBundleFromOptions ¶
func NewBundleFromOptions(options *model.PlacementSettings) (bundle *Bundle, err error)
NewBundleFromOptions will transform options into the bundle.
func NewBundleFromSugarOptions ¶
func NewBundleFromSugarOptions(options *model.PlacementSettings) (*Bundle, error)
NewBundleFromSugarOptions will transform syntax sugar options into the bundle.
func NewFullTableBundles ¶
func NewFullTableBundles(getter PolicyGetter, tbInfo *model.TableInfo) ([]*Bundle, error)
NewFullTableBundles returns a bundle list with both table bundle and partition bundles
func NewPartitionBundle ¶
func NewPartitionBundle(getter PolicyGetter, def model.PartitionDefinition) (*Bundle, error)
NewPartitionBundle creates a bundle for partition key range. It only contains the rules specified independently by the partition. That is to say the inherited rules from table is not included.
func NewPartitionListBundles ¶
func NewPartitionListBundles(getter PolicyGetter, defs []model.PartitionDefinition) ([]*Bundle, error)
NewPartitionListBundles creates a bundle list for a partition list
func NewTableBundle ¶
func NewTableBundle(getter PolicyGetter, tbInfo *model.TableInfo) (*Bundle, error)
NewTableBundle creates a bundle for table key range. If table is a partitioned table, it also contains the rules that inherited from table for every partition. The bundle does not contain the rules specified independently by each partition
func (*Bundle) GetLeaderDC ¶
GetLeaderDC returns the leader's DC by Bundle if found.
type Constraint ¶
type Constraint struct { Key string `json:"key,omitempty"` Op ConstraintOp `json:"op,omitempty"` Values []string `json:"values,omitempty"` }
Constraint is used to filter store when trying to place peer of a region.
func NewConstraint ¶
func NewConstraint(label string) (Constraint, error)
NewConstraint will create a Constraint from a string.
func NewConstraintDirect ¶
func NewConstraintDirect(key string, op ConstraintOp, val ...string) Constraint
NewConstraintDirect will create a Constraint from argument directly.
func (*Constraint) CompatibleWith ¶
func (c *Constraint) CompatibleWith(o *Constraint) ConstraintCompatibility
CompatibleWith will check if two constraints are compatible. Return (compatible, duplicated).
func (*Constraint) Restore ¶
func (c *Constraint) Restore() (string, error)
Restore converts a Constraint to a string.
type ConstraintCompatibility ¶
type ConstraintCompatibility byte
ConstraintCompatibility is the return type of CompatibleWith.
const ( // ConstraintCompatible indicates two constraints are compatible. ConstraintCompatible ConstraintCompatibility = iota // ConstraintIncompatible indicates two constraints are incompatible. ConstraintIncompatible // ConstraintDuplicated indicates two constraints are duplicated. ConstraintDuplicated )
type ConstraintOp ¶
type ConstraintOp string
ConstraintOp defines how a Constraint matches a store.
const ( // In restricts the store label value should in the value list. // If label does not exist, `in` is always false. In ConstraintOp = "in" // NotIn restricts the store label value should not in the value list. // If label does not exist, `notIn` is always true. NotIn ConstraintOp = "notIn" // Exists restricts the store should have the label. Exists ConstraintOp = "exists" // NotExists restricts the store should not have the label. NotExists ConstraintOp = "notExists" )
type Constraints ¶
type Constraints []Constraint
Constraints is a slice of constraints.
func NewConstraints ¶
func NewConstraints(labels []string) (Constraints, error)
NewConstraints will check each labels, and build the Constraints.
func NewConstraintsDirect ¶
func NewConstraintsDirect(c ...Constraint) Constraints
NewConstraintsDirect is a helper for creating new constraints from individual constraint.
func NewConstraintsFromYaml ¶
func NewConstraintsFromYaml(c []byte) (Constraints, error)
NewConstraintsFromYaml will transform parse the raw 'array' constraints and call NewConstraints. Refer to https://github.com/pingcap/tidb/blob/master/docs/design/2020-06-24-placement-rules-in-sql.md.
func (*Constraints) Add ¶
func (constraints *Constraints) Add(label Constraint) error
Add will add a new label constraint, with validation of all constraints. Note that Add does not validate one single constraint.
func (*Constraints) Restore ¶
func (constraints *Constraints) Restore() (string, error)
Restore converts label constraints to a string.
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 PolicyGetter ¶
type PolicyGetter interface {
GetPolicy(policyID int64) (*model.PolicyInfo, error)
}
PolicyGetter is the interface to get the policy
type Rule ¶
type Rule struct { GroupID string `json:"group_id"` ID string `json:"id"` Index int `json:"index,omitempty"` Override bool `json:"override,omitempty"` StartKeyHex string `json:"start_key"` EndKeyHex string `json:"end_key"` Role PeerRoleType `json:"role"` Count int `json:"count"` Constraints Constraints `json:"label_constraints,omitempty"` LocationLabels []string `json:"location_labels,omitempty"` }
Rule is the core placement rule struct. Check https://github.com/tikv/pd/blob/master/server/schedule/placement/rule.go.
func NewRule ¶
func NewRule(role PeerRoleType, replicas uint64, cnst Constraints) *Rule
NewRule constructs *Rule from role, count, and constraints. It is here to consistent the behavior of creating new rules.
func NewRules ¶
func NewRules(role PeerRoleType, replicas uint64, cnstr string) ([]*Rule, error)
NewRules constructs []*Rule from a yaml-compatible representation of 'array' or 'dict' constraints. Refer to https://github.com/pingcap/tidb/blob/master/docs/design/2020-06-24-placement-rules-in-sql.md.
type RuleGroupConfig ¶
type RuleGroupConfig struct { ID string `json:"id"` Index int `json:"index"` Override bool `json:"override"` }
RuleGroupConfig defines basic config of rule group
type TiFlashRule ¶
type TiFlashRule struct { GroupID string ID string Index int Override bool Role PeerRoleType Count int Constraints Constraints LocationLabels []string IsolationLevel string StartKey []byte EndKey []byte }
TiFlashRule extends Rule with other necessary fields.
func (*TiFlashRule) MarshalJSON ¶
func (r *TiFlashRule) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler interface for TiFlashRule.
func (*TiFlashRule) UnmarshalJSON ¶
func (r *TiFlashRule) UnmarshalJSON(bytes []byte) error
UnmarshalJSON implements json.Unmarshaler interface for TiFlashRule.