-
Notifications
You must be signed in to change notification settings - Fork 134
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
Fix potential race condition when registering remote storage info #481
Conversation
@smallzhongfeng Could you help me review this pr? |
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.
Is it possible to add a unit for data race case?
appIdToStorages.putIfAbsent(appId, pathToStorages.get(remoteStorage)); | ||
return hdfsStorage; | ||
}); | ||
appIdToStorages.computeIfAbsent(appId, key -> pathToStorages.get(remoteStorage)); |
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 line doesn't have race condition. putIfAbsent
should be just fine?
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.
If using putIfAbsent
, the pathToStorages.get(remoteStorage)
will be invoked everytime. Although it looks unrelated with this PR. Anyway, this is a performance improvement
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.
Similar above problems exist in current codebase, maybe we could create some issues as good first issue
.
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.
Anyway, this is a performance improvement
Good to know. I was forgetting the performance difference. Although, putIfAbsent
is more cleaner in most cases.
Similar above problems exist in current codebase, maybe we could create some issues as good first issue.
Yes, please create some new issues.
Thanks for your review @advancedxy . Merged |
### What changes were proposed in this pull request? 1. Use the concurrentHashMap's computeIfAbsent to keep thread safe ### Why are the changes needed? 1. To fix potential race condition when registering remote storage info ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing UTs
Late LGTM. |
What changes were proposed in this pull request?
Why are the changes needed?
Does this PR introduce any user-facing change?
No
How was this patch tested?
Existing UTs