Skip to content

Commit

Permalink
scheduler: rename scatter-range to scatter-range-scheduler (#8607)
Browse files Browse the repository at this point in the history
close #8379

Signed-off-by: okJiang <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
okJiang and ti-chi-bot[bot] authored Sep 24, 2024
1 parent ade5a93 commit ec59a71
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
RegionLabelRulesByIDs = "/pd/api/v1/config/region-label/rules/ids"
// Scheduler
Schedulers = "/pd/api/v1/schedulers"
scatterRangeScheduler = "/pd/api/v1/schedulers/scatter-range-"
scatterRangeScheduler = "/pd/api/v1/schedulers/scatter-range-scheduler-"
// Admin
ResetTS = "/pd/api/v1/admin/reset-ts"
BaseAllocID = "/pd/api/v1/admin/base-alloc-id"
Expand Down Expand Up @@ -183,6 +183,7 @@ func SchedulerByName(name string) string {
}

// ScatterRangeSchedulerWithName returns the scatter range scheduler API with name parameter.
// It is used in https://github.com/pingcap/tidb/blob/2a3352c45dd0f8dd5102adb92879bbfa964e7f5f/pkg/server/handler/tikvhandler/tikv_handler.go#L1252.
func ScatterRangeSchedulerWithName(name string) string {
return fmt.Sprintf("%s%s", scatterRangeScheduler, name)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/scatter_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (conf *scatterRangeSchedulerConfig) getEndKey() []byte {
func (conf *scatterRangeSchedulerConfig) getSchedulerName() string {
conf.RLock()
defer conf.RUnlock()
return fmt.Sprintf("scatter-range-%s", conf.RangeName)
return fmt.Sprintf("%s-%s", types.ScatterRangeScheduler, conf.RangeName)
}

type scatterRangeScheduler struct {
Expand Down
7 changes: 7 additions & 0 deletions pkg/schedule/schedulers/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,12 @@ func FindSchedulerTypeByName(name string) types.CheckerSchedulerType {
}
}
}
// This is for compatibility. Because the string of ScatterRangeScheduler is
// "scatter-range" before. If user adds a ScatterRangeScheduler(which is
// "scatter-range" yet) and then upgrades the cluster(its ScatterRangeScheduler
// is "scatter-range-scheduler"), we need these codes to keep the compatibility.
if len(typ) == 0 && strings.Contains(name, "scatter-range") {
return types.ScatterRangeScheduler
}
return typ
}
6 changes: 3 additions & 3 deletions pkg/schedule/types/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const (
// RandomMergeScheduler is random merge scheduler name.
RandomMergeScheduler CheckerSchedulerType = "random-merge-scheduler"
// ScatterRangeScheduler is scatter range scheduler name.
// TODO: update to `scatter-range-scheduler`
ScatterRangeScheduler CheckerSchedulerType = "scatter-range"
ScatterRangeScheduler CheckerSchedulerType = "scatter-range-scheduler"
// ShuffleHotRegionScheduler is shuffle hot region scheduler name.
ShuffleHotRegionScheduler CheckerSchedulerType = "shuffle-hot-region-scheduler"
// ShuffleLeaderScheduler is shuffle leader scheduler name.
Expand Down Expand Up @@ -135,7 +134,8 @@ var (
"grant-hot-region-scheduler": GrantHotRegionScheduler,
"balance-hot-region-scheduler": BalanceHotRegionScheduler,
"random-merge-scheduler": RandomMergeScheduler,
// TODO: update to `scatter-range-scheduler`
"scatter-range-scheduler": ScatterRangeScheduler,
// TODO: remove `scatter-range` after remove `NewScatterRangeSchedulerCommand` from pd-ctl
"scatter-range": ScatterRangeScheduler,
"shuffle-hot-region-scheduler": ShuffleHotRegionScheduler,
"shuffle-leader-scheduler": ShuffleLeaderScheduler,
Expand Down
4 changes: 2 additions & 2 deletions tests/server/api/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ func (suite *scheduleTestSuite) checkAPI(cluster *tests.TestCluster) {
},
},
{
name: "scatter-range",
createdName: "scatter-range-test",
name: "scatter-range-scheduler",
createdName: "scatter-range-scheduler-test",
args: []arg{{"start_key", ""}, {"end_key", ""}, {"range_name", "test"}},
// Test the scheduler config handler.
extraTestFunc: func(name string) {
Expand Down
14 changes: 13 additions & 1 deletion tools/pd-ctl/pdctl/command/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func NewAddSchedulerCommand() *cobra.Command {
c.AddCommand(NewShuffleRegionSchedulerCommand())
c.AddCommand(NewShuffleHotRegionSchedulerCommand())
c.AddCommand(NewScatterRangeSchedulerCommand())
c.AddCommand(NewScatterRangeSchedulerCommandV2())
c.AddCommand(NewBalanceLeaderSchedulerCommand())
c.AddCommand(NewBalanceRegionSchedulerCommand())
c.AddCommand(NewBalanceHotRegionSchedulerCommand())
Expand Down Expand Up @@ -422,7 +423,18 @@ func addSchedulerCommandFunc(cmd *cobra.Command, args []string) {
// NewScatterRangeSchedulerCommand returns a command to add a scatter-range-scheduler.
func NewScatterRangeSchedulerCommand() *cobra.Command {
c := &cobra.Command{
Use: "scatter-range [--format=raw|encode|hex] <start_key> <end_key> <range_name>",
Use: "scatter-range [--format=raw|encode|hex] <start_key> <end_key> <range_name>",
Run: addSchedulerForScatterRangeCommandFunc,
Deprecated: "scatter-range will be deprecated in the future, please use `scatter-range-scheduler` instead",
}
c.Flags().String("format", "hex", "the key format")
return c
}

// NewScatterRangeSchedulerCommandV2 returns a command to add a scatter-range-scheduler.
func NewScatterRangeSchedulerCommandV2() *cobra.Command {
c := &cobra.Command{
Use: "scatter-range-scheduler [--format=raw|encode|hex] <start_key> <end_key> <range_name>",
Short: "add a scheduler to scatter range",
Run: addSchedulerForScatterRangeCommandFunc,
}
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-ctl/tests/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
"test", "test#", "?test",
/* TODO: to handle case like "tes&t", we need to modify the server's JSON render to unescape the HTML characters */
} {
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "add", "scatter-range", "--format=raw", "a", "b", name}, nil)
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "add", "scatter-range-scheduler", "--format=raw", "a", "b", name}, nil)
re.Contains(echo, "Success!")
schedulerName := fmt.Sprintf("scatter-range-%s", name)
schedulerName := fmt.Sprintf("scatter-range-scheduler-%s", name)
// test show scheduler
testutil.Eventually(re, func() bool {
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "show"}, nil)
Expand Down

0 comments on commit ec59a71

Please sign in to comment.