Skip to content

Commit

Permalink
This is an automated cherry-pick of tikv#6650
Browse files Browse the repository at this point in the history
close tikv#6649

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
lhy1024 authored and ti-chi-bot committed Jun 26, 2023
1 parent 898dde2 commit a1ab4e6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 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
5 changes: 5 additions & 0 deletions server/statistics/hot_peer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ func (f *hotPeerCache) checkPeerFlow(peer *core.PeerInfo, region *core.RegionInf
actionType: Update,
stores: make([]uint64, len(region.GetPeers())),
}
<<<<<<< HEAD:server/statistics/hot_peer_cache.go
for _, peer := range region.GetPeers() {
newItem.stores = append(newItem.stores, peer.GetStoreId())
=======
for i, peer := range peers {
newItem.stores[i] = peer.GetStoreId()
>>>>>>> cd5b1cebe (pd-ctl: fix hot region show (#6650)):pkg/statistics/hot_peer_cache.go
}

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

package statistics

<<<<<<< HEAD:server/statistics/hot_regions_stat.go
import (
"time"

"github.com/tikv/pd/server/core"
)
=======
import "time"
>>>>>>> cd5b1cebe (pd-ctl: fix hot region show (#6650)):pkg/statistics/hot_regions_stat.go

// HotPeersStat records all hot regions statistics
type HotPeersStat struct {
Expand All @@ -44,14 +48,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 a1ab4e6

Please sign in to comment.