MyCATApache/Mycat-Server · error · ConfigException

host empty in node

Error message

host empty in node: ${name}

What it means

loadNode requires every <node> element in cluster.xml to define a non-empty 'host' property. If props.get("host") is null or an empty string, ConfigException 'host empty in node: <name>' is thrown. The host is mandatory to contact the node.

Solutions

  1. Add a host property to the offending node: <property name="host">10.0.0.1</property>.
  2. Check the property element name is exactly 'host' and the value is non-empty after trimming.
  3. Replace unresolved placeholders (e.g. ${HOST}) with concrete hostnames/IPs.
  4. Restart Mycat after fixing cluster.xml.

Example fix

<!-- before -->
<node name="nodeM1">
  <property name="port">3311</property>
</node>
<!-- after -->
<node name="nodeM1">
  <property name="host">10.0.0.1</property>
  <property name="port">3311</property>
</node>
Defensive patterns

Strategy: validation

Validate before calling

// Every <node> must have a non-empty host property
var nl = doc.getElementsByTagName("node");
for (int i = 0; i < nl.getLength(); i++) {
  var el = (Element) nl.item(i);
  var props = el.getElementsByTagName("property");
  boolean hasHost = false;
  for (int j = 0; j < props.getLength(); j++) {
    var p = (Element) props.item(j);
    if ("host".equals(p.getAttribute("name")) && !p.getTextContent().trim().isEmpty()) hasHost = true;
  }
  if (!hasHost) throw new IllegalStateException("node " + el.getAttribute("name") + " missing host");
}

Try / catch

try { new ClusterConfig(); } catch (ConfigException e) { if (e.getMessage().startsWith("host empty in node")) { log.error("Add host property to node in cluster.xml"); } throw e; }

Prevention

When it happens

Trigger: A <node name="X"> element in cluster.xml lacks a <property name="host"> child or its value is empty; thrown at ClusterConfig.java:79 during loadNode.

Common situations: Hand-edited cluster.xml where the host property line was deleted or left as <property name="host"></property>, placeholder values like ${HOST} not substituted, or a misspelled property name (Host vs host).

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/main/java/io/mycat/config/model/ClusterConfig.java:79

    }

    private static Map<String, MycatNodeConfig> loadNode(Element root, int port) {
        Map<String, MycatNodeConfig> nodes = new HashMap<String, MycatNodeConfig>();
        NodeList list = root.getElementsByTagName("node");
        Set<String> hostSet = new HashSet<String>();
        for (int i = 0, n = list.getLength(); i < n; i++) {
            Node node = list.item(i);
            if (node instanceof Element) {
                Element element = (Element) node;
                String name = element.getAttribute("name").trim();
                if (nodes.containsKey(name)) {
                    throw new ConfigException("node name duplicated :" + name);
                }

                Map<String, Object> props = ConfigUtil.loadElements(element);
                String host = (String) props.get("host");
                if (null == host || "".equals(host)) {
                    throw new ConfigException("host empty in node: " + name);
                }
                if (hostSet.contains(host)) {
                    throw new ConfigException("node host duplicated :" + host);
                }

                String wei = (String) props.get("weight");
                if (null == wei || "".equals(wei)) {
                    throw new ConfigException("weight should not be null in host:" + host);
                }
                int weight = Integer.parseInt(wei);
                if (weight <= 0) {
                    throw new ConfigException("weight should be > 0 in host:" + host + " weight:" + weight);
                }

                MycatNodeConfig conf = new MycatNodeConfig(name, host, port, weight);
                nodes.put(name, conf);
                hostSet.add(host);
            }

View on GitHub (pinned to 65f8d8beb7)