Skip to content

Commit c20874e

Browse files
authored
domain: enable revive (pingcap#49946)
ref pingcap#40786
1 parent d6aeaf0 commit c20874e

15 files changed

+65
-67
lines changed

build/nogo_config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@
548548
"pkg/resourcemanager/": "resourcemanager code",
549549
"pkg/keyspace/": "keyspace code",
550550
"pkg/owner/": "owner code",
551-
"pkg/timer/": "timer code"
551+
"pkg/timer/": "timer code",
552+
"pkg/domain": "domain code"
552553
}
553554
},
554555
"shift": {

pkg/domain/domain.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,15 @@ func (do *Domain) sysFacHack() (pools.Resource, error) {
340340
return do.sysExecutorFactory(do)
341341
}
342342

343-
func (do *Domain) fetchPolicies(m *meta.Meta) ([]*model.PolicyInfo, error) {
343+
func (*Domain) fetchPolicies(m *meta.Meta) ([]*model.PolicyInfo, error) {
344344
allPolicies, err := m.ListPolicies()
345345
if err != nil {
346346
return nil, err
347347
}
348348
return allPolicies, nil
349349
}
350350

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

383-
func (do *Domain) splitForConcurrentFetch(schemas []*model.DBInfo) [][]*model.DBInfo {
383+
func (*Domain) splitForConcurrentFetch(schemas []*model.DBInfo) [][]*model.DBInfo {
384384
groupSize := (len(schemas) + fetchSchemaConcurrency - 1) / fetchSchemaConcurrency
385385
splitted := make([][]*model.DBInfo, 0, fetchSchemaConcurrency)
386386
schemaCnt := len(schemas)
@@ -394,7 +394,7 @@ func (do *Domain) splitForConcurrentFetch(schemas []*model.DBInfo) [][]*model.DB
394394
return splitted
395395
}
396396

397-
func (do *Domain) fetchSchemasWithTables(schemas []*model.DBInfo, m *meta.Meta, done chan error) {
397+
func (*Domain) fetchSchemasWithTables(schemas []*model.DBInfo, m *meta.Meta, done chan error) {
398398
for _, di := range schemas {
399399
if di.State != model.StatePublic {
400400
// schema is not public, can't be used outside.
@@ -456,16 +456,16 @@ func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64
456456
if diff.RegenerateSchemaMap {
457457
return nil, nil, nil, errors.Errorf("Meets a schema diff with RegenerateSchemaMap flag")
458458
}
459-
IDs, err := builder.ApplyDiff(m, diff)
459+
ids, err := builder.ApplyDiff(m, diff)
460460
if err != nil {
461461
return nil, nil, nil, err
462462
}
463463
if canSkipSchemaCheckerDDL(diff.Type) {
464464
continue
465465
}
466466
diffTypes = append(diffTypes, diff.Type.String())
467-
phyTblIDs = append(phyTblIDs, IDs...)
468-
for i := 0; i < len(IDs); i++ {
467+
phyTblIDs = append(phyTblIDs, ids...)
468+
for i := 0; i < len(ids); i++ {
469469
actions = append(actions, uint64(diff.Type))
470470
}
471471
}
@@ -554,7 +554,7 @@ func (do *Domain) Store() kv.Storage {
554554
}
555555

556556
// GetScope gets the status variables scope.
557-
func (do *Domain) GetScope(status string) variable.ScopeFlag {
557+
func (*Domain) GetScope(string) variable.ScopeFlag {
558558
// Now domain status variables scope are all default scope.
559559
return variable.DefaultStatusVarScopeFlag
560560
}
@@ -595,7 +595,7 @@ func (do *Domain) Reload() error {
595595
if err != nil {
596596
if version = getFlashbackStartTSFromErrorMsg(err); version != 0 {
597597
// use the lastest available version to create domain
598-
version -= 1
598+
version--
599599
is, hitCache, oldSchemaVersion, changes, err = do.loadInfoSchema(version)
600600
}
601601
}
@@ -1422,7 +1422,7 @@ func (do *Domain) checkReplicaRead(ctx context.Context, pdClient pd.Client) erro
14221422
for _, s := range servers {
14231423
if v, ok := s.Labels[placement.DCLabelKey]; ok && v != "" {
14241424
if _, ok := storeZones[v]; ok {
1425-
storeZones[v] += 1
1425+
storeZones[v]++
14261426
if v == zone {
14271427
svrIdsInThisZone = append(svrIdsInThisZone, s.ID)
14281428
}
@@ -2385,7 +2385,7 @@ func (do *Domain) syncIndexUsageWorker(owner owner.Manager) {
23852385
}
23862386
}
23872387

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

2409-
func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager) {
2409+
func (do *Domain) updateStatsWorker(_ sessionctx.Context, owner owner.Manager) {
24102410
defer util.Recover(metrics.LabelDomain, "updateStatsWorker", nil, false)
24112411
logutil.BgLogger().Info("updateStatsWorker started.")
24122412
lease := do.statsLease
@@ -2500,7 +2500,7 @@ func (do *Domain) analyzeJobsCleanupWorker(owner owner.Manager) {
25002500
defer util.Recover(metrics.LabelDomain, "analyzeJobsCleanupWorker", nil, false)
25012501
// For GC.
25022502
const gcInterval = time.Hour
2503-
const DaysToKeep = 7
2503+
const daysToKeep = 7
25042504
gcTicker := time.NewTicker(gcInterval)
25052505
// For clean up.
25062506
// Default stats lease is 3 * time.Second.
@@ -2518,7 +2518,7 @@ func (do *Domain) analyzeJobsCleanupWorker(owner owner.Manager) {
25182518
case <-gcTicker.C:
25192519
// Only the owner should perform this operation.
25202520
if owner.IsOwner() {
2521-
updateTime := time.Now().AddDate(0, 0, -DaysToKeep)
2521+
updateTime := time.Now().AddDate(0, 0, -daysToKeep)
25222522
err := statsHandle.DeleteAnalyzeJobs(updateTime)
25232523
if err != nil {
25242524
logutil.BgLogger().Warn("gc analyze history failed", zap.Error(err))
@@ -2820,7 +2820,7 @@ func (do *Domain) acquireServerID(ctx context.Context) error {
28202820
}
28212821
}
28222822

2823-
func (do *Domain) releaseServerID(ctx context.Context) {
2823+
func (do *Domain) releaseServerID(context.Context) {
28242824
serverID := do.ServerID()
28252825
if serverID == 0 {
28262826
return
@@ -2840,7 +2840,7 @@ func (do *Domain) releaseServerID(ctx context.Context) {
28402840
}
28412841

28422842
// propose server ID by random.
2843-
func (do *Domain) proposeServerID(ctx context.Context, conflictCnt int) (uint64, error) {
2843+
func (*Domain) proposeServerID(ctx context.Context, conflictCnt int) (uint64, error) {
28442844
// get a random server ID in range [min, max]
28452845
randomServerID := func(min uint64, max uint64) uint64 {
28462846
return uint64(rand.Int63n(int64(max-min+1)) + int64(min)) // #nosec G404

pkg/domain/domain_sysvars.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (do *Domain) setPDClientDynamicOption(name, sVal string) {
7272
}
7373
}
7474

75-
func (do *Domain) setGlobalResourceControl(enable bool) {
75+
func (*Domain) setGlobalResourceControl(enable bool) {
7676
if enable {
7777
variable.EnableGlobalResourceControlFunc()
7878
} else {

pkg/domain/domainctx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
type domainKeyType int
2323

2424
// String defines a Stringer function for debugging and pretty printing.
25-
func (k domainKeyType) String() string {
25+
func (domainKeyType) String() string {
2626
return "domain"
2727
}
2828

pkg/domain/extract.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ const (
6262
)
6363

6464
func taskTypeToString(t ExtractType) string {
65-
switch t {
66-
case ExtractPlanType:
65+
if t == ExtractPlanType {
6766
return "Plan"
6867
}
6968
return "Unknown"
@@ -131,8 +130,7 @@ func newExtractWorker(sctx sessionctx.Context, isBackgroundWorker bool) *extract
131130
}
132131

133132
func (w *extractWorker) extractTask(ctx context.Context, task *ExtractTask) (string, error) {
134-
switch task.ExtractType {
135-
case ExtractPlanType:
133+
if task.ExtractType == ExtractPlanType {
136134
return w.extractPlanTask(ctx, task)
137135
}
138136
return "", errors.New("unknown extract task")
@@ -453,8 +451,7 @@ func dumpExtractMeta(task *ExtractTask, zw *zip.Writer) error {
453451
}
454452
varMap := make(map[string]string)
455453
varMap[ExtractTaskType] = taskTypeToString(task.ExtractType)
456-
switch task.ExtractType {
457-
case ExtractPlanType:
454+
if task.ExtractType == ExtractPlanType {
458455
varMap[ExtractPlanTaskSkipStats] = strconv.FormatBool(task.SkipStats)
459456
}
460457

pkg/domain/infosync/info.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,12 @@ func GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rul
10631063
}
10641064

10651065
// CalculateTiFlashProgress calculates TiFlash replica progress
1066-
func CalculateTiFlashProgress(tableID int64, replicaCount uint64, TiFlashStores map[int64]pdhttp.StoreInfo) (float64, error) {
1066+
func CalculateTiFlashProgress(tableID int64, replicaCount uint64, tiFlashStores map[int64]pdhttp.StoreInfo) (float64, error) {
10671067
is, err := getGlobalInfoSyncer()
10681068
if err != nil {
10691069
return 0, errors.Trace(err)
10701070
}
1071-
return is.tiflashReplicaManager.CalculateTiFlashProgress(tableID, replicaCount, TiFlashStores)
1071+
return is.tiflashReplicaManager.CalculateTiFlashProgress(tableID, replicaCount, tiFlashStores)
10721072
}
10731073

10741074
// UpdateTiFlashProgressCache updates tiflashProgressCache

pkg/domain/infosync/label_manager.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (lm *PDLabelManager) GetAllLabelRules(ctx context.Context) ([]*label.Rule,
6060
}
6161

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

8080
// PutLabelRule implements PutLabelRule
81-
func (mm *mockLabelManager) PutLabelRule(ctx context.Context, rule *label.Rule) error {
81+
func (mm *mockLabelManager) PutLabelRule(_ context.Context, rule *label.Rule) error {
8282
mm.Lock()
8383
defer mm.Unlock()
8484
if rule == nil {
@@ -93,7 +93,7 @@ func (mm *mockLabelManager) PutLabelRule(ctx context.Context, rule *label.Rule)
9393
}
9494

9595
// UpdateLabelRules implements UpdateLabelRules
96-
func (mm *mockLabelManager) UpdateLabelRules(ctx context.Context, patch *pd.LabelRulePatch) error {
96+
func (mm *mockLabelManager) UpdateLabelRules(_ context.Context, patch *pd.LabelRulePatch) error {
9797
mm.Lock()
9898
defer mm.Unlock()
9999
if patch == nil {
@@ -116,7 +116,7 @@ func (mm *mockLabelManager) UpdateLabelRules(ctx context.Context, patch *pd.Labe
116116
}
117117

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

137137
// mockLabelManager implements GetLabelRules
138-
func (mm *mockLabelManager) GetLabelRules(ctx context.Context, ruleIDs []string) (map[string]*label.Rule, error) {
138+
func (mm *mockLabelManager) GetLabelRules(_ context.Context, ruleIDs []string) (map[string]*label.Rule, error) {
139139
mm.RLock()
140140
defer mm.RUnlock()
141141
r := make(map[string]*label.Rule, len(ruleIDs))

pkg/domain/infosync/resource_manager_client.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewMockResourceManagerClient() pd.ResourceManagerClient {
5858

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

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

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

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

101-
func (m *mockResourceManagerClient) ModifyResourceGroup(ctx context.Context, group *rmpb.ResourceGroup) (string, error) {
101+
func (m *mockResourceManagerClient) ModifyResourceGroup(_ context.Context, group *rmpb.ResourceGroup) (string, error) {
102102
m.Lock()
103103
defer m.Unlock()
104104

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

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

135-
func (m *mockResourceManagerClient) AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error) {
135+
func (*mockResourceManagerClient) AcquireTokenBuckets(context.Context, *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error) {
136136
return nil, nil
137137
}
138138

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

143-
func (m *mockResourceManagerClient) LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, int64, error) {
143+
func (*mockResourceManagerClient) LoadResourceGroups(context.Context) ([]*rmpb.ResourceGroup, int64, error) {
144144
return nil, 0, nil
145145
}
146146

147-
func (m *mockResourceManagerClient) Watch(ctx context.Context, key []byte, opts ...pd.OpOption) (chan []*meta_storagepb.Event, error) {
147+
func (m *mockResourceManagerClient) Watch(_ context.Context, key []byte, _ ...pd.OpOption) (chan []*meta_storagepb.Event, error) {
148148
if bytes.Equal(pd.GroupSettingsPathPrefixBytes, key) {
149149
return m.eventCh, nil
150150
}

pkg/domain/infosync/schedule_manager.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323

2424
// ScheduleManager manages schedule configs
2525
type ScheduleManager interface {
26-
GetScheduleConfig(ctx context.Context) (map[string]interface{}, error)
27-
SetScheduleConfig(ctx context.Context, config map[string]interface{}) error
26+
GetScheduleConfig(ctx context.Context) (map[string]any, error)
27+
SetScheduleConfig(ctx context.Context, config map[string]any) error
2828
}
2929

3030
// PDScheduleManager manages schedule with pd
@@ -38,7 +38,7 @@ type mockScheduleManager struct {
3838
}
3939

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

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

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

5757
if mm.schedules == nil {
58-
mm.schedules = make(map[string]interface{})
58+
mm.schedules = make(map[string]any)
5959
}
6060
for key, value := range config {
6161
mm.schedules[key] = value

0 commit comments

Comments
 (0)