MyCATApache/Mycat-Server · error · ConfigException

node host duplicated

Error message

node host duplicated :${host}

What it means

loadNode tracks hosts already seen in hostSet; if two different <node> elements declare the same host value, ConfigException 'node host duplicated : <host>' is thrown at ClusterConfig.java:82. Each cluster node must have a distinct host address so traffic can be routed unambiguously.

Solutions

  1. Search cluster.xml for the duplicated host value and give each node a unique host.
  2. If both really are the same machine, use distinct hostnames (or per-interface IPs) and unique ports.
  3. Remove redundant duplicate node definitions if they were accidental copy-paste.
  4. Keep nodes and groups consistent after renaming hosts.

Example fix

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

Strategy: validation

Validate before calling

// No two nodes may share the same host
java.util.Set<String> hosts = new java.util.HashSet<>();
var nl = doc.getElementsByTagName("node");
for (int i = 0; i < nl.getLength(); i++) {
  var el = (Element) nl.item(i);
  String host = hostOf(el); // read property name="host"
  if (!hosts.add(host)) throw new IllegalStateException("duplicate host: " + host);
}

Try / catch

try { new ClusterConfig(); } catch (ConfigException e) { if (e.getMessage().startsWith("node host duplicated")) { log.error("Assign a unique host per <node> in cluster.xml"); } throw e; }

Prevention

When it happens

Trigger: Two <node> elements in cluster.xml both set property host to the same IP/hostname (e.g. 10.0.0.1); thrown when the second one is processed.

Common situations: Cloning a node block and forgetting to change the host, two nodes pointing at the same machine with only the port differing (not allowed here), or an HA setup modeled incorrectly.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

        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);
            }
        }
        return nodes;
    }

View on GitHub (pinned to 65f8d8beb7)