You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/10/19 18:00:31 UTC

[GitHub] [kafka] jolshan opened a new pull request #9454: KAFKA-10618: Add UUID class, use in protocols

jolshan opened a new pull request #9454:
URL: https://github.com/apache/kafka/pull/9454


   In order to support topic IDs, we need to create a public UUID class. This class will be used in protocols. This PR creates the class, modifies code to use the class in the message protocol and changes the code surrounding the existing messages/json that used the old UUID class.
   
   SimpleExampleMessage was used only for testing, so all usages of UUID have been switched to the new class.
   
   SubscriptionInfoData uses UUID for processId extensively. It also utilizes java.util.UUID implementation of Comparable<UUID> so that UUIDs can be ordered. I felt that this functionality was not necessary for the UUIDs used for topic IDs so I decided to convert to java.util.UUID on the boundary of SubscriptionInfoData. I was only able to find the sorting necessary for testing, though, so this still may be changed.
   
   I also added tests for the methods of the new UUID class. The existing SimpleExampleMessage tests should be sufficient for testing the new UUID class in message protocols.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] rajinisivaram commented on pull request #9454: KAFKA-10618: Add UUID class, use in protocols

Posted by GitBox <gi...@apache.org>.
rajinisivaram commented on pull request #9454:
URL: https://github.com/apache/kafka/pull/9454#issuecomment-713428460


   @jolshan Thanks for the PR, merging to trunk.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] jolshan commented on a change in pull request #9454: KAFKA-10618: Add UUID class, use in protocols

Posted by GitBox <gi...@apache.org>.
jolshan commented on a change in pull request #9454:
URL: https://github.com/apache/kafka/pull/9454#discussion_r508597656



