From f27397b6a75a0db87e32cc02e2c2974e1b483a81 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Wed, 10 Mar 2021 19:01:24 +0800 Subject: [PATCH] fix lint Signed-off-by: Song Gao --- server/statistics/hot_peer.go | 11 +++++------ server/statistics/hot_peer_cache.go | 14 +++++++------- server/statistics/hot_peer_cache_test.go | 5 ----- server/statistics/region_collection_test.go | 6 ++++++ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/server/statistics/hot_peer.go b/server/statistics/hot_peer.go index 8310bb5fbe6..d353c8920d3 100644 --- a/server/statistics/hot_peer.go +++ b/server/statistics/hot_peer.go @@ -27,19 +27,18 @@ const ( ) type dimStat struct { - typ int + typ int Rolling *movingaverage.TimeMedian // it's used to statistic hot degree and average speed. LastAverage *movingaverage.AvgOverTime // it's used to obtain the average speed in last second as instantaneous speed. } func newDimStat(typ int) *dimStat { reportInterval := RegionHeartBeatReportInterval * time.Second - ds := &dimStat{ - typ: typ, + return &dimStat{ + typ: typ, + Rolling: movingaverage.NewTimeMedian(DefaultAotSize, rollingWindowsSize, reportInterval), + LastAverage: movingaverage.NewAvgOverTime(reportInterval), } - ds.Rolling = movingaverage.NewTimeMedian(DefaultAotSize, rollingWindowsSize, reportInterval) - ds.LastAverage = movingaverage.NewAvgOverTime(reportInterval) - return ds } func (d *dimStat) Add(delta float64, interval time.Duration) { diff --git a/server/statistics/hot_peer_cache.go b/server/statistics/hot_peer_cache.go index 658ee1185ac..5695b617034 100644 --- a/server/statistics/hot_peer_cache.go +++ b/server/statistics/hot_peer_cache.go @@ -56,7 +56,7 @@ var ( // hotPeerCache saves the hot peer's statistics. type hotPeerCache struct { mu struct { - sync.RWMutex + sync.Mutex peersOfStore map[uint64]*TopN // storeID -> hot peers storesOfRegion map[uint64]map[uint64]struct{} // regionID -> storeIDs } @@ -75,8 +75,8 @@ func NewHotStoresStats(kind FlowKind) *hotPeerCache { // RegionStats returns hot items func (f *hotPeerCache) RegionStats(minHotDegree int) map[uint64][]*HotPeerStat { - f.mu.RLock() - defer f.mu.RUnlock() + f.mu.Lock() + defer f.mu.Unlock() res := make(map[uint64][]*HotPeerStat) for storeID, peers := range f.mu.peersOfStore { values := peers.GetAll() @@ -219,8 +219,8 @@ func (f *hotPeerCache) CheckRegionFlow(region *core.RegionInfo) (ret []*HotPeerS } func (f *hotPeerCache) IsRegionHot(region *core.RegionInfo, hotDegree int) bool { - f.mu.RLock() - defer f.mu.RUnlock() + f.mu.Lock() + defer f.mu.Unlock() switch f.kind { case WriteFlow: return f.isRegionHotWithAnyPeersLocked(region, hotDegree) @@ -231,8 +231,8 @@ func (f *hotPeerCache) IsRegionHot(region *core.RegionInfo, hotDegree int) bool } func (f *hotPeerCache) CollectMetrics(typ string) { - f.mu.RLock() - defer f.mu.RUnlock() + f.mu.Lock() + defer f.mu.Unlock() for storeID, peers := range f.mu.peersOfStore { store := storeTag(storeID) thresholds := f.calcHotThresholdsLocked(storeID) diff --git a/server/statistics/hot_peer_cache_test.go b/server/statistics/hot_peer_cache_test.go index 1fc926ae592..f837e2908a3 100644 --- a/server/statistics/hot_peer_cache_test.go +++ b/server/statistics/hot_peer_cache_test.go @@ -16,7 +16,6 @@ package statistics import ( "math/rand" "sync" - "testing" "time" . "github.com/pingcap/check" @@ -25,10 +24,6 @@ import ( "github.com/tikv/pd/server/core" ) -func Test(t *testing.T) { - TestingT(t) -} - var _ = Suite(&testHotPeerCache{}) type testHotPeerCache struct{} diff --git a/server/statistics/region_collection_test.go b/server/statistics/region_collection_test.go index f98ae31423e..42b640f1e8b 100644 --- a/server/statistics/region_collection_test.go +++ b/server/statistics/region_collection_test.go @@ -14,6 +14,8 @@ package statistics import ( + "testing" + . "github.com/pingcap/check" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" @@ -23,6 +25,10 @@ import ( "github.com/tikv/pd/server/schedule/placement" ) +func TestStatistics(t *testing.T) { + TestingT(t) +} + var _ = Suite(&testRegionStatisticsSuite{}) type testRegionStatisticsSuite struct {