-
Notifications
You must be signed in to change notification settings - Fork 9k
HDFS-16939. Fix the thread safety bug in LowRedundancyBlocks. #5450
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 8000 account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
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.
should
boolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas)
be made synchronized instead. Its other callers are synchronized methods:hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/LowRedundancyBlocks.java
Line 345 in 01027e5
hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/LowRedundancyBlocks.java
Line 468 in 01027e5
Uh oh!
There was an error while loading. Please reload this page.
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 will just ensure only one thread getting into the remove method. But what if there is one thread trying to remove, other trying to add or size(). I feel following should help:
all code-pieces where we do operation on an element in
priorityQueues
, we callsyncOnBlockInfoSet
to do that operation. for ex:size=syncOnBlockInfoSet(priority, null, "size")
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.
Sorry I don't quite understand. Since the callers are already synchronized, why is it necessary to made
boolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas)
synchronized?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.
add() and size() are already synchronized in the current code.
hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/LowRedundancyBlocks.java
Line 290 in 01027e5
hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/LowRedundancyBlocks.java
Line 125 in 01027e5
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.
Since
boolean remove(BlockInfo block, int priLevel)
10000 forwards the call toboolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas)
, I am suggesting that lets makeboolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas)
synchronized instead.Callers of
boolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas)
are synchronized means that we can haveboolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas)
as synchronized without any perf-loss.Uh oh!
There was an error while loading. Please reload this page.
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.
these method being synchronized means that only one thread can enter into the synchronized method, but doesn't make the object its working on synchronized. There could be one thread calling size which leads to
priorityQueues.get(i).size()
, and other calling add which leads topriorityQueues.get(priLevel).add(blockInfo)
simultaneously.Example of probable issue is:
for adding element
hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightLinkedSet.java
Lines 87 to 125 in ccdb978
hadoop/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightLinkedSet.java
Line 101 in ccdb978
Please feel free to disagree.
Thanks.
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.
Thanks for your suggestion, I'll make both
boolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas)
andboolean remove(BlockInfo block, int priLevel)
synchronized to ensure correctness.However, I think you misunderstood the semantics of
synchronized
a method. Refer to java doc: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.
@saxenapranav Thanks for your pretty review comment. I am not sure if get your points totally. IMO, this improvement is safe and self-contained, because
synchronized
is reentrant and exclusive. So I am confused if it could involve other consistency issues.I would like to give my +1 if you were worried about perf-loss only for
synchronized-synchronized
, for this case I think it could be acceptable, anyway totally agree that both changes about performance we should given the benchmark comparison.Thanks @zhangshuyan0 and @saxenapranav , Please feel free to correct me if something wrong.
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.
Agreeing with both @Hexiaoqiao @zhangshuyan0.
Thanks @zhangshuyan0 for taking suggestion.