Skip to content

Commit 474798a

Browse files
authored
KAFKA-20072: Don't generate IDs with hyphens (#21313)
The `Uuid#randomUuid` method has been modified to avoid generating UUIDs containing hyphens. Reviewers: Mickael Maison <mickael.maison@gmail.com>, David Arthur <mumrah@gmail.com>, Sean Quah <squah@confluent.io>
1 parent 4bb8f0f commit 474798a

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

clients/src/main/java/org/apache/kafka/common/Uuid.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ private static Uuid unsafeRandomUuid() {
7070

7171
/**
7272
* Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
73-
*
74-
* This will not generate a UUID equal to 0, 1, or one whose string representation starts with a dash ("-")
73+
* <p>
74+
* This will not generate a UUID equal to 0, 1, or one whose string representation contains a dash ("-").
7575
*/
7676
public static Uuid randomUuid() {
7777
Uuid uuid = unsafeRandomUuid();
78-
while (RESERVED.contains(uuid) || uuid.toString().startsWith("-")) {
78+
while (RESERVED.contains(uuid) || uuid.toString().contains("-")) {
7979
uuid = unsafeRandomUuid();
8080
}
8181
return uuid;

clients/src/test/java/org/apache/kafka/common/UuidTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testRandomUuid() {
8383

8484
assertNotEquals(Uuid.ZERO_UUID, randomID);
8585
assertNotEquals(Uuid.METADATA_TOPIC_ID, randomID);
86-
assertFalse(randomID.toString().startsWith("-"));
86+
assertFalse(randomID.toString().contains("-"));
8787
}
8888

8989
@Test

docs/design/protocol.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,19 @@ Others have asked if maybe we shouldn't support many different protocols. Prior
215215
Another question is why we don't adopt XMPP, STOMP, AMQP or an existing protocol. The answer to this varies by protocol, but in general the problem is that the protocol does determine large parts of the implementation and we couldn't do what we are doing if we didn't have control over the protocol. Our belief is that it is possible to do better than existing messaging systems have in providing a truly distributed messaging system, and to do this we need to build something that works differently.
216216

217217
A final question is why we don't use a system like Protocol Buffers or Thrift to define our request messages. These packages excel at helping you to managing lots and lots of serialized messages. However we have only a few messages. Support across languages is somewhat spotty (depending on the package). Finally the mapping between binary log format and wire protocol is something we manage somewhat carefully and this would not be possible with these systems. Finally we prefer the style of versioning APIs explicitly and checking this to inferring new values as nulls as it allows more nuanced control of compatibility.
218+
219+
## Recommendations for 3rd‑party Clients: Member ID Format
220+
221+
When a Kafka client participates in group protocols (e.g., `ConsumerGroupHeartbeat` RPC), it must generate a **member ID** to identify itself to the broker. While the protocol does not strictly enforce the format of this ID, we strongly recommend the following:
222+
223+
1. **Use a base64‑encoded UUID** as the member ID.
224+
2. **Encode the UUID using URL‑safe base64** (without `+` or `/` characters).
225+
3. **Omit hyphens** — the resulting string should be a continuous sequence of alphanumeric characters (e.g., `abc123def456`).
226+
227+
**Example**
228+
A standard UUID (`00000000-0000-0000-0000-000000000000`) should be transformed into a URL‑safe base64 string like: `YzYxNjQ4OTItZDE1Mi00Y2E4LWIyNzUtYmIwMzAwMDAwMDAw`
229+
230+
*(Note: This is illustrative; actual encoding depends on the UUID bytes.)*
231+
232+
**Important**
233+
While this is a strong recommendation, the protocol does **not** reject member IDs that deviate from this format.

0 commit comments

Comments
 (0)