MyCATApache/Mycat-Server · error · ConfigException

dataNode reference dataHost: not exists!

Error message

dataNode ${dnName} reference dataHost:${host} not exists!

What it means

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.

Solutions

  1. Add the missing <dataHost name="..."> definition to schema.xml
  2. Fix the dataNode's dataHost attribute to reference an existing dataHost name
  3. Check range-expanded host names against actual <dataHost> name attributes

Example fix

// before (schema.xml)
<dataNode name="dn1" dataHost="host1" database="db1" /> <!-- host1 undefined -->
// after
<dataHost name="host1" maxCon="1000" minCon="10" balance="0">
  <heartbeat>select user()</heartbeat>
  <writeHost host="h1" url="127.0.0.1:3306" user="root" password="x" />
</dataHost>
<dataNode name="dn1" dataHost="host1" database="db1" />
Defensive patterns

Strategy: validation

Validate before calling

// verify every dataNode's dataHost exists before load
Set<String> hosts = collectDataHostNames("schema.xml");
for (Element dn : dataNodeElements("schema.xml")) {
    for (String h : expand(dn.getAttribute("dataHost"))) {
        if (!hosts.contains(h.trim()))
            throw new IllegalStateException("Unknown dataHost: " + h);
    }
}

Try / catch

try {
    configLoader.load();
} catch (ConfigException e) {
    if (e.getMessage().contains("reference dataHost") && e.getMessage().contains("not exists")) {
        String host = extractBetween(e.getMessage(), "dataHost:", " not exists");
        log.error("Define <dataHost name='" + host + "'> or fix the dataNode reference", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/f04c66a1b7b76544. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java:685

                String database = databases[i1];
                String[] hd = new String[2];
                hd[0] = hostString;
                hd[1] = database;
                mhdList.add(hd);
            }
        }
        return mhdList;
    }

    private void createDataNode(String dnName, String database, String host) {

        DataNodeConfig conf = new DataNodeConfig(dnName, database, host);
        if (dataNodes.containsKey(conf.getName())) {
            throw new ConfigException("dataNode " + conf.getName() + " duplicated!");
        }

        if (!dataHosts.containsKey(host)) {
            throw new ConfigException("dataNode " + dnName + " reference dataHost:" + host + " not exists!");
        }

        dataHosts.get(host).addDataNode(conf.getName());
        dataNodes.put(conf.getName(), conf);
    }

    private boolean empty(String dnName) {
        return dnName == null || dnName.length() == 0;
    }

    private DBHostConfig createDBHostConf(String dataHost, Element node,
                                          String dbType, String dbDriver, int maxCon, int minCon, String filters, long logTime) {

        String nodeHost = node.getAttribute("host");
        String nodeUrl = node.getAttribute("url");
        String user = node.getAttribute("user");
        String password = node.getAttribute("password");
        String usingDecrypt = node.getAttribute("usingDecrypt");

View on GitHub (pinned to 65f8d8beb7)