开发者社区> 问答> 正文

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 138 0
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
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载