{"record":{"id":"3180892c9a5fe32a","repo":"MyCATApache/Mycat-Server","slug":"datacenter-id-can-t-be-greater-than-d-or-less-tha","errorCode":null,"errorMessage":"datacenter Id can't be greater than %d or less than 0","messagePattern":"datacenter Id can't be greater than (.+?) or less than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/sequence/handler/IncrSequenceTimeHandler.java","lineNumber":90,"sourceCode":"\t\tprivate final static long workerIdShift = sequenceBits;\n\t\tprivate final static long datacenterIdShift = sequenceBits + workerIdBits;\n\t\t// 时间毫秒左移22位\n\t\tprivate final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;\n\n\t\tprivate final static long sequenceMask = -1L ^ (-1L << sequenceBits);\n\n\t\tprivate static long lastTimestamp = -1L;\n\n\t\tprivate long sequence = 0L;\n\t\tprivate final long workerId;\n\t\tprivate final long datacenterId;\n\n\t\tpublic IdWorker(long workerId, long datacenterId) {\n\t\t\tif (workerId > maxWorkerId || workerId < 0) {\n\t\t\t\tthrow new IllegalArgumentException(\"worker Id can't be greater than %d or less than 0\");\n\t\t\t}\n\t\t\tif (datacenterId > maxDatacenterId || datacenterId < 0) {\n\t\t\t\tthrow new IllegalArgumentException(\"datacenter Id can't be greater than %d or less than 0\");\n\t\t\t}\n\t\t\tthis.workerId = workerId;\n\t\t\tthis.datacenterId = datacenterId;\n\t\t}\n\n\t\tpublic synchronized long nextId() {\n\t\t\tlong timestamp = timeGen();\n\t\t\tif (timestamp < lastTimestamp) {\n\t\t\ttry {\n\t\t\t\tthrow new Exception(\"Clock moved backwards.  Refusing to generate id for \"+ (lastTimestamp - timestamp) + \" milliseconds\");\n\t\t\t} catch (Exception e) {\n\t\t\t\tLOGGER.error(\"error\",e);\n\t\t\t}\n\t\t\t}\n\n\t\t\tif (lastTimestamp == timestamp) {\n\t\t\t\t// 当前毫秒内，则+1\n\t\t\t\tsequence = (sequence + 1) & sequenceMask;","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/sequence/handler/IncrSequenceTimeHandler.java#L72-L108","documentation":"The IdWorker reserves 5 bits for the datacenter Id, so datacenterId must be between 0 and 31 (maxDatacenterId = -1L ^ (-1L << 5)); otherwise the constructor throws IllegalArgumentException to prevent bit overflow into the timestamp portion of the generated ID. Like the worker-Id check, the %d placeholder in the message is never formatted.","triggerScenarios":"Constructing IdWorker with a DATAACENTERID from sequence_time_conf.properties that is negative or greater than 31; IncrSequenceTimeHandler.load() calls new IdWorker(workid, dataCenterId) with the unvalidated property value.","commonSituations":"DATAACENTERID copied from a scheme with more datacenter bits; typos such as DATAACENTERID=100; reusing another deployment's properties file without adjusting the value; negative values produced by script-generated configs.","solutions":["Set DATAACENTERID in sequence_time_conf.properties to an integer in [0, 31], unique per datacenter","Restart MyCAT to reload the properties","If more than 32 datacenters are needed, widen datacenterIdBits in IdWorker and recompute maxDatacenterId"],"exampleFix":"// before (sequence_time_conf.properties)\nDATAACENTERID=99\n// after\nDATAACENTERID=1","handlingStrategy":"validation","validationCode":"long datacenterId = Long.parseLong(props.getProperty(\"DATAACENTERID\"));\nif (datacenterId < 0 || datacenterId > 31) {\n    throw new IllegalArgumentException(\"DATAACENTERID must be in [0,31], got \" + datacenterId);\n}","typeGuard":null,"tryCatchPattern":"try {\n    handler.load();\n} catch (IllegalArgumentException e) {\n    LOGGER.error(\"Invalid DATAACENTERID in sequence_time_conf.properties: {}\", e.getMessage());\n    throw new ConfigurationException(e);\n}","preventionTips":["Assign DATAACENTERID per datacenter within 0-31 and document it","Check both IDs together whenever editing sequence_time_conf.properties","Fail fast with an explicit range check before constructing IdWorker"],"tags":["snowflake-id","config-validation","argument-out-of-range"],"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"}