Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

placement: make Constraints can use dict format #47344

Merged
merged 4 commits into from
Oct 10, 2023

Conversation

nolouch
Copy link
Member

@nolouch nolouch commented Sep 27, 2023

What problem does this PR solve?

Issue Number: close #47254

Problem Summary:
The customer wants to define a cluster with 5 replicas and distributed in 3 regions, leader can be in every region. currently, the rule in SQL cannot conver it.

//  cannot be 2:2:1 distributed
MySQL > create  placement policy mydeploy FOLLOWER_CONSTRAINTS='{ "+region=us-east-1":1, "+region=us-east-2": 2, "+region=us-west-1": 1}';

// leader is located in  us-east-1
MySQL > create  placement policy mydeploy  LEADER_CONSTRAINTS='{"+region=us-east-1":1}'  FOLLOWER_CONSTRAINTS='{ "+region=us-east-1":1, "+region=us-east-2": 2, "+region=us-west-1": 1}';


// cannot create
mysql> create placement policy mydeploy221 CONSTRAINTS='{ "+region=us-east-1":2, "+region=us-east-2": 2, "+region=us-west-1": 1}';
ERROR 1105 (HY000): invalid label constraints format: 'Constraints' should be [constraint1, ...] or any yaml compatible array representation

What is changed and how it works?

supports the dict format for CONSTRAINTS

create placement policy mydeploy221 CONSTRAINTS='{ "+region=us-east-1":2, "+region=us-east-2": 2, "+region=us-west-1": 1}'

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 27, 2023
@nolouch nolouch force-pushed the placement-const branch 2 times, most recently from 23007e2 to 136736a Compare September 27, 2023 16:14
@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

Merging #47344 (8448ec9) into master (9e4922a) will increase coverage by 0.6150%.
The diff coverage is 91.1764%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #47344        +/-   ##
================================================
+ Coverage   72.1485%   72.7635%   +0.6150%     
================================================
  Files          1354       1375        +21     
  Lines        401261     407634      +6373     
================================================
+ Hits         289504     296609      +7105     
+ Misses        92452      92209       -243     
+ Partials      19305      18816       -489     
Flag Coverage Δ
integration 39.5575% <0.0000%> (?)
unit 72.1381% <91.1764%> (-0.0105%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9913% <ø> (ø)
parser 84.6574% <ø> (-0.0108%) ⬇️
br 48.8805% <ø> (-4.3208%) ⬇️

Signed-off-by: nolouch <nolouch@gmail.com>
@nolouch
Copy link
Member Author

nolouch commented Sep 27, 2023

/test unit-test

@tiprow
Copy link

tiprow bot commented Sep 27, 2023

@nolouch: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

}
rules, err = NewRulesWithDictConstraints(role, cnstr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just use error from NewRulesWithDictConstraints, instead of Unmarshal before. Retuning ErrInvalidConstraintsFormat and wrap the error in NewRules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here do precheck to ensure that it is in the actual dict format, then wrap two errors in NewRules or return dict constraints error(definitely it's dict format), it's easier to handle errors. otherwise, we need to unwrap errors from NewRulesWithDictConstraints and handle the error to remove the repeated string in the error message.

ddl/placement/bundle.go Outdated Show resolved Hide resolved
Signed-off-by: nolouch <nolouch@gmail.com>
@nolouch
Copy link
Member Author

nolouch commented Oct 7, 2023

/retest-required

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 8, 2023
Copy link
Contributor

@CabinfeverB CabinfeverB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest LGTM
I found some info in docs https://docs.pingcap.com/tidb/stable/placement-rules-in-sql.

You can either specify constraints in list format ([+disk=ssd]) or in dictionary format ({+disk=ssd: 1,+disk=nvme: 2}).

It seems support dictionary format?

}
if len(followerConstraints) == 0 {
if followerCount > 0 {
return nil, fmt.Errorf("%w: specify follower count without specify follower constraints", ErrInvalidPlacementOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about " specify follower count without specify follower constraints when specify other constraints"?
because we can specify follower count only.

@nolouch
Copy link
Member Author

nolouch commented Oct 10, 2023

@CabinfeverB {+disk=ssd: 1,+disk=nvme: 2} supported in FOLLOW_CONSTRAINT and LEADER_CONSTRAINT, but not avaliable for CONSTRAINT

PTAL again

Signed-off-by: nolouch <nolouch@gmail.com>
Signed-off-by: nolouch <nolouch@gmail.com>
@ti-chi-bot
Copy link

ti-chi-bot bot commented Oct 10, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CabinfeverB, xhebox

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 10, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Oct 10, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-10-08 02:36:15.45353053 +0000 UTC m=+933373.040640675: ☑️ agreed by xhebox.
  • 2023-10-10 06:39:53.437293756 +0000 UTC m=+1120791.024403885: ☑️ agreed by CabinfeverB.

@ti-chi-bot ti-chi-bot bot merged commit 80faa9c into pingcap:master Oct 10, 2023
@nolouch nolouch deleted the placement-const branch October 10, 2023 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule in SQL supports to define 2:2:1 cluster topology
3 participants