tikv / pd

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

statistics: fix data race in `IsRegionHot` #8336

Closed lhy1024 closed 4 days ago

lhy1024 commented 4 days ago

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.
HuSharp commented 4 days ago

img_v3_02c8_640a6768-c954-4a46-92a5-6de029e70fcg CI can find the data race problem, but it's strange why it hasn't been found in two weeks.

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/master/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
ti-chi-bot[bot] commented 4 days ago

[LGTM Timeline notifier]

Timeline:

ti-chi-bot commented 4 days ago

In response to a cherrypick label: new pull request created to branch release-8.2: #8341.

HuSharp commented 3 days ago

img_v3_02c8_640a6768-c954-4a46-92a5-6de029e70fcg CI can find the data race problem, but it's strange why it hasn't been found in two weeks.

fixed in https://github.com/tikv/pd/pull/8342