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

api: add a new scheduler to balance the regions of the given key range #8988

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

bufferflies
Copy link
Contributor

What problem does this PR solve?

Issue Number: Close #8987

What is changed and how does it work?

Check List

Tests

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

Code changes

Side effects

Related changes

Release note

None.

Copy link
Contributor

ti-chi-bot bot commented Jan 10, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jan 10, 2025
Copy link
Contributor

ti-chi-bot bot commented Jan 10, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from bufferflies, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 10, 2025
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 64.25121% with 74 lines in your changes missing coverage. Please review.

Project coverage is 76.32%. Comparing base (75cdec4) to head (8bdb7bc).
Report is 1105 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8988      +/-   ##
==========================================
+ Coverage   74.91%   76.32%   +1.40%     
==========================================
  Files         416      466      +50     
  Lines       42103    70740   +28637     
==========================================
+ Hits        31543    53994   +22451     
- Misses       7810    13391    +5581     
- Partials     2750     3355     +605     
Flag Coverage Δ
unittests 76.32% <64.25%> (+1.40%) ⬆️

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

@bufferflies bufferflies force-pushed the balance_key_range branch 2 times, most recently from fe71a54 to cb8a4b9 Compare January 14, 2025 08:21
Signed-off-by: 童剑 <[email protected]>
@bufferflies bufferflies marked this pull request as ready for review January 14, 2025 09:56
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 14, 2025
schedulerType := types.ConvertOldStrToType[scheduler.Type]
schedulerType, ok := types.ConvertOldStrToType[scheduler.Type]
if !ok {
log.Error("scheduler not found ", zap.String("type", scheduler.Type))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Error("scheduler not found ", zap.String("type", scheduler.Type))
log.Error("scheduler not found", zap.String("type", scheduler.Type))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -35,6 +35,8 @@ const (
OpMerge
// Initiated by range scheduler.
OpRange
// Initiated by key range scheduler.
OpKeyRange
Copy link
Member

Choose a reason for hiding this comment

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

Can we just reuse range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

type balanceKeyRangeSchedulerConfig struct {
syncutil.RWMutex
schedulerConfig
balanceKeyRangeSchedulerParam
Copy link
Member

Choose a reason for hiding this comment

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

Shall we use a slice to support multiple key ranges with different roles or engines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to support a multi-key range with same role and engine.

@@ -143,6 +147,7 @@ var (
"split-bucket-scheduler": SplitBucketScheduler,
"transfer-witness-leader-scheduler": TransferWitnessLeaderScheduler,
"label-scheduler": LabelScheduler,
"balance-key-range-scheduler": BalanceKeyRangeScheduler,
Copy link
Member

Choose a reason for hiding this comment

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

How about balance range scheduler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

})
re.Equal(float64(time.Hour.Nanoseconds()), conf["timeout"])
ranges := conf["ranges"].([]any)[0].(map[string]any)
re.Equal(base64.StdEncoding.EncodeToString([]byte("a")), ranges["start-key"])
Copy link
Member

Choose a reason for hiding this comment

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

base64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed it

@@ -374,6 +375,17 @@ func NewBalanceWitnessSchedulerCommand() *cobra.Command {
return c
}

// NewBalanceRangeSchedulerCommand returns a command to add a balance-key-range-scheduler.
func NewBalanceRangeSchedulerCommand() *cobra.Command {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to support it? It's hard to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it's helpful to debug it in the first step, and then it recommends the SQL function description

Signed-off-by: 童剑 <[email protected]>
@bufferflies bufferflies changed the title api: add new scheduler for balance the regions of the given key range api: add a new scheduler to balance the regions of the given key range Jan 17, 2025
Role string `json:"role"`
Engine string `json:"engine"`
Timeout time.Duration `json:"timeout"`
Ranges []core.KeyRange `json:"ranges"`
Copy link
Contributor

@nolouch nolouch Jan 17, 2025

Choose a reason for hiding this comment

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

I wonder if we can let the API interface like:

type KeyRange strut {
     Alias string `json:"alias"`
     KeyRange string `json:"range"`
}

Then we can alias the table name by tidb or others to help the user read it.

type balanceKeyRangeSchedulerParam struct {
Role string `json:"role"`
Engine string `json:"engine"`
Timeout time.Duration `json:"timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do all ranges share the same timeout?

@@ -0,0 +1,151 @@
package schedulers
Copy link
Member

Choose a reason for hiding this comment

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

Need a license and please also change the filename.

"github.com/tikv/pd/pkg/utils/syncutil"
)

type balanceKeyRangeSchedulerHandler struct {
Copy link
Member

Choose a reason for hiding this comment

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

Keep using balanceRangeSchedulerHandler?

}

// EncodeConfig serializes the config.
func (s *balanceKeyRangeScheduler) EncodeConfig() ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

It's a little bit confusing to have both EncodeConfig and encodeConfig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has signed the dco. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

api: add new scheduler for balance the regions of the given key range
3 participants