HDFS-9398. Make ByteArraryManager log message in one-line format.  Contributed 
by Mingliang Liu


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/9614dea7
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/9614dea7
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/9614dea7

Branch: refs/heads/HDFS-8707
Commit: 9614dea71a9700741388956044c5e6fde1754e28
Parents: 2801b42
Author: Tsz-Wo Nicholas Sze <szets...@hortonworks.com>
Authored: Sat Nov 7 22:21:28 2015 +0800
Committer: Tsz-Wo Nicholas Sze <szets...@hortonworks.com>
Committed: Sat Nov 7 22:21:28 2015 +0800

----------------------------------------------------------------------
 .../hadoop/hdfs/util/ByteArrayManager.java      | 63 ++++++++++++++++----
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt     |  3 +
 2 files changed, 54 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/9614dea7/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ByteArrayManager.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ByteArrayManager.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ByteArrayManager.java
index e361252..a9adb7e 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ByteArrayManager.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ByteArrayManager.java
@@ -36,6 +36,18 @@ import org.slf4j.LoggerFactory;
 @InterfaceAudience.Private
 public abstract class ByteArrayManager {
   static final Logger LOG = LoggerFactory.getLogger(ByteArrayManager.class);
+  private static final ThreadLocal<StringBuilder> DEBUG_MESSAGE =
+      new ThreadLocal<StringBuilder>() {
+    protected StringBuilder initialValue() {
+      return new StringBuilder();
+    }
+  };
+
+  private static void logDebugMessage() {
+    final StringBuilder b = DEBUG_MESSAGE.get();
+    LOG.debug(b.toString());
+    b.setLength(0);
+  }
 
   static final int MIN_ARRAY_LENGTH = 32;
   static final byte[] EMPTY_BYTE_ARRAY = {};
@@ -148,18 +160,27 @@ public abstract class ByteArrayManager {
      * via the {@link FixedLengthManager#recycle(byte[])} method.
      */
     synchronized byte[] allocate() throws InterruptedException {
-      LOG.debug(", {}", this);
+      if (LOG.isDebugEnabled()) {
+        DEBUG_MESSAGE.get().append(", ").append(this);
+      }
       for(; numAllocated >= maxAllocated;) {
-        LOG.debug(": wait ...");
+        if (LOG.isDebugEnabled()) {
+          DEBUG_MESSAGE.get().append(": wait ...");
+          logDebugMessage();
+        }
 
         wait();
 
-        LOG.debug("wake up: {}", this);
+        if (LOG.isDebugEnabled()) {
+          DEBUG_MESSAGE.get().append("wake up: ").append(this);
+        }
       }
       numAllocated++;
 
       final byte[] array = freeQueue.poll();
-      LOG.debug(", recycled? {}", array != null);
+      if (LOG.isDebugEnabled()) {
+        DEBUG_MESSAGE.get().append(", recycled? ").append(array != null);
+      }
       return array != null? array : new byte[byteArrayLength];
     }
 
@@ -173,7 +194,9 @@ public abstract class ByteArrayManager {
     synchronized int recycle(byte[] array) {
       Preconditions.checkNotNull(array);
       Preconditions.checkArgument(array.length == byteArrayLength);
-      LOG.debug(", {}", this);
+      if (LOG.isDebugEnabled()) {
+        DEBUG_MESSAGE.get().append(", ").append(this);
+      }
 
       notify();
       numAllocated--;
@@ -184,7 +207,9 @@ public abstract class ByteArrayManager {
       }
 
       if (freeQueue.size() < maxAllocated - numAllocated) {
-        LOG.debug(", freeQueue.offer");
+        if (LOG.isDebugEnabled()) {
+          DEBUG_MESSAGE.get().append(", freeQueue.offer");
+        }
         freeQueue.offer(array);
       }
       return freeQueue.size();
@@ -324,7 +349,9 @@ public abstract class ByteArrayManager {
     public byte[] newByteArray(final int arrayLength)
         throws InterruptedException {
       Preconditions.checkArgument(arrayLength >= 0);
-      LOG.debug("allocate({})", arrayLength);
+      if (LOG.isDebugEnabled()) {
+        
DEBUG_MESSAGE.get().append("allocate(").append(arrayLength).append(")");
+      }
 
       final byte[] array;
       if (arrayLength == 0) {
@@ -338,12 +365,18 @@ public abstract class ByteArrayManager {
         final FixedLengthManager manager =
             managers.get(powerOfTwo, aboveThreshold);
 
-        LOG.debug(": count={}, {}Threshold", count,
-            aboveThreshold ? "above" : "below");
+        if (LOG.isDebugEnabled()) {
+          DEBUG_MESSAGE.get().append(": count=").append(count)
+              .append(aboveThreshold? ", aboveThreshold": ", belowThreshold");
+        }
         array = manager != null? manager.allocate(): new byte[powerOfTwo];
       }
 
-      LOG.debug(", return byte[{}]", array.length);
+      if (LOG.isDebugEnabled()) {
+        DEBUG_MESSAGE.get().append(", return byte[")
+            .append(array.length).append("]");
+        logDebugMessage();
+      }
       return array;
     }
 
@@ -358,7 +391,10 @@ public abstract class ByteArrayManager {
     @Override
     public int release(final byte[] array) {
       Preconditions.checkNotNull(array);
-      LOG.debug("recycle: array.length={}", array.length);
+      if (LOG.isDebugEnabled()) {
+        DEBUG_MESSAGE.get()
+            .append("recycle: array.length=").append(array.length);
+      }
 
       final int freeQueueSize;
       if (array.length == 0) {
@@ -368,7 +404,10 @@ public abstract class ByteArrayManager {
         freeQueueSize = manager == null? -1: manager.recycle(array);
       }
 
-      LOG.debug(", freeQueueSize={}", freeQueueSize);
+      if (LOG.isDebugEnabled()) {
+        DEBUG_MESSAGE.get().append(", freeQueueSize=").append(freeQueueSize);
+        logDebugMessage();
+      }
       return freeQueueSize;
     }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/9614dea7/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt 
b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index dbffc3f..1b97b53 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -1635,6 +1635,9 @@ Release 2.8.0 - UNRELEASED
     HDFS-9379. Make NNThroughputBenchmark$BlockReportStats support more than 10
     datanodes. (Mingliang Liu via Arpit Agarwal)
 
+    HDFS-9398. Make ByteArraryManager log message in one-line format.
+    (Mingliang Liu via szetszwo)
+
   OPTIMIZATIONS
 
     HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

Reply via email to