MyCATApache/Mycat-Server · error · IllegalArgumentException

worker Id can't be greater than

Error message

worker Id can't be greater than %d or less than 0

What it means

The IdWorker used by IncrSequenceTimeHandler implements a Snowflake-style 64-bit ID in which 5 bits are reserved for the worker Id, so it must be an integer between 0 and 31 (maxWorkerId = -1L ^ (-1L << 5)). The constructor validates this and throws IllegalArgumentException before any ID is generated. The message contains an unformatted %d placeholder (String.format is never applied), a known bug in this codebase.

Solutions

  1. Open sequence_time_conf.properties and set WORKID to a value in [0, 31], unique per MyCAT instance
  2. Restart MyCAT so the handler reloads the properties and constructs IdWorker successfully
  3. If IDs must exceed 31 instances, increase workerIdBits in IdWorker and recompute maxWorkerId (accepting fewer sequence bits)

Example fix

// before (sequence_time_conf.properties)
WORKID=64
// after
WORKID=4
Defensive patterns

Strategy: validation

Validate before calling

long workerId = Long.parseLong(props.getProperty("WORKID"));
if (workerId < 0 || workerId > 31) {
    throw new IllegalArgumentException("WORKID must be in [0,31], got " + workerId);
}

Try / catch

try {
    handler.load();
} catch (IllegalArgumentException e) {
    LOGGER.error("Invalid WORKID/DATAACENTERID in sequence_time_conf.properties: {}", e.getMessage());
    throw new ConfigurationException(e);
}

Prevention

When it happens

Trigger: Constructing IdWorker with a WORKID read from sequence_time_conf.properties that is negative or greater than 31 — e.g. WORKID=32, WORKID=100, or a negative value; load() in IncrSequenceTimeHandler calls new IdWorker(workid, dataCenterId) on handler initialization.

Common situations: Operators copy WORKID values from another cluster (where 6+ bits are used) into sequence_time_conf.properties; a typo like WORKID=032 is fine but WORKID=320 is not; automated config generation produces out-of-range IDs; WORKID accidentally set to a non-zero-based index.

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/e6e1374b888c7128. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/route/sequence/handler/IncrSequenceTimeHandler.java:87

		// 毫秒内自增位
		private final static long sequenceBits = 12L;
		// 机器ID偏左移12位
		private final static long workerIdShift = sequenceBits;
		private final static long datacenterIdShift = sequenceBits + workerIdBits;
		// 时间毫秒左移22位
		private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;

		private final static long sequenceMask = -1L ^ (-1L << sequenceBits);

		private static long lastTimestamp = -1L;

		private long sequence = 0L;
		private final long workerId;
		private final long datacenterId;

		public IdWorker(long workerId, long datacenterId) {
			if (workerId > maxWorkerId || workerId < 0) {
				throw new IllegalArgumentException("worker Id can't be greater than %d or less than 0");
			}
			if (datacenterId > maxDatacenterId || datacenterId < 0) {
				throw new IllegalArgumentException("datacenter Id can't be greater than %d or less than 0");
			}
			this.workerId = workerId;
			this.datacenterId = datacenterId;
		}

		public synchronized long nextId() {
			long timestamp = timeGen();
			if (timestamp < lastTimestamp) {
			try {
				throw new Exception("Clock moved backwards.  Refusing to generate id for "+ (lastTimestamp - timestamp) + " milliseconds");
			} catch (Exception e) {
				LOGGER.error("error",e);
			}
			}

View on GitHub (pinned to 65f8d8beb7)