MyCATApache/Mycat-Server · critical · RuntimeException

groupPartionSize must >0,but cur is

Error message

groupPartionSize must >0,but cur is {intGroupPartionSize}

What it means

PartitionByRangeDateHash.init() validates that the groupPartionSize configuration property is a positive integer, since each time partition holds this many hash slots. If intGroupPartionSize <= 0 it throws this RuntimeException during rule initialization. A non-positive size would cause division/hash-slot math to break at routing time.

Solutions

  1. Set groupPartionSize to a positive integer in the rule configuration (e.g. 4 or 8) matching your datanode layout.
  2. Ensure the total partition count (dateRangeSize * groupPartionSize) matches the number of configured datanodes/functional nodes.
  3. Review how the property is injected if it is generated dynamically, and clamp/validate it before calling init().
  4. Restart Mycat after correcting schema.xml so the rule re-initializes.

Example fix

// before
<property name="groupPartionSize">0</property>
// after
<property name="groupPartionSize">4</property>
Defensive patterns

Strategy: validation

Validate before calling

int size = Integer.parseInt(props.getProperty("groupPartionSize"));
if (size <= 0) throw new IllegalArgumentException("groupPartionSize must be > 0");

Try / catch

try { rule.init(); } catch (RuntimeException e) { if (e.getMessage().contains("groupPartionSize must >0")) { /* fix the property value */ } throw e; }

Prevention

When it happens

Trigger: Calling init() with <property name="groupPartionSize">0</property>, a negative value, or a value that fails to parse meaningfully, when setting up the rule in schema.xml.

Common situations: Copy-paste of a rule template leaving groupPartionSize at 0; computing the value from another config field that evaluated to 0; misunderstanding the property as a day count and setting it to 0 intending 'no sub-partitions'.

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


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/ba4d01aa14f8a6e0. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/route/function/PartitionByRangeDateHash.java:60

    public void init()
    {
        try
        {
            SimpleDateFormat sdfInit = new SimpleDateFormat(dateFormat);
            sdfInit.setTimeZone(UTC);
            beginDate = sdfInit.parse(sBeginDate).getTime();
            intGroupPartionSize = Integer.parseInt(groupPartionSize);
            formatter = new ThreadLocal<SimpleDateFormat>() {
                @Override
                protected SimpleDateFormat initialValue() {
                    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
                    sdf.setTimeZone(UTC); 
                    return sdf;
                }
            };
            if (intGroupPartionSize <= 0)
            {
                throw new RuntimeException("groupPartionSize must >0,but cur is " + intGroupPartionSize);
            }
        } catch (ParseException e)
        {
            throw new IllegalArgumentException(e);
        }
        partionTime = Integer.parseInt(sPartionDay) * oneDay;
    }

    @Override
    public Integer calculate(String columnValue)  {
        try
        {
            long targetTime = formatter.get().parse(
                    columnValue).getTime();
            int targetPartition = (int) ((targetTime - beginDate) / partionTime);
            int innerIndex =  Hashing.consistentHash(targetTime,intGroupPartionSize);
            return targetPartition * intGroupPartionSize + innerIndex;

View on GitHub (pinned to 65f8d8beb7)