diff --git a/pkg/schedule/schedulers/evict_leader.go b/pkg/schedule/schedulers/evict_leader.go index 355ea4d4017..403ce79ac28 100644 --- a/pkg/schedule/schedulers/evict_leader.go +++ b/pkg/schedule/schedulers/evict_leader.go @@ -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") } diff --git a/pkg/schedule/schedulers/grant_leader.go b/pkg/schedule/schedulers/grant_leader.go index 6e3ce6c282d..9cf605bf099 100644 --- a/pkg/schedule/schedulers/grant_leader.go +++ b/pkg/schedule/schedulers/grant_leader.go @@ -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") } diff --git a/pkg/schedule/schedulers/init.go b/pkg/schedule/schedulers/init.go index 711ed8f68e2..7c946dd4a05 100644 --- a/pkg/schedule/schedulers/init.go +++ b/pkg/schedule/schedulers/init.go @@ -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) @@ -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") } diff --git a/plugin/scheduler_example/evict_leader.go b/plugin/scheduler_example/evict_leader.go index 1d10530d44e..251583bb1e3 100644 --- a/plugin/scheduler_example/evict_leader.go +++ b/plugin/scheduler_example/evict_leader.go @@ -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) @@ -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") } diff --git a/tests/pdctl/scheduler/scheduler_test.go b/tests/pdctl/scheduler/scheduler_test.go index 8694f06a05a..31079e5df1e 100644 --- a/tests/pdctl/scheduler/scheduler_test.go +++ b/tests/pdctl/scheduler/scheduler_test.go @@ -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)