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

Do Not Call Map containsKey In Conjunction with get

VotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.2.0
    • 3.3.0
    • namenode
    • 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

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment