From ea43015dc40a6b34907aaad5237a66589c1b0834 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 19 Nov 2019 21:11:16 +0800 Subject: [PATCH] cleanup lint tools Signed-off-by: Ryan Leung --- Makefile | 8 +------- pkg/btree/btree.go | 11 ----------- pkg/mock/mockhbstream/mockhbstream.go | 4 +--- server/core/region.go | 8 ++------ server/schedule/scheduler.go | 2 +- server/schedulers/balance_test.go | 1 - server/schedulers/hot_region.go | 3 +-- server/schedulers/scatter_range.go | 6 ++---- server/schedulers/utils.go | 4 ++-- server/testutil.go | 2 ++ tests/server/api_test.go | 4 ++-- tools.json | 4 ---- tools/pd-analysis/analysis/parse_log.go | 4 ++-- .../simulator/cases/redundant_balance_region.go | 4 ++-- 14 files changed, 18 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index d0f813894d7..d5214ac9e58 100644 --- a/Makefile +++ b/Makefile @@ -109,14 +109,8 @@ static: export GO111MODULE=on static: @ # Not running vet and fmt through metalinter becauase it ends up looking at vendor gofmt -s -l $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(GOCHECKER) - ./scripts/retool do govet --shadow $$($(PACKAGE_DIRECTORIES)) 2>&1 | $(GOCHECKER) - CGO_ENABLED=0 ./scripts/retool do golangci-lint run --disable-all --deadline 120s \ - --enable misspell \ - --enable staticcheck \ - --enable ineffassign \ - --enable unconvert \ - $$($(PACKAGE_DIRECTORIES)) + CGO_ENABLED=0 ./scripts/retool do golangci-lint run --enable misspell --disable errcheck --deadline 120s $$($(PACKAGE_DIRECTORIES)) lint: @echo "linting" diff --git a/pkg/btree/btree.go b/pkg/btree/btree.go index 2ab69bf9be7..4c6b528fa4d 100644 --- a/pkg/btree/btree.go +++ b/pkg/btree/btree.go @@ -53,10 +53,7 @@ package btree import ( - "fmt" - "io" "sort" - "strings" "sync" ) @@ -741,14 +738,6 @@ func (n *node) iterate(dir direction, start, stop Item, includeStart bool, hit b return hit, true } -// Used for testing/debugging purposes. -func (n *node) print(w io.Writer, level int) { - fmt.Fprintf(w, "%sNODE:%v, %v\n", strings.Repeat(" ", level), n.items, n.indices) - for _, c := range n.children { - c.print(w, level+1) - } -} - // BTree is an implementation of a B-Tree. // // BTree stores Item instances in an ordered structure, allowing easy insertion, diff --git a/pkg/mock/mockhbstream/mockhbstream.go b/pkg/mock/mockhbstream/mockhbstream.go index 3fd270ef538..a3f4299aed8 100644 --- a/pkg/mock/mockhbstream/mockhbstream.go +++ b/pkg/mock/mockhbstream/mockhbstream.go @@ -45,9 +45,7 @@ func (s HeartbeatStream) Send(m *pdpb.RegionHeartbeatResponse) error { } // SendMsg is used to send the message. -func (s HeartbeatStream) SendMsg(region *core.RegionInfo, msg *pdpb.RegionHeartbeatResponse) { - return -} +func (s HeartbeatStream) SendMsg(region *core.RegionInfo, msg *pdpb.RegionHeartbeatResponse) {} // Recv mocks method. func (s HeartbeatStream) Recv() *pdpb.RegionHeartbeatResponse { diff --git a/server/core/region.go b/server/core/region.go index 2b726d05b42..b769af7b90e 100644 --- a/server/core/region.go +++ b/server/core/region.go @@ -676,14 +676,10 @@ func (r *RegionsInfo) GetRegions() []*RegionInfo { func (r *RegionsInfo) GetStoreRegions(storeID uint64) []*RegionInfo { regions := make([]*RegionInfo, 0, r.GetStoreLeaderCount(storeID)+r.GetStoreFollowerCount(storeID)) if leaders, ok := r.leaders[storeID]; ok { - for _, region := range leaders.scanRanges() { - regions = append(regions, region) - } + regions = append(regions, leaders.scanRanges()...) } if followers, ok := r.followers[storeID]; ok { - for _, region := range followers.scanRanges() { - regions = append(regions, region) - } + regions = append(regions, followers.scanRanges()...) } return regions } diff --git a/server/schedule/scheduler.go b/server/schedule/scheduler.go index 8e41cce907a..3be255cabe2 100644 --- a/server/schedule/scheduler.go +++ b/server/schedule/scheduler.go @@ -129,7 +129,7 @@ func CreateScheduler(typ string, opController *OperatorController, storage *core func FindSchedulerTypeByName(name string) string { var typ string for registerdType := range schedulerMap { - if strings.Index(name, registerdType) != -1 { + if strings.Contains(name, registerdType) { if len(registerdType) > len(typ) { typ = registerdType } diff --git a/server/schedulers/balance_test.go b/server/schedulers/balance_test.go index 72a66a3ac32..4b8429b267d 100644 --- a/server/schedulers/balance_test.go +++ b/server/schedulers/balance_test.go @@ -423,7 +423,6 @@ type testBalanceLeaderRangeSchedulerSuite struct { ctx context.Context cancel context.CancelFunc tc *mockcluster.Cluster - lb schedule.Scheduler oc *schedule.OperatorController } diff --git a/server/schedulers/hot_region.go b/server/schedulers/hot_region.go index 5d714d63c7b..8432a10b430 100644 --- a/server/schedulers/hot_region.go +++ b/server/schedulers/hot_region.go @@ -62,7 +62,6 @@ const ( // HotWriteRegionType is hot write region scheduler type. HotWriteRegionType = "hot-write-region" minFlowBytes = 128 * 1024 - minScoreLimit = 0.35 ) // BalanceType : the perspective of balance @@ -533,7 +532,7 @@ func (h *balanceHotRegionsScheduler) GetHotWriteStatus() *statistics.StoreHotPee func (h *balanceHotRegionsScheduler) GetStoresScore() map[uint64]float64 { h.RLock() defer h.RUnlock() - storesScore := make(map[uint64]float64, 0) + storesScore := make(map[uint64]float64) for _, info := range h.scoreInfos.ToSlice() { storesScore[info.GetStoreID()] = info.GetScore() } diff --git a/server/schedulers/scatter_range.go b/server/schedulers/scatter_range.go index e130910e85d..22897abbd23 100644 --- a/server/schedulers/scatter_range.go +++ b/server/schedulers/scatter_range.go @@ -220,10 +220,8 @@ func (l *scatterRangeScheduler) Schedule(cluster opt.Cluster) []*operator.Operat } type scatterRangeHandler struct { - scheduleName string - storage *core.Storage - rd *render.Render - config *scatterRangeSchedulerConfig + rd *render.Render + config *scatterRangeSchedulerConfig } func (handler *scatterRangeHandler) UpdateConfig(w http.ResponseWriter, r *http.Request) { diff --git a/server/schedulers/utils.go b/server/schedulers/utils.go index e0e13f6c5ad..980dd4e30e4 100644 --- a/server/schedulers/utils.go +++ b/server/schedulers/utils.go @@ -187,7 +187,7 @@ func NewScoreInfos() *ScoreInfos { // Add adds a scoreInfo into the slice. func (s *ScoreInfos) Add(scoreInfo *ScoreInfo) { infosLen := len(s.scoreInfos) - if s.isSorted == true && infosLen != 0 && s.scoreInfos[infosLen-1].score > scoreInfo.score { + if s.isSorted && infosLen != 0 && s.scoreInfos[infosLen-1].score > scoreInfo.score { s.isSorted = false } s.scoreInfos = append(s.scoreInfos, scoreInfo) @@ -297,7 +297,7 @@ func AggregateScores(storesStats []*ScoreInfos, weights []float64) *ScoreInfos { num = len(weights) } - scoreMap := make(map[uint64]float64, 0) + scoreMap := make(map[uint64]float64) for i := 0; i < num; i++ { scoreInfos := storesStats[i] for _, info := range scoreInfos.ToSlice() { diff --git a/server/testutil.go b/server/testutil.go index 32e37d66bb9..dad059e411e 100644 --- a/server/testutil.go +++ b/server/testutil.go @@ -42,9 +42,11 @@ func NewTestServer(c *check.C) (*Server, CleanupFunc, error) { cfg := NewTestSingleConfig(c) s, err := CreateServer(cfg) if err != nil { + cancel() return nil, nil, err } if err = s.Run(ctx); err != nil { + cancel() return nil, nil, err } diff --git a/tests/server/api_test.go b/tests/server/api_test.go index 8577be62877..213a64baae9 100644 --- a/tests/server/api_test.go +++ b/tests/server/api_test.go @@ -29,8 +29,8 @@ func (s *serverTestSuite) TestReconnect(c *C) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() cluster, err := tests.NewTestCluster(3, func(conf *config.Config) { - conf.TickInterval = typeutil.Duration{50 * time.Millisecond} - conf.ElectionInterval = typeutil.Duration{250 * time.Millisecond} + conf.TickInterval = typeutil.Duration{Duration: 50 * time.Millisecond} + conf.ElectionInterval = typeutil.Duration{Duration: 250 * time.Millisecond} }) c.Assert(err, IsNil) defer cluster.Destroy() diff --git a/tools.json b/tools.json index 25cc8d486d1..65c91253132 100644 --- a/tools.json +++ b/tools.json @@ -4,10 +4,6 @@ "Repository": "github.com/mgechev/revive", "Commit": "7773f47324c2bf1c8f7a5500aff2b6c01d3ed73b" }, - { - "Repository": "github.com/dnephin/govet", - "Commit": "4a96d43e39d340b63daa8bc5576985aa599885f6" - }, { "Repository": "github.com/pingcap/failpoint/failpoint-ctl", "Commit": "30cc7431d99c6a7f2836387d4bb255a3bd6a5e0a" diff --git a/tools/pd-analysis/analysis/parse_log.go b/tools/pd-analysis/analysis/parse_log.go index 0de4eca79f0..414621f6a0a 100644 --- a/tools/pd-analysis/analysis/parse_log.go +++ b/tools/pd-analysis/analysis/parse_log.go @@ -40,7 +40,7 @@ type Interpreter interface { } // CompileRegex is to provide regexp for transfer counter. -func (TransferCounter) CompileRegex(operator string) (*regexp.Regexp, error) { +func (c *TransferCounter) CompileRegex(operator string) (*regexp.Regexp, error) { var r *regexp.Regexp var err error @@ -56,7 +56,7 @@ func (TransferCounter) CompileRegex(operator string) (*regexp.Regexp, error) { return r, err } -func (TransferCounter) parseLine(content string, r *regexp.Regexp) ([]uint64, error) { +func (c *TransferCounter) parseLine(content string, r *regexp.Regexp) ([]uint64, error) { results := make([]uint64, 0, 4) subStrings := r.FindStringSubmatch(content) if len(subStrings) == 0 { diff --git a/tools/pd-simulator/simulator/cases/redundant_balance_region.go b/tools/pd-simulator/simulator/cases/redundant_balance_region.go index ecee1610755..0287ab7ddf4 100644 --- a/tools/pd-simulator/simulator/cases/redundant_balance_region.go +++ b/tools/pd-simulator/simulator/cases/redundant_balance_region.go @@ -66,8 +66,8 @@ func newRedundantBalanceRegion() *Case { }) } - storesLastUpdateTime := make([]int64, storeNum+1, storeNum+1) - storeLastAvailable := make([]uint64, storeNum+1, storeNum+1) + storesLastUpdateTime := make([]int64, storeNum+1) + storeLastAvailable := make([]uint64, storeNum+1) simCase.Checker = func(regions *core.RegionsInfo, stats []info.StoreStats) bool { res := true curTime := time.Now().Unix()