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

membuffer: fix data race when IsReadOnly and Set may be concurrently invoked #1479

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

you06
Copy link
Contributor

@you06 you06 commented Oct 17, 2024

ref pingcap/tidb#56178

TiDB concurrently call IsReadOnly and some write operations in union statement, so we need to avoid data race by mutex.

@ti-chi-bot ti-chi-bot bot added 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. labels Oct 17, 2024
Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

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

Is there a test case in tidb to verify the fix?

Copy link

ti-chi-bot bot commented Oct 18, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk

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 the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Oct 18, 2024
Copy link

ti-chi-bot bot commented Oct 18, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-18 08:12:09.98758155 +0000 UTC m=+604327.136491367: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot added the approved label Oct 18, 2024
@ekexium
Copy link
Contributor

ekexium commented Oct 18, 2024

I understand it fixes the data race. I'm just wondering whether it means we are using it correctly. What is the expected behavior when dirty is accessed concurrently?

I haven't checked the case yet but a first rough thought might be like:

Thread-1 gets dirty = false
Thread-2 writes dirty = true
Thread-1 does something that depends on dirty = false? // this can be problematic?

@you06
Copy link
Contributor Author

you06 commented Oct 23, 2024

Is there a test case in tidb to verify the fix?

There is a test case in the issue.

@you06
Copy link
Contributor Author

you06 commented Oct 23, 2024

I understand it fixes the data race. I'm just wondering whether it means we are using it correctly. What is the expected behavior when dirty is accessed concurrently?

I haven't checked the case yet but a first rough thought might be like:

Thread-1 gets dirty = false
Thread-2 writes dirty = true
Thread-1 does something that depends on dirty = false? // this can be problematic?

For this question, we're just avoiding the race between UpdateFlags and IsDirty, if IsDirty() == true, the result from membuffer will be not-exist error and it finally read from the store.

This is a large topic because TiDB used to pretend it's executor is running in serial mode. So there may be some hidden issues with high possibility.

@cfzjywxk cfzjywxk added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 30, 2024
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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants