diff --git a/pkg/schedule/handler/handler.go b/pkg/schedule/handler/handler.go index 5068ee02d5f..fb19d80bfd7 100644 --- a/pkg/schedule/handler/handler.go +++ b/pkg/schedule/handler/handler.go @@ -1333,19 +1333,28 @@ func (h *Handler) BalanceKeyrange(data string) (string, error) { // CheckBalanceKeyrangeStatus returns the status of the balance-keyrange scheduler. func (h *Handler) CheckBalanceKeyrangeStatus() (any, error) { sc, err := h.GetSchedulersController() + makeJsonResp := func(s string) any { + return struct { + Scheduling bool `json:"scheduling"` + ErrMsg string `json:"err_msg"` + }{ + Scheduling: false, + ErrMsg: s, + } + } if err != nil { - return "", err + return makeJsonResp("Get scheduler control error"), err } s := sc.GetScheduler(types.BalanceKeyrangeScheduler.String()) if s == nil { - return "", nil + return makeJsonResp("No scheduler found"), nil } if s.IsDisable() { - return "", nil + return makeJsonResp("Scheduler disabled"), nil } st := sc.GetSchedulerStatus(types.BalanceKeyrangeScheduler.String()) if st == nil { - return "", nil + return makeJsonResp("can't get scheduler status"), nil } return st, nil } diff --git a/pkg/schedule/schedulers/balance_keyrange.go b/pkg/schedule/schedulers/balance_keyrange.go index f23943d3f30..4e5b60c2449 100644 --- a/pkg/schedule/schedulers/balance_keyrange.go +++ b/pkg/schedule/schedulers/balance_keyrange.go @@ -359,11 +359,13 @@ func (s *balanceKeyrangeScheduler) GetStatus() any { RunningOps []*OperatorWrapper `json:"running"` Pending []*OperatorWrapper `json:"pending"` TotalCount int `json:"total"` + ErrMsg string `json:"err_msg"` }{ Scheduling: scheduling, RunningOps: running, Pending: pending, TotalCount: total, + ErrMsg: "", } return j } diff --git a/pkg/schedule/schedulers/balance_keyrange_test.go b/pkg/schedule/schedulers/balance_keyrange_test.go index fd8066a55fa..2588c4d78e6 100644 --- a/pkg/schedule/schedulers/balance_keyrange_test.go +++ b/pkg/schedule/schedulers/balance_keyrange_test.go @@ -247,7 +247,7 @@ func assertValidateMigrationPlan(re *require.Assertions, ops []*MigrationOp, sto storesIn[op.ToStore] += len(op.Regions) storesOut[op.FromStore] += len(op.Regions) // For each region in migration plan, it no longer exists in FromStore, and exists in ToStore - for rid, _ := range op.Regions { + for rid := range op.Regions { inTo := false inFr := false r, ok := regionMap[rid] @@ -281,7 +281,7 @@ type regionStoresPair struct { func buildRedistributeRegionsTestCases(storeIDs []uint64, regionDist []regionStoresPair) ([]*metapb.Store, []*core.RegionInfo) { storeIdLabels := []uint64{} - for _ = range storeIDs { + for range storeIDs { storeIdLabels = append(storeIdLabels, 0) } return buildRedistributeRegionsTestCasesWithLabel(storeIDs, storeIdLabels, regionDist) diff --git a/server/api/region.go b/server/api/region.go index 978c81a102b..3b5010a4be8 100644 --- a/server/api/region.go +++ b/server/api/region.go @@ -133,7 +133,6 @@ func (h *regionsHandler) CheckRegionsReplicated(w http.ResponseWriter, r *http.R // @Tags region // @Summary -// @Accept json // @Param start_key body string true "Regions start key, hex encoded" // @Param end_key body string true "Regions end key, hex encoded" // @Param batch_size body string true "Maximum operators scheduled in one"