MyCATApache/Mycat-Server · error · ConfigException

weight should not be null in host

Error message

weight should not be null in host:${host}

What it means

Every <node> in cluster.xml must define a non-empty 'weight' property used for load balancing. If the weight value is null or empty, ConfigException 'weight should not be null in host: <host>' is thrown at ClusterConfig.java:87.

Solutions

  1. Add a positive integer weight to the node: <property name="weight">1</property>.
  2. Set weights proportional to node capacity (e.g. bigger machine = higher weight).
  3. Check for misspelled property names or unsubstituted placeholders.
  4. Restart Mycat to reload cluster.xml.

Example fix

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

Strategy: validation

Validate before calling

// Every node must declare a non-empty weight
var nl = doc.getElementsByTagName("node");
for (int i = 0; i < nl.getLength(); i++) {
  var el = (Element) nl.item(i);
  String w = propOf(el, "weight");
  if (w == null || w.trim().isEmpty()) throw new IllegalStateException("node " + el.getAttribute("name") + " missing weight");
}

Try / catch

try { new ClusterConfig(); } catch (ConfigException e) { if (e.getMessage().startsWith("weight should not be null")) { log.error("Add weight property to node in cluster.xml"); } throw e; }

Prevention

When it happens

Trigger: A node element defines host and port but omits <property name="weight"> or leaves it empty; thrown during loadNode.

Common situations: Adding a new node and forgetting the weight line, an older cluster.xml upgraded to a Mycat version that made weight mandatory, or a template with placeholder ${WEIGHT} left unsubstituted.

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/4915682cb44456cb. Report an issue: GitHub.

Appendix: source

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

            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;
    }

    private static Map<String, List<String>> loadGroup(Element root, Map<String, MycatNodeConfig> nodes) {
        Map<String, List<String>> groups = new HashMap<String, List<String>>();
        NodeList list = root.getElementsByTagName("group");
        for (int i = 0, n = list.getLength(); i < n; i++) {

View on GitHub (pinned to 65f8d8beb7)