Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: 童剑 <[email protected]>
  • Loading branch information
bufferflies committed Jan 13, 2025
1 parent 1e6d628 commit d1da5b5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
24 changes: 21 additions & 3 deletions pkg/schedule/schedulers/balance_key_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/pingcap/log"
"github.com/unrolled/render"

"github.com/pingcap/log"

"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/core/constant"
"github.com/tikv/pd/pkg/errs"
Expand All @@ -19,6 +20,7 @@ import (
)

const (
// DefaultTimeout is the default balance key range scheduler timeout.
DefaultTimeout = 1 * time.Hour
)

Expand All @@ -38,7 +40,7 @@ func newBalanceKeyRangeHandler(conf *balanceKeyRangeSchedulerConfig) http.Handle
return router
}

func (handler *balanceKeyRangeSchedulerHandler) updateConfig(w http.ResponseWriter, r *http.Request) {
func (handler *balanceKeyRangeSchedulerHandler) updateConfig(w http.ResponseWriter, _ *http.Request) {
handler.rd.JSON(w, http.StatusBadRequest, "update config is not supported")
}

Expand Down Expand Up @@ -80,11 +82,24 @@ func (conf *balanceKeyRangeSchedulerConfig) clone() *balanceKeyRangeSchedulerPar
}
}

// EncodeConfig serializes the config.
func (s *balanceKeyRangeScheduler) EncodeConfig() ([]byte, error) {
return s.conf.encodeConfig()
}

// ReloadConfig reloads the config.
func (s *balanceKeyRangeScheduler) ReloadConfig() error {
s.conf.Lock()
defer s.conf.Unlock()

newCfg := &balanceKeyRangeSchedulerConfig{}
if err := s.conf.load(newCfg); err != nil {
return err
}
s.conf.Ranges = newCfg.Ranges
s.conf.Timeout = newCfg.Timeout
s.conf.Role = newCfg.Role
s.conf.Engine = newCfg.Engine
return nil
}

Expand All @@ -101,11 +116,13 @@ func (s *balanceKeyRangeScheduler) ServeHTTP(w http.ResponseWriter, r *http.Requ
s.handler.ServeHTTP(w, r)
}

func (s *balanceKeyRangeScheduler) Schedule(_cluster sche.SchedulerCluster, _dryRun bool) ([]*operator.Operator, []plan.Plan) {
// Schedule schedules the balance key range operator.
func (*balanceKeyRangeScheduler) Schedule(_cluster sche.SchedulerCluster, _dryRun bool) ([]*operator.Operator, []plan.Plan) {
log.Debug("balance key range scheduler is scheduling, need to implement")
return nil, nil
}

// IsScheduleAllowed checks if the scheduler is allowed to schedule new operators.
func (s *balanceKeyRangeScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpKeyRange) < cluster.GetSchedulerConfig().GetRegionScheduleLimit()
if !allowed {
Expand All @@ -114,6 +131,7 @@ func (s *balanceKeyRangeScheduler) IsScheduleAllowed(cluster sche.SchedulerClust
return allowed
}

// BalanceKeyRangeCreateOption is used to create a scheduler with an option.
type BalanceKeyRangeCreateOption func(s *balanceKeyRangeScheduler)

// newBalanceKeyRangeScheduler creates a scheduler that tends to keep given peer role on
Expand Down
7 changes: 0 additions & 7 deletions pkg/schedule/schedulers/balance_key_range_test.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/schedule/schedulers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,5 +590,4 @@ func schedulersRegister() {
conf.init(sche.GetName(), storage, conf)
return sche, nil
})

}
2 changes: 1 addition & 1 deletion server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3209,7 +3209,7 @@ func TestAddScheduler(t *testing.T) {
re.NoError(err)
re.NoError(controller.AddScheduler(gls))

gls, err = schedulers.CreateScheduler(types.BalanceKeyRangeScheduler, oc, storage.NewStorageWithMemoryBackend(), schedulers.ConfigSliceDecoder(types.BalanceKeyRangeScheduler, []string{}), controller.RemoveScheduler)
_, err = schedulers.CreateScheduler(types.BalanceKeyRangeScheduler, oc, storage.NewStorageWithMemoryBackend(), schedulers.ConfigSliceDecoder(types.BalanceKeyRangeScheduler, []string{}), controller.RemoveScheduler)
re.Error(err)

gls, err = schedulers.CreateScheduler(types.BalanceKeyRangeScheduler, oc, storage.NewStorageWithMemoryBackend(), schedulers.ConfigSliceDecoder(types.BalanceKeyRangeScheduler, []string{"leaner", "tiflash", "100", "200"}), controller.RemoveScheduler)
Expand Down
1 change: 1 addition & 0 deletions tools/pd-ctl/pdctl/command/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func NewBalanceWitnessSchedulerCommand() *cobra.Command {
return c
}

// NewBalanceKeyRangeSchedulerCommand returns a command to add a balance-key-range-scheduler.
func NewBalanceKeyRangeSchedulerCommand() *cobra.Command {
c := &cobra.Command{
Use: "balance-key-range-scheduler [--format=raw|encode|hex] <engine> <role> <start_key> <end_key>",
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-ctl/tests/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (suite *schedulerTestSuite) checkSchedulerConfig(cluster *pdTests.TestClust
mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", "balance-key-range-scheduler", "show"}, &conf)
re.Equal("learner", conf["role"])
re.Equal("tiflash", conf["engine"])
ranges := conf["ranges"].([]interface{})[0].(map[string]interface{})
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"])

Expand Down

0 comments on commit d1da5b5

Please sign in to comment.