Skip to content

Commit

Permalink
server: fix the issue that panic when collecting hot-cache metrics (t…
Browse files Browse the repository at this point in the history
…ikv#1091)

* server: fix the issue that panic when collecting hot-cache metrics
  • Loading branch information
nolouch committed May 30, 2018
1 parent 7e98269 commit 67d56d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ func (c *clusterInfo) collectMetrics() {
defer c.RUnlock()
c.regionStats.Collect()
c.labelLevelStats.Collect()
// collect hot cache metrics
c.HotCache.CollectMetrics(c.Stores)
}

func (c *clusterInfo) GetRegionStatsByType(typ regionStatisticType) []*core.RegionInfo {
Expand Down
2 changes: 0 additions & 2 deletions server/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,6 @@ func (c *coordinator) collectHotSpotMetrics() {
}
}

// collect hot cache metrics
c.cluster.HotCache.CollectMetrics(c.cluster.Stores)
}

func (c *coordinator) shouldRun() bool {
Expand Down
24 changes: 24 additions & 0 deletions server/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package server

import (
"fmt"
"math/rand"
"time"

. "github.com/pingcap/check"
Expand Down Expand Up @@ -234,6 +235,29 @@ func dispatchHeartbeat(c *C, co *coordinator, region *core.RegionInfo, stream *m
co.dispatch(region)
}

func (s *testCoordinatorSuite) TestCollectMetrics(c *C) {
_, opt := newTestScheduleConfig()
tc := newTestClusterInfo(opt)
hbStreams := newHeartbeatStreams(tc.getClusterID())
defer hbStreams.Close()

co := newCoordinator(tc.clusterInfo, hbStreams, namespace.DefaultClassifier)
co.run()
// Make sure there are no problem when concurrent write and read
for i := 0; i <= 10; i++ {
go func(i int) {
for j := 0; j < 10000; j++ {
tc.addRegionStore(uint64(i%5), rand.Intn(200))
}
}(i)
}
for i := 0; i < 1000; i++ {
co.collectHotSpotMetrics()
co.collectSchedulerMetrics()
co.cluster.collectMetrics()
}
}

func (s *testCoordinatorSuite) TestCheckRegion(c *C) {
cfg, opt := newTestScheduleConfig()
cfg.EnableRaftLearner = true
Expand Down

0 comments on commit 67d56d7

Please sign in to comment.