Skip to content

Commit

Permalink
cherry pick #21278 to release-3.0
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Dec 10, 2020
1 parent e0348fb commit 839ba17
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.inferGopath": false
}
1 change: 1 addition & 0 deletions store/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ type HotTableIndex struct {
func (h *Helper) FetchRegionTableIndex(metrics map[uint64]RegionMetric, allSchemas []*model.DBInfo) ([]HotTableIndex, error) {
hotTables := make([]HotTableIndex, 0, len(metrics))
for regionID, regionMetric := range metrics {
regionMetric := regionMetric
t := HotTableIndex{RegionID: regionID, RegionMetric: &regionMetric}
region, err := h.RegionCache.LocateRegionByID(tikv.NewBackoffer(context.Background(), 500), regionID)
if err != nil {
Expand Down
24 changes: 20 additions & 4 deletions store/helper/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/gorilla/mux"
. "github.com/pingcap/check"
"github.com/pingcap/log"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/store/helper"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/mocktikv"
Expand Down Expand Up @@ -63,8 +64,13 @@ func (s *mockStore) TLSConfig() *tls.Config {
func (s *HelperTestSuite) SetUpSuite(c *C) {
go s.mockPDHTTPServer(c)
time.Sleep(100 * time.Millisecond)
mvccStore := mocktikv.MustNewMVCCStore()
mockTikvStore, err := mockstore.NewMockTikvStore(mockstore.WithMVCCStore(mvccStore))
mockTikvStore, err := mockstore.NewMockTikvStore(
mockstore.WithCluster(func() *mocktikv.Cluster {
cluster := mocktikv.NewCluster()
mocktikv.BootstrapWithMultiRegions(cluster, []byte("x"))
return cluster
}()),
)
s.store = &mockStore{
mockTikvStore.(tikv.Storage),
[]string{"127.0.0.1:10100/"},
Expand All @@ -79,7 +85,12 @@ func (s *HelperTestSuite) TestHotRegion(c *C) {
}
regionMetric, err := helper.FetchHotRegion(pdapi.HotRead)
c.Assert(err, IsNil, Commentf("err: %+v", err))
c.Assert(fmt.Sprintf("%v", regionMetric), Equals, "map[1:{100 1 0}]")
dbInfo := &model.DBInfo{
Name: model.NewCIStr("test"),
}
c.Assert(fmt.Sprintf("%v", regionMetric), Equals, "map[3:{100 1 0} 4:{200 2 0}]")
res, err := helper.FetchRegionTableIndex(regionMetric, []*model.DBInfo{dbInfo})
c.Assert(res[0].RegionMetric, Not(Equals), res[1].RegionMetric)
}

func (s *HelperTestSuite) TestTiKVRegionsInfo(c *C) {
Expand Down Expand Up @@ -123,9 +134,14 @@ func (s *HelperTestSuite) mockHotRegionResponse(w http.ResponseWriter, req *http
RegionsStat: []helper.RegionStat{
{
FlowBytes: 100,
RegionID: 1,
RegionID: 3,
HotDegree: 1,
},
{
FlowBytes: 200,
RegionID: 4,
HotDegree: 2,
},
},
}
resp := helper.StoreHotRegionInfos{
Expand Down
2 changes: 1 addition & 1 deletion store/tikv/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package tikv
import (
"github.com/google/uuid"
"github.com/pingcap/errors"
"github.com/pingcap/pd/client"
pd "github.com/pingcap/pd/client"
"github.com/pingcap/tidb/kv"
)

Expand Down

0 comments on commit 839ba17

Please sign in to comment.