-
Notifications
You must be signed in to change notification settings - Fork 719
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
server: fix data race in RaftCluster #1272
Conversation
Would you explain more details of what's wrong before and how does this PR fix it? |
Do we need to backport it to 2.1 and 2.0 branch? |
@disksing I‘m not sure how much impact it will cause, since it happens rarely. |
@@ -27,6 +27,8 @@ import ( | |||
|
|||
// HandleRegionHeartbeat processes RegionInfo reports from client. | |||
func (c *RaftCluster) HandleRegionHeartbeat(region *core.RegionInfo) error { | |||
c.RLock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this lock is in the hot path, can we bench it or remove it?
2d2e946
to
69e8056
Compare
69e8056
to
960ec67
Compare
@disksing After running a benchmark, it doesn't have much impact on performance. |
What problem does this PR solve?
When the leader drops which could be caused by some reasons (e.g. cannot read from disk), it will elect a new leader which will call
createRaftCluster
to reassigncachedCluster
,coordinator
andrunning
inRaftCluster
. At that time, if we readRaftCluster
without lock, the data race may happens. This PR closes #1270.What is changed and how it works?
This PR adds some locks when reading from
cachedCluster
andcoordinator
in order to prevent reading and writingRaftCluster
at the same time.Check List
Tests
Related changes