tikv / pd

Placement driver for TiKV
Apache License 2.0
1.03k stars 714 forks source link

statistics: fix data race in `IsRegionHot` (#8336) #8341

Closed ti-chi-bot closed 4 days ago

ti-chi-bot commented 4 days ago

This is an automated cherry-pick of #8336

What problem does this PR solve?

Issue Number: Close #8335

Before #8164 it is

// IsRegionHot checks if the region is hot.
func (w *HotCache) IsRegionHot(region *core.RegionInfo, minHotDegree int) bool {
    checkRegionHotWriteTask := newCheckRegionHotTask(region, minHotDegree)
    checkRegionHotReadTask := newCheckRegionHotTask(region, minHotDegree)
    succ1 := w.CheckWriteAsync(checkRegionHotWriteTask)
    succ2 := w.CheckReadAsync(checkRegionHotReadTask)
    if succ1 && succ2 {
        return checkRegionHotWriteTask.waitRet(w.ctx) || checkRegionHotReadTask.waitRet(w.ctx)
    }
    return false
}

What is changed and how does it work?

Check List

Tests


- Test2:
This test will be successful in this PR and be failed in master branches

--- FAIL: TestIsHot (0.00s) /home/lhy1024/pd/pkg/statistics/hot_cache_test.go:34: Error Trace: /home/lhy1024/pd/pkg/statistics/hot_cache_test.go:34 Error: Should be true Test: TestIsHot FAIL

### Release note

<!--

A bugfix or a new feature needs a release note. If there is no need to give a release note, just leave it with the `None`.

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

-->

```release-note
None.
ti-chi-bot[bot] commented 4 days ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: HuSharp, rleungx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/tikv/pd/blob/release-8.2/OWNERS)~~ [HuSharp,rleungx] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment