Skip to content

Commit

Permalink
scheduler: fix the bug that balance-hot-region-scheduler does not sto…
Browse files Browse the repository at this point in the history
…re config when it starts (#5702)

close #5701

Signed-off-by: HunDunDM <hundundm@gmail.com>
  • Loading branch information
HunDunDM authored Nov 11, 2022
1 parent 179dbe1 commit fcfcda3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/cluster/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,15 @@ func TestAddScheduler(t *testing.T) {
re.NoError(err)
re.NoError(co.addScheduler(gls))

hb, err := schedule.CreateScheduler(schedulers.HotRegionType, oc, storage.NewStorageWithMemoryBackend(), schedule.ConfigJSONDecoder([]byte("{}")))
re.NoError(err)
conf, err = hb.EncodeConfig()
re.NoError(err)
data = make(map[string]interface{})
re.NoError(json.Unmarshal(conf, &data))
re.Contains(data, "enable-for-tiflash")
re.Equal("true", data["enable-for-tiflash"].(string))

// Transfer all leaders to store 1.
waitOperator(re, co, 2)
region2 := tc.GetRegion(2)
Expand Down
4 changes: 4 additions & 0 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (h *hotScheduler) GetType() string {
return HotRegionType
}

func (h *hotScheduler) EncodeConfig() ([]byte, error) {
return h.conf.EncodeConfig()
}

func (h *hotScheduler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.conf.ServeHTTP(w, r)
}
Expand Down
14 changes: 14 additions & 0 deletions server/schedulers/hot_region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2618,3 +2618,17 @@ func TestExpect(t *testing.T) {
re.Equal(testCase.allow, bs.checkDstByPriorityAndTolerance(srcToDst(testCase.load), srcToDst(testCase.expect), toleranceRatio))
}
}

// ref https://github.com/tikv/pd/issues/5701
func TestEncodeConfig(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
opt := config.NewTestOptions()
tc := mockcluster.NewCluster(ctx, opt)
sche, err := schedule.CreateScheduler(HotRegionType, schedule.NewOperatorController(ctx, tc, nil), storage.NewStorageWithMemoryBackend(), schedule.ConfigJSONDecoder([]byte("null")))
re.NoError(err)
data, err := sche.EncodeConfig()
re.NoError(err)
re.NotEqual("null", string(data))
}

0 comments on commit fcfcda3

Please sign in to comment.