Skip to content

Commit

Permalink
statistics: fix data race in IsRegionHot
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 authored and ti-chi-bot committed Jun 27, 2024
1 parent 6fbe737 commit 154b89c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/statistics/hot_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,20 @@ func (w *HotCache) IsRegionHot(region *core.RegionInfo, minHotDegree int) bool {
succ1 := w.CheckWriteAsync(checkRegionHotWriteTask)
succ2 := w.CheckReadAsync(checkRegionHotReadTask)
if succ1 && succ2 {
select {
case <-w.ctx.Done():
return false
case r := <-retWrite:
return r
case r := <-retRead:
return r
}
return waitRet(w.ctx, retWrite) || waitRet(w.ctx, retRead)
}
return false
}

func waitRet(ctx context.Context, ret chan bool) bool {
select {
case <-ctx.Done():
return false
case r := <-ret:
return r
}
}

// GetHotPeerStat returns hot peer stat with specified regionID and storeID.
func (w *HotCache) GetHotPeerStat(kind utils.RWType, regionID, storeID uint64) *HotPeerStat {
ret := make(chan *HotPeerStat, 1)
Expand Down

0 comments on commit 154b89c

Please sign in to comment.