{"record":{"id":"17780ae464f9c08f","repo":"alibaba/nacos","slug":"worker-id-can-t-be-greater-than-d-or-less-than-0","errorCode":null,"errorMessage":"worker Id can't be greater than %d or less than 0, current workId %d","messagePattern":"worker Id can't be greater than (.+?) or less than 0, current workId (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"critical","filePath":"core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java","lineNumber":153,"sourceCode":"    \n    @Override\n    public Map<Object, Object> info() {\n        Map<Object, Object> info = new HashMap<>(4);\n        info.put(\"currentId\", currentId);\n        info.put(\"workerId\", workerId);\n        return info;\n    }\n    \n    // ==============================Constructors=====================================\n    \n    /**\n     * init\n     *\n     * @param workerId worker id (0~1024)\n     */\n    public void initialize(long workerId) {\n        if (workerId > WORKER_ID_MAX_VALUE || workerId < 0) {\n            throw new IllegalArgumentException(\n                String.format(\n                    \"worker Id can't be greater than %d or less than 0, current workId %d\",\n                    WORKER_ID_MAX_VALUE, workerId));\n        }\n        this.workerId = workerId;\n    }\n    \n    /**\n     * Block to the next millisecond until a new timestamp is obtained\n     *\n     * @param lastTimestamp The time intercept of the last ID generated\n     * @return Current timestamp\n     */\n    private long waitUntilNextTime(long lastTimestamp) {\n        long time;\n        time = currentTimeMillis();\n        while (time <= lastTimestamp) {\n            time = currentTimeMillis();","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java#L135-L171","documentation":"Thrown by SnowFlowerIdGenerator.initialize(workerId) when the worker id is outside the allowed range [0, 1024]. WORKER_ID_MAX_VALUE is 1024. It is an IllegalArgumentException raised during init() (called at bean construction), so it prevents server startup.","triggerScenarios":"Explicitly setting nacos.core.snowflake.worker-id to a value < 0 or > 1024. When unset, the IP-derived worker id could in theory also exceed the range, but the explicit override is the usual cause.","commonSituations":"An operator sets a worker-id from a node-indexing scheme that exceeds 1024; negative value typo; multiple nodes accidentally given the same high id; copying a config across environments with a stale large value.","solutions":["Set nacos.core.snowflake.worker-id to a value in [0, 1024], unique per cluster node.","If you omit the property, Nacos derives a worker id from the IP — ensure that derivation stays in range across all nodes.","In large clusters (>1024 nodes), you cannot use the built-in snowflake worker-id space as-is; coordinate a sharding scheme."],"exampleFix":"// before\n-Dnacos.core.snowflake.worker-id=5000\n\n// after\n-Dnacos.core.snowflake.worker-id=5","handlingStrategy":"validation","validationCode":"final long MAX = 1024L;\nif (workerId < 0 || workerId > MAX) {\n    throw new IllegalArgumentException(\"workerId must be in [0,\" + MAX + \"]\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    snowFlowerIdGenerator.initialize(workerId);\n} catch (IllegalArgumentException e) {\n    // choose a valid worker-id in [0,1024] and retry\n}","preventionTips":["Assign each node a unique worker-id in [0,1024].","Validate the configured value before startup."],"tags":["id-generator","snowflake","validation","configuration","startup"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}