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


##########
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:
   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:
   ```
   private Object syncOnBlockInfoSet(int priority, BlockInfo blockInfo, String 
operation) {
       LightWeightLinkedSet<BlockInfo> blockInfos 
=priorityQueues.get(priority); 
       synchronized (blockInfos) {
         if("size".equalsIgnoreCase(operation)) {
           return blockInfos.size();
         }
         if("remove".equalsIgnoreCase(operation)) {
           return blockInfos.remove(blockInfo);
         }
         //implement other required methods.
         else {
           return null;
         }
       }
     }
   ```
   
   all code-pieces where we do operation on an element in `priorityQueues`, we 
call `syncOnBlockInfoSet` to do that operation. for ex: 
`size=syncOnBlockInfoSet(priority, null, "size")`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to