Skip to content

Commit

Permalink
This is an automated cherry-pick of #58637
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
JaySon-Huang authored and ti-chi-bot committed Jan 24, 2025
1 parent 5e39597 commit fb4dc8b
Show file tree
Hide file tree
Showing 4 changed files with 1,498 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ddl/placement/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,19 @@ func (b *Bundle) String() string {

// Tidy will post optimize Rules, trying to generate rules that suits PD.
func (b *Bundle) Tidy() error {
<<<<<<< HEAD:ddl/placement/bundle.go
extraCnt := map[PeerRoleType]int{}
newRules := b.Rules[:0]

// One Bundle is from one PlacementSettings, rule share same location labels, so we can use the first rule's location labels.
var locationLabels []string
=======
// refer to tidb#58633
// Does not explicitly set exclude rule with label.key==EngineLabelKey, because the
// PD may wrongly add peer to the unexpected stores if that key is specified.
tempRules := b.Rules[:0]
id := 0
>>>>>>> 4240ce4acc9 (ddl: Remove explicit exclude for "engine" notIn "tiflash" (#58637)):pkg/ddl/placement/bundle.go
for _, rule := range b.Rules {
if len(rule.LocationLabels) > 0 {
locationLabels = rule.LocationLabels
Expand All @@ -304,6 +312,7 @@ func (b *Bundle) Tidy() error {
if rule.Count <= 0 {
continue
}
<<<<<<< HEAD:ddl/placement/bundle.go
// merge all empty constraints
if len(rule.Constraints) == 0 {
extraCnt[rule.Role] += rule.Count
Expand All @@ -326,6 +335,20 @@ func (b *Bundle) Tidy() error {
// it is seen as an empty constraint, so merge it
if len(rule.Constraints) == 1 {
extraCnt[rule.Role] += rule.Count
=======
rule.ID = strconv.Itoa(id)
tempRules = append(tempRules, rule)
id++
}

groups := make(map[string]*constraintsGroup)
finalRules := tempRules[:0]
for _, rule := range tempRules {
key := ConstraintsFingerPrint(&rule.LabelConstraints)
existing, ok := groups[key]
if !ok {
groups[key] = &constraintsGroup{rules: []*pd.Rule{rule}}
>>>>>>> 4240ce4acc9 (ddl: Remove explicit exclude for "engine" notIn "tiflash" (#58637)):pkg/ddl/placement/bundle.go
continue
}
rule.ID = strconv.Itoa(i)
Expand Down
5 changes: 5 additions & 0 deletions ddl/placement/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ func NewConstraint(label string) (Constraint, error) {
return r, fmt.Errorf("%w: %s", ErrInvalidConstraintFormat, label)
}

<<<<<<< HEAD:ddl/placement/constraint.go
if op == In && key == EngineLabelKey && strings.ToLower(val) == EngineLabelTiFlash {
=======
// Does not allow adding rule of tiflash.
if op == pd.In && key == EngineLabelKey && strings.ToLower(val) == EngineLabelTiFlash {
>>>>>>> 4240ce4acc9 (ddl: Remove explicit exclude for "engine" notIn "tiflash" (#58637)):pkg/ddl/placement/constraint.go
return r, fmt.Errorf("%w: %s", ErrUnsupportedConstraint, label)
}

Expand Down
9 changes: 9 additions & 0 deletions ddl/placement/constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ func TestNewConstraint(t *testing.T) {
Values: []string{"tiflash"},
},
},
{
name: "not tiflash_compute",
input: "-engine = tiflash_compute ",
label: pd.LabelConstraint{
Key: "engine",
Op: pd.NotIn,
Values: []string{"tiflash_compute"},
},
},
{
name: "disallow tiflash",
input: "+engine=Tiflash",
Expand Down
Loading

0 comments on commit fb4dc8b

Please sign in to comment.