Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics: fix data race in IsRegionHot #8336

Merged
merged 2 commits into from
Jun 27, 2024
Merged

Conversation

lhy1024
Copy link
Contributor

@lhy1024 lhy1024 commented Jun 27, 2024

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

  • Unit test

  • Test1:
    This test will meet data race in master and is normal in this PR.

for i in {1..50}; do
	go clean -testcache
	go test -timeout 120s -run ^TestSpecialUseHotRegion$ github.com/tikv/pd/pkg/schedule/schedulers -race
done

  • 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

None.

Signed-off-by: lhy1024 <admin@liudos.us>
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed dco-signoff: yes Indicates the PR's author has signed the dco. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed do-not-merge/needs-triage-completed labels Jun 27, 2024
@@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If retRead and retWrite are true and false, we should return true, not either of them.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 27, 2024
Signed-off-by: lhy1024 <admin@liudos.us>
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 27, 2024
@HuSharp
Copy link
Member

HuSharp commented Jun 27, 2024

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.

Copy link
Contributor

ti-chi-bot bot commented Jun 27, 2024

[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:

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 ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 27, 2024
Copy link
Contributor

ti-chi-bot bot commented Jun 27, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-27 07:41:34.356528884 +0000 UTC m=+878220.842017713: ☑️ agreed by rleungx.
  • 2024-06-27 08:16:53.20871402 +0000 UTC m=+880339.694202852: ☑️ agreed by HuSharp.

@ti-chi-bot ti-chi-bot bot merged commit 114cb56 into tikv:master Jun 27, 2024
17 checks passed
@lhy1024 lhy1024 deleted the fix-race4 branch June 27, 2024 08:37
@ti-chi-bot
Copy link
Member

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

ti-chi-bot bot pushed a commit that referenced this pull request Jun 27, 2024
close #8335

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: lhy1024 <admin@liudos.us>
@HuSharp
Copy link
Member

HuSharp commented Jun 28, 2024

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 #8342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm needs-cherry-pick-release-8.2 release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

statistics: meet data race when check IsRegionHot
4 participants