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
…8773)

ref #8756

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

Co-authored-by: okJiang <[email protected]>
  • Loading branch information
ti-chi-bot and okJiang authored Nov 5, 2024
1 parent ba7d856 commit a385ada
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 @@ -77,7 +77,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 @@ -56,7 +56,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
schedule.RegisterSliceDecoderBuilder(EvictLeaderType, func(args []string) schedule.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 @@ -235,7 +235,7 @@ func schedulersRegister() {
// grant leader
schedule.RegisterSliceDecoderBuilder(GrantLeaderType, func(args []string) schedule.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() {
schedule.RegisterSliceDecoderBuilder(EvictLeaderType, func(args []string) schedule.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 @@ -529,6 +529,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 a385ada

Please sign in to comment.