开发者社区 问答 正文

instance的lazy启动在HA模式下不成立

在HA模式下,instance的lazy启动不成立。

首先看CanalController的代码

for (Map.Entry<String, InstanceConfig> entry : instanceConfigs.entrySet()) { final String destination = entry.getKey(); InstanceConfig config = entry.getValue(); // 创建destination的工作节点 if (!config.getLazy() && !embededCanalServer.isStart(destination)) { // HA机制启动 ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(destination); if (!runningMonitor.isStart()) { runningMonitor.start(); } }

    if (autoScan) {
        instanceConfigMonitors.get(config.getMode()).register(destination, defaultAction);
    }
}

lazy模式下,ServerRunningMonitor不会启动,那么在zookeeper的/otter/canal/destinations/destination/cluster节点下不会有数据,running节点也不会有数据

再看ClusterNodeAccessStrategy的代码 public SocketAddress nextNode() { if (runningAddress != null) {// 如果服务已经启动,直接选择当前正在工作的节点 return runningAddress; } else if (!currentAddress.isEmpty()) { // 如果不存在已经启动的服务,可能服务是一种lazy启动,随机选择一台触发服务器进行启动 return currentAddress.get(0);// 默认返回第一个节点,之前已经做过shuffle } else { throw new CanalClientException("no alive canal server"); } }

由于cluster和running节点都不存在,此处会进入else分支,客户端会一直报错,没办法触发laze启动。

原提问者GitHub用户lulu2panpan

展开
收起
绿子直子 2023-05-09 15:54:12 169 发布于北京 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • ServerRunningMonitor只是检测running节点的变化,不管是否lazy模式,都会为每个instance创建一个cid节点,这里的currentAddress拿的应该是这个list.

    看了下代码,目前cid节点的注册是依赖了ServerRunningMonitor.start()方法,逻辑上这里的确会有一点问题。

    改进办法:ServerRunningMonitor可以增加init方法,init方法调用创建cid,init方法不受lazy模式控制

    原回答者GitHub用户agapple

    2023-05-10 10:49:05 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答分类:
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问