{"record":{"id":"1552c993584bff06","repo":"MyCATApache/Mycat-Server","slug":"schema-name-duplicated","errorCode":null,"errorMessage":"schema ${name} duplicated!","messagePattern":"schema (.+?) duplicated!","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java","lineNumber":172,"sourceCode":"            }\n\n            // check dataNode already exists or not,看schema标签中是否有datanode\n            String defaultDbType = null;\n            //校验检查并添加dataNode\n            if (dataNode != null && !dataNode.isEmpty()) {\n                List<String> dataNodeLst = new ArrayList<String>(1);\n                dataNodeLst.add(dataNode);\n                checkDataNodeExists(dataNodeLst);\n                String dataHost = dataNodes.get(dataNode).getDataHost();\n                defaultDbType = dataHosts.get(dataHost).getDbType();\n            } else {\n                dataNode = null;\n            }\n            //加载schema下所有tables\n            Map<String, TableConfig> tables = loadTables(schemaElement);\n            //判断schema是否重复\n            if (schemas.containsKey(name)) {\n                throw new ConfigException(\"schema \" + name + \" duplicated!\");\n            }\n\n            // 设置了table的不需要设置dataNode属性，没有设置table的必须设置dataNode属性\n            if (dataNode == null && tables.size() == 0) {\n                throw new ConfigException(\n                        \"schema \" + name + \" didn't config tables,so you must set dataNode property!\");\n            }\n\n            SchemaConfig schemaConfig = new SchemaConfig(name, dataNode,\n                    tables, sqlMaxLimit, \"true\".equalsIgnoreCase(checkSQLSchemaStr),randomDataNode);\n\n            //设定DB类型，这对之后的sql语句路由解析有帮助\n            if (defaultDbType != null) {\n                schemaConfig.setDefaultDataNodeDbType(defaultDbType);\n                if (!\"mysql\".equalsIgnoreCase(defaultDbType)) {\n                    schemaConfig.setNeedSupportMultiDBType(true);\n                }\n            }","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java#L154-L190","documentation":"loadSchemas builds the schemas map keyed by the <schema> element's name attribute. If two schema elements in schema.xml use the same name, the second triggers this ConfigException. Duplicate schema names would break route resolution since a logical schema must map to exactly one configuration.","triggerScenarios":"schema.xml containing two <schema name=\"TESTDB\"> blocks; load() -> loadSchemas() finds schemas.containsKey(name) true on the second occurrence.","commonSituations":"Copy-pasting a schema block to add tables but forgetting the first copy; scripted config generation appending schemas; merging schema.xml fragments from different environments.","solutions":["Search schema.xml for duplicate <schema name=\"...\"> entries; merge their <table> definitions into one block or rename one schema.","If generated, fix the generator/template so each schema name is emitted once.","Restart and confirm MyCat loads the configuration."],"exampleFix":"// before (schema.xml)\n<schema name=\"TESTDB\" checkSQLschema=\"false\">\n  <table name=\"a\" dataNode=\"dn1\" />\n</schema>\n<schema name=\"TESTDB\">\n  <table name=\"b\" dataNode=\"dn2\" />\n</schema>\n// after\n<schema name=\"TESTDB\" checkSQLschema=\"false\">\n  <table name=\"a\" dataNode=\"dn1\" />\n  <table name=\"b\" dataNode=\"dn2\" />\n</schema>","handlingStrategy":"validation","validationCode":"// Fail fast on duplicate schema names\nSet<String> seen = new HashSet<>();\nNodeList schemas = doc.getElementsByTagName(\"schema\");\nfor (int i = 0; i < schemas.getLength(); i++) {\n    String name = ((Element) schemas.item(i)).getAttribute(\"name\");\n    if (!seen.add(name)) throw new IllegalStateException(\"duplicate schema: \" + name);\n}","typeGuard":null,"tryCatchPattern":"try {\n    loader = new XMLSchemaLoader();\n} catch (ConfigException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"duplicated!\")) {\n        LOG.error(\"Duplicate schema name in schema.xml: {}\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Merge tables of a logical schema into a single <schema> block instead of duplicating it.","If schema.xml is generated, enforce uniqueness in the generator/template.","Review schema.xml diffs for duplicated blocks before deploy."],"tags":["configuration","xml","duplicate-key","schema"],"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"}