{"record":{"id":"3289d597f77dced6","repo":"MyCATApache/Mycat-Server","slug":"e-3289d5","errorCode":null,"errorMessage":"${e}","messagePattern":"\\$\\{e\\}","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/main/java/io/mycat/migrate/MigrateTaskWatch.java","lineNumber":41,"sourceCode":"\n/**\n * ......./migrate/schemal/taskid/datahost   [任务数据]\n * Created by magicdoom on 2016/9/28.\n */\npublic class MigrateTaskWatch {\n    private static final Logger LOGGER = LoggerFactory.getLogger(MigrateTaskWatch.class);\n\n    public static void start() {\n        String migratePath = ZKUtils.getZKBasePath() + \"migrate\";\n        // modify by jian.xie,cjw,zwy 如果migrate 启动的时候不存在，无法监听，需要这里监听一次\n        // 如果第一次没有migrate节点这里应该无法使用集群 还需优化\n        try {\n            CuratorFramework client = ZKUtils.getConnection();\n            if (client.checkExists().forPath(migratePath) == null) {\n                client.create().creatingParentsIfNeeded().forPath(migratePath);\n            }\n        }catch (Exception e){\n            throw new RuntimeException(e);\n        }\n        ZKUtils.addChildPathCache(migratePath, new PathChildrenCacheListener() {\n            @Override\n            public void childEvent(CuratorFramework curatorFramework,\n                                   PathChildrenCacheEvent fevent) throws Exception {\n\n                switch (fevent.getType()) {\n                    case CHILD_ADDED:\n                        LOGGER.info(\"table CHILD_ADDED: \" + fevent.getData().getPath());\n                        ZKUtils.addChildPathCache(fevent.getData().getPath(), new TaskPathChildrenCacheListener());\n                        break;\n                    default:\n                        break;\n                }\n            }\n        });\n\n    }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/migrate/MigrateTaskWatch.java#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n}catch (Exception e){\n    throw new RuntimeException(e);\n}\n// after\n}catch (Exception e){\n    throw new RuntimeException(\"Failed to init ZK migrate path \" + migratePath, e);\n}","handlingStrategy":"retry","validationCode":"// preflight ZK health\nZooKeeper zk = new ZooKeeper(zkUrl, 30000, ev -> {});\nif (zk.getState() != States.CONNECTED) throw new IllegalStateException(\"ZK not reachable\");","typeGuard":null,"tryCatchPattern":"try { MigrateTaskWatch.start(); } catch (RuntimeException e) {\n    // check KeeperException code\n    if (e.getCause() instanceof org.apache.zookeeper.KeeperException ke\n        && ke.code() == KeeperException.Code.CONNECTIONLOSS) {\n        // wait for reconnect and retry start\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["zookeeper","curator","migration","connectivity"],"backgroundTag":"connection-refused","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}