Skip to content
New issue

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

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

Already on GitHub? # to your account

请问服务宕机了,zk能感知到吗 #52

Open
WinfridDu opened this issue Sep 2, 2021 · 4 comments
Open

请问服务宕机了,zk能感知到吗 #52

WinfridDu opened this issue Sep 2, 2021 · 4 comments

Comments

@WinfridDu
Copy link

看代码服务注册是创建的永久节点,那zk怎么感知服务宕机呢

@deepbreath373
Copy link

deepbreath373 commented Feb 11, 2022

我也有点疑惑,虽然有watcher来监听节点的变化,但是如果是永久节点,那么服务如果宕机了,这些不可用的服务节点没有被手动删除,可能就会导致调用方调用失败。
我的看法是应该创建成临时节点,如果服务者程序意外宕机,在 Session 超时之后,也能自动删除服务节点,自动下线有问题的服务。
--——------------------------
我看了看 Dubbo 中的 ZookeeperRegistry 的 doRegister 方法,Dubbo 中是采用分类设置的方式,如果是 Root、Service、Type 的节点就是持久节点,如果是服务对应的 URL 则是临时节点。
eg: dubbo(root)/com.example.service(service)/providers(type)/127.0.0.1(url)
所以当某个服务器宕机后,就会将其对应的URL节点删除。
----——------------------------------
再次查看了 Guide 哥的框架源码,发现有一个 CustomShutdownHook 钩子类,其中的 clearAll() 方法写到:
CuratorUtils.clearRegistry(CuratorUtils.getZkClient(), inetSocketAddress);
所以在 Server 端宕机断连的时候会使用该方法清除 Zookeeper 上的服务节点。

@DogerRain
Copy link

虽然dubbo是临时节点,那如果dubbo的 server 在 Session 超时内,client发起请求,岂不是会发生错误,直到zk剔除server的节点? @deepbreath373

@jmkill1
Copy link

jmkill1 commented Apr 9, 2022

我也有点疑惑,虽然有watcher来监听节点的变化,但是如果是永久节点,那么服务如果宕机了,这些不可用的服务节点没有被手动删除,可能就会导致调用方调用失败。 我的看法是应该创建成临时节点,如果服务者程序意外宕机,在 Session 超时之后,也能自动删除服务节点,自动下线有问题的服务。 --——------------------------ 我看了看 Dubbo 中的 ZookeeperRegistry 的 doRegister 方法,Dubbo 中是采用分类设置的方式,如果是 Root、Service、Type 的节点就是持久节点,如果是服务对应的 URL 则是临时节点。 eg: dubbo(root)/com.example.service(service)/providers(type)/127.0.0.1(url) 所以当某个服务器宕机后,就会将其对应的URL节点删除。 ----——------------------------------ 再次查看了 Guide 哥的框架源码,发现有一个 CustomShutdownHook 钩子类,其中的 clearAll() 方法写到: CuratorUtils.clearRegistry(CuratorUtils.getZkClient(), inetSocketAddress); 所以在 Server 端宕机断连的时候会使用该方法清除 Zookeeper 上的服务节点。

我将服务强制下线后,仍然能够在zookeeper上面观察到已经下线的服务,这时候如果有客户端进来就会报错,Zookeeper并没有监听到服务下线了
image

@TeamBreakerr
Copy link

同感,应该创建成临时节点

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

No branches or pull requests

5 participants