Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store/helper: fill data in the information.tidb_hot_table for partitioned table #14331

Merged
merged 3 commits into from Jan 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 33 additions & 10 deletions store/helper/helper.go
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"math"
"net/http"
Expand Down Expand Up @@ -95,9 +96,9 @@ type HotRegionsStat struct {
// RegionStat records each hot region's statistics
// it's the response of PD.
type RegionStat struct {
RegionID uint64 `json:"region_id"`
FlowBytes uint64 `json:"flow_bytes"`
HotDegree int `json:"hot_degree"`
RegionID uint64 `json:"region_id"`
FlowBytes float64 `json:"flow_bytes"`
HotDegree int `json:"hot_degree"`
}

// RegionMetric presents the final metric output entry.
Expand Down Expand Up @@ -148,7 +149,7 @@ func (h *Helper) FetchHotRegion(rw string) (map[uint64]RegionMetric, error) {
metric := make(map[uint64]RegionMetric)
for _, hotRegions := range regionResp.AsLeader {
for _, region := range hotRegions.RegionsStat {
metric[region.RegionID] = RegionMetric{FlowBytes: region.FlowBytes, MaxHotDegree: region.HotDegree}
metric[region.RegionID] = RegionMetric{FlowBytes: uint64(region.FlowBytes), MaxHotDegree: region.HotDegree}
}
}
return metric, nil
Expand Down Expand Up @@ -226,14 +227,36 @@ func (h *Helper) FetchRegionTableIndex(metrics map[uint64]RegionMetric, allSchem
func (h *Helper) FindTableIndexOfRegion(allSchemas []*model.DBInfo, hotRange *RegionFrameRange) *FrameItem {
for _, db := range allSchemas {
for _, tbl := range db.Tables {
if f := hotRange.GetRecordFrame(tbl.ID, db.Name.O, tbl.Name.O); f != nil {
if f := findRangeInTable(hotRange, db, tbl); f != nil {
return f
}
for _, idx := range tbl.Indices {
if f := hotRange.GetIndexFrame(tbl.ID, idx.ID, db.Name.O, tbl.Name.O, idx.Name.O); f != nil {
return f
}
}
}
}
return nil
}

func findRangeInTable(hotRange *RegionFrameRange, db *model.DBInfo, tbl *model.TableInfo) *FrameItem {
pi := tbl.GetPartitionInfo()
if pi == nil {
return findRangeInPartition(hotRange, tbl.ID, db.Name.O, tbl.Name.O, tbl.Indices)
}

for _, def := range pi.Definitions {
tablePartition := fmt.Sprintf("%s(%s)", tbl.Name.O, def.Name)
if f := findRangeInPartition(hotRange, def.ID, db.Name.O, tablePartition, tbl.Indices); f != nil {
return f
}
}
return nil
}

func findRangeInPartition(hotRange *RegionFrameRange, physicalID int64, dbName, tblName string, indices []*model.IndexInfo) *FrameItem {
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
if f := hotRange.GetRecordFrame(physicalID, dbName, tblName); f != nil {
return f
}
for _, idx := range indices {
if f := hotRange.GetIndexFrame(physicalID, idx.ID, dbName, tblName, idx.Name.O); f != nil {
return f
}
}
return nil
Expand Down