diff --git a/pkg/core/basic_cluster.go b/pkg/core/basic_cluster.go index f7c3c5e93b1..45e06648c35 100644 --- a/pkg/core/basic_cluster.go +++ b/pkg/core/basic_cluster.go @@ -16,6 +16,7 @@ package core import ( "bytes" + "encoding/json" "github.com/tikv/pd/pkg/core/constant" ) @@ -156,6 +157,15 @@ type KeyRange struct { EndKey []byte `json:"end-key"` } +// MarshalJSON marshals to json. +func (kr KeyRange) MarshalJSON() ([]byte, error) { + m := map[string]string{ + "start-key": HexRegionKeyStr(kr.StartKey), + "end-key": HexRegionKeyStr(kr.EndKey), + } + return json.Marshal(m) +} + // NewKeyRange create a KeyRange with the given start key and end key. func NewKeyRange(startKey, endKey string) KeyRange { return KeyRange{ diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index 50525d885fd..1492709fc79 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -375,12 +375,13 @@ func NewBalanceWitnessSchedulerCommand() *cobra.Command { return c } -// NewBalanceRangeSchedulerCommand returns a command to add a balance-key-range-scheduler. +// NewBalanceRangeSchedulerCommand returns a command to add a balance-range-scheduler. func NewBalanceRangeSchedulerCommand() *cobra.Command { c := &cobra.Command{ - Use: "balance-range-scheduler [--format=raw|encode|hex] ", - Short: "add a scheduler to balance region for given range", - Run: addSchedulerForBalanceRangeCommandFunc, + Use: "balance-range-scheduler [--format=raw|encode|hex] ", + Short: "add a scheduler to balance region for given range", + Run: addSchedulerForBalanceRangeCommandFunc, + Deprecated: "balance-range will be deprecated in the future, please use sql instead", } c.Flags().String("format", "hex", "the key format") return c diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index f95cf033239..1d011329c42 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -15,7 +15,6 @@ package scheduler_test import ( - "encoding/base64" "encoding/json" "fmt" "reflect" @@ -554,8 +553,8 @@ func (suite *schedulerTestSuite) checkSchedulerConfig(cluster *pdTests.TestClust }) 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"]) - re.Equal(base64.StdEncoding.EncodeToString([]byte("b")), ranges["end-key"]) + re.Equal(core.HexRegionKeyStr([]byte("a")), ranges["start-key"]) + re.Equal(core.HexRegionKeyStr([]byte("b")), ranges["end-key"]) echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "add", "balance-range-scheduler", "--format=raw", "tiflash", "learner", "a", "b"}, nil) re.Contains(echo, "400")