MyCATApache/Mycat-Server · error · ConfigException

weight should be > 0 in host

Error message

weight should be > 0 in host:${host} weight:${weight}

What it means

After parsing the weight value with Integer.parseInt, loadNode requires it to be strictly positive; weight <= 0 throws ConfigException 'weight should be > 0 in host: <host> weight: <weight>'. Zero or negative weights would break weighted load balancing.

Solutions

  1. Change the weight property to a positive integer (>= 1).
  2. If you meant to exclude a node, remove it from the <group nodeList> instead of setting weight 0.
  3. Validate all weight values are positive integers before deployment.
  4. Restart Mycat after editing cluster.xml.

Example fix

<!-- before -->
<property name="weight">0</property>
<!-- after -->
<property name="weight">1</property>
Defensive patterns

Strategy: validation

Validate before calling

String w = propOf(nodeEl, "weight");
int weight = Integer.parseInt(w.trim());
if (weight <= 0) throw new IllegalStateException("weight must be > 0 for node " + nodeEl.getAttribute("name"));

Try / catch

try { new ClusterConfig(); } catch (ConfigException e) { if (e.getMessage().startsWith("weight should be > 0")) { log.error("Set a positive integer weight in cluster.xml"); } throw e; }

Prevention

When it happens

Trigger: A node's weight property parses to an integer <= 0 (e.g. weight=0 or weight=-1); thrown at ClusterConfig.java:91.

Common situations: Setting weight=0 to 'disable' a node (use removal or group membership instead), copy-pasted negative value, or a typo like weight="-5".

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/67950e8efc26fbee. Report an issue: GitHub.

Appendix: source

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

                    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++) {
            Node node = list.item(i);
            if (node instanceof Element) {
                Element e = (Element) node;
                String groupName = e.getAttribute("name").trim();

View on GitHub (pinned to 65f8d8beb7)