{"record":{"id":"f2cde120ad4b29ff","repo":"MyCATApache/Mycat-Server","slug":"rulename-datanode","errorCode":null,"errorMessage":"{ruleName}数量与dataNode数量不符","messagePattern":"(.+?)数量与dataNode数量不符","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/function/PartitionByCRC32PreSlot.java","lineNumber":163,"sourceCode":"\n        return map;\n    }\n\n    @Override\n    public void init() {\n\n        super.init();\n        if (ruleName != null) {\n            Properties p = loadProps(ruleName, false);\n            rangeMap = convertToMap(p);\n            checkSize();\n            hack();\n        }\n    }\n\n    private void checkSize(){\n        if (this.getCount() != this.rangeMap.size()){\n            throw new RuntimeException(ruleName + \"数量与dataNode数量不符\");\n        }\n    }\n\n    public void reInit() {\n\n        if (ruleName != null) {\n            Properties p = loadProps(ruleName, true);\n            rangeMap = convertToMap(p);\n            checkSize();\n            hack();\n        }\n    }\n\n\n    private void hack() {\n        //todo   优化\n        Iterator<Map.Entry<Integer, List<Range>>> iterator = rangeMap.entrySet().iterator();\n        while (iterator.hasNext()) {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/function/PartitionByCRC32PreSlot.java#L145-L181","documentation":"PartitionByCRC32PreSlot throws this RuntimeException during checkSize() when the configured rule count (getCount()) does not match the number of entries in the slot range map (rangeMap.size()), i.e. the number of dataNodes. It fires during init()/reInit() when the partition configuration file and the declared count are inconsistent. The algorithm cannot map slots to dataNodes reliably until they agree.","triggerScenarios":"Calling init() or reInit() on a PartitionByCRC32PreSlot instance where mapFile defines a number of slot ranges different from the count property (getCount()); editing the map file to add/remove dataNodes without updating count in schema/rule XML.","commonSituations":"Operators manually edit the CRC32 slot map file (e.g. partition-hash-int.txt style file) to add a dataNode but forget to change count in rule.xml; mismatched copies of map files across a cluster; upgrading Mycat with an old map file against a new cluster size.","solutions":["Count the entries in the map file referenced by mapFile and set the count property (ruleName config) to exactly that number.","If you intended a different cluster size, regenerate the slot map file to have the same number of ranges as dataNodes.","Call reInit() after fixing configuration and verify getCount() == rangeMap.size() before routing traffic."],"exampleFix":"// before\n<function name=\"partition-by-crc32preslot\" class=\"PartitionByCRC32PreSlot\">\n  <property name=\"count\">4</property> <!-- map file has 5 dataNodes -->\n</function>\n// after\n<function name=\"partition-by-crc32preslot\" class=\"PartitionByCRC32PreSlot\">\n  <property name=\"count\">5</property>\n</function>","handlingStrategy":"validation","validationCode":"int mapEntries = java.nio.file.Files.readAllLines(java.nio.file.Paths.get(mapFile)).stream().filter(l -> !l.trim().isEmpty() && !l.trim().startsWith(\"#\")).mapToInt(l -> 1).sum();\nif (mapEntries != declaredCount) throw new IllegalStateException(\"count (\" + declaredCount + \") != map file entries (\" + mapEntries + \");\n","typeGuard":null,"tryCatchPattern":"try {\n    function.init();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"数量与dataNode数量不符\")) {\n        // re-sync count with map file, then reInit\n    }\n}","preventionTips":["Regenerate map file and count together with a script so they can never drift","Add a config-validation step in deployment comparing count to map entries","Keep map files under version control next to rule.xml"],"tags":["sharding","configuration","mismatch"],"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-16T04:17:20.429Z"}