Skip to content

Commit

Permalink
domain: enable revive (#49946)
Browse files Browse the repository at this point in the history
ref #40786
  • Loading branch information
hawkingrei authored Jan 2, 2024
1 parent d6aeaf0 commit c20874e
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 67 deletions.
3 changes: 2 additions & 1 deletion build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@
"pkg/resourcemanager/": "resourcemanager code",
"pkg/keyspace/": "keyspace code",
"pkg/owner/": "owner code",
"pkg/timer/": "timer code"
"pkg/timer/": "timer code",
"pkg/domain": "domain code"
}
},
"shift": {
Expand Down
32 changes: 16 additions & 16 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ func (do *Domain) sysFacHack() (pools.Resource, error) {
return do.sysExecutorFactory(do)
}

func (do *Domain) fetchPolicies(m *meta.Meta) ([]*model.PolicyInfo, error) {
func (*Domain) fetchPolicies(m *meta.Meta) ([]*model.PolicyInfo, error) {
allPolicies, err := m.ListPolicies()
if err != nil {
return nil, err
}
return allPolicies, nil
}

func (do *Domain) fetchResourceGroups(m *meta.Meta) ([]*model.ResourceGroupInfo, error) {
func (*Domain) fetchResourceGroups(m *meta.Meta) ([]*model.ResourceGroupInfo, error) {
allResourceGroups, err := m.ListResourceGroups()
if err != nil {
return nil, err
Expand Down Expand Up @@ -380,7 +380,7 @@ func (do *Domain) fetchAllSchemasWithTables(m *meta.Meta) ([]*model.DBInfo, erro
// so we decrease the concurrency.
const fetchSchemaConcurrency = 1

func (do *Domain) splitForConcurrentFetch(schemas []*model.DBInfo) [][]*model.DBInfo {
func (*Domain) splitForConcurrentFetch(schemas []*model.DBInfo) [][]*model.DBInfo {
groupSize := (len(schemas) + fetchSchemaConcurrency - 1) / fetchSchemaConcurrency
splitted := make([][]*model.DBInfo, 0, fetchSchemaConcurrency)
schemaCnt := len(schemas)
Expand All @@ -394,7 +394,7 @@ func (do *Domain) splitForConcurrentFetch(schemas []*model.DBInfo) [][]*model.DB
return splitted
}

func (do *Domain) fetchSchemasWithTables(schemas []*model.DBInfo, m *meta.Meta, done chan error) {
func (*Domain) fetchSchemasWithTables(schemas []*model.DBInfo, m *meta.Meta, done chan error) {
for _, di := range schemas {
if di.State != model.StatePublic {
// schema is not public, can't be used outside.
Expand Down Expand Up @@ -456,16 +456,16 @@ func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64
if diff.RegenerateSchemaMap {
return nil, nil, nil, errors.Errorf("Meets a schema diff with RegenerateSchemaMap flag")
}
IDs, err := builder.ApplyDiff(m, diff)
ids, err := builder.ApplyDiff(m, diff)
if err != nil {
return nil, nil, nil, err
}
if canSkipSchemaCheckerDDL(diff.Type) {
continue
}
diffTypes = append(diffTypes, diff.Type.String())
phyTblIDs = append(phyTblIDs, IDs...)
for i := 0; i < len(IDs); i++ {
phyTblIDs = append(phyTblIDs, ids...)
for i := 0; i < len(ids); i++ {
actions = append(actions, uint64(diff.Type))
}
}
Expand Down Expand Up @@ -554,7 +554,7 @@ func (do *Domain) Store() kv.Storage {
}

// GetScope gets the status variables scope.
func (do *Domain) GetScope(status string) variable.ScopeFlag {
func (*Domain) GetScope(string) variable.ScopeFlag {
// Now domain status variables scope are all default scope.
return variable.DefaultStatusVarScopeFlag
}
Expand Down Expand Up @@ -595,7 +595,7 @@ func (do *Domain) Reload() error {
if err != nil {
if version = getFlashbackStartTSFromErrorMsg(err); version != 0 {
// use the lastest available version to create domain
version -= 1
version--
is, hitCache, oldSchemaVersion, changes, err = do.loadInfoSchema(version)
}
}
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (do *Domain) checkReplicaRead(ctx context.Context, pdClient pd.Client) erro
for _, s := range servers {
if v, ok := s.Labels[placement.DCLabelKey]; ok && v != "" {
if _, ok := storeZones[v]; ok {
storeZones[v] += 1
storeZones[v]++
if v == zone {
svrIdsInThisZone = append(svrIdsInThisZone, s.ID)
}
Expand Down Expand Up @@ -2385,7 +2385,7 @@ func (do *Domain) syncIndexUsageWorker(owner owner.Manager) {
}
}

func (do *Domain) updateStatsWorkerExitPreprocessing(statsHandle *handle.Handle, owner owner.Manager) {
func (*Domain) updateStatsWorkerExitPreprocessing(statsHandle *handle.Handle, owner owner.Manager) {
ch := make(chan struct{}, 1)
timeout, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand All @@ -2406,7 +2406,7 @@ func (do *Domain) updateStatsWorkerExitPreprocessing(statsHandle *handle.Handle,
}
}

func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager) {
func (do *Domain) updateStatsWorker(_ sessionctx.Context, owner owner.Manager) {
defer util.Recover(metrics.LabelDomain, "updateStatsWorker", nil, false)
logutil.BgLogger().Info("updateStatsWorker started.")
lease := do.statsLease
Expand Down Expand Up @@ -2500,7 +2500,7 @@ func (do *Domain) analyzeJobsCleanupWorker(owner owner.Manager) {
defer util.Recover(metrics.LabelDomain, "analyzeJobsCleanupWorker", nil, false)
// For GC.
const gcInterval = time.Hour
const DaysToKeep = 7
const daysToKeep = 7
gcTicker := time.NewTicker(gcInterval)
// For clean up.
// Default stats lease is 3 * time.Second.
Expand All @@ -2518,7 +2518,7 @@ func (do *Domain) analyzeJobsCleanupWorker(owner owner.Manager) {
case <-gcTicker.C:
// Only the owner should perform this operation.
if owner.IsOwner() {
updateTime := time.Now().AddDate(0, 0, -DaysToKeep)
updateTime := time.Now().AddDate(0, 0, -daysToKeep)
err := statsHandle.DeleteAnalyzeJobs(updateTime)
if err != nil {
logutil.BgLogger().Warn("gc analyze history failed", zap.Error(err))
Expand Down Expand Up @@ -2820,7 +2820,7 @@ func (do *Domain) acquireServerID(ctx context.Context) error {
}
}

func (do *Domain) releaseServerID(ctx context.Context) {
func (do *Domain) releaseServerID(context.Context) {
serverID := do.ServerID()
if serverID == 0 {
return
Expand All @@ -2840,7 +2840,7 @@ func (do *Domain) releaseServerID(ctx context.Context) {
}

// propose server ID by random.
func (do *Domain) proposeServerID(ctx context.Context, conflictCnt int) (uint64, error) {
func (*Domain) proposeServerID(ctx context.Context, conflictCnt int) (uint64, error) {
// get a random server ID in range [min, max]
randomServerID := func(min uint64, max uint64) uint64 {
return uint64(rand.Int63n(int64(max-min+1)) + int64(min)) // #nosec G404
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/domain_sysvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (do *Domain) setPDClientDynamicOption(name, sVal string) {
}
}

func (do *Domain) setGlobalResourceControl(enable bool) {
func (*Domain) setGlobalResourceControl(enable bool) {
if enable {
variable.EnableGlobalResourceControlFunc()
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/domainctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type domainKeyType int

// String defines a Stringer function for debugging and pretty printing.
func (k domainKeyType) String() string {
func (domainKeyType) String() string {
return "domain"
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/domain/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ const (
)

func taskTypeToString(t ExtractType) string {
switch t {
case ExtractPlanType:
if t == ExtractPlanType {
return "Plan"
}
return "Unknown"
Expand Down Expand Up @@ -131,8 +130,7 @@ func newExtractWorker(sctx sessionctx.Context, isBackgroundWorker bool) *extract
}

func (w *extractWorker) extractTask(ctx context.Context, task *ExtractTask) (string, error) {
switch task.ExtractType {
case ExtractPlanType:
if task.ExtractType == ExtractPlanType {
return w.extractPlanTask(ctx, task)
}
return "", errors.New("unknown extract task")
Expand Down Expand Up @@ -453,8 +451,7 @@ func dumpExtractMeta(task *ExtractTask, zw *zip.Writer) error {
}
varMap := make(map[string]string)
varMap[ExtractTaskType] = taskTypeToString(task.ExtractType)
switch task.ExtractType {
case ExtractPlanType:
if task.ExtractType == ExtractPlanType {
varMap[ExtractPlanTaskSkipStats] = strconv.FormatBool(task.SkipStats)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,12 @@ func GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rul
}

// CalculateTiFlashProgress calculates TiFlash replica progress
func CalculateTiFlashProgress(tableID int64, replicaCount uint64, TiFlashStores map[int64]pdhttp.StoreInfo) (float64, error) {
func CalculateTiFlashProgress(tableID int64, replicaCount uint64, tiFlashStores map[int64]pdhttp.StoreInfo) (float64, error) {
is, err := getGlobalInfoSyncer()
if err != nil {
return 0, errors.Trace(err)
}
return is.tiflashReplicaManager.CalculateTiFlashProgress(tableID, replicaCount, TiFlashStores)
return is.tiflashReplicaManager.CalculateTiFlashProgress(tableID, replicaCount, tiFlashStores)
}

// UpdateTiFlashProgressCache updates tiflashProgressCache
Expand Down
10 changes: 5 additions & 5 deletions pkg/domain/infosync/label_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (lm *PDLabelManager) GetAllLabelRules(ctx context.Context) ([]*label.Rule,
}

// GetLabelRules implements GetLabelRules
func (lm *PDLabelManager) GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rule, error) {
func (lm *PDLabelManager) GetLabelRules(ctx context.Context, _ []string) (map[string]*label.Rule, error) {
labelRules, err := lm.pdHTTPCli.GetAllRegionLabelRules(ctx)
if err != nil {
return nil, err
Expand All @@ -78,7 +78,7 @@ type mockLabelManager struct {
}

// PutLabelRule implements PutLabelRule
func (mm *mockLabelManager) PutLabelRule(ctx context.Context, rule *label.Rule) error {
func (mm *mockLabelManager) PutLabelRule(_ context.Context, rule *label.Rule) error {
mm.Lock()
defer mm.Unlock()
if rule == nil {
Expand All @@ -93,7 +93,7 @@ func (mm *mockLabelManager) PutLabelRule(ctx context.Context, rule *label.Rule)
}

// UpdateLabelRules implements UpdateLabelRules
func (mm *mockLabelManager) UpdateLabelRules(ctx context.Context, patch *pd.LabelRulePatch) error {
func (mm *mockLabelManager) UpdateLabelRules(_ context.Context, patch *pd.LabelRulePatch) error {
mm.Lock()
defer mm.Unlock()
if patch == nil {
Expand All @@ -116,7 +116,7 @@ func (mm *mockLabelManager) UpdateLabelRules(ctx context.Context, patch *pd.Labe
}

// mockLabelManager implements GetAllLabelRules
func (mm *mockLabelManager) GetAllLabelRules(ctx context.Context) ([]*label.Rule, error) {
func (mm *mockLabelManager) GetAllLabelRules(context.Context) ([]*label.Rule, error) {
mm.RLock()
defer mm.RUnlock()
r := make([]*label.Rule, 0, len(mm.labelRules))
Expand All @@ -135,7 +135,7 @@ func (mm *mockLabelManager) GetAllLabelRules(ctx context.Context) ([]*label.Rule
}

// mockLabelManager implements GetLabelRules
func (mm *mockLabelManager) GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rule, error) {
func (mm *mockLabelManager) GetLabelRules(_ context.Context, ruleIDs []string) (map[string]*label.Rule, error) {
mm.RLock()
defer mm.RUnlock()
r := make(map[string]*label.Rule, len(ruleIDs))
Expand Down
18 changes: 9 additions & 9 deletions pkg/domain/infosync/resource_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewMockResourceManagerClient() pd.ResourceManagerClient {

var _ pd.ResourceManagerClient = (*mockResourceManagerClient)(nil)

func (m *mockResourceManagerClient) ListResourceGroups(ctx context.Context, opts ...pd.GetResourceGroupOption) ([]*rmpb.ResourceGroup, error) {
func (m *mockResourceManagerClient) ListResourceGroups(context.Context, ...pd.GetResourceGroupOption) ([]*rmpb.ResourceGroup, error) {
m.RLock()
defer m.RUnlock()
groups := make([]*rmpb.ResourceGroup, 0, len(m.groups))
Expand All @@ -68,7 +68,7 @@ func (m *mockResourceManagerClient) ListResourceGroups(ctx context.Context, opts
return groups, nil
}

func (m *mockResourceManagerClient) GetResourceGroup(ctx context.Context, name string, opts ...pd.GetResourceGroupOption) (*rmpb.ResourceGroup, error) {
func (m *mockResourceManagerClient) GetResourceGroup(_ context.Context, name string, _ ...pd.GetResourceGroupOption) (*rmpb.ResourceGroup, error) {
m.RLock()
defer m.RUnlock()
group, ok := m.groups[name]
Expand All @@ -78,7 +78,7 @@ func (m *mockResourceManagerClient) GetResourceGroup(ctx context.Context, name s
return group, nil
}

func (m *mockResourceManagerClient) AddResourceGroup(ctx context.Context, group *rmpb.ResourceGroup) (string, error) {
func (m *mockResourceManagerClient) AddResourceGroup(_ context.Context, group *rmpb.ResourceGroup) (string, error) {
m.Lock()
defer m.Unlock()
if _, ok := m.groups[group.Name]; ok {
Expand All @@ -98,7 +98,7 @@ func (m *mockResourceManagerClient) AddResourceGroup(ctx context.Context, group
return "Success!", nil
}

func (m *mockResourceManagerClient) ModifyResourceGroup(ctx context.Context, group *rmpb.ResourceGroup) (string, error) {
func (m *mockResourceManagerClient) ModifyResourceGroup(_ context.Context, group *rmpb.ResourceGroup) (string, error) {
m.Lock()
defer m.Unlock()

Expand All @@ -115,7 +115,7 @@ func (m *mockResourceManagerClient) ModifyResourceGroup(ctx context.Context, gro
return "Success!", nil
}

func (m *mockResourceManagerClient) DeleteResourceGroup(ctx context.Context, name string) (string, error) {
func (m *mockResourceManagerClient) DeleteResourceGroup(_ context.Context, name string) (string, error) {
m.Lock()
defer m.Unlock()
group := m.groups[name]
Expand All @@ -132,19 +132,19 @@ func (m *mockResourceManagerClient) DeleteResourceGroup(ctx context.Context, nam
return "Success!", nil
}

func (m *mockResourceManagerClient) AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error) {
func (*mockResourceManagerClient) AcquireTokenBuckets(context.Context, *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error) {
return nil, nil
}

func (m *mockResourceManagerClient) WatchResourceGroup(ctx context.Context, revision int64) (chan []*rmpb.ResourceGroup, error) {
func (*mockResourceManagerClient) WatchResourceGroup(context.Context, int64) (chan []*rmpb.ResourceGroup, error) {
return nil, nil
}

func (m *mockResourceManagerClient) LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, int64, error) {
func (*mockResourceManagerClient) LoadResourceGroups(context.Context) ([]*rmpb.ResourceGroup, int64, error) {
return nil, 0, nil
}

func (m *mockResourceManagerClient) Watch(ctx context.Context, key []byte, opts ...pd.OpOption) (chan []*meta_storagepb.Event, error) {
func (m *mockResourceManagerClient) Watch(_ context.Context, key []byte, _ ...pd.OpOption) (chan []*meta_storagepb.Event, error) {
if bytes.Equal(pd.GroupSettingsPathPrefixBytes, key) {
return m.eventCh, nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/domain/infosync/schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

// ScheduleManager manages schedule configs
type ScheduleManager interface {
GetScheduleConfig(ctx context.Context) (map[string]interface{}, error)
SetScheduleConfig(ctx context.Context, config map[string]interface{}) error
GetScheduleConfig(ctx context.Context) (map[string]any, error)
SetScheduleConfig(ctx context.Context, config map[string]any) error
}

// PDScheduleManager manages schedule with pd
Expand All @@ -38,7 +38,7 @@ type mockScheduleManager struct {
}

// GetScheduleConfig get schedule config from schedules map
func (mm *mockScheduleManager) GetScheduleConfig(ctx context.Context) (map[string]interface{}, error) {
func (mm *mockScheduleManager) GetScheduleConfig(context.Context) (map[string]interface{}, error) {
mm.Lock()

schedules := make(map[string]interface{})
Expand All @@ -51,11 +51,11 @@ func (mm *mockScheduleManager) GetScheduleConfig(ctx context.Context) (map[strin
}

// SetScheduleConfig set schedule config to schedules map
func (mm *mockScheduleManager) SetScheduleConfig(ctx context.Context, config map[string]interface{}) error {
func (mm *mockScheduleManager) SetScheduleConfig(_ context.Context, config map[string]interface{}) error {
mm.Lock()

if mm.schedules == nil {
mm.schedules = make(map[string]interface{})
mm.schedules = make(map[string]any)
}
for key, value := range config {
mm.schedules[key] = value
Expand Down
Loading

0 comments on commit c20874e

Please sign in to comment.