-
Notifications
You must be signed in to change notification settings - Fork 893
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
Issue 1606: Fixed race condition during expansion of concurrent open hash maps #1607
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sijie
approved these changes
Aug 16, 2018
eolivelli
approved these changes
Aug 16, 2018
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.
Makes sense.
Good catch
+1
run pr validation |
merlimat
added a commit
that referenced
this pull request
Aug 16, 2018
… hash maps ### Motivation As reported in #1606, there is a race condition in the concurrent open hash maps implementation. The race happens when the maps gets re-hashed after the expansion and the new arrays are substituting the old ones. The race itself is that a thread doing a `get()` on the map is first checking the current `capacity` of the map, uses that to get the bucket and then tries to do optimistic read of the value in that bucket. This assumes `capacity` update is visible only after the `values` array is already swapped, but that is not always the case in current code. ### Changes * Use `volatile` qualifier for `capacity` and `values` arrays to ensure ordering of memory read is respected by compiler * In rehashing, update `capacity` after `values` Author: Matteo Merli <mmerli@apache.org> Reviewers: Enrico Olivelli <eolivelli@gmail.com>, Sijie Guo <sijie@apache.org> This closes #1607 from merlimat/fix-concurrent-maps, closes #1606 (cherry picked from commit a7e66e1) Signed-off-by: Matteo Merli <mmerli@apache.org>
merlimat
added a commit
that referenced
this pull request
Aug 16, 2018
… hash maps ### Motivation As reported in #1606, there is a race condition in the concurrent open hash maps implementation. The race happens when the maps gets re-hashed after the expansion and the new arrays are substituting the old ones. The race itself is that a thread doing a `get()` on the map is first checking the current `capacity` of the map, uses that to get the bucket and then tries to do optimistic read of the value in that bucket. This assumes `capacity` update is visible only after the `values` array is already swapped, but that is not always the case in current code. ### Changes * Use `volatile` qualifier for `capacity` and `values` arrays to ensure ordering of memory read is respected by compiler * In rehashing, update `capacity` after `values` Author: Matteo Merli <mmerli@apache.org> Reviewers: Enrico Olivelli <eolivelli@gmail.com>, Sijie Guo <sijie@apache.org> This closes #1607 from merlimat/fix-concurrent-maps, closes #1606 (cherry picked from commit a7e66e1) Signed-off-by: Matteo Merli <mmerli@apache.org>
sijie
pushed a commit
to apache/pulsar
that referenced
this pull request
Aug 17, 2018
…2387) ### Motivation Porting same fix as apache/bookkeeper#1607 to correct issue reported on apache/bookkeeper#1606. There is a race condition in the concurrent open hash maps implementation. The race happens when the maps gets re-hashed after the expansion and the new arrays are substituting the old ones. The race itself is that a thread doing a `get()` on the map is first checking the current capacity of the map, uses that to get the bucket and then tries to do optimistic read of the value in that bucket. This assumes `capacity` update is visible only after the `values` array is already swapped, but that is not always the case in current code. ### Changes * Use `volatile` qualifier for `capacity` and `values` arrays to ensure ordering of memory read is respected by compiler * In rehashing, update `capacity` after `values` where it was not already the case
sijie
pushed a commit
to apache/pulsar
that referenced
this pull request
Aug 27, 2018
…2387) ### Motivation Porting same fix as apache/bookkeeper#1607 to correct issue reported on apache/bookkeeper#1606. There is a race condition in the concurrent open hash maps implementation. The race happens when the maps gets re-hashed after the expansion and the new arrays are substituting the old ones. The race itself is that a thread doing a `get()` on the map is first checking the current capacity of the map, uses that to get the bucket and then tries to do optimistic read of the value in that bucket. This assumes `capacity` update is visible only after the `values` array is already swapped, but that is not always the case in current code. ### Changes * Use `volatile` qualifier for `capacity` and `values` arrays to ensure ordering of memory read is respected by compiler * In rehashing, update `capacity` after `values` where it was not already the case
reddycharan
pushed a commit
to reddycharan/bookkeeper
that referenced
this pull request
Oct 17, 2018
…t open hash maps ### Motivation As reported in apache#1606, there is a race condition in the concurrent open hash maps implementation. The race happens when the maps gets re-hashed after the expansion and the new arrays are substituting the old ones. The race itself is that a thread doing a `get()` on the map is first checking the current `capacity` of the map, uses that to get the bucket and then tries to do optimistic read of the value in that bucket. This assumes `capacity` update is visible only after the `values` array is already swapped, but that is not always the case in current code. ### Changes * Use `volatile` qualifier for `capacity` and `values` arrays to ensure ordering of memory read is respected by compiler * In rehashing, update `capacity` after `values` Author: Matteo Merli <mmerli@apache.org> Reviewers: Enrico Olivelli <eolivelli@gmail.com>, Sijie Guo <sijie@apache.org> This closes apache#1607 from merlimat/fix-concurrent-maps, closes apache#1606 (cherry picked from commit a7e66e1) Signed-off-by: Matteo Merli <mmerli@apache.org> (cherry picked from commit 36edaca) Signed-off-by: JV Jujjuri <vjujjuri@salesforce.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
As reported in #1606, there is a race condition in the concurrent open hash maps implementation. The race happens when the maps gets re-hashed after the expansion and the new arrays are substituting the old ones.
The race itself is that a thread doing a
get()
on the map is first checking the currentcapacity
of the map, uses that to get the bucket and then tries to do optimistic read of the value in that bucket.This assumes
capacity
update is visible only after thevalues
array is already swapped, but that is not always the case in current code.Changes
volatile
qualifier forcapacity
andvalues
arrays to ensure ordering of memory read is respected by compilercapacity
aftervalues