Stephen O'Donnell created HDFS-16530:
----------------------------------------

             Summary: setReplication debug log creates a new string even if 
debug is disabled
                 Key: HDFS-16530
                 URL: https://issues.apache.org/jira/browse/HDFS-16530
             Project: Hadoop HDFS
          Issue Type: Improvement
          Components: namenode
            Reporter: Stephen O'Donnell
            Assignee: Stephen O'Donnell


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

{code}
      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());
      }
    }
{code}

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:

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

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



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-dev-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-dev-h...@hadoop.apache.org

Reply via email to