[ 
https://issues.apache.org/jira/browse/HDFS-16939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17696652#comment-17696652
 ] 

ASF GitHub Bot commented on HDFS-16939:
---------------------------------------

zhangshuyan0 commented on code in PR #5450:
URL: https://github.com/apache/hadoop/pull/5450#discussion_r1125809336


##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/LowRedundancyBlocks.java:
##########
@@ -369,7 +369,7 @@ synchronized boolean remove(BlockInfo block,
    * @return true if the block was found and removed from one of the priority
    *         queues
    */
-  boolean remove(BlockInfo block, int priLevel) {
+  synchronized boolean remove(BlockInfo block, int priLevel) {

Review Comment:
   Thanks for your suggestion, I'll make both `boolean remove(BlockInfo block, 
int priLevel, int oldExpectedReplicas)` and `boolean remove(BlockInfo block, 
int priLevel)` synchronized to ensure correctness.
   
   However, I think you misunderstood the semantics of `synchronized` a method. 
 Refer to [java 
doc](https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html):
   >  When one thread is executing a synchronized method for an object, all 
other threads that invoke synchronized methods for the same object block 
(suspend execution) until the first thread is done with the object.





> Fix the thread safety bug in LowRedundancyBlocks
> ------------------------------------------------
>
>                 Key: HDFS-16939
>                 URL: https://issues.apache.org/jira/browse/HDFS-16939
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: namanode
>            Reporter: Shuyan Zhang
>            Assignee: Shuyan Zhang
>            Priority: Major
>              Labels: pull-request-available
>
> The remove method in LowRedundancyBlocks is not protected by synchronized. 
> This method is private and is called by BlockManager. As a result, 
> priorityQueues has the risk of being accessed concurrently by multiple 
> threads.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to