Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leaf_name携带 - 导致获取workerId报错 #74

Closed
wuweishuo opened this issue Dec 30, 2019 · 3 comments
Closed

leaf_name携带 - 导致获取workerId报错 #74

wuweishuo opened this issue Dec 30, 2019 · 3 comments

Comments

@wuweishuo
Copy link

//表示新启动的节点,创建持久节点 ,不用check时间
String newNode = createNode(curator);
zk_AddressNode = newNode;
String[] nodeKey = newNode.split("-");
workerID = Integer.parseInt(nodeKey[1]);
doService(curator);
updateLocalWorkerID(workerID);
LOGGER.info("[New NODE]can not find node on forever node that endpoint ip-{} port-{} workid-{},create own node on forever node and start SUCCESS ", ip, port, workerID);

workerID = Integer.parseInt(nodeKey[1]); 获取到的为leaf_name的值
改为workerID = Integer.parseInt(nodeKey[nodeKey.length - 1]);

@Issocala
Copy link
Contributor

这里的nodeMap里面的数据格式类似于192.168.2.116:2184-0000000001,直接nodeKey[1]就已经获取到workerID了,leaf_name在snowflake节点下,所以并不会有问题。

@wuweishuo
Copy link
Author

String newNode = createNode(curator); 返回的是全路径而不是节点名

@Issocala
Copy link
Contributor

Issocala commented Jan 2, 2020

让我们将目光移至String[] nodeKey = newNode.split("-")这行,你会发现是的,workerID = Integer.parseInt(nodeKey[1]); 仍然在获取workerID。当然我们可以说改为nodeKey[nodeKey.length - 1]更为严谨。不过至少原来的设计并不会有什么问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants