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

pd-ctl: fix hot region show (#6650) #6680

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
}
27 changes: 22 additions & 5 deletions server/cluster/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,28 @@
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:

Check warning on line 525 in server/cluster/coordinator.go

View check run for this annotation

Codecov / codecov/patch

server/cluster/coordinator.go#L525

Added line #L525 was not covered by tests
}
}
}
}
Expand Down