Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Song Gao <disxiaofei@163.com>
  • Loading branch information
Yisaer committed Mar 11, 2021
1 parent 1884756 commit f27397b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
11 changes: 5 additions & 6 deletions server/statistics/hot_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions server/statistics/hot_peer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions server/statistics/hot_peer_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package statistics
import (
"math/rand"
"sync"
"testing"
"time"

. "github.com/pingcap/check"
Expand All @@ -25,10 +24,6 @@ import (
"github.com/tikv/pd/server/core"
)

func Test(t *testing.T) {
TestingT(t)
}

var _ = Suite(&testHotPeerCache{})

type testHotPeerCache struct{}
Expand Down
6 changes: 6 additions & 0 deletions server/statistics/region_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package statistics

import (
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
Expand All @@ -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 {
Expand Down

0 comments on commit f27397b

Please sign in to comment.