HDDS-14855. Add synchronization in ThrottledAsyncChecker#schedule#9942
Closed
ChenSammi wants to merge 1 commit intoapache:masterfrom
Closed
HDDS-14855. Add synchronization in ThrottledAsyncChecker#schedule#9942ChenSammi wants to merge 1 commit intoapache:masterfrom
ChenSammi wants to merge 1 commit intoapache:masterfrom
Conversation
Contributor
Gargi-jais11
left a comment
There was a problem hiding this comment.
Thanks @ChenSammi for the patch. Just one minor comment.
Comment on lines
118
to
+121
| public Optional<ListenableFuture<V>> schedule( | ||
| Checkable<K, V> target, K context) { | ||
| if (checksInProgress.containsKey(target)) { | ||
| return Optional.empty(); | ||
| } | ||
| synchronized (ThrottledAsyncChecker.this) { | ||
| if (checksInProgress.containsKey(target)) { |
Contributor
There was a problem hiding this comment.
Why not simply make the method itself synchronized instead of using a block? This has the same effecct and simple to read.
Contributor
There was a problem hiding this comment.
Agree. The callback uses synchronized (ThrottledAsyncChecker.this) only because it is a different object. Here we can simplify as @Gargi-jais11 suggested.
Contributor
|
Thanks @ChenSammi for the patch. Since @ptlrs in #9948 made exactly the same change as suggested here, I merged that one. Thank you both for the fix. |
This file contains hidden or 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
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.
What changes were proposed in this pull request?
ThrottledAsyncChecker has checksInProgress and completedChecks to track the check task in running, and the lastest check task result, while both have thread unsafe data type.
Synchronization is added when element is removed from checksInProgress and completedChecks, but there is no synchronization when element in added during schedule() call.
So add synchronization in ThrottledAsyncChecker#schedule to avoid schedule multiple times for same target.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-14855
How was this patch tested?