Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <[email protected]>
  • Loading branch information
nolouch committed Jul 4, 2024
1 parent 1eadd59 commit 9df2b97
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
34 changes: 17 additions & 17 deletions pkg/mcs/resourcemanager/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/resourcemanager/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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()
}

0 comments on commit 9df2b97

Please sign in to comment.