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

监听任务节点创建逻辑的疑问 #37

Open
furaul opened this issue Dec 30, 2019 · 2 comments
Open

监听任务节点创建逻辑的疑问 #37

furaul opened this issue Dec 30, 2019 · 2 comments

Comments

@furaul
Copy link

furaul commented Dec 30, 2019

com.xiaoju.automarket.elasticjobstarter.dynamic.service.JobService#monitorJobRegister
方法的实现里面有一行获取监听到节点的配置。
String config = new String((byte[])client.getData().forPath(data.getPath() + "/config"));
这一行直接去读取config节点。
看了下jobx的源码里面新任务注册的逻辑。

com.xiaoju.automarket.elastic.job.lite.internal.config.ConfigurationService#persist
com.xiaoju.automarket.elastic.job.lite.internal.storage.JobNodeStorage#replaceJobNode
com.xiaoju.automarket.elastic.job.reg.base.RegistryCenter#persist
client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(key, value.getBytes(Charsets.UTF_8));

创建/xxx/MyJob/config节点之前,会先创建/xxx/MyJob节点。
在极端情况下,/xxx/MyJob创建之后,/xxx/MyJob/config节点创建之前,监听逻辑读取config节点报错。
org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /xxx/MyJob/config

curator里面的创建任务节点相关代码见
org.apache.curator.framework.imps.CreateBuilderImpl#pathInForeground
会根据org.apache.curator.framework.imps.CreateBuilderImpl#createParentsIfNeeded判断是否创建父节点,如果该值为true,会先创建父节点,再创建子节点。

@furaul
Copy link
Author

furaul commented Jan 2, 2020

@yinjihuan 大佬有时间帮忙看下

@cjoin
Copy link

cjoin commented Nov 12, 2020

我实现的方式是, 在addJob逻辑结束后, 更新一下zk节点的数据, 监听程序新增一个监听数据更新的逻辑, 与新增逻辑基本相同.
就可以保证这种极端情况下, 也能把一台服务器新增的定时任务, 同步到另一台服务器

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

2 participants