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 2022/03/15 16:38:47 UTC

[GitHub] [kafka] mumrah commented on a change in pull request #11901: Don't generate Uuid with a leading "-"

mumrah commented on a change in pull request #11901:
URL: https://github.com/apache/kafka/pull/11901#discussion_r827189541



##########
File path: clients/src/main/java/org/apache/kafka/common/Uuid.java
##########
@@ -51,15 +49,22 @@ public Uuid(long mostSigBits, long leastSigBits) {
         this.leastSignificantBits = leastSigBits;
     }
 
+    private static Uuid unsafeRandomUuid() {
+        java.util.UUID jUuid = java.util.UUID.randomUUID();
+        return new Uuid(jUuid.getMostSignificantBits(), jUuid.getLeastSignificantBits());
+    }
+
     /**
      * Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
+     *
+     * This will not generate a UUID equal to 0, 1, or one whose string representation starts with a dash ("-")
      */
     public static Uuid randomUuid() {
-        java.util.UUID uuid = java.util.UUID.randomUUID();
-        while (uuid.equals(METADATA_TOPIC_ID_INTERNAL) || uuid.equals(ZERO_ID_INTERNAL)) {
-            uuid = java.util.UUID.randomUUID();
+        Uuid uuid = unsafeRandomUuid();
+        while (uuid.equals(METADATA_TOPIC_ID) || uuid.equals(ZERO_UUID) || uuid.toString().startsWith("-")) {
+            uuid = unsafeRandomUuid();

Review comment:
       You're right we will need to support leading "-" indefinitely since ZK clusters or existing KRaft clusters may have this type of clusterId. I left `Uuid#fromString` unchanged so we don't break compatibility with any extant cluster IDs.
   
   Agree that we should change our examples in the docs and perhaps add a note that older cluster IDs may have this problem and require the `=`




-- 
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.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

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