{"record":{"id":"24a6690f0201a245","repo":"MyCATApache/Mycat-Server","slug":"error-check-your-partitionscope-definition","errorCode":null,"errorMessage":"error,check your partitionScope definition.","messagePattern":"error,check your partitionScope definition\\.","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/main/java/io/mycat/route/util/PartitionUtil.java","lineNumber":69,"sourceCode":"     */\n    public PartitionUtil(int[] count, int[] length) {\n        if (count == null || length == null || (count.length != length.length)) {\n            throw new RuntimeException(\"error,check your scope & scopeLength definition.\");\n        }\n        int segmentLength = 0;\n        for (int i = 0; i < count.length; i++) {\n            segmentLength += count[i];\n        }\n        int[] ai = new int[segmentLength + 1];\n\n        int index = 0;\n        for (int i = 0; i < count.length; i++) {\n            for (int j = 0; j < count[i]; j++) {\n                ai[++index] = ai[index - 1] + length[i];\n            }\n        }\n        if (ai[ai.length - 1] != PARTITION_LENGTH) {\n            throw new RuntimeException(\"error,check your partitionScope definition.\");\n        }\n\n        // 数据映射操作\n        for (int i = 1; i < ai.length; i++) {\n            for (int j = ai[i - 1]; j < ai[i]; j++) {\n                segment[j] = (i - 1);\n            }\n        }\n    }\n\n    public int partition(long hash) {\n        return segment[(int) (hash & AND_VALUE)];\n    }\n\n    public int partition(String key, int start, int end) {\n        return partition(StringUtil.hash(key, start, end));\n    }\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/PartitionUtil.java#L51-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (schema.xml rule config)\n<property name=\"count\">3</property>\n<property name=\"length\">400</property>  <!-- 3*400=1200 != 1024 -->\n// after\n<property name=\"count\">2</property>\n<property name=\"length\">512</property>  <!-- 2*512=1024 -->","handlingStrategy":"validation","validationCode":"// validate before constructing PartitionUtil\nint total = 0;\nfor (int i = 0; i < partitionCount.length; i++) { total += partitionCount[i] * partitionLength[i]; }\nif (total != 1024) throw new IllegalStateException(\"partition lengths sum to \" + total + \", expected 1024\");","typeGuard":null,"tryCatchPattern":"try { PartitionUtil pu = new PartitionUtil(count, length); } catch (RuntimeException e) { /* log config error, fail startup */ }","preventionTips":["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"],"tags":["config","sharding","partitioning"],"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"}