MyCATApache/Mycat-Server · critical · RuntimeException
${e}
Error message
${e} What it means
MigrateTaskWatch.start connects to ZooKeeper via ZKUtils.getConnection() and ensures the /migratePath node exists before registering a PathChildrenCacheListener. Any ZK exception (no connection, session expired, no auth, create failure) is wrapped in a RuntimeException, so the whole migration watch cannot start.
Solutions
- Verify ZooKeeper connectivity (zkCli.sh -server host:2181) and that the address in MyCAT config is correct.
- Check ZK ACLs/chroot permissions allow creating nodes under the migrate path.
- Restart MyCAT so ZKUtils reconnects; inspect the wrapped 'Caused by' for KeeperException code.
- Confirm the ZK ensemble has a quorum (all servers up) before starting migration.
Example fix
// before
}catch (Exception e){
throw new RuntimeException(e);
}
// after
}catch (Exception e){
throw new RuntimeException("Failed to init ZK migrate path " + migratePath, e);
} Defensive patterns
Strategy: retry
Validate before calling
// preflight ZK health
ZooKeeper zk = new ZooKeeper(zkUrl, 30000, ev -> {});
if (zk.getState() != States.CONNECTED) throw new IllegalStateException("ZK not reachable"); Try / catch
try { MigrateTaskWatch.start(); } catch (RuntimeException e) {
// check KeeperException code
if (e.getCause() instanceof org.apache.zookeeper.KeeperException ke
&& ke.code() == KeeperException.Code.CONNECTIONLOSS) {
// wait for reconnect and retry start
}
throw e;
} Prevention
- Verify ZK ensemble quorum before launching migration
- Set ZK session timeout larger than migration operation time
- Check ACLs allow create under the migrate path
- Monitor ZK connectivity from the MyCAT host
When it happens
Trigger: ZooKeeper is unreachable or the session expired when ZKUtils.getConnection() is called; checkExists().forPath() throws (NoAuth, session loss); create() fails due to permissions or connection loss.
Common situations: ZooKeeper cluster down or misconfigured myid/zookeeper URL in MyCAT config; ZK ACLs deny the MyCAT user create rights; network partition between MyCAT and the ZK ensemble.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- ${e}
- dataHost: do not config the salveIDs field
- cannot get the slaveID for dataHost
- failed to connect to zookeeper service
- SelfCheck### there are some datasource connection failed…
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/3289d597f77dced6.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/migrate/MigrateTaskWatch.java:41
/**
* ......./migrate/schemal/taskid/datahost [任务数据]
* Created by magicdoom on 2016/9/28.
*/
public class MigrateTaskWatch {
private static final Logger LOGGER = LoggerFactory.getLogger(MigrateTaskWatch.class);
public static void start() {
String migratePath = ZKUtils.getZKBasePath() + "migrate";
// modify by jian.xie,cjw,zwy 如果migrate 启动的时候不存在,无法监听,需要这里监听一次
// 如果第一次没有migrate节点这里应该无法使用集群 还需优化
try {
CuratorFramework client = ZKUtils.getConnection();
if (client.checkExists().forPath(migratePath) == null) {
client.create().creatingParentsIfNeeded().forPath(migratePath);
}
}catch (Exception e){
throw new RuntimeException(e);
}
ZKUtils.addChildPathCache(migratePath, new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework curatorFramework,
PathChildrenCacheEvent fevent) throws Exception {
switch (fevent.getType()) {
case CHILD_ADDED:
LOGGER.info("table CHILD_ADDED: " + fevent.getData().getPath());
ZKUtils.addChildPathCache(fevent.getData().getPath(), new TaskPathChildrenCacheListener());
break;
default:
break;
}
}
});
}View on GitHub (pinned to 65f8d8beb7)