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

setReplication debug log creates a new string even if debug is disabled

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

Details

    Description

      In FSDirAttrOp, HDFS-14521 made a good change to move a noisy logger to debug:

            if (oldBR > targetReplication) {
              FSDirectory.LOG.debug("Decreasing replication from {} to {} for {}",
                                   oldBR, targetReplication, iip.getPath());
            } else if (oldBR < targetReplication) {
              FSDirectory.LOG.debug("Increasing replication from {} to {} for {}",
                                   oldBR, targetReplication, iip.getPath());
            } else {
              FSDirectory.LOG.debug("Replication remains unchanged at {} for {}",
                                   oldBR, iip.getPath());
            }
          }
      

      However the `iip.getPath()` method must be evaluated to pass the resulting string into the LOG.debug method, even if debug is not enabled:

      This code may form a new string where it does not need to:

        public String getPath() {
          if (pathname == null) {
            pathname = DFSUtil.byteArray2PathString(path);
          }
          return pathname;
        }
      

      We should wrap the entire logging block in `if LOG.debugEnabled()` to avoid any overhead when the logger is not enabled.

      Attachments

        Activity

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

          People

            sodonnell Stephen O'Donnell
            sodonnell Stephen O'Donnell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m

                Slack

                  Issue deployment