store: thread safe for Register kv.Driver#28267
store: thread safe for Register kv.Driver#28267ti-chi-bot merged 4 commits intopingcap:masterfrom w169q169:issue-27993
Conversation
|
[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. DetailsReviewer can indicate their review by submitting an approval review. |
|
Also you can report an unstable test in #25899 (if you don't have write permission, create an unstable test issue and notify me) and let this PR fixes it. |
moving the tests using |
tisonkun
left a comment
There was a problem hiding this comment.
You convince me that this function is not in a significant path and we can use defensive code trade off a bit performance.
@morgo please give a final check.
... also, I'm curious that Golang doesn't have a concurrent map out-of-the-box?
store/store.go
Outdated
|
|
||
| storesLock.RLock() | ||
|
|
||
| d, ok := stores[name] |
There was a problem hiding this comment.
Move two storesLock.RUnlock() right after this line?
There was a problem hiding this comment.
... or write a function to retrieve the driver, like:
func loadDriver(name string) (kv.Driver, bool) {
storesLock.RUnlock()
defer storesLock.Unlock()
d, ok := stores[name]
return d, ok
}There was a problem hiding this comment.
I'd prefer write a function to get the driver , and scope for lock is more less in this way
|
@morgo this unstable test occurs several times in these days. Could you please do a final check on this fix? |
|
/merge |
|
This pull request has been accepted and is ready to merge. DetailsCommit hash: 311ce77 |
|
@w169q169: 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. DetailsInstructions 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. |
|
Thank you for the contribution! |
What problem does this PR solve?
Issue Number: close #28318
introduced in #27993
Problem Summary:
What is changed and how it works?
What's Changed:
Registerfunction is not thread safe.tidb/store/store.go
Lines 31 to 40 in e60f20b
Run those parallel test functions will suffer fatal error for concurrent map writes on occasionally.
tidb/store/store_test.go
Lines 765 to 770 in e60f20b
tidb/store/store_test.go
Lines 780 to 785 in e60f20b
How it Works:
Add mutex Lock for map variable in package write and read.
Release note