Uploaded image for project: 'Hadoop HDFS'
  1. Hadoop HDFS
  2. HDFS-14799

Do Not Call Map containsKey In Conjunction with get

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2.0
    • Fix Version/s: 3.3.0
    • Component/s: namenode
    • Labels:
    • Hadoop Flags:
      Reviewed

      Description

      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;
        }
      

      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.

        private LightWeightHashSet<Block> getECBlocksSet(final DatanodeInfo dn) {
          return nodeToECBlocks.get(dn);
        }
      

        Attachments

        1. HDFS-14799.001.patch
          1 kB
          Hemanth Boyina

          Activity

            People

            • Assignee:
              hemanthboyina Hemanth Boyina
              Reporter:
              belugabehr David Mollitor
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: