hadoop-hdfs-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Mollitor (Jira)" <j...@apache.org>
Subject [jira] [Created] (HDFS-14799) Do Not Call Map containsKey In Conjunction with get
Date Thu, 29 Aug 2019 20:46:00 GMT
David Mollitor created HDFS-14799:
-------------------------------------

             Summary: 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


{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


Mime
View raw message