This repository was archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Remove scheduler #426
Merged
Merged
Remove scheduler #426
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d6d4023
*: move remove schedulers logic out from restore.
d9218cf
task: add flag of remove scheduler
d6b37a0
tests: add tests of remove scheduler
a3d81e3
Merge branch 'master' of https://github.com/pingcap/br into remove-sc…
00f4aa1
task: move remove-scheduler flag to backup config
306566b
backup: return staged undo function.
YuJuncen 892a712
conn, backup: run undo anyway.
04bdac6
Merge branch 'master' into remove-scheduler
3pointer 3fd8aa3
backup: hide remove schedulers flag
017cbe2
Merge branch 'remove-scheduler' of https://github.com/YuJuncen/br int…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. | ||
|
|
||
| package conn | ||
|
|
||
| import ( | ||
| "context" | ||
| "math" | ||
|
|
||
| "github.com/pingcap/errors" | ||
|
|
||
| "github.com/pingcap/br/pkg/utils" | ||
| ) | ||
|
|
||
| // clusterConfig represents a set of scheduler whose config have been modified | ||
| // along with their original config. | ||
| type clusterConfig struct { | ||
| // Enable PD schedulers before restore | ||
| scheduler []string | ||
| // Original scheudle configuration | ||
| scheduleCfg map[string]interface{} | ||
| } | ||
|
|
||
| var ( | ||
| schedulers = map[string]struct{}{ | ||
| "balance-leader-scheduler": {}, | ||
| "balance-hot-region-scheduler": {}, | ||
| "balance-region-scheduler": {}, | ||
|
|
||
| "shuffle-leader-scheduler": {}, | ||
| "shuffle-region-scheduler": {}, | ||
| "shuffle-hot-region-scheduler": {}, | ||
| } | ||
| pdRegionMergeCfg = []string{ | ||
| "max-merge-region-keys", | ||
| "max-merge-region-size", | ||
| } | ||
| pdScheduleLimitCfg = []string{ | ||
| "leader-schedule-limit", | ||
| "region-schedule-limit", | ||
| "max-snapshot-count", | ||
| } | ||
| ) | ||
|
|
||
| func addPDLeaderScheduler(ctx context.Context, mgr *Mgr, removedSchedulers []string) error { | ||
| for _, scheduler := range removedSchedulers { | ||
| err := mgr.AddScheduler(ctx, scheduler) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func restoreSchedulers(ctx context.Context, mgr *Mgr, clusterCfg clusterConfig) error { | ||
| if err := addPDLeaderScheduler(ctx, mgr, clusterCfg.scheduler); err != nil { | ||
| return errors.Annotate(err, "fail to add PD schedulers") | ||
| } | ||
| mergeCfg := make(map[string]interface{}) | ||
| for _, cfgKey := range pdRegionMergeCfg { | ||
| value := clusterCfg.scheduleCfg[cfgKey] | ||
| if value == nil { | ||
| // Ignore non-exist config. | ||
| continue | ||
| } | ||
| mergeCfg[cfgKey] = value | ||
| } | ||
| if err := mgr.UpdatePDScheduleConfig(ctx, mergeCfg); err != nil { | ||
| return errors.Annotate(err, "fail to update PD merge config") | ||
| } | ||
|
|
||
| scheduleLimitCfg := make(map[string]interface{}) | ||
| for _, cfgKey := range pdScheduleLimitCfg { | ||
| value := clusterCfg.scheduleCfg[cfgKey] | ||
| if value == nil { | ||
| // Ignore non-exist config. | ||
| continue | ||
| } | ||
| scheduleLimitCfg[cfgKey] = value | ||
| } | ||
| if err := mgr.UpdatePDScheduleConfig(ctx, scheduleLimitCfg); err != nil { | ||
| return errors.Annotate(err, "fail to update PD schedule config") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (mgr *Mgr) makeUndoFunctionByConfig(config clusterConfig) utils.UndoFunc { | ||
| restore := func(ctx context.Context) error { | ||
| return restoreSchedulers(ctx, mgr, config) | ||
| } | ||
| return restore | ||
| } | ||
|
|
||
| // RemoveSchedulers removes the schedulers that may slow down BR speed. | ||
| func (mgr *Mgr) RemoveSchedulers(ctx context.Context) (undo utils.UndoFunc, err error) { | ||
| undo = utils.Nop | ||
|
|
||
| // Remove default PD scheduler that may affect restore process. | ||
| existSchedulers, err := mgr.ListSchedulers(ctx) | ||
| if err != nil { | ||
| return | ||
| } | ||
| needRemoveSchedulers := make([]string, 0, len(existSchedulers)) | ||
| for _, s := range existSchedulers { | ||
| if _, ok := schedulers[s]; ok { | ||
| needRemoveSchedulers = append(needRemoveSchedulers, s) | ||
| } | ||
| } | ||
| scheduler, err := removePDLeaderScheduler(ctx, mgr, needRemoveSchedulers) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| undo = mgr.makeUndoFunctionByConfig(clusterConfig{scheduler: scheduler}) | ||
|
|
||
| stores, err := mgr.GetPDClient().GetAllStores(ctx) | ||
| if err != nil { | ||
| return | ||
| } | ||
| scheduleCfg, err := mgr.GetPDScheduleConfig(ctx) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| undo = mgr.makeUndoFunctionByConfig(clusterConfig{scheduler: scheduler, scheduleCfg: scheduleCfg}) | ||
|
|
||
| disableMergeCfg := make(map[string]interface{}) | ||
| for _, cfgKey := range pdRegionMergeCfg { | ||
| value := scheduleCfg[cfgKey] | ||
| if value == nil { | ||
| // Ignore non-exist config. | ||
| continue | ||
| } | ||
| // Disable region merge by setting config to 0. | ||
| disableMergeCfg[cfgKey] = 0 | ||
| } | ||
| err = mgr.UpdatePDScheduleConfig(ctx, disableMergeCfg) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| scheduleLimitCfg := make(map[string]interface{}) | ||
| for _, cfgKey := range pdScheduleLimitCfg { | ||
| value := scheduleCfg[cfgKey] | ||
| if value == nil { | ||
| // Ignore non-exist config. | ||
| continue | ||
| } | ||
|
|
||
| // Speed update PD scheduler by enlarging scheduling limits. | ||
| // Multiply limits by store count but no more than 40. | ||
| // Larger limit may make cluster unstable. | ||
| limit := int(value.(float64)) | ||
| scheduleLimitCfg[cfgKey] = math.Min(40, float64(limit*len(stores))) | ||
| } | ||
| return undo, mgr.UpdatePDScheduleConfig(ctx, scheduleLimitCfg) | ||
| } | ||
|
|
||
| func removePDLeaderScheduler(ctx context.Context, mgr *Mgr, existSchedulers []string) ([]string, error) { | ||
| removedSchedulers := make([]string, 0, len(existSchedulers)) | ||
| for _, scheduler := range existSchedulers { | ||
| err := mgr.RemoveScheduler(ctx, scheduler) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| removedSchedulers = append(removedSchedulers, scheduler) | ||
| } | ||
| return removedSchedulers, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
maybe we should hide it or let user know this will impact on online cluster.