##########
File path: clients/src/test/java/org/apache/kafka/common/UUIDTest.java
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.common;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class UUIDTest {
+
+    @Test
+    public void testSignificantBits() {
+        UUID id = new UUID(34L, 98L);
+
+        assertEquals(id.getMostSignificantBits(), 34L);
+        assertEquals(id.getLeastSignificantBits(), 98L);
+    }
+
+    @Test
+    public void testUUIDEquality() {
+        UUID id1 = new UUID(12L, 13L);
+        UUID id2 = new UUID(12L, 13L);
+        UUID id3 = new UUID(24L, 38L);
+
+        assertEquals(UUID.ZERO_UUID, UUID.ZERO_UUID);
+        assertEquals(id1, id2);
+        assertNotEquals(id1, id3);
+
+        assertEquals(UUID.ZERO_UUID.hashCode(), UUID.ZERO_UUID.hashCode());
+        assertEquals(id1.hashCode(), id2.hashCode());
+        assertNotEquals(id1.hashCode(), id3.hashCode());
+    }
+
+    @Test
+    public void testStringConversion() {
+        UUID id = UUID.randomUUID();

Review comment:
       I thought about that, but since the likelihood we would get the zero/sentinel id is so low even if they were allowed, I didn't know if the test would be useful. The sentinel ID is also a private variable, but I suppose I could just construct a new one if we want to test. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] rajinisivaram merged pull request #9454: KAFKA-10618: Add UUID class, use in protocols

Posted by GitBox <gi...@apache.org>.
rajinisivaram merged pull request #9454:
URL: https://github.com/apache/kafka/pull/9454


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] rajinisivaram commented on a change in pull request #9454: KAFKA-10618: Add UUID class, use in protocols

Posted by GitBox <gi...@apache.org>.
rajinisivaram commented on a change in pull request #9454:
URL: https://github.com/apache/kafka/pull/9454#discussion_r508396130



##########
File path: clients/src/main/java/org/apache/kafka/common/protocol/types/Type.java
##########
@@ -331,14 +331,14 @@ public String documentation() {
     public static final DocumentedType UUID = new DocumentedType() {
         @Override
         public void write(ByteBuffer buffer, Object o) {
-            final java.util.UUID uuid = (java.util.UUID) o;
+            final org.apache.kafka.common.UUID uuid = (org.apache.kafka.common.UUID) o;

Review comment:
       We have already imported UUID, do we need to qualify here? I can see it was this way before, but not sure why.

##########
File path: clients/src/main/java/org/apache/kafka/common/protocol/types/Type.java
##########
@@ -331,14 +331,14 @@ public String documentation() {
     public static final DocumentedType UUID = new DocumentedType() {
         @Override
         public void write(ByteBuffer buffer, Object o) {
-            final java.util.UUID uuid = (java.util.UUID) o;
+            final org.apache.kafka.common.UUID uuid = (org.apache.kafka.common.UUID) o;
             buffer.putLong(uuid.getMostSignificantBits());
             buffer.putLong(uuid.getLeastSignificantBits());
         }
 
         @Override
         public Object read(ByteBuffer buffer) {
-            return new java.util.UUID(buffer.getLong(), buffer.getLong());
+            return new org.apache.kafka.common.UUID(buffer.getLong(), buffer.getLong());

Review comment:
       Same as before, why don't we just use `UUID` since package was imported?

##########
File path: clients/src/test/java/org/apache/kafka/common/UUIDTest.java
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.common;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class UUIDTest {
+
+    @Test
+    public void testSignificantBits() {
+        UUID id = new UUID(34L, 98L);
+
+        assertEquals(id.getMostSignificantBits(), 34L);
+        assertEquals(id.getLeastSignificantBits(), 98L);
+    }
+
+    @Test
+    public void testUUIDEquality() {
+        UUID id1 = new UUID(12L, 13L);
+        UUID id2 = new UUID(12L, 13L);
+        UUID id3 = new UUID(24L, 38L);
+
+        assertEquals(UUID.ZERO_UUID, UUID.ZERO_UUID);
+        assertEquals(id1, id2);
+        assertNotEquals(id1, id3);
+
+        assertEquals(UUID.ZERO_UUID.hashCode(), UUID.ZERO_UUID.hashCode());
+        assertEquals(id1.hashCode(), id2.hashCode());
+        assertNotEquals(id1.hashCode(), id3.hashCode());
+    }
+
+    @Test
+    public void testStringConversion() {
+        UUID id = UUID.randomUUID();

Review comment:
       Should we have a separate unit test for `UUID.randomUUID` to verify it is not zero or the sentinel?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] jolshan commented on pull request #9454: KAFKA-10618: Add UUID class, use in protocols

Posted by GitBox <gi...@apache.org>.
jolshan commented on pull request #9454:
URL: https://github.com/apache/kafka/pull/9454#issuecomment-713108774


   Two tests failed, but they seem to be flaky based on other open PRs.
   StoreQueryIntegrationTest.shouldQueryOnlyActivePartitionStoresByDefault
   EosBetaUpgradeIntegrationTest.shouldUpgradeFromEosAlphaToEosBeta[true]


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] jolshan commented on a change in pull request #9454: KAFKA-10618: Add UUID class, use in protocols

Posted by GitBox <gi...@apache.org>.
jolshan commented on a change in pull request #9454:
URL: https://github.com/apache/kafka/pull/9454#discussion_r508631712



##########
File path: clients/src/main/java/org/apache/kafka/common/protocol/types/Type.java
##########
@@ -331,14 +331,14 @@ public String documentation() {
     public static final DocumentedType UUID = new DocumentedType() {
         @Override
         public void write(ByteBuffer buffer, Object o) {
-            final java.util.UUID uuid = (java.util.UUID) o;
+            final org.apache.kafka.common.UUID uuid = (org.apache.kafka.common.UUID) o;

Review comment:
       My best guess is that since the type is also called UUID, originally the qualification was to differentiate. But it doesn't seem to be needed, so I'll update this to just say UUID.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org