Skip to content

Commit

Permalink
Merge branch 'master' into update_dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Jun 27, 2023
2 parents 29480ec + cd5b1ce commit 432c2b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
27 changes: 22 additions & 5 deletions pkg/schedule/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,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
4 changes: 2 additions & 2 deletions pkg/statistics/hot_peer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func (f *hotPeerCache) checkPeerFlow(peer *core.PeerInfo, region *core.RegionInf
actionType: Update,
stores: make([]uint64, len(peers)),
}
for _, peer := range peers {
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 pkg/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/pkg/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 432c2b3

Please sign in to comment.