You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by mj...@apache.org on 2023/10/30 22:34:24 UTC

(kafka) branch 3.4 updated (7a3085ce69c -> bc435f07e31)

This is an automated email from the ASF dual-hosted git repository.

mjsax pushed a change to branch 3.4
in repository https://gitbox.apache.org/repos/asf/kafka.git


    from 7a3085ce69c KAFKA-14767: Fix missing commitId build error after git gc (#13315)
     new 0c637ba16e4 KAFKA-15602: revert KAFKA-4852 (#14617)
     new bc435f07e31 HOTFIX: remove unused import to fix checkstyle error

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../common/serialization/ByteBufferSerializer.java | 34 ++++++++++------------
 .../common/serialization/SerializationTest.java    | 18 ------------
 2 files changed, 15 insertions(+), 37 deletions(-)


(kafka) 02/02: HOTFIX: remove unused import to fix checkstyle error

Posted by mj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mjsax pushed a commit to branch 3.4
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit bc435f07e3175189283e0b637f6a46075af8e43b
Author: Matthias J. Sax <ma...@confluent.io>
AuthorDate: Mon Oct 30 13:22:03 2023 -0700

    HOTFIX: remove unused import to fix checkstyle error
---
 .../java/org/apache/kafka/common/serialization/SerializationTest.java   | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java b/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
index c910812172c..e66151cd1b0 100644
--- a/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
@@ -31,8 +31,6 @@ import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.Stack;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;


(kafka) 01/02: KAFKA-15602: revert KAFKA-4852 (#14617)

Posted by mj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mjsax pushed a commit to branch 3.4
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit 0c637ba16e493212af6c9b8e4d6427a7acb7d93b
Author: Matthias J. Sax <ma...@confluent.io>
AuthorDate: Mon Oct 30 13:14:15 2023 -0700

    KAFKA-15602: revert KAFKA-4852 (#14617)
    
    This PR reverts
     - https://github.com/apache/kafka/commit/51dbd175b08e78aeca03d6752847aa5f23c98659
     - https://github.com/apache/kafka/commit/496ae054c2d43c0905167745bfb2f4a0725e9fc2
    
    Reviewers:  Philip Nee <pn...@confluent.io>, Guozhang Wang <gu...@confluent.io>
---
 .../common/serialization/ByteBufferSerializer.java | 34 ++++++++++------------
 .../common/serialization/SerializationTest.java    | 16 ----------
 2 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/common/serialization/ByteBufferSerializer.java b/clients/src/main/java/org/apache/kafka/common/serialization/ByteBufferSerializer.java
index 06b66a62cb0..43b3d6e38a7 100644
--- a/clients/src/main/java/org/apache/kafka/common/serialization/ByteBufferSerializer.java
+++ b/clients/src/main/java/org/apache/kafka/common/serialization/ByteBufferSerializer.java
@@ -16,38 +16,34 @@
  */
 package org.apache.kafka.common.serialization;
 
-import org.apache.kafka.common.utils.Utils;
-
 import java.nio.ByteBuffer;
 
 /**
- * Do not need to flip before call <i>serialize(String, ByteBuffer)</i>. For example:
- *
- * <blockquote>
- * <pre>
- * ByteBufferSerializer serializer = ...; // Create Serializer
- * ByteBuffer buffer = ...;               // Allocate ByteBuffer
- * buffer.put(data);                      // Put data into buffer, do not need to flip
- * serializer.serialize(topic, buffer);   // Serialize buffer
- * </pre>
- * </blockquote>
+ * {@code ByteBufferSerializer} always {@link ByteBuffer#rewind() rewinds} the position of the input buffer to zero for
+ * serialization. A manual rewind is not necessary.
+ * <p>
+ * Note: any existing buffer position is ignored.
+ * <p>
+ * The position is also rewound back to zero before {@link #serialize(String, ByteBuffer)}
+ * returns.
  */
 public class ByteBufferSerializer implements Serializer<ByteBuffer> {
-
-    @Override
     public byte[] serialize(String topic, ByteBuffer data) {
-        if (data == null) {
+        if (data == null)
             return null;
-        }
+
+        data.rewind();
 
         if (data.hasArray()) {
-            final byte[] arr = data.array();
+            byte[] arr = data.array();
             if (data.arrayOffset() == 0 && arr.length == data.remaining()) {
                 return arr;
             }
         }
 
-        data.flip();
-        return Utils.toArray(data);
+        byte[] ret = new byte[data.remaining()];
+        data.get(ret, 0, ret.length);
+        data.rewind();
+        return ret;
     }
 }
diff --git a/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java b/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
index a0b67a03d42..c910812172c 100644
--- a/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/serialization/SerializationTest.java
@@ -373,20 +373,4 @@ public class SerializationTest {
         return Serdes.serdeFrom(serializer, deserializer);
     }
 
-    @Test
-    public void testByteBufferSerializer() {
-        final byte[] bytes = "Hello".getBytes(UTF_8);
-        final ByteBuffer heapBuffer0 = ByteBuffer.allocate(bytes.length + 1).put(bytes);
-        final ByteBuffer heapBuffer1 = ByteBuffer.allocate(bytes.length).put(bytes);
-        final ByteBuffer heapBuffer2 = ByteBuffer.wrap(bytes);
-        final ByteBuffer directBuffer0 = ByteBuffer.allocateDirect(bytes.length + 1).put(bytes);
-        final ByteBuffer directBuffer1 = ByteBuffer.allocateDirect(bytes.length).put(bytes);
-        try (final ByteBufferSerializer serializer = new ByteBufferSerializer()) {
-            assertArrayEquals(bytes, serializer.serialize(topic, heapBuffer0));
-            assertArrayEquals(bytes, serializer.serialize(topic, heapBuffer1));
-            assertArrayEquals(bytes, serializer.serialize(topic, heapBuffer2));
-            assertArrayEquals(bytes, serializer.serialize(topic, directBuffer0));
-            assertArrayEquals(bytes, serializer.serialize(topic, directBuffer1));
-        }
-    }
 }