MyCATApache/Mycat-Server · error · ConfigException
rule function duplicated!
Error message
rule function ${name} duplicated! What it means
loadFunctions iterates <function> elements in rule.xml and stores them by name in a map. If two <function> blocks share the same name attribute, the second is rejected with this ConfigException. Duplicate function names would make algorithm lookup ambiguous.
Solutions
- Search rule.xml for repeated <function name="..."> names; delete or rename the duplicate.
- If you need the same algorithm with different parameters, create uniquely named functions and reference them from the corresponding tableRules.
- Restart/reload and verify MyCat starts cleanly.
Example fix
// before (rule.xml) <function name="mod-long" class="io.mycat.route.function.PartitionByMod"> <property name="count">4</property> </function> <function name="mod-long" class="io.mycat.route.function.PartitionByMod"> <property name="count">8</property> </function> // after <function name="mod-long-4" class="io.mycat.route.function.PartitionByMod"> <property name="count">4</property> </function> <function name="mod-long-8" class="io.mycat.route.function.PartitionByMod"> <property name="count">8</property> </function>
Defensive patterns
Strategy: validation
Validate before calling
// Detect duplicate <function> names before deployment
Set<String> seen = new HashSet<>();
NodeList fns = doc.getElementsByTagName("function");
for (int i = 0; i < fns.getLength(); i++) {
String name = ((Element) fns.item(i)).getAttribute("name");
if (!seen.add(name)) throw new IllegalStateException("duplicate function: " + name);
} Try / catch
try {
ruleLoader.load();
} catch (ConfigException e) {
if (e.getMessage().startsWith("rule function") && e.getMessage().contains("duplicated!")) {
LOG.error("Duplicate <function> name in rule.xml: {}", e.getMessage());
}
throw e;
} Prevention
- Use uniquely named functions per parameter set (e.g. mod-long-4 vs mod-long-8).
- Review rule.xml diffs for appended function blocks.
- Add a uniqueness lint to the config pipeline.
When it happens
Trigger: rule.xml defines two <function name="X" ...> elements with identical names, possibly with different class attributes; load() -> loadFunctions() hits functions.containsKey(name).
Common situations: Appending a new function definition without removing the old one during tuning (e.g. changing count); merging rule.xml from two environments; copy-paste duplication.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- table rule duplicated!
- only one rule can defined
- can't find function of name
- table rule coulmns has multi values
- schema duplicated!
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/a4130c4eaaea2433.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/loader/xml/XMLRuleLoader.java:199
* @param root
* @throws ClassNotFoundException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
private void loadFunctions(Element root) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
InvocationTargetException {
NodeList list = root.getElementsByTagName("function");
for (int i = 0, n = list.getLength(); i < n; ++i) {
Node node = list.item(i);
if (node instanceof Element) {
Element e = (Element) node;
//获取name标签
String name = e.getAttribute("name");
//如果Map已有,则function重复
if (functions.containsKey(name)) {
throw new ConfigException("rule function " + name
+ " duplicated!");
}
//获取class标签
String clazz = e.getAttribute("class");
//根据class利用反射新建分片算法
AbstractPartitionAlgorithm function = createFunction(name, clazz);
//根据读取参数配置分片算法
ParameterMapping.mapping(function, ConfigUtil.loadElements(e));
//每个AbstractPartitionAlgorithm可能会实现init来初始化
function.init();
//放入functions map
functions.put(name, function);
}
}
}
private AbstractPartitionAlgorithm createFunction(String name, String clazz)
throws ClassNotFoundException, InstantiationException,
View on GitHub (pinned to 65f8d8beb7)