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 0bb25b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 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
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 0bb25b9

Please sign in to comment.