Meituan-Dianping / Leaf

Distributed ID Generate Service
Apache License 2.0
6.42k stars 1.84k forks source link

leaf may break with special name #188

Open qixiaobo opened 2 years ago

qixiaobo commented 2 years ago
[ERROR] [main] c.s.i.l.s.SnowflakeZookeeperHolder:? []Start node ERROR {}
java.lang.NumberFormatException: For input string: "server"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)
    at java.lang.Integer.parseInt(Integer.java:615)
    at com.sankuai.inf.leaf.snowflake.SnowflakeZookeeperHolder.init(SnowflakeZookeeperHolder.java:89)
    at com.sankuai.inf.leaf.snowflake.SnowflakeIDGenImpl.<init>(SnowflakeIDGenImpl.java:50)

I Found that https://github.com/Meituan-Dianping/Leaf/blob/86a6441d263497b9f9ee321de13422b9c63f0c06/leaf-core/src/main/java/com/sankuai/inf/leaf/snowflake/SnowflakeZookeeperHolder.java#L89

//表示新启动的节点,创建持久节点 ,不用check时间
                    String newNode = createNode(curator);
                    zk_AddressNode = newNode;
                    String[] nodeKey = newNode.split("-");
                    workerID = Integer.parseInt(nodeKey[1]);

While We set this application name to xxx-xxx like below idgen-server then newNode will return snowflake.idgen-server.forever.xxxx:xxxx-sequence So server will be parsed. Then this will cause leaf not start as expected

qixiaobo commented 2 years ago

We should achieve workId as the last index of nodeKey other than 1

qixiaobo commented 2 years ago

A simple workaround is just to make this name to idgen_server