MyCATApache/Mycat-Server · critical · RuntimeException
error,check your partitionScope definition.
Error message
error,check your partitionScope definition.
What it means
PartitionUtil builds its internal cumulative partition boundary array from per-partition length arrays and validates the total equals PARTITION_LENGTH (the full hash ring, e.g. 1024). If the configured partition lengths do not sum to the full range, the constructor throws this RuntimeException immediately. It is a fail-fast guard against a misconfigured partition scope in partition-charset files or count/length arrays.
Solutions
- Fix the partition rule config so partitionCount[i] * partitionLength[i] values sum exactly to 1024 (PARTITION_LENGTH)
- If using a partition pattern file, make each region's start contiguous with the previous end with no gaps or overlaps (e.g. lines 0-1023 covering the full range once)
- Verify the schema.xml rule function's count/length attributes match the intended total, e.g. <function name="..." count="2" length="512"/> sums to 1024
Example fix
// before (schema.xml rule config) <property name="count">3</property> <property name="length">400</property> <!-- 3*400=1200 != 1024 --> // after <property name="count">2</property> <property name="length">512</property> <!-- 2*512=1024 -->
Defensive patterns
Strategy: validation
Validate before calling
// validate before constructing PartitionUtil
int total = 0;
for (int i = 0; i < partitionCount.length; i++) { total += partitionCount[i] * partitionLength[i]; }
if (total != 1024) throw new IllegalStateException("partition lengths sum to " + total + ", expected 1024"); Try / catch
try { PartitionUtil pu = new PartitionUtil(count, length); } catch (RuntimeException e) { /* log config error, fail startup */ } Prevention
- Keep partitionCount*partitionLength sums equal to 1024
- Generate range files programmatically instead of by hand
- Add a startup config test that constructs all PartitionUtil instances
When it happens
Trigger: Constructing PartitionUtil where the sum of all partition lengths (partitionCount[i] * partitionLength[i], or values from a partition pattern file) does not equal PARTITION_LENGTH (1024). Caused by inconsistent partitionCount/partitionLength values passed in or a partition-range file whose ranges overlap or leave gaps.
Common situations: Editing partition-range pattern files (e.g. for hash-int or long range rules) by hand and leaving gaps or overlaps between regions; copying a rule config for a different modulo (e.g. 1024 vs 3600) without updating counts; sum of lengths accidentally doubled by overlapping file entries.
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
- rule is not found!
- Illegal table conf : table
- in noSharding mode schema must have default dataNode
- ruleRequired but rule is null
- no rule is found
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/24a6690f0201a245.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/route/util/PartitionUtil.java:69
*/
public PartitionUtil(int[] count, int[] length) {
if (count == null || length == null || (count.length != length.length)) {
throw new RuntimeException("error,check your scope & scopeLength definition.");
}
int segmentLength = 0;
for (int i = 0; i < count.length; i++) {
segmentLength += count[i];
}
int[] ai = new int[segmentLength + 1];
int index = 0;
for (int i = 0; i < count.length; i++) {
for (int j = 0; j < count[i]; j++) {
ai[++index] = ai[index - 1] + length[i];
}
}
if (ai[ai.length - 1] != PARTITION_LENGTH) {
throw new RuntimeException("error,check your partitionScope definition.");
}
// 数据映射操作
for (int i = 1; i < ai.length; i++) {
for (int j = ai[i - 1]; j < ai[i]; j++) {
segment[j] = (i - 1);
}
}
}
public int partition(long hash) {
return segment[(int) (hash & AND_VALUE)];
}
public int partition(String key, int start, int end) {
return partition(StringUtil.hash(key, start, end));
}
View on GitHub (pinned to 65f8d8beb7)