{"record":{"id":"dcdfa346af7a80ad","repo":"MyCATApache/Mycat-Server","slug":"node-name-duplicated-name","errorCode":null,"errorMessage":"node name duplicated :${name}","messagePattern":"node name duplicated :(.+?)","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/model/ClusterConfig.java","lineNumber":73,"sourceCode":"    public Map<String, MycatNodeConfig> getNodes() {\n        return nodes;\n    }\n\n    public Map<String, List<String>> getGroups() {\n        return groups;\n    }\n\n    private static Map<String, MycatNodeConfig> loadNode(Element root, int port) {\n        Map<String, MycatNodeConfig> nodes = new HashMap<String, MycatNodeConfig>();\n        NodeList list = root.getElementsByTagName(\"node\");\n        Set<String> hostSet = new HashSet<String>();\n        for (int i = 0, n = list.getLength(); i < n; i++) {\n            Node node = list.item(i);\n            if (node instanceof Element) {\n                Element element = (Element) node;\n                String name = element.getAttribute(\"name\").trim();\n                if (nodes.containsKey(name)) {\n                    throw new ConfigException(\"node name duplicated :\" + name);\n                }\n\n                Map<String, Object> props = ConfigUtil.loadElements(element);\n                String host = (String) props.get(\"host\");\n                if (null == host || \"\".equals(host)) {\n                    throw new ConfigException(\"host empty in node: \" + name);\n                }\n                if (hostSet.contains(host)) {\n                    throw new ConfigException(\"node host duplicated :\" + host);\n                }\n\n                String wei = (String) props.get(\"weight\");\n                if (null == wei || \"\".equals(wei)) {\n                    throw new ConfigException(\"weight should not be null in host:\" + host);\n                }\n                int weight = Integer.parseInt(wei);\n                if (weight <= 0) {\n                    throw new ConfigException(\"weight should be > 0 in host:\" + host + \" weight:\" + weight);","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/model/ClusterConfig.java#L55-L91","documentation":"ClusterConfig.loadNode parses <node> elements from the Mycat cluster XML (cluster.xml). Each node must have a unique 'name' attribute; if a second element has the same name it throws ConfigException 'node name duplicated'. This prevents ambiguous node definitions in the cluster model.","triggerScenarios":"XML contains two or more <node name=\"X\" ...> elements with the same trimmed name; thrown at ClusterConfig.java:73 while loadNode iterates the node list.","commonSituations":"Copy-paste of a <node> block when adding a second host without renaming it, merge conflicts in cluster.xml that duplicated a block, or automated config generation emitting duplicates.","solutions":["Open cluster.xml and find all <node> elements sharing the same name attribute.","Rename one node to a unique name (e.g. nodeM1, nodeM2) and update any <group nodeList=...> references to match.","Search the file for 'node name=' and de-duplicate before restarting Mycat.","If config is generated, fix the generator/template to enforce unique names."],"exampleFix":"<!-- before -->\n<node name=\"nodeM1\" host=\"10.0.0.1\" ... />\n<node name=\"nodeM1\" host=\"10.0.0.2\" ... />\n<!-- after -->\n<node name=\"nodeM1\" host=\"10.0.0.1\" ... />\n<node name=\"nodeM2\" host=\"10.0.0.2\" ... />","handlingStrategy":"validation","validationCode":"// Before startup, check for duplicate node names in cluster.xml\nimport javax.xml.xpath.*;\nvar doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(\"cluster.xml\");\nvar nodes = XPathFactory.newInstance().newXPath().evaluate(\"//node/@name\", doc, XPathConstants.NODESET);\nvar seen = new java.util.HashSet<String>();\nfor (int i = 0; i < nodes.getLength(); i++) {\n  String n = nodes.item(i).getNodeValue().trim();\n  if (!seen.add(n)) throw new IllegalStateException(\"duplicate node name: \" + n);\n}","typeGuard":null,"tryCatchPattern":"try { new ClusterConfig(); } catch (ConfigException e) { if (e.getMessage().startsWith(\"node name duplicated\")) { log.error(\"Fix duplicate <node name> in cluster.xml\"); } throw e; }","preventionTips":["Lint cluster.xml for duplicate names in CI","Avoid copy-pasting node blocks without renaming","Keep node names in a shared naming convention","Review merge conflicts in cluster.xml carefully"],"tags":["xml","config","duplicate-name","cluster","mycat"],"backgroundTag":"invalid-config-value","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}