From 9df2b97f817c5e7aaf38a53114dbe4412ad75eeb Mon Sep 17 00:00:00 2001 From: nolouch Date: Thu, 4 Jul 2024 14:53:49 +0800 Subject: [PATCH] fix Signed-off-by: nolouch --- pkg/mcs/resourcemanager/server/config.go | 34 +++++++++---------- pkg/mcs/resourcemanager/server/config_test.go | 2 +- .../resourcemanager/resource_manager_test.go | 2 -- .../resource_manager_command_test.go | 10 +++--- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/pkg/mcs/resourcemanager/server/config.go b/pkg/mcs/resourcemanager/server/config.go index e1c34bba4af..3f1e6977f6f 100644 --- a/pkg/mcs/resourcemanager/server/config.go +++ b/pkg/mcs/resourcemanager/server/config.go @@ -155,30 +155,30 @@ type RequestUnitConfig struct { } // Adjust adjusts the configuration and initializes it with the default value if necessary. -func (ruc *RequestUnitConfig) Adjust() { +func (ruc *RequestUnitConfig) Adjust(meta *configutil.ConfigMetaData) { if ruc == nil { return } - if ruc.ReadBaseCost == 0 { - ruc.ReadBaseCost = defaultReadBaseCost + if !meta.IsDefined("read-base-cost") { + configutil.AdjustFloat64(&ruc.ReadBaseCost, defaultReadBaseCost) } - if ruc.ReadPerBatchBaseCost == 0 { - ruc.ReadPerBatchBaseCost = defaultReadPerBatchBaseCost + if !meta.IsDefined("read-per-batch-base-cost") { + configutil.AdjustFloat64(&ruc.ReadPerBatchBaseCost, defaultReadPerBatchBaseCost) } - if ruc.ReadCostPerByte == 0 { - ruc.ReadCostPerByte = defaultReadCostPerByte + if !meta.IsDefined("read-cost-per-byte") { + configutil.AdjustFloat64(&ruc.ReadCostPerByte, defaultReadCostPerByte) } - if ruc.WriteBaseCost == 0 { - ruc.WriteBaseCost = defaultWriteBaseCost + if !meta.IsDefined("write-base-cost") { + configutil.AdjustFloat64(&ruc.WriteBaseCost, defaultWriteBaseCost) } - if ruc.WritePerBatchBaseCost == 0 { - ruc.WritePerBatchBaseCost = defaultWritePerBatchBaseCost + if !meta.IsDefined("write-per-batch-base-cost") { + configutil.AdjustFloat64(&ruc.WritePerBatchBaseCost, defaultWritePerBatchBaseCost) } - if ruc.WriteCostPerByte == 0 { - ruc.WriteCostPerByte = defaultWriteCostPerByte + if !meta.IsDefined("write-cost-per-byte") { + configutil.AdjustFloat64(&ruc.WriteCostPerByte, defaultWriteCostPerByte) } - if ruc.CPUMsCost == 0 { - ruc.CPUMsCost = defaultCPUMsCost + if !meta.IsDefined("read-cpu-ms-cost") { + configutil.AdjustFloat64(&ruc.CPUMsCost, defaultCPUMsCost) } } @@ -212,11 +212,11 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error { configutil.AdjustCommandLineString(flagSet, &c.ListenAddr, "listen-addr") configutil.AdjustCommandLineString(flagSet, &c.AdvertiseListenAddr, "advertise-listen-addr") - return c.Adjust(meta, false) + return c.Adjust(meta) } // Adjust is used to adjust the resource manager configurations. -func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error { +func (c *Config) Adjust(meta *toml.MetaData) error { configMetaData := configutil.NewConfigMetadata(meta) if err := configMetaData.CheckUndecoded(); err != nil { c.WarningMsgs = append(c.WarningMsgs, err.Error()) diff --git a/pkg/mcs/resourcemanager/server/config_test.go b/pkg/mcs/resourcemanager/server/config_test.go index 47d1ed36515..ae9dfc2cad3 100644 --- a/pkg/mcs/resourcemanager/server/config_test.go +++ b/pkg/mcs/resourcemanager/server/config_test.go @@ -40,7 +40,7 @@ read-cpu-ms-cost = 5.0 cfg := NewConfig() meta, err := toml.Decode(cfgData, &cfg) re.NoError(err) - err = cfg.Adjust(&meta, false) + err = cfg.Adjust(&meta) re.NoError(err) re.Equal(2*time.Second, cfg.Controller.DegradedModeWaitDuration.Duration) diff --git a/tests/integrations/mcs/resourcemanager/resource_manager_test.go b/tests/integrations/mcs/resourcemanager/resource_manager_test.go index abb4ab56d06..cdb8049cff0 100644 --- a/tests/integrations/mcs/resourcemanager/resource_manager_test.go +++ b/tests/integrations/mcs/resourcemanager/resource_manager_test.go @@ -1448,8 +1448,6 @@ func (suite *resourceManagerClientTestSuite) TestResourceGroupControllerConfigCh LTBTokenRPCMaxDelay: typeutil.Duration(defaultCfg.LTBTokenRPCMaxDelay), RequestUnit: server.RequestUnitConfig(defaultCfg.RequestUnit), EnableControllerTraceLog: defaultCfg.EnableControllerTraceLog, - RequestUnit: server.RequestUnitConfig(defaultCfg.RequestUnit), - EnableControllerTraceLog: defaultCfg.EnableControllerTraceLog, } expectRUCfg := controller.GenerateRUConfig(defaultCfg) expectRUCfg.DegradedModeWaitDuration = time.Second diff --git a/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go b/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go index 5cfc16ffb02..d387a2b87ae 100644 --- a/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go +++ b/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go @@ -58,7 +58,7 @@ func (s *testResourceManagerSuite) TearDownSuite() { func (s *testResourceManagerSuite) TestConfigController() { re := s.Require() - expectCfg := server.ControllerConfig{} + expectCfg := server.Config{} expectCfg.Adjust(nil) // Show controller config checkShow := func() { @@ -69,7 +69,7 @@ func (s *testResourceManagerSuite) TestConfigController() { actualCfg := server.ControllerConfig{} err = json.Unmarshal(output, &actualCfg) re.NoError(err, string(output)) - re.Equal(expectCfg, actualCfg) + re.Equal(expectCfg.Controller, actualCfg) } // Check default config @@ -80,20 +80,20 @@ func (s *testResourceManagerSuite) TestConfigController() { output, err := tests.ExecuteCommand(ctl.GetRootCmd(), args...) re.NoError(err) re.Contains(string(output), "Success!") - expectCfg.LTBMaxWaitDuration = typeutil.Duration{Duration: 1 * time.Hour} + expectCfg.Controller.LTBMaxWaitDuration = typeutil.Duration{Duration: 1 * time.Hour} checkShow() args = []string{"-u", s.pdAddr, "resource-manager", "config", "controller", "set", "enable-controller-trace-log", "true"} output, err = tests.ExecuteCommand(ctl.GetRootCmd(), args...) re.NoError(err) re.Contains(string(output), "Success!") - expectCfg.EnableControllerTraceLog = true + expectCfg.Controller.EnableControllerTraceLog = true checkShow() args = []string{"-u", s.pdAddr, "resource-manager", "config", "controller", "set", "write-base-cost", "2"} output, err = tests.ExecuteCommand(ctl.GetRootCmd(), args...) re.NoError(err) re.Contains(string(output), "Success!") - expectCfg.RequestUnit.WriteBaseCost = 2 + expectCfg.Controller.RequestUnit.WriteBaseCost = 2 checkShow() }