Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clients/src/main/java/org/apache/kafka/common/Uuid.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ private static Uuid unsafeRandomUuid() {

/**
* 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 ("-")
* <p>
* This will not generate a UUID equal to 0, 1, or one whose string representation contains a dash ("-").
*/
public static Uuid randomUuid() {
Uuid uuid = unsafeRandomUuid();
while (RESERVED.contains(uuid) || uuid.toString().startsWith("-")) {
while (RESERVED.contains(uuid) || uuid.toString().contains("-")) {
Copy link
Copy Markdown
Contributor

@squah-confluent squah-confluent Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the probability of rejecting a generated uuid rises from 1.56% (= 1/64) to 30.5% (= 1 - (63/64)**19 * 15/16, taking into account fixed bits in version 4 uuids). The new p99 number of rejections is ~3.88 (was 1.11) which I think is not too bad.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing the math :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30% failure rate for a general utility class is really high and I don't think it makes sense. Uuids are occasionally used in cases where performance matters. Also, the reasoning for the change is unclear.

Copy link
Copy Markdown
Member

@mumrah mumrah Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ijuma -- that's a very good point about performance! I did check through fetch/produce paths originally, but of course that doesn't protect us from future usages (or things not caught during the review).

I'll file a patch shortly that makes this new behavior opt-in.

As to the reasoning, the original Jira I wrote was about issues with double-clicking on IDs. Really it's just meant to be a small quality of life improvement.

Copy link
Copy Markdown
Member

@mumrah mumrah Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #22442

uuid = unsafeRandomUuid();
}
return uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testRandomUuid() {

assertNotEquals(Uuid.ZERO_UUID, randomID);
assertNotEquals(Uuid.METADATA_TOPIC_ID, randomID);
assertFalse(randomID.toString().startsWith("-"));
assertFalse(randomID.toString().contains("-"));
}

@Test
Expand Down