placement

package
v1.1.0-beta.0...-db2776a Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
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"

	// DefaultKwd is used to reset the default rule (remove bundle).
	DefaultKwd = "default"
	// TiDBBundleRangePrefixForGlobal is the bundle prefix of system global range.
	TiDBBundleRangePrefixForGlobal = "TiDB_GLOBAL"
	// TiDBBundleRangePrefixForMeta is the bundle prefix of system meta range.
	TiDBBundleRangePrefixForMeta = "TiDB_META"
	// KeyRangeGlobal is the key range for system global range.
	KeyRangeGlobal = "global"
	// KeyRangeMeta is the key range for system meta range.
	KeyRangeMeta = "meta"
)
View Source
const (
	// RuleIndexKeyRangeForGlobal is the index for a rule of whole system range.
	RuleIndexKeyRangeForGlobal = 20
	// RuleIndexKeyRangeForMeta is the index for a rule of system meta range.
	RuleIndexKeyRangeForMeta = 21
	// 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
)
View Source
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

View Source
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, ...]")
	// ErrInvalidConstraintsReplicas is from rule.go.
	ErrInvalidConstraintsReplicas = 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

func AddConstraint

func AddConstraint(constraints *[]pd.LabelConstraint, label pd.LabelConstraint) error

AddConstraint will add a new label constraint, with validation of all constraints. Note that Add does not validate one single constraint.

func ConstraintsFingerPrint

func ConstraintsFingerPrint(constraints *[]pd.LabelConstraint) string

ConstraintsFingerPrint returns a unique string for the constraints.

func GetRangeStartAndEndKeyHex

func GetRangeStartAndEndKeyHex(rangeBundleID string) (startKey string, endKey string)

GetRangeStartAndEndKeyHex get startKeyHex and endKeyHex of range by rangeBundleID.

func GroupID

func GroupID(id int64) string

GroupID accepts a tableID or whatever integer, and encode the integer into a valid GroupID for PD.

func NewConstraint

func NewConstraint(label string) (pd.LabelConstraint, error)

NewConstraint will create a Constraint from a string.

func NewConstraintDirect

func NewConstraintDirect(key string, op pd.LabelConstraintOp, val ...string) pd.LabelConstraint

NewConstraintDirect will create a Constraint from argument directly.

func NewConstraints

func NewConstraints(labels []string) ([]pd.LabelConstraint, error)

NewConstraints will check each labels, and build the Constraints.

func NewConstraintsDirect

func NewConstraintsDirect(c ...pd.LabelConstraint) []pd.LabelConstraint

NewConstraintsDirect is a helper for creating new constraints from individual constraint.

func NewConstraintsFromYaml

func NewConstraintsFromYaml(c []byte) ([]pd.LabelConstraint, 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 NewRule

func NewRule(role pd.PeerRoleType, replicas uint64, cnst []pd.LabelConstraint) *pd.Rule

NewRule constructs *Rule from role, count, and constraints. It is here to consistent the behavior of creating new rules.

func RestoreConstraint

func RestoreConstraint(c *pd.LabelConstraint) (string, error)

RestoreConstraint converts a Constraint to a string.

func RestoreConstraints

func RestoreConstraints(constraints *[]pd.LabelConstraint) (string, error)

RestoreConstraints converts label constraints to a string.

Types

type Bundle

type Bundle pd.GroupBundle

Bundle is a group of all rules and configurations. It is used to support rule cache. Alias `pd.GroupBundle` is to wrap more methods.

func NewBundle

func NewBundle(id int64) *Bundle

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) Clone

func (b *Bundle) Clone() *Bundle

Clone is used to duplicate a bundle.

func (*Bundle) GetLeaderDC

func (b *Bundle) GetLeaderDC(dcLabelKey string) (string, bool)

GetLeaderDC returns the leader's DC by Bundle if found.

func (*Bundle) IsEmpty

func (b *Bundle) IsEmpty() bool

IsEmpty is used to check if a bundle is empty.

func (*Bundle) ObjectID

func (b *Bundle) ObjectID() (int64, error)

ObjectID extracts the db/table/partition ID from the group ID

func (*Bundle) RebuildForRange

func (b *Bundle) RebuildForRange(rangeName string, policyName string) *Bundle

RebuildForRange rebuilds the bundle for system range.

func (*Bundle) Reset

func (b *Bundle) Reset(ruleIndex int, newIDs []int64) *Bundle

Reset resets the bundle ID and keyrange of all rules.

func (*Bundle) String

func (b *Bundle) String() string

String implements fmt.Stringer.

func (*Bundle) Tidy

func (b *Bundle) Tidy() error

Tidy will post optimize Rules, trying to generate rules that suits PD.

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
)

func ConstraintCompatibleWith

func ConstraintCompatibleWith(c *pd.LabelConstraint, o *pd.LabelConstraint) ConstraintCompatibility

ConstraintCompatibleWith will check if two constraints are compatible. Return (compatible, duplicated).

type PolicyGetter

type PolicyGetter interface {
	GetPolicy(policyID int64) (*model.PolicyInfo, error)
}

PolicyGetter is the interface to get the policy

type RuleBuilder

type RuleBuilder struct {
	// contains filtered or unexported fields
}

RuleBuilder is used to build the Rules from a constraint string.

func NewRuleBuilder

func NewRuleBuilder() *RuleBuilder

NewRuleBuilder creates a new RuleBuilder.

func (*RuleBuilder) BuildRules

func (b *RuleBuilder) BuildRules() ([]*pd.Rule, error)

BuildRules 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.

func (*RuleBuilder) BuildRulesWithDictConstraintsOnly

func (b *RuleBuilder) BuildRulesWithDictConstraintsOnly() ([]*pd.Rule, error)

BuildRulesWithDictConstraintsOnly constructs []*Rule from a yaml-compatible representation of 'dict' constraints.

func (*RuleBuilder) SetConstraintStr

func (b *RuleBuilder) SetConstraintStr(constraintStr string) *RuleBuilder

SetConstraintStr sets the constraint string.

func (*RuleBuilder) SetReplicasNum

func (b *RuleBuilder) SetReplicasNum(num uint64) *RuleBuilder

SetReplicasNum sets the replicas number in the rule.

func (*RuleBuilder) SetRole

func (b *RuleBuilder) SetRole(role pd.PeerRoleType) *RuleBuilder

SetRole sets the role of the rule.

func (*RuleBuilder) SetSkipCheckReplicasConsistent

func (b *RuleBuilder) SetSkipCheckReplicasConsistent(skip bool) *RuleBuilder

SetSkipCheckReplicasConsistent sets the skipCheckReplicasConsistent flag.

Jump to

Keyboard shortcuts

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