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

Hudson commented on HDFS-14799:
-------------------------------

FAILURE: Integrated in Jenkins build Hadoop-trunk-Commit #17299 (See 
[https://builds.apache.org/job/Hadoop-trunk-Commit/17299/])
HDFS-14799. Do Not Call Map containsKey In Conjunction with get. (ayushsaxena: 
rev e04b8a46c3088d13bf010f2959062e1440332bcc)
* (edit) 
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/InvalidateBlocks.java


> Do Not Call Map containsKey In Conjunction with get
> ---------------------------------------------------
>
>                 Key: HDFS-14799
>                 URL: https://issues.apache.org/jira/browse/HDFS-14799
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: namenode
>    Affects Versions: 3.2.0
>            Reporter: David Mollitor
>            Assignee: hemanthboyina
>            Priority: Minor
>              Labels: newbie, noob
>             Fix For: 3.3.0
>
>         Attachments: HDFS-14799.001.patch
>
>
> {code:java|title=InvalidateBlocks.java}
>   private final Map<DatanodeInfo, LightWeightHashSet<Block>>
>       nodeToBlocks = new HashMap<>();
>   private final Map<DatanodeInfo, LightWeightHashSet<Block>>
>       nodeToECBlocks = new HashMap<>();
> ...
>   private LightWeightHashSet<Block> getBlocksSet(final DatanodeInfo dn) {
>     if (nodeToBlocks.containsKey(dn)) {
>       return nodeToBlocks.get(dn);
>     }
>     return null;
>   }
>   private LightWeightHashSet<Block> getECBlocksSet(final DatanodeInfo dn) {
>     if (nodeToECBlocks.containsKey(dn)) {
>       return nodeToECBlocks.get(dn);
>     }
>     return null;
>   }
> {code}
> There is no need to check for {{containsKey}} here since a call to {{get}} 
> will already return 'null' if the key is not there.  This just adds overhead 
> of having to dive into the Map twice to get the value.
> {code}
>   private LightWeightHashSet<Block> getECBlocksSet(final DatanodeInfo dn) {
>     return nodeToECBlocks.get(dn);
>   }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

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

Reply via email to