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

kv: fix lock ordering in Replica.applySnapshot #60504

Merged

Conversation

nvanbenschoten
Copy link
Member

Fixes #60479.

ad78116 was a nice improvement that avoided a number of tricky questions about exposing an inconsistent in-memory replica state during a snapshot. However, it appears to have introduced a deadlock due to lock ordering issues (see referenced issue).

This commit fixes that issue by locking the Store mutex before the Replica mutex in Replica.applySnapshot's combined critical section.

Release note: None

Fixes cockroachdb#60479.

ad78116 was a nice improvement that avoided a number of tricky questions
about exposing an inconsistent in-memory replica state during a
snapshot. However, it appears to have introduced a deadlock due to lock
ordering issues (see referenced issue).

This commit fixes that issue by locking the Store mutex before the
Replica mutex in `Replica.applySnapshot`'s combined critical section.

Release note: None
This operation is expensive as it reads from disk multiple times, so it
is better to do it under a read lock to avoid disrupting in-flight
requests.

Release note: None
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@nvanbenschoten
Copy link
Member Author

Friendly ping on this.

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, 7 of 7 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@tbg
Copy link
Member

tbg commented Feb 16, 2021

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 16, 2021

Build succeeded:

@craig craig bot merged commit 4ec622e into cockroachdb:master Feb 16, 2021
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/fixLockOrdering branch February 17, 2021 21:30
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.

roachtest: restore2TB/nodes=10 failed
3 participants