Skip to content

Commit

Permalink
pd-ctl: fix hot region show (tikv#6650) (tikv#6679)
Browse files Browse the repository at this point in the history
close tikv#6649, ref tikv#6650

Signed-off-by: ti-chi-bot <[email protected]>
Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: lhy1024 <[email protected]>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 4, 2023
1 parent 15324c5 commit 086871d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
27 changes: 22 additions & 5 deletions server/cluster/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,28 @@ func (c *coordinator) getHotRegionsByType(typ statistics.RWType) *statistics.Sto
default:
}
// update params `IsLearner` and `LastUpdateTime`
for _, stores := range []statistics.StoreHotPeersStat{infos.AsLeader, infos.AsPeer} {
for _, store := range stores {
for _, hotPeer := range store.Stats {
region := c.cluster.GetRegion(hotPeer.RegionID)
hotPeer.UpdateHotPeerStatShow(region)
s := []statistics.StoreHotPeersStat{infos.AsLeader, infos.AsPeer}
for i, stores := range s {
for j, store := range stores {
for k := range store.Stats {
h := &s[i][j].Stats[k]
region := c.cluster.GetRegion(h.RegionID)
if region != nil {
h.IsLearner = core.IsLearner(region.GetPeer(h.StoreID))
}
switch typ {
case statistics.Write:
if region != nil {
h.LastUpdateTime = time.Unix(int64(region.GetInterval().GetEndTimestamp()), 0)
}
case statistics.Read:
store := c.cluster.GetStore(h.StoreID)
if store != nil {
ts := store.GetMeta().GetLastHeartbeat()
h.LastUpdateTime = time.Unix(ts/1e9, ts%1e9)
}
default:
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions server/statistics/hot_peer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,17 @@ func (f *hotPeerCache) checkPeerFlow(peer *core.PeerInfo, region *core.RegionInf
}
}

peers := region.GetPeers()
newItem := &HotPeerStat{
StoreID: storeID,
RegionID: regionID,
Loads: f.kind.GetLoadRatesFromPeer(peer),
isLeader: region.GetLeader().GetStoreId() == storeID,
actionType: Update,
stores: make([]uint64, len(region.GetPeers())),
stores: make([]uint64, len(peers)),
}
for _, peer := range region.GetPeers() {
newItem.stores = append(newItem.stores, peer.GetStoreId())
for i, peer := range peers {
newItem.stores[i] = peer.GetStoreId()
}

if oldItem == nil {
Expand Down
17 changes: 2 additions & 15 deletions server/statistics/hot_regions_stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@

package statistics

import (
"time"

"github.com/tikv/pd/server/core"
)
import "time"

// HotPeersStat records all hot regions statistics
type HotPeersStat struct {
Expand All @@ -44,14 +40,5 @@ type HotPeerStatShow struct {
KeyRate float64 `json:"flow_keys"`
QueryRate float64 `json:"flow_query"`
AntiCount int `json:"anti_count"`
LastUpdateTime time.Time `json:"last_update_time"`
}

// UpdateHotPeerStatShow updates the region information, such as `IsLearner` and `LastUpdateTime`.
func (h *HotPeerStatShow) UpdateHotPeerStatShow(region *core.RegionInfo) {
if region == nil {
return
}
h.IsLearner = core.IsLearner(region.GetPeer(h.StoreID))
h.LastUpdateTime = time.Unix(int64(region.GetInterval().GetEndTimestamp()), 0)
LastUpdateTime time.Time `json:"last_update_time,omitempty"`
}

0 comments on commit 086871d

Please sign in to comment.