{"record":{"id":"4cf4ff032e89dcd3","repo":"MyCATApache/Mycat-Server","slug":"datahost-name-name-duplicated","errorCode":null,"errorMessage":"dataHost name ${name}duplicated!","messagePattern":"dataHost name (.+?)duplicated!","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java","lineNumber":755,"sourceCode":"        DBHostConfig conf = new DBHostConfig(nodeHost, ip, port, nodeUrl, user, passwordEncryty, password,checkAlive);\n        conf.setDbType(dbType);\n        conf.setMaxCon(maxCon);\n        conf.setMinCon(minCon);\n        conf.setFilters(filters);\n        conf.setLogTime(logTime);\n        conf.setWeight(weight);    //新增权重\n        return conf;\n    }\n\n    private void loadDataHosts(Element root) {\n        NodeList list = root.getElementsByTagName(\"dataHost\");\n        for (int i = 0, n = list.getLength(); i < n; ++i) {\n\n            Element element = (Element) list.item(i);\n            String name = element.getAttribute(\"name\");\n            //判断是否重复\n            if (dataHosts.containsKey(name)) {\n                throw new ConfigException(\"dataHost name \" + name + \"duplicated!\");\n            }\n            //读取最大连接数\n            int maxCon = Integer.parseInt(element.getAttribute(\"maxCon\"));\n            //读取最小连接数\n            int minCon = Integer.parseInt(element.getAttribute(\"minCon\"));\n            /**\n             * 读取负载均衡配置\n             * 1. balance=\"0\", 不开启分离机制，所有读操作都发送到当前可用的 writeHost 上。\n             * 2. balance=\"1\"，全部的 readHost 和 stand by writeHost 参不 select 的负载均衡\n             * 3. balance=\"2\"，所有读操作都随机的在 writeHost、readhost 上分发。\n             * 4. balance=\"3\"，所有读请求随机的分发到 wiriterHost 对应的 readhost 执行，writerHost 不负担读压力\n             */\n            int balance = Integer.parseInt(element.getAttribute(\"balance\"));\n            /**\n             * 负载均衡配置\n             * 1. balanceType=0, 随机\n             * 2. balanceType=1，加权轮询\n             * 3. balanceType=2，最少活跃","sourceCodeStart":737,"sourceCodeEnd":773,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java#L737-L773","documentation":"During loading of schema.xml, XMLSchemaLoader iterates all <dataHost> elements and keeps them in a map keyed by the 'name' attribute. If a second dataHost reuses an already-registered name, the loader throws this ConfigException because dataHost names must be unique for pool routing. Startup aborts.","triggerScenarios":"Parsing <schema> XML where two <dataHost name=\"hostM1\"> elements (or a duplicated include) define the same name attribute.","commonSituations":"Copy-pasting a dataHost block to add a second host and forgetting to change the name; merging config fragments that each define hostM1; automated config generation emitting duplicate names.","solutions":["Search schema.xml for duplicate dataHost name attributes; rename the second occurrence to a unique name","Update all <dataNode dataHost=\"...\"> references that should point to the renamed host","If the duplication comes from merged/included config files, deduplicate the fragments before deployment","Restart MyCat and verify the schema loads"],"exampleFix":"// before\n<dataHost name=\"hostM1\" ...>...</dataHost>\n<dataHost name=\"hostM1\" ...>...</dataHost>\n// after\n<dataHost name=\"hostM1\" ...>...</dataHost>\n<dataHost name=\"hostM2\" ...>...</dataHost>","handlingStrategy":"validation","validationCode":"// detect duplicate dataHost names in schema.xml\nSet<String> seen = new HashSet<>();\nNodeList list = doc.getElementsByTagName(\"dataHost\");\nfor (int i = 0; i < list.getLength(); i++) {\n    String name = ((Element) list.item(i)).getAttribute(\"name\");\n    if (!seen.add(name)) throw new IllegalStateException(\"Duplicate dataHost name: \" + name);\n}","typeGuard":"null","tryCatchPattern":"try {\n    schemaLoader.load();\n} catch (ConfigException e) {\n    LOG.error(\"Duplicate dataHost name in schema.xml: \" + e.getMessage());\n    throw new ConfigurationException(\"Ensure dataHost names are unique\", e);\n}","preventionTips":["Adopt a naming convention (hostM1, hostM2, ...) when adding dataHosts","Run a uniqueness lint on schema.xml in CI","Avoid copy-pasting dataHost blocks without renaming"],"tags":["configuration","xml","duplicate"],"backgroundTag":"conflicting-config-options","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}