{"record":{"id":"f04c66a1b7b76544","repo":"MyCATApache/Mycat-Server","slug":"datanode-dnname-reference-datahost-host-not","errorCode":null,"errorMessage":"dataNode ${dnName} reference dataHost:${host} not exists!","messagePattern":"dataNode (.+?) reference dataHost:(.+?) not exists!","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java","lineNumber":685,"sourceCode":"                String database = databases[i1];\n                String[] hd = new String[2];\n                hd[0] = hostString;\n                hd[1] = database;\n                mhdList.add(hd);\n            }\n        }\n        return mhdList;\n    }\n\n    private void createDataNode(String dnName, String database, String host) {\n\n        DataNodeConfig conf = new DataNodeConfig(dnName, database, host);\n        if (dataNodes.containsKey(conf.getName())) {\n            throw new ConfigException(\"dataNode \" + conf.getName() + \" duplicated!\");\n        }\n\n        if (!dataHosts.containsKey(host)) {\n            throw new ConfigException(\"dataNode \" + dnName + \" reference dataHost:\" + host + \" not exists!\");\n        }\n\n        dataHosts.get(host).addDataNode(conf.getName());\n        dataNodes.put(conf.getName(), conf);\n    }\n\n    private boolean empty(String dnName) {\n        return dnName == null || dnName.length() == 0;\n    }\n\n    private DBHostConfig createDBHostConf(String dataHost, Element node,\n                                          String dbType, String dbDriver, int maxCon, int minCon, String filters, long logTime) {\n\n        String nodeHost = node.getAttribute(\"host\");\n        String nodeUrl = node.getAttribute(\"url\");\n        String user = node.getAttribute(\"user\");\n        String password = node.getAttribute(\"password\");\n        String usingDecrypt = node.getAttribute(\"usingDecrypt\");","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java#L667-L703","documentation":"Thrown by XMLSchemaLoader.createDataNode when a <dataNode> references a dataHost that has no corresponding <dataHost> definition. The loader registers dataHosts before dataNodes and requires every dataNode's host to exist so the node can be attached to a physical host.","triggerScenarios":"A <dataNode name=\"dn1\" dataHost=\"host9\" database=\"db1\" /> where no <dataHost name=\"host9\"> exists; also produced by range-expanded dataHost attributes whose expanded names (e.g. host$1-5) don't match defined dataHost names.","commonSituations":"Typo in the dataHost attribute; dataHost element deleted or renamed while dataNodes still reference it; range-expanded host names (localhost$1-2) not matching the actual <dataHost name=\"localhost1\"> definitions.","solutions":["Add the missing <dataHost name=\"...\"> definition to schema.xml","Fix the dataNode's dataHost attribute to reference an existing dataHost name","Check range-expanded host names against actual <dataHost> name attributes"],"exampleFix":"// before (schema.xml)\n<dataNode name=\"dn1\" dataHost=\"host1\" database=\"db1\" /> <!-- host1 undefined -->\n// after\n<dataHost name=\"host1\" maxCon=\"1000\" minCon=\"10\" balance=\"0\">\n  <heartbeat>select user()</heartbeat>\n  <writeHost host=\"h1\" url=\"127.0.0.1:3306\" user=\"root\" password=\"x\" />\n</dataHost>\n<dataNode name=\"dn1\" dataHost=\"host1\" database=\"db1\" />","handlingStrategy":"validation","validationCode":"// verify every dataNode's dataHost exists before load\nSet<String> hosts = collectDataHostNames(\"schema.xml\");\nfor (Element dn : dataNodeElements(\"schema.xml\")) {\n    for (String h : expand(dn.getAttribute(\"dataHost\"))) {\n        if (!hosts.contains(h.trim()))\n            throw new IllegalStateException(\"Unknown dataHost: \" + h);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    configLoader.load();\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"reference dataHost\") && e.getMessage().contains(\"not exists\")) {\n        String host = extractBetween(e.getMessage(), \"dataHost:\", \" not exists\");\n        log.error(\"Define <dataHost name='\" + host + \"'> or fix the dataNode reference\", e);\n    }\n    throw e;\n}","preventionTips":["Define dataHost elements before/above dataNodes in schema.xml and never rename without grepping references","Remember expanded host names (host$1-2) must match real <dataHost name=...> values exactly","Cross-check dataHost references whenever deleting or consolidating hosts"],"tags":["config","xml","missing-reference","datahost"],"backgroundTag":"resource-not-found","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"}