Hi Samuli,

Cluster ID is allowed to start with a hyphen. But you must pass it to the 
kafka-storage format command line like this:

> kafka-storage.sh format --cluster-id=$MY_CLUSTER_ID ...

Note the equals sign.

We didn't want people to have to deal with this, which is why we made 
generate-uuid not create cluster IDs that started with a hyphen.

best,
Colin


On Tue, Oct 22, 2024, at 06:44, Samuli Ruohola wrote:
> Hi!
>
> Thank you for the Apache Kafka! We are grateful for it.
>
> In our root cause analysis process discussions, we were asked to share
> following piece of information to the Apache Kafka community.
>
> Following is a known topic, in generic, it seems, already. E.g. there are
> existing tickets, and Uuid.java implementation already handles the
> "problem", in one way.
>
> Following was still asked to be raised up.
>
> Kafka cluster ID does not work exactly as it is defined in documentation of
> Apache Kafka.
> ( Those are not exactly in sync. )
> Regarding location of one character.
>
> In the documentation of Apache Kafka, hyphen, "-" is allowed to be in the
> beginning, according to the exact definition and regexp:
>
> https://kafka.apache.org/documentation/
>
> Quotation:
>
> "The cluster id ... the allowed characters are defined by the regular
> expression [a-zA-Z0-9_\-]+".
>
> According to that, hyphen, "-", is allowed to be in the beginning of the
> value of cluster ID. But that is incorrect.
>
> In reality, the Apache Kafka instance / cluster does not start up with
> hyphen "-" in the beginning of the value of the cluster ID.
>
> The problem: kafka-storage could not parse command line argument ( cluster
> ID ).
> There comes an error: "argument --cluster-id/-t: expected one argument"
>
>
> More:
>
> It seems to be a known issue in Apache kafka. Because there exists
> following source codes / function:
>
> ...
>      * This will not generate a UUID equal to 0, 1, or one whose string
> representation starts with a dash ("-")
>      */
>     public static Uuid randomUuid() {
>         Uuid uuid = unsafeRandomUuid();
>         while (RESERVED.contains(uuid) || uuid.toString().*startsWith*("*-*"))
> {
>             uuid = unsafeRandomUuid();
>         }
>         return uuid;
>     }
>     }
>
> https://fossies.org/dox/kafka-3.8.0-src/Uuid_8java_source.html
> https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/Uuid.java
> https://issues.apache.org/jira/browse/KAFKA-13741
>
> An other older ticket related to UUID / cluster ID starting with "hyphen":
> https://issues.apache.org/jira/browse/KAFKA-15754
>
>
> We generated/generate the cluster ID in our own function. And that caused
> trouble.
>
> Best Regards
> Sam

Reply via email to