Skip to content

Commit

Permalink
*: Enhancement makefile static (tikv#6809)
Browse files Browse the repository at this point in the history
close tikv#6808

Currently, there are no static checks for subdirectories

Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp authored and nolouch committed Dec 6, 2023
1 parent ba26ef4 commit 3846eac
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 57 deletions.
3 changes: 2 additions & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ install-tools:
cd .. && $(MAKE) install-tools

static: install-tools
@ echo "gofmt ..."
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ echo "golangci-lint ..."
@ golangci-lint run -c ../.golangci.yml --verbose ./... --allow-parallel-runners
@ golangci-lint run -c ../.golangci.yml --verbose ./...
@ echo "revive ..."
@ revive -formatter friendly -config ../revive.toml ./...

Expand Down
2 changes: 1 addition & 1 deletion client/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
// Note: keep the same as the ones defined on the server side, because the client side checks if an error message
// contains this string to judge whether the leader is changed.
NotServedErr = "is not served"
// RetryTimeoutErr indicates the request is timeout.
// RetryTimeoutErr indicates the server is busy.
RetryTimeoutErr = "retry timeout"
)

Expand Down
28 changes: 14 additions & 14 deletions client/resource_group/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const (
defaultDegradedModeWaitDuration = "0s"
)

// ControllerConfig is the configuration of the resource manager controller which includes some option for client needed.
type ControllerConfig struct {
// Config is the configuration of the resource manager controller which includes some option for client needed.
type Config struct {
// EnableDegradedMode is to control whether resource control client enable degraded mode when server is disconnect.
DegradedModeWaitDuration string `toml:"degraded-mode-wait-duration" json:"degraded-mode-wait-duration"`

Expand All @@ -80,9 +80,9 @@ type ControllerConfig struct {
RequestUnit RequestUnitConfig `toml:"request-unit" json:"request-unit"`
}

// DefaultControllerConfig returns the default resource manager controller configuration.
func DefaultControllerConfig() *ControllerConfig {
return &ControllerConfig{
// DefaultConfig returns the default resource manager controller configuration.
func DefaultConfig() *Config {
return &Config{
DegradedModeWaitDuration: defaultDegradedModeWaitDuration,
RequestUnit: DefaultRequestUnitConfig(),
}
Expand Down Expand Up @@ -117,10 +117,10 @@ func DefaultRequestUnitConfig() RequestUnitConfig {
}
}

// Config is the configuration of the resource units, which gives the read/write request
// RUConfig is the configuration of the resource units, which gives the read/write request
// units or request resource cost standards. It should be calculated by a given `RequestUnitConfig`
// or `RequestResourceConfig`.
type Config struct {
type RUConfig struct {
// RU model config
ReadBaseCost RequestUnit
ReadBytesCost RequestUnit
Expand All @@ -133,16 +133,16 @@ type Config struct {
DegradedModeWaitDuration time.Duration
}

// DefaultConfig returns the default configuration.
func DefaultConfig() *Config {
return GenerateConfig(
DefaultControllerConfig(),
// DefaultRUConfig returns the default configuration.
func DefaultRUConfig() *RUConfig {
return GenerateRUConfig(
DefaultConfig(),
)
}

// GenerateConfig generates the configuration by the given request unit configuration.
func GenerateConfig(config *ControllerConfig) *Config {
cfg := &Config{
// GenerateRUConfig generates the configuration by the given request unit configuration.
func GenerateRUConfig(config *Config) *RUConfig {
cfg := &RUConfig{
ReadBaseCost: RequestUnit(config.RequestUnit.ReadBaseCost),
ReadBytesCost: RequestUnit(config.RequestUnit.ReadCostPerByte),
WriteBaseCost: RequestUnit(config.RequestUnit.WriteBaseCost),
Expand Down
53 changes: 27 additions & 26 deletions client/resource_group/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ type ResourceControlCreateOption func(controller *ResourceGroupsController)
// EnableSingleGroupByKeyspace is the option to enable single group by keyspace feature.
func EnableSingleGroupByKeyspace() ResourceControlCreateOption {
return func(controller *ResourceGroupsController) {
controller.config.isSingleGroupByKeyspace = true
controller.ruConfig.isSingleGroupByKeyspace = true
}
}

// WithMaxWaitDuration is the option to set the max wait duration for acquiring token buckets.
func WithMaxWaitDuration(d time.Duration) ResourceControlCreateOption {
return func(controller *ResourceGroupsController) {
controller.config.maxWaitDuration = d
controller.ruConfig.maxWaitDuration = d
}
}

var _ ResourceGroupKVInterceptor = (*ResourceGroupsController)(nil)

// ResourceGroupsController impls ResourceGroupKVInterceptor.
// ResourceGroupsController implements ResourceGroupKVInterceptor.
type ResourceGroupsController struct {
clientUniqueID uint64
provider ResourceGroupProvider
groupsController sync.Map
config *Config
ruConfig *RUConfig

loopCtx context.Context
loopCancel func()
Expand Down Expand Up @@ -128,49 +128,50 @@ func NewResourceGroupController(
requestUnitConfig *RequestUnitConfig,
opts ...ResourceControlCreateOption,
) (*ResourceGroupsController, error) {
controllerConfig, err := loadServerConfig(ctx, provider)
config, err := loadServerConfig(ctx, provider)
if err != nil {
return nil, err
}
if requestUnitConfig != nil {
controllerConfig.RequestUnit = *requestUnitConfig
config.RequestUnit = *requestUnitConfig
}
config := GenerateConfig(controllerConfig)
log.Info("load resource controller config", zap.Reflect("config", config))
ruConfig := GenerateRUConfig(config)
controller := &ResourceGroupsController{
clientUniqueID: clientUniqueID,
provider: provider,
config: config,
ruConfig: ruConfig,
lowTokenNotifyChan: make(chan struct{}, 1),
tokenResponseChan: make(chan []*rmpb.TokenBucketResponse, 1),
tokenBucketUpdateChan: make(chan *groupCostController, maxNotificationChanLen),
}
for _, opt := range opts {
opt(controller)
}
controller.calculators = []ResourceCalculator{newKVCalculator(controller.config), newSQLCalculator(controller.config)}
controller.calculators = []ResourceCalculator{newKVCalculator(controller.ruConfig), newSQLCalculator(controller.ruConfig)}
return controller, nil
}

func loadServerConfig(ctx context.Context, provider ResourceGroupProvider) (*ControllerConfig, error) {
func loadServerConfig(ctx context.Context, provider ResourceGroupProvider) (*Config, error) {
items, _, err := provider.LoadGlobalConfig(ctx, nil, controllerConfigPath)
if err != nil {
return nil, err
}
if len(items) == 0 {
log.Warn("[resource group controller] server does not save config, load config failed")
return DefaultControllerConfig(), nil
return DefaultConfig(), nil
}
controllerConfig := &ControllerConfig{}
err = json.Unmarshal(items[0].PayLoad, controllerConfig)
config := &Config{}
err = json.Unmarshal(items[0].PayLoad, config)
if err != nil {
return nil, err
}
return controllerConfig, nil
return config, nil
}

// GetConfig returns the config of controller. It's only used for test.
func (c *ResourceGroupsController) GetConfig() *Config {
return c.config
func (c *ResourceGroupsController) GetConfig() *RUConfig {
return c.ruConfig
}

// Source List
Expand All @@ -183,8 +184,8 @@ const (
func (c *ResourceGroupsController) Start(ctx context.Context) {
c.loopCtx, c.loopCancel = context.WithCancel(ctx)
go func() {
if c.config.DegradedModeWaitDuration > 0 {
c.run.responseDeadline = time.NewTimer(c.config.DegradedModeWaitDuration)
if c.ruConfig.DegradedModeWaitDuration > 0 {
c.run.responseDeadline = time.NewTimer(c.ruConfig.DegradedModeWaitDuration)
c.run.responseDeadline.Stop()
defer c.run.responseDeadline.Stop()
}
Expand Down Expand Up @@ -213,11 +214,11 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
log.Warn("load resource group revision failed", zap.Error(err))
}
var watchChannel chan []*meta_storagepb.Event
if !c.config.isSingleGroupByKeyspace {
if !c.ruConfig.isSingleGroupByKeyspace {
watchChannel, err = c.provider.Watch(ctx, pd.GroupSettingsPathPrefixBytes, pd.WithRev(revision), pd.WithPrefix())
}
watchRetryTimer := time.NewTimer(watchRetryInterval)
if err == nil || c.config.isSingleGroupByKeyspace {
if err == nil || c.ruConfig.isSingleGroupByKeyspace {
watchRetryTimer.Stop()
}
defer watchRetryTimer.Stop()
Expand Down Expand Up @@ -258,7 +259,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) {
c.executeOnAllGroups((*groupCostController).resetEmergencyTokenAcquisition)
case resp, ok := <-watchChannel:
failpoint.Inject("disableWatch", func() {
if c.config.isSingleGroupByKeyspace {
if c.ruConfig.isSingleGroupByKeyspace {
panic("disableWatch")
}
})
Expand Down Expand Up @@ -334,7 +335,7 @@ func (c *ResourceGroupsController) tryGetResourceGroup(ctx context.Context, name
return gc, nil
}
// Initialize the resource group controller.
gc, err := newGroupCostController(group, c.config, c.lowTokenNotifyChan, c.tokenBucketUpdateChan)
gc, err := newGroupCostController(group, c.ruConfig, c.lowTokenNotifyChan, c.tokenBucketUpdateChan)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -424,8 +425,8 @@ func (c *ResourceGroupsController) sendTokenBucketRequests(ctx context.Context,
TargetRequestPeriodMs: uint64(defaultTargetPeriod / time.Millisecond),
ClientUniqueId: c.clientUniqueID,
}
if c.config.DegradedModeWaitDuration > 0 && c.responseDeadlineCh == nil {
c.run.responseDeadline.Reset(c.config.DegradedModeWaitDuration)
if c.ruConfig.DegradedModeWaitDuration > 0 && c.responseDeadlineCh == nil {
c.run.responseDeadline.Reset(c.ruConfig.DegradedModeWaitDuration)
c.responseDeadlineCh = c.run.responseDeadline.C
}
go func() {
Expand Down Expand Up @@ -484,7 +485,7 @@ type groupCostController struct {
// invariant attributes
name string
mode rmpb.GroupMode
mainCfg *Config
mainCfg *RUConfig
// meta info
meta *rmpb.ResourceGroup
metaLock sync.RWMutex
Expand Down Expand Up @@ -573,7 +574,7 @@ type tokenCounter struct {

func newGroupCostController(
group *rmpb.ResourceGroup,
mainCfg *Config,
mainCfg *RUConfig,
lowRUNotifyChan chan struct{},
tokenBucketUpdateChan chan *groupCostController,
) (*groupCostController, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/resource_group/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func createTestGroupCostController(re *require.Assertions) *groupCostController
}
ch1 := make(chan struct{})
ch2 := make(chan *groupCostController)
gc, err := newGroupCostController(group, DefaultConfig(), ch1, ch2)
gc, err := newGroupCostController(group, DefaultRUConfig(), ch1, ch2)
re.NoError(err)
return gc
}
Expand Down
4 changes: 2 additions & 2 deletions client/resource_group/controller/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ type tokenBucketReconfigureArgs struct {
NotifyThreshold float64
}

// LimiterOption is used to modify the Limiter during construction.
// LimiterOption configures Limiter.
type LimiterOption func(*Limiter)

func resetLowProcess() func(*Limiter) {
Expand Down Expand Up @@ -387,7 +387,7 @@ func (lim *Limiter) reserveN(now time.Time, n float64, maxFutureReserve time.Dur
return r
}

// ResetRemainingNotifyTimes resets remainingNotifyTimes.
// ResetRemainingNotifyTimes resets the remaining notify times to 3.
func (lim *Limiter) ResetRemainingNotifyTimes() {
lim.mu.Lock()
defer lim.mu.Unlock()
Expand Down
12 changes: 6 additions & 6 deletions client/resource_group/controller/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ type ResourceCalculator interface {

// KVCalculator is used to calculate the KV-side consumption.
type KVCalculator struct {
*Config
*RUConfig
}

var _ ResourceCalculator = (*KVCalculator)(nil)

func newKVCalculator(cfg *Config) *KVCalculator {
return &KVCalculator{Config: cfg}
func newKVCalculator(cfg *RUConfig) *KVCalculator {
return &KVCalculator{RUConfig: cfg}
}

// Trickle ...
Expand Down Expand Up @@ -140,13 +140,13 @@ func (kc *KVCalculator) payBackWriteCost(consumption *rmpb.Consumption, req Requ

// SQLCalculator is used to calculate the SQL-side consumption.
type SQLCalculator struct {
*Config
*RUConfig
}

var _ ResourceCalculator = (*SQLCalculator)(nil)

func newSQLCalculator(cfg *Config) *SQLCalculator {
return &SQLCalculator{Config: cfg}
func newSQLCalculator(cfg *RUConfig) *SQLCalculator {
return &SQLCalculator{RUConfig: cfg}
}

// Trickle update sql layer CPU consumption.
Expand Down
5 changes: 5 additions & 0 deletions client/resource_group/controller/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func (tri *TestRequestInfo) StoreID() uint64 {
return tri.storeID
}

// ReplicaNumber implements the RequestInfo interface.
func (tri *TestRequestInfo) ReplicaNumber() int64 {
return 1
}

// TestResponseInfo is used to test the response info interface.
type TestResponseInfo struct {
readBytes uint64
Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

static: install-tools
@ echo "gofmt ..."
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ echo "golangci-lint ..."
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./... --allow-parallel-runners
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./...
@ echo "revive ..."
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml ./...

Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/mcs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

static: install-tools
@ echo "gofmt ..."
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ echo "golangci-lint ..."
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./... --allow-parallel-runners
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./...
@ echo "revive ..."
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml ./...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ func (suite *resourceManagerClientTestSuite) TestLoadRequestUnitConfig() {
re.NoError(err)
config := ctr.GetConfig()
re.NotNil(config)
expectedConfig := controller.DefaultConfig()
expectedConfig := controller.DefaultRUConfig()
re.Equal(expectedConfig.ReadBaseCost, config.ReadBaseCost)
re.Equal(expectedConfig.ReadBytesCost, config.ReadBytesCost)
re.Equal(expectedConfig.WriteBaseCost, config.WriteBaseCost)
Expand All @@ -1096,9 +1096,9 @@ func (suite *resourceManagerClientTestSuite) TestLoadRequestUnitConfig() {
re.NoError(err)
config = ctr.GetConfig()
re.NotNil(config)
controllerConfig := controller.DefaultControllerConfig()
controllerConfig := controller.DefaultConfig()
controllerConfig.RequestUnit = *ruConfig
expectedConfig = controller.GenerateConfig(controllerConfig)
expectedConfig = controller.GenerateRUConfig(controllerConfig)
re.Equal(expectedConfig.ReadBaseCost, config.ReadBaseCost)
re.Equal(expectedConfig.ReadBytesCost, config.ReadBytesCost)
re.Equal(expectedConfig.WriteBaseCost, config.WriteBaseCost)
Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/tso/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

static: install-tools
@ echo "gofmt ..."
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ echo "golangci-lint ..."
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./... --allow-parallel-runners
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./...
@ echo "revive ..."
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml ./...

Expand Down

0 comments on commit 3846eac

Please sign in to comment.