Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch committed Apr 18, 2018
1 parent f2d5a19 commit be57eaf
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions server/schedule/hot_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (w *HotSpotCache) CheckRead(region *core.RegionInfo, stores *core.StoresInf
} else {
ReadBytesPerSec = uint64(float64(region.ReadBytes) / float64(RegionHeartBeatReportInterval))
}
region.ReadBytes = ReadBytesPerSec
hotRegionThreshold := calculateReadHotThreshold(stores)
return w.isNeedUpdateStatCache(region, ReadBytesPerSec, hotRegionThreshold, value, ReadFlow)
}
Expand Down Expand Up @@ -123,7 +122,7 @@ func calculateReadHotThreshold(stores *core.StoresInfo) uint64 {
return hotRegionThreshold
}

func (w *HotSpotCache) isNeedUpdateStatCache(region *core.RegionInfo, flowBytes uint64, hotRegionThreshold uint64, v *core.RegionStat, kind FlowKind) (bool, *core.RegionStat) {
func (w *HotSpotCache) isNeedUpdateStatCache(region *core.RegionInfo, flowBytes uint64, hotRegionThreshold uint64, oldItem *core.RegionStat, kind FlowKind) (bool, *core.RegionStat) {
newItem := &core.RegionStat{
RegionID: region.GetId(),
FlowBytes: flowBytes,
Expand All @@ -133,27 +132,27 @@ func (w *HotSpotCache) isNeedUpdateStatCache(region *core.RegionInfo, flowBytes
AntiCount: hotRegionAntiCount,
}

if v != nil {
newItem.HotDegree = v.HotDegree + 1
if oldItem != nil {
newItem.HotDegree = oldItem.HotDegree + 1
}
if flowBytes >= hotRegionThreshold {
if v == nil {
if oldItem == nil {
w.incMetrics("add_item", kind)
}
return true, newItem
}
// smaller than hotReionThreshold
if v == nil {
if oldItem == nil {
return false, newItem
}
if v.AntiCount <= 0 {
if oldItem.AntiCount <= 0 {
w.incMetrics("remove_item", kind)
return true, nil
}
// eliminate some noise
newItem.HotDegree = v.HotDegree - 1
newItem.AntiCount = v.AntiCount - 1
newItem.FlowBytes = v.FlowBytes
newItem.HotDegree = oldItem.HotDegree - 1
newItem.AntiCount = oldItem.AntiCount - 1
newItem.FlowBytes = oldItem.FlowBytes
return true, newItem
}

Expand Down

0 comments on commit be57eaf

Please sign in to comment.