Skip to content

Commit 6202371

Browse files
committed
fix
Signed-off-by: nolouch <[email protected]>
1 parent ac180ff commit 6202371

File tree

5 files changed

+49
-37
lines changed

5 files changed

+49
-37
lines changed

Diff for: client/resource_group/controller/config.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ const (
5353
// defaultMaxWaitDuration is the max duration to wait for the token before throwing error.
5454
defaultMaxWaitDuration = 30 * time.Second
5555
<<<<<<< HEAD
56-
=======
5756
// defaultLTBTokenRPCMaxDelay is the upper bound of backoff delay for local token bucket RPC.
5857
defaultLTBTokenRPCMaxDelay = 1 * time.Second
5958
// defaultWaitRetryTimes is the times to retry when waiting for the token.
6059
defaultWaitRetryTimes = 20
60+
=======
61+
// defaultWaitRetryTimes is the times to retry when waiting for the token.
62+
defaultWaitRetryTimes = 10
63+
>>>>>>> b9240a065... resource_group: add retry configurations (#8041)
6164
// defaultWaitRetryInterval is the interval to retry when waiting for the token.
6265
defaultWaitRetryInterval = 50 * time.Millisecond
63-
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
6466
)
6567

6668
const (
@@ -110,11 +112,16 @@ type BaseConfig struct {
110112
LTBMaxWaitDuration Duration `toml:"ltb-max-wait-duration" json:"ltb-max-wait-duration"`
111113

112114
<<<<<<< HEAD
113-
=======
114115
// LTBTokenRPCMaxDelay is the upper bound of backoff delay for local token bucket RPC.
115116
LTBTokenRPCMaxDelay Duration `toml:"ltb-token-rpc-max-delay" json:"ltb-token-rpc-max-delay"`
117+
=======
118+
// WaitRetryInterval is the interval to retry when waiting for the token.
119+
WaitRetryInterval Duration `toml:"wait-retry-interval" json:"wait-retry-interval"`
120+
121+
// WaitRetryTimes is the times to retry when waiting for the token.
122+
WaitRetryTimes int `toml:"wait-retry-times" json:"wait-retry-times"`
123+
>>>>>>> b9240a065... resource_group: add retry configurations (#8041)
116124

117-
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
118125
// RequestUnit is the configuration determines the coefficients of the RRU and WRU cost.
119126
// This configuration should be modified carefully.
120127
RequestUnit RequestUnitConfig `toml:"request-unit" json:"request-unit"`
@@ -147,12 +154,6 @@ func (c *Config) Adjust() {
147154
// DefaultConfig returns the default resource manager controller configuration.
148155
func DefaultConfig() *Config {
149156
return &Config{
150-
<<<<<<< HEAD
151-
DegradedModeWaitDuration: NewDuration(defaultDegradedModeWaitDuration),
152-
LTBMaxWaitDuration: NewDuration(defaultMaxWaitDuration),
153-
RequestUnit: DefaultRequestUnitConfig(),
154-
EnableControllerTraceLog: false,
155-
=======
156157
BaseConfig: BaseConfig{
157158
DegradedModeWaitDuration: NewDuration(defaultDegradedModeWaitDuration),
158159
RequestUnit: DefaultRequestUnitConfig(),
@@ -166,7 +167,6 @@ func DefaultConfig() *Config {
166167
WaitRetryTimes: defaultWaitRetryTimes,
167168
},
168169
},
169-
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
170170
}
171171
}
172172

@@ -222,6 +222,8 @@ type RUConfig struct {
222222

223223
// some config for client
224224
LTBMaxWaitDuration time.Duration
225+
WaitRetryInterval time.Duration
226+
WaitRetryTimes int
225227
DegradedModeWaitDuration time.Duration
226228
}
227229

@@ -243,6 +245,8 @@ func GenerateRUConfig(config *Config) *RUConfig {
243245
WriteBytesCost: RequestUnit(config.RequestUnit.WriteCostPerByte),
244246
CPUMsCost: RequestUnit(config.RequestUnit.CPUMsCost),
245247
LTBMaxWaitDuration: config.LTBMaxWaitDuration.Duration,
248+
WaitRetryInterval: config.WaitRetryInterval.Duration,
249+
WaitRetryTimes: config.WaitRetryTimes,
246250
DegradedModeWaitDuration: config.DegradedModeWaitDuration.Duration,
247251
}
248252
}

Diff for: client/resource_group/controller/controller.go

+29-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
)
3939

4040
const (
41+
<<<<<<< HEAD
4142
controllerConfigPath = "resource_group/controller"
4243
maxRetry = 10
4344
retryInterval = 50 * time.Millisecond
@@ -46,6 +47,14 @@ const (
4647
trickleReserveDuration = 1250 * time.Millisecond
4748
slowNotifyFilterDuration = 10 * time.Millisecond
4849
watchRetryInterval = 30 * time.Second
50+
=======
51+
controllerConfigPath = "resource_group/controller"
52+
maxNotificationChanLen = 200
53+
needTokensAmplification = 1.1
54+
trickleReserveDuration = 1250 * time.Millisecond
55+
56+
watchRetryInterval = 30 * time.Second
57+
>>>>>>> b9240a065... resource_group: add retry configurations (#8041)
4958
)
5059

5160
type selectType int
@@ -104,6 +113,20 @@ func WithMaxWaitDuration(d time.Duration) ResourceControlCreateOption {
104113
}
105114
}
106115

116+
// WithWaitRetryInterval is the option to set the retry interval when waiting for the token.
117+
func WithWaitRetryInterval(d time.Duration) ResourceControlCreateOption {
118+
return func(controller *ResourceGroupsController) {
119+
controller.ruConfig.WaitRetryInterval = d
120+
}
121+
}
122+
123+
// WithWaitRetryTimes is the option to set the times to retry when waiting for the token.
124+
func WithWaitRetryTimes(times int) ResourceControlCreateOption {
125+
return func(controller *ResourceGroupsController) {
126+
controller.ruConfig.WaitRetryTimes = times
127+
}
128+
}
129+
107130
var _ ResourceGroupKVInterceptor = (*ResourceGroupsController)(nil)
108131

109132
// ResourceGroupsController implements ResourceGroupKVInterceptor.
@@ -189,9 +212,9 @@ func loadServerConfig(ctx context.Context, provider ResourceGroupProvider) (*Con
189212
return config, nil
190213
}
191214
<<<<<<< HEAD
192-
config := &Config{}
193215
=======
194-
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
216+
config := DefaultConfig()
217+
>>>>>>> b9240a065... resource_group: add retry configurations (#8041)
195218
err = json.Unmarshal(kvs[0].GetValue(), config)
196219
if err != nil {
197220
return nil, err
@@ -371,7 +394,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
371394
}
372395
for _, item := range resp {
373396
cfgRevision = item.Kv.ModRevision
374-
config := &Config{}
397+
config := DefaultConfig()
375398
if err := json.Unmarshal(item.Kv.Value, config); err != nil {
376399
continue
377400
}
@@ -1233,7 +1256,7 @@ func (gc *groupCostController) onRequestWait(
12331256
var i int
12341257
var d time.Duration
12351258
retryLoop:
1236-
for i = 0; i < maxRetry; i++ {
1259+
for i = 0; i < gc.mainCfg.WaitRetryTimes; i++ {
12371260
switch gc.mode {
12381261
case rmpb.GroupMode_RawMode:
12391262
res := make([]*Reservation, 0, len(requestResourceLimitTypeList))
@@ -1257,8 +1280,8 @@ func (gc *groupCostController) onRequestWait(
12571280
}
12581281
}
12591282
gc.metrics.requestRetryCounter.Inc()
1260-
time.Sleep(retryInterval)
1261-
waitDuration += retryInterval
1283+
time.Sleep(gc.mainCfg.WaitRetryInterval)
1284+
waitDuration += gc.mainCfg.WaitRetryInterval
12621285
}
12631286
if err != nil {
12641287
if errs.ErrClientResourceGroupThrottled.Equal(err) {

Diff for: pkg/mcs/resourcemanager/server/config.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ func (rmc *ControllerConfig) Adjust(meta *configutil.ConfigMetaData) {
117117
if rmc == nil {
118118
return
119119
}
120-
<<<<<<< HEAD
121-
rmc.RequestUnit.Adjust()
122-
123-
configutil.AdjustDuration(&rmc.DegradedModeWaitDuration, defaultDegradedModeWaitDuration)
124-
configutil.AdjustDuration(&rmc.LTBMaxWaitDuration, defaultMaxWaitDuration)
125-
=======
126120
rmc.RequestUnit.Adjust(meta.Child("request-unit"))
127121
if !meta.IsDefined("degraded-mode-wait-duration") {
128122
configutil.AdjustDuration(&rmc.DegradedModeWaitDuration, defaultDegradedModeWaitDuration)
@@ -133,7 +127,6 @@ func (rmc *ControllerConfig) Adjust(meta *configutil.ConfigMetaData) {
133127
if !meta.IsDefined("ltb-token-rpc-max-delay") {
134128
configutil.AdjustDuration(&rmc.LTBTokenRPCMaxDelay, defaultLTBTokenRPCMaxDelay)
135129
}
136-
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
137130
failpoint.Inject("enableDegradedMode", func() {
138131
configutil.AdjustDuration(&rmc.DegradedModeWaitDuration, time.Second)
139132
})
@@ -163,7 +156,7 @@ type RequestUnitConfig struct {
163156
}
164157

165158
// Adjust adjusts the configuration and initializes it with the default value if necessary.
166-
func (ruc *RequestUnitConfig) Adjust() {
159+
func (ruc *RequestUnitConfig) Adjust(_ *configutil.ConfigMetaData) {
167160
if ruc == nil {
168161
return
169162
}

Diff for: pkg/mcs/resourcemanager/server/config_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,9 @@ read-cpu-ms-cost = 5.0
4343
err = cfg.Adjust(&meta, false)
4444
re.NoError(err)
4545

46-
<<<<<<< HEAD
47-
re.Equal(cfg.Controller.DegradedModeWaitDuration.Duration, time.Second*2)
48-
re.Equal(cfg.Controller.LTBMaxWaitDuration.Duration, time.Second*60)
49-
=======
5046
re.Equal(2*time.Second, cfg.Controller.DegradedModeWaitDuration.Duration)
5147
re.Equal(60*time.Second, cfg.Controller.LTBMaxWaitDuration.Duration)
5248
re.Equal(500*time.Millisecond, cfg.Controller.LTBTokenRPCMaxDelay.Duration)
53-
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
5449
re.LessOrEqual(math.Abs(cfg.Controller.RequestUnit.CPUMsCost-5), 1e-7)
5550
re.LessOrEqual(math.Abs(cfg.Controller.RequestUnit.WriteCostPerByte-4), 1e-7)
5651
re.LessOrEqual(math.Abs(cfg.Controller.RequestUnit.WriteBaseCost-3), 1e-7)

Diff for: tests/integrations/mcs/resourcemanager/resource_manager_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/tikv/pd/client/resource_group/controller"
3434
"github.com/tikv/pd/pkg/mcs/resourcemanager/server"
3535
"github.com/tikv/pd/pkg/utils/testutil"
36+
"github.com/tikv/pd/pkg/utils/typeutil"
3637
"github.com/tikv/pd/tests"
3738
"go.uber.org/goleak"
3839

@@ -1365,10 +1366,6 @@ func (suite *resourceManagerClientTestSuite) TestResourceGroupControllerConfigCh
13651366
tokenRPCMaxDelay := 2 * time.Second
13661367
readBaseCost := 1.5
13671368
defaultCfg := controller.DefaultConfig()
1368-
<<<<<<< HEAD
1369-
// failpoint enableDegradedMode will setup and set it be 1s.
1370-
defaultCfg.DegradedModeWaitDuration.Duration = time.Second
1371-
=======
13721369
expectCfg := server.ControllerConfig{
13731370
// failpoint enableDegradedMode will setup and set it be 1s.
13741371
DegradedModeWaitDuration: typeutil.NewDuration(time.Second),
@@ -1377,13 +1374,13 @@ func (suite *resourceManagerClientTestSuite) TestResourceGroupControllerConfigCh
13771374
RequestUnit: server.RequestUnitConfig(defaultCfg.RequestUnit),
13781375
EnableControllerTraceLog: defaultCfg.EnableControllerTraceLog,
13791376
}
1380-
>>>>>>> 6b25787af (resource_control: allow configuration of the maximum retry time for the local bucket (#8352))
13811377
expectRUCfg := controller.GenerateRUConfig(defaultCfg)
1378+
expectRUCfg.DegradedModeWaitDuration = time.Second
13821379
// initial config verification
13831380
respString := sendRequest("GET", getAddr()+configURL, nil)
1384-
defaultString, err := json.Marshal(defaultCfg)
1381+
expectStr, err := json.Marshal(expectCfg)
13851382
re.NoError(err)
1386-
re.JSONEq(string(respString), string(defaultString))
1383+
re.JSONEq(string(respString), string(expectStr))
13871384
re.EqualValues(expectRUCfg, c1.GetConfig())
13881385

13891386
testCases := []struct {

0 commit comments

Comments
 (0)