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

  1. Verify ZooKeeper connectivity (zkCli.sh -server host:2181) and that the address in MyCAT config is correct.
  2. Check ZK ACLs/chroot permissions allow creating nodes under the migrate path.
  3. Restart MyCAT so ZKUtils reconnects; inspect the wrapped 'Caused by' for KeeperException code.
  4. 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

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


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)