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

Íñigo Goiri commented on HDFS-14862:
------------------------------------

A couple comments:
* How much more effective is a synchronizedList for clear and contains than 
synchronizing the whole method? At the end we end up synchronizing a lot for 
the addLocation. I agree that better to make it per data structure than for the 
whole class.
* What are the uses for getLocations()? Do they expect to change the actual 
list?
* Not sure what was the plan having an ArrayList for the movedBlocks. What is 
the potential for this to have more than 2 maps?

> Review of MovedBlocks
> ---------------------
>
>                 Key: HDFS-14862
>                 URL: https://issues.apache.org/jira/browse/HDFS-14862
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: balancer & mover
>    Affects Versions: 3.2.0
>            Reporter: David Mollitor
>            Assignee: David Mollitor
>            Priority: Minor
>         Attachments: HDFS-14862.1.patch
>
>
> Internal data structure needs to be protected (synchronized) but is scoped as 
> {{protected}} so any sub-class could modify without a lock.  Synchronize the 
> collection itself for protection.  It also returns the internal data 
> structure in {{getLocations}} so the structure could be modified outside of 
> the lock.  Create a copy instead.
> {code:java}
>     /** The locations of the replicas of the block. */
>     protected final List<L> locations = new ArrayList<L>(3);
>     
>     public Locations(Block block) {
>       this.block = block;
>     }
>     
>     /** clean block locations */
>     public synchronized void clearLocations() {
>       locations.clear();
>     }
> ...
>    /** @return its locations */
>     public synchronized List<L> getLocations() {
>       return locations;
>     }
> {code}
>  
> [https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/MovedBlocks.java#L43]
> Also, remove a bunch of superfluous and complicated code.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to