From 0cdc90c158b2d789ce8c35166198d2c1c1de0877 Mon Sep 17 00:00:00 2001 From: yisaer Date: Thu, 22 Jul 2021 12:49:51 +0800 Subject: [PATCH 01/11] support api Signed-off-by: yisaer --- server/schedulers/hot_region_config.go | 26 +++++++++++++++++-------- tests/pdctl/scheduler/scheduler_test.go | 15 ++++++++++++++ tools/pd-ctl/pdctl/command/scheduler.go | 20 ++++++++++++++++++- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/server/schedulers/hot_region_config.go b/server/schedulers/hot_region_config.go index 7283eadfb3e..20ca2ed9fd6 100644 --- a/server/schedulers/hot_region_config.go +++ b/server/schedulers/hot_region_config.go @@ -30,6 +30,12 @@ import ( "github.com/unrolled/render" ) +const ( + NonePriority = "" + BytePriority = "byte" + KeyPriority = "key" +) + // params about hot region. func initHotRegionScheduleConfig() *hotRegionSchedulerConfig { return &hotRegionSchedulerConfig{ @@ -45,6 +51,8 @@ func initHotRegionScheduleConfig() *hotRegionSchedulerConfig { MaxPeerNum: 1000, SrcToleranceRatio: 1.05, // Tolerate 5% difference DstToleranceRatio: 1.05, // Tolerate 5% difference + ReadPriorities: []string{}, + WritePriorities: []string{}, } } @@ -59,14 +67,16 @@ type hotRegionSchedulerConfig struct { // rank step ratio decide the step when calculate rank // step = max current * rank step ratio - ByteRateRankStepRatio float64 `json:"byte-rate-rank-step-ratio"` - KeyRateRankStepRatio float64 `json:"key-rate-rank-step-ratio"` - QueryRateRankStepRatio float64 `json:"query-rate-rank-step-ratio"` - CountRankStepRatio float64 `json:"count-rank-step-ratio"` - GreatDecRatio float64 `json:"great-dec-ratio"` - MinorDecRatio float64 `json:"minor-dec-ratio"` - SrcToleranceRatio float64 `json:"src-tolerance-ratio"` - DstToleranceRatio float64 `json:"dst-tolerance-ratio"` + ByteRateRankStepRatio float64 `json:"byte-rate-rank-step-ratio"` + KeyRateRankStepRatio float64 `json:"key-rate-rank-step-ratio"` + QueryRateRankStepRatio float64 `json:"query-rate-rank-step-ratio"` + CountRankStepRatio float64 `json:"count-rank-step-ratio"` + GreatDecRatio float64 `json:"great-dec-ratio"` + MinorDecRatio float64 `json:"minor-dec-ratio"` + SrcToleranceRatio float64 `json:"src-tolerance-ratio"` + DstToleranceRatio float64 `json:"dst-tolerance-ratio"` + ReadPriorities []string `json:"read-priorities"` + WritePriorities []string `json:"write-priorities"` } func (conf *hotRegionSchedulerConfig) EncodeConfig() ([]byte, error) { diff --git a/tests/pdctl/scheduler/scheduler_test.go b/tests/pdctl/scheduler/scheduler_test.go index c4a257ffccb..75eee67157b 100644 --- a/tests/pdctl/scheduler/scheduler_test.go +++ b/tests/pdctl/scheduler/scheduler_test.go @@ -269,6 +269,8 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { "minor-dec-ratio": 0.99, "src-tolerance-ratio": 1.05, "dst-tolerance-ratio": 1.05, + "read-priorities": []interface{}{}, + "write-priorities": []interface{}{}, } c.Assert(conf, DeepEquals, expected1) mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "src-tolerance-ratio", "1.02"}, nil) @@ -277,6 +279,19 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "key"}, nil) + expected1["read-priorities"] = []interface{}{"key"} + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "key,byte"}, nil) + expected1["read-priorities"] = []interface{}{"key", "byte"} + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "none"}, nil) + expected1["read-priorities"] = []interface{}{} + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) + // test show scheduler with paused and disabled status. checkSchedulerWithStatusCommand := func(args []string, status string, expected []string) { if args != nil { diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index dd93df487cf..fee39547723 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -17,6 +17,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/tikv/pd/server/schedulers" "net/http" "net/url" "path" @@ -527,7 +528,24 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar if err != nil { val = value } - input[key] = val + if schedulerName == "balance-hot-region-scheduler" && (key == "read-priorities" || key == "write-priorities") { + priorities := make([]string, 0) + if value == "none" { + } else { + for _, priority := range strings.Split(value, ",") { + if priority != schedulers.BytePriority && priority != schedulers.KeyPriority { + cmd.Println(fmt.Sprintf("priority should be one of %s,%s,%s", + schedulers.BytePriority, + schedulers.KeyPriority, + "none")) + } + priorities = append(priorities, priority) + } + } + input[key] = priorities + } else { + input[key] = val + } postJSON(cmd, path.Join(schedulerConfigPrefix, schedulerName, "config"), input) } From 9641180d2938ac92b5fdaf56c1474f07c853e250 Mon Sep 17 00:00:00 2001 From: yisaer Date: Thu, 22 Jul 2021 12:59:53 +0800 Subject: [PATCH 02/11] support api Signed-off-by: yisaer --- tools/pd-ctl/pdctl/command/scheduler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index fee39547723..4e4b9528018 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -17,7 +17,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/tikv/pd/server/schedulers" "net/http" "net/url" "path" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/errors" "github.com/spf13/cobra" + "github.com/tikv/pd/server/schedulers" ) var ( From 7c3b792c2bf8b613a6fc1c20df715f8563e5e8f4 Mon Sep 17 00:00:00 2001 From: yisaer Date: Thu, 22 Jul 2021 13:10:07 +0800 Subject: [PATCH 03/11] support api Signed-off-by: yisaer --- server/schedulers/hot_region_config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/schedulers/hot_region_config.go b/server/schedulers/hot_region_config.go index 20ca2ed9fd6..32cbd8ab255 100644 --- a/server/schedulers/hot_region_config.go +++ b/server/schedulers/hot_region_config.go @@ -31,8 +31,11 @@ import ( ) const ( + // NonePriority indicates there is no dim priority for hot-region-scheduler NonePriority = "" + // BytePriority indicates hot-region-scheduler prefer byte dim BytePriority = "byte" + // KeyPriority indicates hot-region-scheduler prefer key dim KeyPriority = "key" ) From 467c36e0141d39e6eff5bc5abafe31b8c075bea4 Mon Sep 17 00:00:00 2001 From: yisaer Date: Thu, 22 Jul 2021 13:30:34 +0800 Subject: [PATCH 04/11] address the comment Signed-off-by: yisaer --- server/schedulers/hot_region_config.go | 2 +- tests/pdctl/scheduler/scheduler_test.go | 10 ++++++++++ tools/pd-ctl/pdctl/command/scheduler.go | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/schedulers/hot_region_config.go b/server/schedulers/hot_region_config.go index 32cbd8ab255..f0ce5caab65 100644 --- a/server/schedulers/hot_region_config.go +++ b/server/schedulers/hot_region_config.go @@ -36,7 +36,7 @@ const ( // BytePriority indicates hot-region-scheduler prefer byte dim BytePriority = "byte" // KeyPriority indicates hot-region-scheduler prefer key dim - KeyPriority = "key" + KeyPriority = "key" ) // params about hot region. diff --git a/tests/pdctl/scheduler/scheduler_test.go b/tests/pdctl/scheduler/scheduler_test.go index 75eee67157b..15c32daa813 100644 --- a/tests/pdctl/scheduler/scheduler_test.go +++ b/tests/pdctl/scheduler/scheduler_test.go @@ -292,6 +292,16 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "foo,bar"}, nil) + expected1["read-priorities"] = []interface{}{} + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) + + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", ""}, nil) + expected1["read-priorities"] = []interface{}{} + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) + // test show scheduler with paused and disabled status. checkSchedulerWithStatusCommand := func(args []string, status string, expected []string) { if args != nil { diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index 4e4b9528018..5705f75af44 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -538,6 +538,7 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar schedulers.BytePriority, schedulers.KeyPriority, "none")) + return } priorities = append(priorities, priority) } From fcd72d2c6e14de04fc6ee1857b9ab6cb8440c385 Mon Sep 17 00:00:00 2001 From: yisaer Date: Thu, 22 Jul 2021 13:35:52 +0800 Subject: [PATCH 05/11] address the comment Signed-off-by: yisaer --- tools/pd-ctl/pdctl/command/scheduler.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index 5705f75af44..d699716256a 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -530,8 +530,7 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar } if schedulerName == "balance-hot-region-scheduler" && (key == "read-priorities" || key == "write-priorities") { priorities := make([]string, 0) - if value == "none" { - } else { + if value != "none" { for _, priority := range strings.Split(value, ",") { if priority != schedulers.BytePriority && priority != schedulers.KeyPriority { cmd.Println(fmt.Sprintf("priority should be one of %s,%s,%s", From 807a82894e9d0746e16e8412e1fb913932940817 Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 27 Jul 2021 16:45:16 +0800 Subject: [PATCH 06/11] address the comment Signed-off-by: yisaer --- server/schedulers/hot_region_config.go | 6 ++---- tools/pd-ctl/pdctl/command/scheduler.go | 18 ++++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/server/schedulers/hot_region_config.go b/server/schedulers/hot_region_config.go index f0ce5caab65..7ba6a611b5a 100644 --- a/server/schedulers/hot_region_config.go +++ b/server/schedulers/hot_region_config.go @@ -31,8 +31,6 @@ import ( ) const ( - // NonePriority indicates there is no dim priority for hot-region-scheduler - NonePriority = "" // BytePriority indicates hot-region-scheduler prefer byte dim BytePriority = "byte" // KeyPriority indicates hot-region-scheduler prefer key dim @@ -54,8 +52,8 @@ func initHotRegionScheduleConfig() *hotRegionSchedulerConfig { MaxPeerNum: 1000, SrcToleranceRatio: 1.05, // Tolerate 5% difference DstToleranceRatio: 1.05, // Tolerate 5% difference - ReadPriorities: []string{}, - WritePriorities: []string{}, + ReadPriorities: []string{KeyPriority, BytePriority}, + WritePriorities: []string{BytePriority, KeyPriority}, } } diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index d699716256a..cfba5ae9ab0 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -530,17 +530,15 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar } if schedulerName == "balance-hot-region-scheduler" && (key == "read-priorities" || key == "write-priorities") { priorities := make([]string, 0) - if value != "none" { - for _, priority := range strings.Split(value, ",") { - if priority != schedulers.BytePriority && priority != schedulers.KeyPriority { - cmd.Println(fmt.Sprintf("priority should be one of %s,%s,%s", - schedulers.BytePriority, - schedulers.KeyPriority, - "none")) - return - } - priorities = append(priorities, priority) + for _, priority := range strings.Split(value, ",") { + if priority != schedulers.BytePriority && priority != schedulers.KeyPriority { + cmd.Println(fmt.Sprintf("priority should be one of %s,%s,%s", + schedulers.BytePriority, + schedulers.KeyPriority, + "none")) + return } + priorities = append(priorities, priority) } input[key] = priorities } else { From 2d2c29922ab9683cd69b174abeab1c2122044f07 Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 27 Jul 2021 16:49:57 +0800 Subject: [PATCH 07/11] address the comment Signed-off-by: yisaer --- tests/pdctl/scheduler/scheduler_test.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tests/pdctl/scheduler/scheduler_test.go b/tests/pdctl/scheduler/scheduler_test.go index 15c32daa813..e85474dfdb1 100644 --- a/tests/pdctl/scheduler/scheduler_test.go +++ b/tests/pdctl/scheduler/scheduler_test.go @@ -269,8 +269,8 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { "minor-dec-ratio": 0.99, "src-tolerance-ratio": 1.05, "dst-tolerance-ratio": 1.05, - "read-priorities": []interface{}{}, - "write-priorities": []interface{}{}, + "read-priorities": []interface{}{"key", "byte"}, + "write-priorities": []interface{}{"byte", "key"}, } c.Assert(conf, DeepEquals, expected1) mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "src-tolerance-ratio", "1.02"}, nil) @@ -287,18 +287,7 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { expected1["read-priorities"] = []interface{}{"key", "byte"} mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) c.Assert(conf1, DeepEquals, expected1) - mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "none"}, nil) - expected1["read-priorities"] = []interface{}{} - mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) - c.Assert(conf1, DeepEquals, expected1) - mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "foo,bar"}, nil) - expected1["read-priorities"] = []interface{}{} - mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) - c.Assert(conf1, DeepEquals, expected1) - - mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", ""}, nil) - expected1["read-priorities"] = []interface{}{} mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) c.Assert(conf1, DeepEquals, expected1) From 610212a30f13986d69d313f327e8154ed9c1644c Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 27 Jul 2021 16:54:28 +0800 Subject: [PATCH 08/11] address the comment Signed-off-by: yisaer --- server/schedulers/hot_region_config.go | 2 +- tests/pdctl/scheduler/scheduler_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/schedulers/hot_region_config.go b/server/schedulers/hot_region_config.go index 7ba6a611b5a..d06308ca0cd 100644 --- a/server/schedulers/hot_region_config.go +++ b/server/schedulers/hot_region_config.go @@ -52,7 +52,7 @@ func initHotRegionScheduleConfig() *hotRegionSchedulerConfig { MaxPeerNum: 1000, SrcToleranceRatio: 1.05, // Tolerate 5% difference DstToleranceRatio: 1.05, // Tolerate 5% difference - ReadPriorities: []string{KeyPriority, BytePriority}, + ReadPriorities: []string{BytePriority, KeyPriority}, WritePriorities: []string{BytePriority, KeyPriority}, } } diff --git a/tests/pdctl/scheduler/scheduler_test.go b/tests/pdctl/scheduler/scheduler_test.go index e85474dfdb1..7e1a9f71dfc 100644 --- a/tests/pdctl/scheduler/scheduler_test.go +++ b/tests/pdctl/scheduler/scheduler_test.go @@ -269,7 +269,7 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { "minor-dec-ratio": 0.99, "src-tolerance-ratio": 1.05, "dst-tolerance-ratio": 1.05, - "read-priorities": []interface{}{"key", "byte"}, + "read-priorities": []interface{}{"byte", "key"}, "write-priorities": []interface{}{"byte", "key"}, } c.Assert(conf, DeepEquals, expected1) From e65b232429e3e5160dc26ea8532d73c51a299c19 Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 27 Jul 2021 17:08:14 +0800 Subject: [PATCH 09/11] address the comment Signed-off-by: yisaer --- tests/pdctl/scheduler/scheduler_test.go | 3 +++ tools/pd-ctl/pdctl/command/scheduler.go | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/pdctl/scheduler/scheduler_test.go b/tests/pdctl/scheduler/scheduler_test.go index 7e1a9f71dfc..0f2c32582f1 100644 --- a/tests/pdctl/scheduler/scheduler_test.go +++ b/tests/pdctl/scheduler/scheduler_test.go @@ -290,6 +290,9 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "foo,bar"}, nil) mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", ""}, nil) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) // test show scheduler with paused and disabled status. checkSchedulerWithStatusCommand := func(args []string, status string, expected []string) { diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index cfba5ae9ab0..df7bc1e5605 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -532,10 +532,9 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar priorities := make([]string, 0) for _, priority := range strings.Split(value, ",") { if priority != schedulers.BytePriority && priority != schedulers.KeyPriority { - cmd.Println(fmt.Sprintf("priority should be one of %s,%s,%s", + cmd.Println(fmt.Sprintf("priority should be one of %s,%s", schedulers.BytePriority, - schedulers.KeyPriority, - "none")) + schedulers.KeyPriority)) return } priorities = append(priorities, priority) From b3e6bd90c348379a15b921befe4548aa46f78d25 Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 27 Jul 2021 18:00:54 +0800 Subject: [PATCH 10/11] address the comment Signed-off-by: yisaer --- tests/pdctl/scheduler/scheduler_test.go | 9 +++++++++ tools/pd-ctl/pdctl/command/scheduler.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/tests/pdctl/scheduler/scheduler_test.go b/tests/pdctl/scheduler/scheduler_test.go index 0f2c32582f1..b29e00f0258 100644 --- a/tests/pdctl/scheduler/scheduler_test.go +++ b/tests/pdctl/scheduler/scheduler_test.go @@ -293,6 +293,15 @@ func (s *schedulerTestSuite) TestScheduler(c *C) { mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", ""}, nil) mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "key,key"}, nil) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "byte,byte"}, nil) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "read-priorities", "key,key,byte"}, nil) + mustExec([]string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler"}, &conf1) + c.Assert(conf1, DeepEquals, expected1) // test show scheduler with paused and disabled status. checkSchedulerWithStatusCommand := func(args []string, status string, expected []string) { diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index df7bc1e5605..a92e2b675db 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -530,6 +530,7 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar } if schedulerName == "balance-hot-region-scheduler" && (key == "read-priorities" || key == "write-priorities") { priorities := make([]string, 0) + prioritiesMap := make(map[string]struct{}, 0) for _, priority := range strings.Split(value, ",") { if priority != schedulers.BytePriority && priority != schedulers.KeyPriority { cmd.Println(fmt.Sprintf("priority should be one of %s,%s", @@ -538,8 +539,13 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar return } priorities = append(priorities, priority) + prioritiesMap[priority] = struct{}{} } input[key] = priorities + if len(priorities) != len(prioritiesMap) { + cmd.Println("priorities shouldn't be repeated") + return + } } else { input[key] = val } From a0d9fd544a9d4f677e752fccec0ba1a579ac0ed5 Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 27 Jul 2021 18:14:31 +0800 Subject: [PATCH 11/11] address the comment Signed-off-by: yisaer --- tools/pd-ctl/pdctl/command/scheduler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index a92e2b675db..43d09dd1327 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -530,10 +530,10 @@ func postSchedulerConfigCommandFunc(cmd *cobra.Command, schedulerName string, ar } if schedulerName == "balance-hot-region-scheduler" && (key == "read-priorities" || key == "write-priorities") { priorities := make([]string, 0) - prioritiesMap := make(map[string]struct{}, 0) + prioritiesMap := make(map[string]struct{}) for _, priority := range strings.Split(value, ",") { if priority != schedulers.BytePriority && priority != schedulers.KeyPriority { - cmd.Println(fmt.Sprintf("priority should be one of %s,%s", + cmd.Println(fmt.Sprintf("priority should be one of [%s, %s]", schedulers.BytePriority, schedulers.KeyPriority)) return