-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: refine the bundle contruction logic #28450
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
if uint64(len(regions)) > followers { | ||
return nil, fmt.Errorf("%w: remain %d region to schedule, only %d follower left", ErrInvalidPlacementOptions, uint64(len(regions)), followers) | ||
} | ||
|
||
if len(regions) == 0 { | ||
constraints, err := NewConstraints(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Rules = append(Rules, NewRule(Follower, followers, constraints)) | ||
} else { | ||
count := followers / uint64(len(regions)) | ||
rem := followers - count*uint64(len(regions)) | ||
for _, region := range regions { | ||
constraints, err = NewConstraints([]string{fmt.Sprintf("+region=%s", region)}) | ||
if err != nil { | ||
return nil, fmt.Errorf("%w: invalid region of 'Regions', '%s'", err, region) | ||
} | ||
replica := count | ||
if rem > 0 { | ||
replica += 1 | ||
rem-- | ||
} | ||
Rules = append(Rules, NewRule(Follower, replica, constraints)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old logic is replaced by region in [a,b,c]
completely, which relies on PD to balance(the result is deterministic). And to balance it perfectly, we must set location labels manually for every rule. PD will score every schedule combination to see if every single rule has the best possible isolation, i.e. peers are far from each other.
Previously we will construct region in [a]
for every region a
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make PD balance the peers, I think it is required that the label must be included in the LocationLabels
?
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
if uint64(len(regions)) > followers { | ||
return nil, fmt.Errorf("%w: remain %d region to schedule, only %d follower left", ErrInvalidPlacementOptions, uint64(len(regions)), followers) | ||
} | ||
|
||
if len(regions) == 0 { | ||
constraints, err := NewConstraints(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Rules = append(Rules, NewRule(Follower, followers, constraints)) | ||
} else { | ||
count := followers / uint64(len(regions)) | ||
rem := followers - count*uint64(len(regions)) | ||
for _, region := range regions { | ||
constraints, err = NewConstraints([]string{fmt.Sprintf("+region=%s", region)}) | ||
if err != nil { | ||
return nil, fmt.Errorf("%w: invalid region of 'Regions', '%s'", err, region) | ||
} | ||
replica := count | ||
if rem > 0 { | ||
replica += 1 | ||
rem-- | ||
} | ||
Rules = append(Rules, NewRule(Follower, replica, constraints)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make PD balance the peers, I think it is required that the label must be included in the LocationLabels
?
Here: For sugar options, there are only 4 location labels, according to https://github.com/pingcap/tidb/blob/master/docs/design/2020-06-24-placement-rules-in-sql.md#direct-assignment. |
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
Role: role, | ||
Count: int(replicas), | ||
Constraints: cnst, | ||
LocationLabels: []string{"region", "zone", "rack", "host"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one question: what this two fields is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For isolation scores, it is used to compare which schedule(in all possible schedule combination cases) is better. Say region=sh,bj,us
, 2,1,0
will have a lower score than 1,1,1
because of the existence of LocationLaels: []string{..., region, ...}
. Similar arguments apply to zone,rack,host
.
As for IsolationLevel
, it means two locations are far enough and will affect schedule behaviors. Refer https://github.com/tikv/pd/blob/740fac18e89fa1754a40f5ec885b5e5b6caa2471/server/schedule/filter/filters.go#L696-L701.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
Signed-off-by: xhe <xw897002528@gmail.com>
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 946e6ab
|
What problem does this PR solve?
Issue Number: #18030
Problem Summary: Several days ago, we had a meeting and decided to change the logic a little bit, refer weekly report.
What is changed and how it works?
voterConstraints
andvoters
are removed. Later parser should remove the counter part, too.NewMergeRules
is replaced withNewBundleFromOptions
for validation.primaryRegion
must be included inregions
.locationLabels: [region, zone, rack, host]
to every rule.locationLabels
to balance the schedule automatically, rather than constructing for every region separately. It is safe since PD will exhaust all combinations recursively for the best isolation result.NewConstraintsDirect
andNewConstraintDirect
helper.Check List
Tests
Documentation
Release note