Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <disxiaofei@163.com>
  • Loading branch information
Yisaer committed May 7, 2021
1 parent 6a9f7e5 commit c83fbc5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
6 changes: 3 additions & 3 deletions server/core/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func CountInJointState(peers ...*metapb.Peer) int {
// PeerInfo provides peer information
type PeerInfo struct {
peerID uint64
StoreID uint64
storeID uint64
writtenBytes uint64
writtenKeys uint64
readBytes uint64
Expand Down Expand Up @@ -105,7 +105,7 @@ func (p *PeerInfo) GetKeysRead() uint64 {

// GetStoreID provides located storeID
func (p *PeerInfo) GetStoreID() uint64 {
return p.StoreID
return p.storeID
}

// GetPeerID provides peer id
Expand All @@ -117,7 +117,7 @@ func (p *PeerInfo) GetPeerID() uint64 {
func FromMetaPeer(peer *metapb.Peer) *PeerInfo {
return &PeerInfo{
peerID: peer.GetId(),
StoreID: peer.GetStoreId(),
storeID: peer.GetStoreId(),
}
}

Expand Down
61 changes: 28 additions & 33 deletions server/statistics/hot_peer_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ func (f *hotPeerCache) Update(item *HotPeerStat) {
}
}

func (f *hotPeerCache) collectPeerMetrics(loads []float64, interval uint64) {
// TODO
}

// CheckRegionFlow checks the flow information of region.
func (f *hotPeerCache) CheckRegionFlow(region *core.RegionInfo) (ret []*HotPeerStat) {
reportInterval := region.GetInterval()
Expand Down Expand Up @@ -169,7 +165,6 @@ func (f *hotPeerCache) CheckPeerFlow(peer *core.PeerInfo, region *core.RegionInf
for i := range deltaLoads {
loads[i] = deltaLoads[i] / float64(interval)
}
f.collectPeerMetrics(loads, interval)
justTransferLeader := f.justTransferLeader(region)
// transfer read leader or remove write peer
isExpired := f.isPeerExpired(peer, region)
Expand Down Expand Up @@ -266,6 +261,34 @@ func (f *hotPeerCache) calcHotThresholds(storeID uint64) []float64 {
return ret
}

// gets the storeIDs, including old region and new region
func (f *hotPeerCache) getAllStoreIDs(region *core.RegionInfo) []uint64 {
storeIDs := make(map[uint64]struct{})
ret := make([]uint64, 0, len(region.GetPeers()))
// old stores
ids, ok := f.storesOfRegion[region.GetID()]
if ok {
for storeID := range ids {
storeIDs[storeID] = struct{}{}
ret = append(ret, storeID)
}
}

// new stores
for _, peer := range region.GetPeers() {
// ReadFlow no need consider the followers.
if f.kind == ReadFlow && peer.GetStoreId() != region.GetLeader().GetStoreId() {
continue
}
if _, ok := storeIDs[peer.GetStoreId()]; !ok {
storeIDs[peer.GetStoreId()] = struct{}{}
ret = append(ret, peer.GetStoreId())
}
}

return ret
}

func (f *hotPeerCache) isOldColdPeer(oldItem *HotPeerStat, storeID uint64) bool {
isOldPeer := func() bool {
for _, id := range oldItem.peers {
Expand Down Expand Up @@ -434,34 +457,6 @@ func (f *hotPeerCache) collectRegionMetrics(loads []float64, interval uint64) {
}
}

// gets the storeIDs, including old region and new region
func (f *hotPeerCache) getAllStoreIDs(region *core.RegionInfo) []uint64 {
storeIDs := make(map[uint64]struct{})
ret := make([]uint64, 0, len(region.GetPeers()))
// old stores
ids, ok := f.storesOfRegion[region.GetID()]
if ok {
for storeID := range ids {
storeIDs[storeID] = struct{}{}
ret = append(ret, storeID)
}
}

// new stores
for _, peer := range region.GetPeers() {
// ReadFlow no need consider the followers.
if f.kind == ReadFlow && peer.GetStoreId() != region.GetLeader().GetStoreId() {
continue
}
if _, ok := storeIDs[peer.GetStoreId()]; !ok {
storeIDs[peer.GetStoreId()] = struct{}{}
ret = append(ret, peer.GetStoreId())
}
}

return ret
}

func (f *hotPeerCache) markExpiredItem(regionID, storeID uint64) *HotPeerStat {
item := f.getOldHotPeerStat(regionID, storeID)
item.needDelete = true
Expand Down

0 comments on commit c83fbc5

Please sign in to comment.