MyCATApache/Mycat-Server · error · RuntimeException
数量与dataNode数量不符
Error message
{ruleName}数量与dataNode数量不符 What it means
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.
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.
Example fix
// before <function name="partition-by-crc32preslot" class="PartitionByCRC32PreSlot"> <property name="count">4</property> <!-- map file has 5 dataNodes --> </function> // after <function name="partition-by-crc32preslot" class="PartitionByCRC32PreSlot"> <property name="count">5</property> </function>
Defensive patterns
Strategy: validation
Validate before calling
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();
if (mapEntries != declaredCount) throw new IllegalStateException("count (" + declaredCount + ") != map file entries (" + mapEntries + ");
Try / catch
try {
function.init();
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("数量与dataNode数量不符")) {
// re-sync count with map file, then reInit
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- only one rule can defined
- can't find function of name
- table rule coulmns has multi values
- rule function duplicated!
- nameSuffix , require name parameter cannot multiple breaks!
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/f2cde120ad4b29ff.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/route/function/PartitionByCRC32PreSlot.java:163
return map;
}
@Override
public void init() {
super.init();
if (ruleName != null) {
Properties p = loadProps(ruleName, false);
rangeMap = convertToMap(p);
checkSize();
hack();
}
}
private void checkSize(){
if (this.getCount() != this.rangeMap.size()){
throw new RuntimeException(ruleName + "数量与dataNode数量不符");
}
}
public void reInit() {
if (ruleName != null) {
Properties p = loadProps(ruleName, true);
rangeMap = convertToMap(p);
checkSize();
hack();
}
}
private void hack() {
//todo 优化
Iterator<Map.Entry<Integer, List<Range>>> iterator = rangeMap.entrySet().iterator();
while (iterator.hasNext()) {View on GitHub (pinned to 65f8d8beb7)