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 a9a607a commit a1d10ec
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
23 changes: 13 additions & 10 deletions client/resource_group/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ const (
defaultTargetPeriod = 5 * time.Second
// defaultMaxWaitDuration is the max duration to wait for the token before throwing error.
defaultMaxWaitDuration = 30 * time.Second
<<<<<<< HEAD
=======
// defaultLTBTokenRPCMaxDelay is the upper bound of backoff delay for local token bucket RPC.
defaultLTBTokenRPCMaxDelay = 1 * time.Second
// defaultWaitRetryTimes is the times to retry when waiting for the token.
defaultWaitRetryTimes = 20
// defaultWaitRetryInterval is the interval to retry when waiting for the token.
defaultWaitRetryInterval = 50 * time.Millisecond
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
)

const (
Expand Down Expand Up @@ -109,12 +106,21 @@ type BaseConfig struct {
// LTBMaxWaitDuration is the max wait time duration for local token bucket.
LTBMaxWaitDuration Duration `toml:"ltb-max-wait-duration" json:"ltb-max-wait-duration"`

<<<<<<< HEAD
<<<<<<< HEAD
=======
// LTBTokenRPCMaxDelay is the upper bound of backoff delay for local token bucket RPC.
LTBTokenRPCMaxDelay Duration `toml:"ltb-token-rpc-max-delay" json:"ltb-token-rpc-max-delay"`

>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
=======
// WaitRetryInterval is the interval to retry when waiting for the token.
WaitRetryInterval Duration `toml:"wait-retry-interval" json:"wait-retry-interval"`

// WaitRetryTimes is the times to retry when waiting for the token.
WaitRetryTimes int `toml:"wait-retry-times" json:"wait-retry-times"`

>>>>>>> b9240a065... resource_group: add retry configurations (#8041)
// RequestUnit is the configuration determines the coefficients of the RRU and WRU cost.
// This configuration should be modified carefully.
RequestUnit RequestUnitConfig `toml:"request-unit" json:"request-unit"`
Expand Down Expand Up @@ -147,12 +153,6 @@ func (c *Config) Adjust() {
// DefaultConfig returns the default resource manager controller configuration.
func DefaultConfig() *Config {
return &Config{
<<<<<<< HEAD
DegradedModeWaitDuration: NewDuration(defaultDegradedModeWaitDuration),
LTBMaxWaitDuration: NewDuration(defaultMaxWaitDuration),
RequestUnit: DefaultRequestUnitConfig(),
EnableControllerTraceLog: false,
=======
BaseConfig: BaseConfig{
DegradedModeWaitDuration: NewDuration(defaultDegradedModeWaitDuration),
RequestUnit: DefaultRequestUnitConfig(),
Expand All @@ -166,7 +166,6 @@ func DefaultConfig() *Config {
WaitRetryTimes: defaultWaitRetryTimes,
},
},
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
}
}

Expand Down Expand Up @@ -222,6 +221,8 @@ type RUConfig struct {

// some config for client
LTBMaxWaitDuration time.Duration
WaitRetryInterval time.Duration
WaitRetryTimes int
DegradedModeWaitDuration time.Duration
}

Expand All @@ -243,6 +244,8 @@ func GenerateRUConfig(config *Config) *RUConfig {
WriteBytesCost: RequestUnit(config.RequestUnit.WriteCostPerByte),
CPUMsCost: RequestUnit(config.RequestUnit.CPUMsCost),
LTBMaxWaitDuration: config.LTBMaxWaitDuration.Duration,
WaitRetryInterval: config.WaitRetryInterval.Duration,
WaitRetryTimes: config.WaitRetryTimes,
DegradedModeWaitDuration: config.DegradedModeWaitDuration.Duration,
}
}
28 changes: 18 additions & 10 deletions client/resource_group/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import (

const (
controllerConfigPath = "resource_group/controller"
maxRetry = 10
retryInterval = 50 * time.Millisecond
maxNotificationChanLen = 200
needTokensAmplification = 1.1
trickleReserveDuration = 1250 * time.Millisecond
Expand Down Expand Up @@ -106,6 +104,20 @@ func WithMaxWaitDuration(d time.Duration) ResourceControlCreateOption {
}
}

// WithWaitRetryInterval is the option to set the retry interval when waiting for the token.
func WithWaitRetryInterval(d time.Duration) ResourceControlCreateOption {
return func(controller *ResourceGroupsController) {
controller.ruConfig.WaitRetryInterval = d
}
}

// WithWaitRetryTimes is the option to set the times to retry when waiting for the token.
func WithWaitRetryTimes(times int) ResourceControlCreateOption {
return func(controller *ResourceGroupsController) {
controller.ruConfig.WaitRetryTimes = times
}
}

var _ ResourceGroupKVInterceptor = (*ResourceGroupsController)(nil)

// ResourceGroupsController implements ResourceGroupKVInterceptor.
Expand Down Expand Up @@ -190,10 +202,6 @@ func loadServerConfig(ctx context.Context, provider ResourceGroupProvider) (*Con
log.Warn("[resource group controller] server does not save config, load config failed")
return config, nil
}
<<<<<<< HEAD
config := &Config{}
=======
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
err = json.Unmarshal(kvs[0].GetValue(), config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -373,7 +381,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
}
for _, item := range resp {
cfgRevision = item.Kv.ModRevision
config := &Config{}
config := DefaultConfig()
if err := json.Unmarshal(item.Kv.Value, config); err != nil {
continue
}
Expand Down Expand Up @@ -1235,7 +1243,7 @@ func (gc *groupCostController) onRequestWait(
var i int
var d time.Duration
retryLoop:
for i = 0; i < maxRetry; i++ {
for i = 0; i < gc.mainCfg.WaitRetryTimes; i++ {
switch gc.mode {
case rmpb.GroupMode_RawMode:
res := make([]*Reservation, 0, len(requestResourceLimitTypeList))
Expand All @@ -1259,8 +1267,8 @@ func (gc *groupCostController) onRequestWait(
}
}
gc.metrics.requestRetryCounter.Inc()
time.Sleep(retryInterval)
waitDuration += retryInterval
time.Sleep(gc.mainCfg.WaitRetryInterval)
waitDuration += gc.mainCfg.WaitRetryInterval
}
if err != nil {
if errs.ErrClientResourceGroupThrottled.Equal(err) {
Expand Down
7 changes: 0 additions & 7 deletions pkg/mcs/resourcemanager/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ func (rmc *ControllerConfig) Adjust(meta *configutil.ConfigMetaData) {
if rmc == nil {
return
}
<<<<<<< HEAD
rmc.RequestUnit.Adjust()

configutil.AdjustDuration(&rmc.DegradedModeWaitDuration, defaultDegradedModeWaitDuration)
configutil.AdjustDuration(&rmc.LTBMaxWaitDuration, defaultMaxWaitDuration)
=======
rmc.RequestUnit.Adjust(meta.Child("request-unit"))

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / statics

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / tso-function-test

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (1)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (2)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (3)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (4)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (5)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (6)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (7)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (8)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (8)

too many arguments in call to rmc.RequestUnit.Adjust

Check failure on line 120 in pkg/mcs/resourcemanager/server/config.go

View workflow job for this annotation

GitHub Actions / chunks (9)

too many arguments in call to rmc.RequestUnit.Adjust
if !meta.IsDefined("degraded-mode-wait-duration") {
configutil.AdjustDuration(&rmc.DegradedModeWaitDuration, defaultDegradedModeWaitDuration)
Expand All @@ -133,7 +127,6 @@ func (rmc *ControllerConfig) Adjust(meta *configutil.ConfigMetaData) {
if !meta.IsDefined("ltb-token-rpc-max-delay") {
configutil.AdjustDuration(&rmc.LTBTokenRPCMaxDelay, defaultLTBTokenRPCMaxDelay)
}
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
failpoint.Inject("enableDegradedMode", func() {
configutil.AdjustDuration(&rmc.DegradedModeWaitDuration, time.Second)
})
Expand Down
12 changes: 7 additions & 5 deletions tests/integrations/mcs/resourcemanager/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/tikv/pd/client/resource_group/controller"
"github.com/tikv/pd/pkg/mcs/resourcemanager/server"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/pkg/utils/typeutil"
"github.com/tikv/pd/tests"
"go.uber.org/goleak"

Expand Down Expand Up @@ -1437,25 +1438,26 @@ func (suite *resourceManagerClientTestSuite) TestResourceGroupControllerConfigCh
tokenRPCMaxDelay := 2 * time.Second
readBaseCost := 1.5
defaultCfg := controller.DefaultConfig()
<<<<<<< HEAD

// failpoint enableDegradedMode will setup and set it be 1s.
defaultCfg.DegradedModeWaitDuration.Duration = time.Second
=======
expectCfg := server.ControllerConfig{
// failpoint enableDegradedMode will setup and set it be 1s.
DegradedModeWaitDuration: typeutil.NewDuration(time.Second),
LTBMaxWaitDuration: typeutil.Duration(defaultCfg.LTBMaxWaitDuration),
LTBTokenRPCMaxDelay: typeutil.Duration(defaultCfg.LTBTokenRPCMaxDelay),
RequestUnit: server.RequestUnitConfig(defaultCfg.RequestUnit),
EnableControllerTraceLog: defaultCfg.EnableControllerTraceLog,
RequestUnit: server.RequestUnitConfig(defaultCfg.RequestUnit),
EnableControllerTraceLog: defaultCfg.EnableControllerTraceLog,
}
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
expectRUCfg := controller.GenerateRUConfig(defaultCfg)
expectRUCfg.DegradedModeWaitDuration = time.Second
// initial config verification
respString := sendRequest("GET", getAddr()+configURL, nil)
defaultString, err := json.Marshal(defaultCfg)
expectStr, err := json.Marshal(expectCfg)
re.NoError(err)
re.JSONEq(string(respString), string(defaultString))
re.JSONEq(string(respString), string(expectStr))
re.EqualValues(expectRUCfg, c1.GetConfig())

testCases := []struct {
Expand Down

0 comments on commit a1d10ec

Please sign in to comment.