Skip to content

Commit

Permalink
scheduler: use right check for evict/grant leader scheduler (#8758)
Browse files Browse the repository at this point in the history
ref #8756

Signed-off-by: okJiang <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
okJiang and ti-chi-bot[bot] authored Nov 5, 2024
1 parent 935b200 commit 10e4889
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (conf *evictLeaderSchedulerConfig) BuildWithArgs(args []string) error {
failpoint.Inject("buildWithArgsErr", func() {
failpoint.Return(errors.New("fail to build with args"))
})
if len(args) != 1 {
if len(args) < 1 {
return errs.ErrSchedulerConfig.FastGenByArgs("id")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/grant_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type grantLeaderSchedulerConfig struct {
}

func (conf *grantLeaderSchedulerConfig) BuildWithArgs(args []string) error {
if len(args) != 1 {
if len(args) < 1 {
return errs.ErrSchedulerConfig.FastGenByArgs("id")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/schedule/schedulers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func schedulersRegister() {
// evict leader
RegisterSliceDecoderBuilder(EvictLeaderType, func(args []string) ConfigDecoder {
return func(v interface{}) error {
if len(args) != 1 {
if len(args) < 1 {
return errs.ErrSchedulerConfig.FastGenByArgs("id")
}
conf, ok := v.(*evictLeaderSchedulerConfig)
Expand Down Expand Up @@ -236,7 +236,7 @@ func schedulersRegister() {
// grant leader
RegisterSliceDecoderBuilder(GrantLeaderType, func(args []string) ConfigDecoder {
return func(v interface{}) error {
if len(args) != 1 {
if len(args) < 1 {
return errs.ErrSchedulerConfig.FastGenByArgs("id")
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/scheduler_example/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
func init() {
schedulers.RegisterSliceDecoderBuilder(EvictLeaderType, func(args []string) schedulers.ConfigDecoder {
return func(v interface{}) error {
if len(args) != 1 {
if len(args) < 1 {
return errors.New("should specify the store-id")
}
conf, ok := v.(*evictLeaderSchedulerConfig)
Expand Down Expand Up @@ -99,7 +99,7 @@ type evictLeaderSchedulerConfig struct {
}

func (conf *evictLeaderSchedulerConfig) BuildWithArgs(args []string) error {
if len(args) != 1 {
if len(args) < 1 {
return errors.New("should specify the store-id")
}

Expand Down
7 changes: 7 additions & 0 deletions tests/pdctl/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,13 @@ func TestEvictLeaderScheduler(t *testing.T) {
output, err := pdctl.ExecuteCommand(cmd, []string{"-u", pdAddr, "scheduler", "add", "evict-leader-scheduler", "2"}...)
re.NoError(err)
re.Contains(string(output), "Success!")
re.False(false, leaderServer.GetRaftCluster().GetStore(2).AllowLeaderTransfer())
// execute twice to verify this issue: https://github.com/tikv/pd/issues/8756
output, err = pdctl.ExecuteCommand(cmd, []string{"-u", pdAddr, "scheduler", "add", "evict-leader-scheduler", "2"}...)
re.NoError(err)
re.Contains(string(output), "Success!")
re.False(false, leaderServer.GetRaftCluster().GetStore(2).AllowLeaderTransfer())

failpoint.Enable("github.com/tikv/pd/pkg/schedule/schedulers/buildWithArgsErr", "return(true)")
output, err = pdctl.ExecuteCommand(cmd, []string{"-u", pdAddr, "scheduler", "add", "evict-leader-scheduler", "1"}...)
re.NoError(err)
Expand Down

0 comments on commit 10e4889

Please sign in to comment.