MyCATApache/Mycat-Server · error · java.lang.RuntimeException

slaveIds range must be 2 size

Error message

${id}slaveIds range must be 2  size

What it means

MigrateHandler.parseSlaveIDs parses a comma-separated slave ID list where each element may be a single ID or a range like '1-5'. When a range element does not split into exactly two parts (e.g. '1-5-9' or 'a--b'), it throws this RuntimeException because a range is only meaningful with a start and an end.

Solutions

  1. Correct the slaveIDs range to exactly two values, e.g. '1-5' instead of '1-5-9' or '1--5'.
  2. Use plain comma-separated single IDs if no range is needed, e.g. '1,2,3'.
  3. Pre-validate the slaveIDs string in tooling with a regex like '\d+-\d+|\d+' before invoking migration.

Example fix

// before
slaveIds="1-2-3"
// after
slaveIds="1-3"
Defensive patterns

Strategy: validation

Validate before calling

// java
if (!slaveIDs.matches("(\\d+(\\s*,\\s*\\d+-\\d+)*\\s*)*")) {
    throw new IllegalArgumentException("bad slaveIDs: " + slaveIDs);
}
for (String id : slaveIDs.split(",")) {
    if (id.contains("-") && id.split("-").length != 2)
        throw new IllegalArgumentException("range must have 2 parts: " + id);
}

Try / catch

try { List<Integer> ids = MigrateHandler.allSlaveIDList(slaveIDs); } catch (RuntimeException e) { log.error("invalid slaveIDs format", e); }

Prevention

When it happens

Trigger: Calling migration APIs (allSlaveIDList -> parseSlaveIDs) with a slaveIDs string containing a hyphenated range with more or fewer than two segments, e.g. 'slaveIDs=1-2-3' or 'slaveIDs=-1-' handled by omitEmptyStrings edge cases, or a typo like '1--5'.

Common situations: Operators hand-editing migration/switch DDL commands and mistyping ranges; scripts generating ID ranges that concatenate an extra '-'; copy-paste from docs adding trailing dashes.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/main/java/io/mycat/server/handler/MigrateHandler.java:409

        } finally {
            try {
                slaveIDsLock.release();
            } catch (Exception e) {
                LOGGER.error("error:", e);
            }
        }

        throw new RuntimeException("cannot get the slaveID  for dataHost :" + dbNode.getDbPool().getHostName());
    }

    private static List<Integer> parseSlaveIDs(String slaveIDs) {
        List<Integer> allSlaveList = new ArrayList<>();
        List<String> stringList = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(slaveIDs);
        for (String id : stringList) {
            if (id.contains("-")) {
                List<String> idRangeList = Splitter.on("-").omitEmptyStrings().trimResults().splitToList(id);
                if (idRangeList.size() != 2)
                    throw new RuntimeException(id + "slaveIds range must be 2  size");
                for (int i = Integer.parseInt(idRangeList.get(0)); i <= Integer.parseInt(idRangeList.get(1)); i++) {
                    allSlaveList.add(i);
                }

            } else {
                allSlaveList.add(Integer.parseInt(id));
            }
        }
        return allSlaveList;
    }


    private static OkPacket getOkPacket() {
        OkPacket packet = new OkPacket();
        packet.packetId = 1;
        packet.affectedRows = 0;
        packet.serverStatus = 2;
        return packet;

View on GitHub (pinned to 65f8d8beb7)