Skip to content

Commit

Permalink
use hex encode
Browse files Browse the repository at this point in the history
Signed-off-by: 童剑 <[email protected]>
  • Loading branch information
bufferflies committed Jan 16, 2025
1 parent d86148f commit 8bdb7bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pkg/core/basic_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package core

import (
"bytes"
"encoding/json"

"github.com/tikv/pd/pkg/core/constant"
)
Expand Down Expand Up @@ -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{
Expand Down
9 changes: 5 additions & 4 deletions tools/pd-ctl/pdctl/command/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] <engine> <role> <start_key> <end_key>",
Short: "add a scheduler to balance region for given range",
Run: addSchedulerForBalanceRangeCommandFunc,
Use: "balance-range-scheduler [--format=raw|encode|hex] <engine> <role> <start_key> <end_key>",
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
Expand Down
5 changes: 2 additions & 3 deletions tools/pd-ctl/tests/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package scheduler_test

import (
"encoding/base64"
"encoding/json"
"fmt"
"reflect"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 8bdb7bc

Please sign in to comment.