-
Notifications
You must be signed in to change notification settings - Fork 729
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
scheduler: add new api to add a new job for the special scheduler #9162
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: 童剑 <[email protected]>
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
c4da339
to
74c5942
Compare
Signed-off-by: 童剑 <[email protected]>
74c5942
to
d628302
Compare
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (60.60%) is below the target coverage (74.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #9162 +/- ##
==========================================
- Coverage 75.76% 75.70% -0.06%
==========================================
Files 476 476
Lines 73149 73285 +136
==========================================
+ Hits 55421 55481 +60
- Misses 14269 14323 +54
- Partials 3459 3481 +22
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR adds a new API for the special scheduler that allows adding and managing jobs by renaming the configuration field from “role” to “rule” and extending job management endpoints while updating tests accordingly.
- Renames the scheduler configuration field from role to rule.
- Introduces new HTTP endpoints to add and delete scheduler jobs.
- Updates tests and core logic to align with the new naming and job state changes.
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tools/pd-ctl/tests/scheduler/scheduler_test.go | Test assertions updated to check for "rule" and new job status value. |
tools/pd-ctl/pdctl/command/scheduler.go | Updated input mapping from "role" to "rule". |
server/api/scheduler.go | Modified scheduler creation to delegate to job update if scheduler exists. |
pkg/schedule/schedulers/balance_range.go | Added job endpoints; updated job ID assignment and JSON marshalling. |
pkg/schedule/schedulers/init.go | Changed parameter handling from role to rule. |
pkg/core/region.go | Renamed Role to Rule with updated JSON encoder/decoder methods. |
Other test and operator files | Adjusted to reflect renaming and new job status handling. |
Files not reviewed (1)
- tools/pd-ut/testdata/group.3.etcdkey: Language not supported
Comments suppressed due to low confidence (1)
pkg/core/region.go:378
- Using a pointer receiver for the String() method may lead to a nil pointer dereference; using a value receiver is safer if no state modification is required.
func (r *Rule) String() string {
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.
Pull Request Overview
This PR adds a new API for scheduling jobs using a specialized scheduler by replacing occurrences of "role" with "rule" and adjusting behavior accordingly. It also introduces new endpoints for job addition and removal, and updates tests and configuration accordingly.
- Updated pd-ctl commands to use "rule" instead of "role".
- Modified API handlers to support job addition/expiration and updated configuration management.
- Adjusted scheduler test cases and core types to align with the new naming.
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tools/pd-ctl/tests/scheduler/scheduler_test.go | Test expectations updated to check for new "rule" and status "running". |
tools/pd-ctl/pdctl/command/scheduler.go | Changed input parameter from "role" to "rule". |
server/api/scheduler.go | Updated scheduler creation logic to forward to job update when scheduler exists. |
pkg/schedule/schedulers/init.go | Updated unescaping and conversion from "role" to "rule" but error messages still refer to "role". |
pkg/schedule/schedulers/balance_range.go | Added job addition and deletion API endpoints; new job ID calculation in addJob may be unsafe. |
pkg/core/region.go | Modified String and JSON functions for Rule from value receiver to pointer receiver. |
Others | Numerous changes across tests and operator influence to adopt the "rule" nomenclature. |
Files not reviewed (1)
- tools/pd-ut/testdata/group.3.etcdkey: Language not supported
Comments suppressed due to low confidence (3)
server/api/scheduler.go:123
- When the scheduler exists and GetSchedulerConfigHandler returns nil (or err is nil), calling err.Error() could lead to a nil pointer dereference. Consider checking if err is nil before calling err.Error() or providing a default error message.
h.r.JSON(w, http.StatusNotAcceptable, err.Error())
pkg/schedule/schedulers/init.go:567
- The error message still refers to "role" even though the new naming convention is "rule". Update the error message for consistency.
return errs.ErrQueryUnescape.FastGenByArgs("role")
pkg/core/region.go:378
- Changing the String method to use a pointer receiver may lead to nil pointer dereferences if called on a non-pointer value. Consider using a value receiver or ensuring callers always use a pointer.
func (r *Rule) String() string {
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
/test |
@bufferflies: The
The following commands are available to trigger optional jobs:
Use
In response to this:
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-sigs/prow repository. |
@@ -360,12 +360,12 @@ func (r *RegionInfo) GetPeer(peerID uint64) *metapb.Peer { | |||
return nil | |||
} | |||
|
|||
// Role is the role of the region. | |||
type Role int | |||
// Rule is the rule for balance range scheduler |
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.
why change name by mistake?
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 design used the rule not role. see pingcap/tidb#59681
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.
If we replace role
with rule
, we also need to edit others
@@ -375,8 +375,8 @@ const ( | |||
) | |||
|
|||
// String returns the string value of the role. |
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.
Some comments also need to be updated
// NewRule creates a new role. | ||
func NewRule(role string) Rule { |
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.
ditto
// GetPeersByRole returns the peers with specified role. | ||
func (r *RegionInfo) GetPeersByRole(role Role) []*metapb.Peer { | ||
switch role { | ||
func (r *RegionInfo) GetPeersByRole(rule Rule) []*metapb.Peer { |
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.
ditto
What problem does this PR solve?
Issue Number: Close #9161
What is changed and how does it work?
Check List
Tests
Code changes
Side effects
Related changes
pingcap/docs
/pingcap/docs-cn
:pingcap/tiup
:Release note