You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-issues@hadoop.apache.org by "Ayush Saxena (Jira)" <ji...@apache.org> on 2019/08/30 03:04:00 UTC

[jira] [Commented] (HDFS-14799) Do Not Call Map containsKey In Conjunction with get

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

Ayush Saxena commented on HDFS-14799:
-------------------------------------

Thanx [~belugabehr] for the report, Makes sense, may be we should find all such occurrences and fix in one go.

> 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
>
> {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: hdfs-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org