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

server: fix data race in RaftCluster #1272

Merged
merged 1 commit into from
Oct 26, 2018

Conversation

rleungx
Copy link
Member

@rleungx rleungx commented Oct 15, 2018

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 reassign cachedCluster, coordinator and running in RaftCluster. At that time, if we read RaftCluster 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 and coordinator in order to prevent reading and writing RaftCluster at the same time.

Check List

Tests

  • Unit test
  • Integration test

Related changes

  • Need to be included in the release notes

@disksing
Copy link
Contributor

Would you explain more details of what's wrong before and how does this PR fix it?

@disksing
Copy link
Contributor

Do we need to backport it to 2.1 and 2.0 branch?

@rleungx
Copy link
Member Author

rleungx commented Oct 15, 2018

@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()
Copy link
Contributor

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?

@disksing
Copy link
Contributor

@nolouch @rleungx Any updates?

@rleungx
Copy link
Member Author

rleungx commented Oct 26, 2018

@disksing After running a benchmark, it doesn't have much impact on performance.

@nolouch nolouch merged commit 58773a9 into tikv:master Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

another data race when running tests
3 participants