kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject kafka git commit: KAFKA-2281: avoid unnecessary value copying if logAsString is false; reviewed by Guozhang Wang
Date Tue, 30 Jun 2015 01:48:33 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 6d4991e31 -> 9ff5b27bc


KAFKA-2281: avoid unnecessary value copying if logAsString is false; reviewed by Guozhang
Wang


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/9ff5b27b
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/9ff5b27b
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/9ff5b27b

Branch: refs/heads/trunk
Commit: 9ff5b27bc572850863f58a3767da3c72aa2a9831
Parents: 6d4991e
Author: Tao Xiao <xiaotao183@gmail.com>
Authored: Mon Jun 29 18:47:47 2015 -0700
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Mon Jun 29 18:48:05 2015 -0700

----------------------------------------------------------------------
 .../producer/internals/ErrorLoggingCallback.java      | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/9ff5b27b/clients/src/main/java/org/apache/kafka/clients/producer/internals/ErrorLoggingCallback.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/clients/producer/internals/ErrorLoggingCallback.java
b/clients/src/main/java/org/apache/kafka/clients/producer/internals/ErrorLoggingCallback.java
index 678d1c6..747e29f 100644
--- a/clients/src/main/java/org/apache/kafka/clients/producer/internals/ErrorLoggingCallback.java
+++ b/clients/src/main/java/org/apache/kafka/clients/producer/internals/ErrorLoggingCallback.java
@@ -23,12 +23,18 @@ public class ErrorLoggingCallback implements Callback {
     private String topic;
     private byte[] key;
     private byte[] value;
+    private int valueLength;
     private boolean logAsString;
 
     public ErrorLoggingCallback(String topic, byte[] key, byte[] value, boolean logAsString)
{
         this.topic = topic;
         this.key = key;
-        this.value = value;
+
+        if (logAsString) {
+            this.value = value;
+        }
+
+        this.valueLength = value == null ? -1 : value.length;
         this.logAsString = logAsString;
     }
 
@@ -36,10 +42,10 @@ public class ErrorLoggingCallback implements Callback {
         if (e != null) {
             String keyString = (key == null) ? "null" :
                     logAsString ? new String(key) : key.length + " bytes";
-            String valueString = (value == null) ? "null" :
-                    logAsString ? new String(value) : value.length + " bytes";
+            String valueString = (valueLength == -1) ? "null" :
+                    logAsString ? new String(value) : valueLength + " bytes";
             log.error("Error when sending message to topic {} with key: {}, value: {} with
error: {}",
-                      topic, keyString, valueString, e.getMessage());
+                    topic, keyString, valueString, e.getMessage());
         }
     }
 }


Mime
View raw message