-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
sessionctx/variable: avoid SysVar clone every time when visiting system variable #26308
Conversation
/run-check_dev_2 |
1 similar comment
/run-check_dev_2 |
@tiancaiamao LGTM, but there is another possible fix I wanted to run by you: The only scenario where Set is required is in changing the value of None-scoped variables (this is a very small amount of the total scope). We could instead move the values of read-only sysvars to a map, and use copy-on-write here. |
This is the map:
The current code in this PR is using a lock to protect the map itself, and the
I don't quite get your point. |
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: a90c3c8
|
@tiancaiamao: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Problem Summary:
The current implementation for system variable is not good. To avoid DATA RACE in the unit test, it Clone() a new object every time.
When I handle #25573, I find it cause unnecessary allocation (every query needs to visit the session variable, and it's copy on read)
What is changed and how it works?
What's Changed:
Change
SetSysVar
implementation to removing the object from the map and then register a new object...How it Works:
SysVar
are almost immutable ... Here I say almost, I mean after initialized, they are not changed any more.So we do not really need to Clone to avoid data race.
We can register this SysVar again, the map is protected under lock, and the SysVar is immutable, it do not need a lock or clone.
This change avoid the copy-on-read and is better for performance.
Check List
Tests
Before vs After:
Side effects
Documentation
Release note