[
https://issues.apache.org/jira/browse/HDFS-8971?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mingliang Liu updated HDFS-8971:
--------------------------------
Attachment: HDFS-8971.000.patch
The v0 patch removes the guards when calling {{LOG.trace}} and {{LOG.debug}}
for the slf4j logger, and uses placeholders for passing parameters. The code to
change was found by script:
{code}
find hadoop-hdfs-project/hadoop-hdfs-client -name "*.java" |xargs egrep
"LOG.isTraceEnabled|LOG.isDebugEnabled" -n
{code}
Some of the existing usage of the {{is\{Trace,Debug\}Enabled}} was not removed
because it's necessary, largely because of the overhead of calculating the
parameters. Those excluded guards are for {{Arrays.asList()}},
{{StringUtils.getStackTrace(Thread.currentThread()))}} and user-defined
methods. For example,
{code:title=LeaseRenewer.java}
if (LOG.isDebugEnabled()) {
LOG.debug("Lease renewer daemon for " + clientsString() + " with renew id "
+ id + " exited");
}
....
/** Get the names of all clients */
private synchronized String clientsString() {
if (dfsclients.isEmpty()) {
return "[]";
} else {
final StringBuilder b = new StringBuilder("[").append(
dfsclients.get(0).getClientName());
for(int i = 1; i < dfsclients.size(); i++) {
b.append(", ").append(dfsclients.get(i).getClientName());
}
return b.append("]").toString();
}
}
{code}
The {{clientString()}} is considered time-consuming and we should not simply
remove the guard when calling the {{LOG.isDebugEnabled()}}.
> Remove guards when calling LOG.debug() and LOG.trace() in client package
> ------------------------------------------------------------------------
>
> Key: HDFS-8971
> URL: https://issues.apache.org/jira/browse/HDFS-8971
> Project: Hadoop HDFS
> Issue Type: Sub-task
> Components: build
> Reporter: Mingliang Liu
> Assignee: Mingliang Liu
> Attachments: HDFS-8971.000.patch
>
>
> We moved the {{shortcircuit}} package from {{hadoop-hdfs}} to
> {{hadoop-hdfs-client}} module in JIRA
> [HDFS-8934|https://issues.apache.org/jira/browse/HDFS-8934] and
> [HDFS-8951|https://issues.apache.org/jira/browse/HDFS-8951], and
> {{BlockReader}} in
> [HDFS-8925|https://issues.apache.org/jira/browse/HDFS-8925]. Meanwhile, we
> also replaced the _log4j_ log with _slf4j_ logger. There were existing code
> in the client package to guard the log when calling {{LOG.debug()}} and
> {{LOG.trace()}}, e.g. in {{ShortCircuitCache.java}}, we have code like this:
> {code:title=Trace with guards|borderStyle=solid}
> 724 if (LOG.isTraceEnabled()) {
> 725 LOG.trace(this + ": found waitable for " + key);
> 726 }
> {code}
> In _slf4j_, this kind of guard is not necessary. We should clean the code by
> removing the guard from the client package.
> {code:title=Trace without guards|borderStyle=solid}
> 724 LOG.trace("{}: found waitable for {}", this, key);
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)