diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index 4c85bb64037..43c6429cd4f 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -641,6 +641,16 @@ func addStoreToSchedulerConfig(cmd *cobra.Command, schedulerName string, args [] cmd.Println(cmd.UsageString()) return } + + exist, err := checkSchedulerExist(cmd, schedulerName) + if err != nil { + return + } + if !exist { + cmd.Printf("Unable to update config: scheduler %s does not exist.\n", schedulerName) + return + } + storeID, err := strconv.ParseUint(args[0], 10, 64) if err != nil { cmd.Println(err) @@ -768,8 +778,17 @@ func deleteStoreFromSchedulerConfig(cmd *cobra.Command, schedulerName string, ar cmd.Println(cmd.Usage()) return } + exist, err := checkSchedulerExist(cmd, schedulerName) + if err != nil { + return + } + if !exist { + cmd.Printf("Unable to update config: scheduler %s does not exist.\n", schedulerName) + return + } + path := path.Join(schedulerConfigPrefix, "/", schedulerName, "delete", args[0]) - _, err := doRequest(cmd, path, http.MethodDelete, http.Header{}) + _, err = doRequest(cmd, path, http.MethodDelete, http.Header{}) if err != nil { cmd.Println(err) return diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index 3a6e29f3586..8c96f5ee3fa 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -204,6 +204,12 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { for idx := range schedulers { checkStorePause([]uint64{}, schedulers[idx]) + + // will fail because the scheduler is not existed + args = []string{"-u", pdAddr, "scheduler", "config", schedulers[idx], "add-store", "3"} + output := mustExec(re, cmd, args, nil) + re.Contains(output, fmt.Sprintf("Unable to update config: scheduler %s does not exist.", schedulers[idx])) + // scheduler add command args = []string{"-u", pdAddr, "scheduler", "add", schedulers[idx], "2"} expected = map[string]bool{ @@ -315,7 +321,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-2"}, nil) re.Contains(echo, "Success!") echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-1"}, nil) - re.Contains(echo, "404") + re.Contains(echo, "Unable to update config: scheduler evict-leader-scheduler does not exist.") testutil.Eventually(re, func() bool { // wait for removed scheduler to be synced to scheduling server. echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", "evict-leader-scheduler"}, nil) return strings.Contains(echo, "[404] scheduler not found")