{"record":{"id":"611eb345094f1b4b","repo":"apache/pulsar","slug":"no-more-range-can-assigned-to-new-consumer-assign","errorCode":null,"errorMessage":"No more range can assigned to new consumer, assigned consumers ${rangeMap.size()}","messagePattern":"No more range can assigned to new consumer, assigned consumers (.+?)","errorType":"exception","errorClass":"ConsumerAssignException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/service/HashRangeAutoSplitStickyKeyConsumerSelector.java","lineNumber":188,"sourceCode":"            Integer lowerKey = rangeMap.lowerKey(entry.getKey());\n            if (lowerKey == null) {\n                lowerKey = 0;\n            }\n            if (entry.getKey() - lowerKey > slots) {\n                slots = entry.getKey() - lowerKey;\n                busiestRange = entry.getKey();\n            }\n        }\n        return busiestRange;\n    }\n\n    private void splitRange(int range, Consumer targetConsumer) throws ConsumerAssignException {\n        Integer lowerKey = rangeMap.lowerKey(range);\n        if (lowerKey == null) {\n            lowerKey = 0;\n        }\n        if (range - lowerKey <= 1) {\n            throw new ConsumerAssignException(\"No more range can assigned to new consumer, assigned consumers \"\n                    + rangeMap.size());\n        }\n        int splitRange = range - ((range - lowerKey) >> 1);\n        rangeMap.put(splitRange, targetConsumer);\n        consumerRange.put(targetConsumer, splitRange);\n    }\n\n    private boolean is2Power(int num) {\n        if (num < 2) {\n            return false;\n        }\n        return (num & num - 1) == 0;\n    }\n}\n","sourceCodeStart":170,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/HashRangeAutoSplitStickyKeyConsumerSelector.java#L170-L203","documentation":"HashRangeAutoSplitStickyKeyConsumerSelector splits an existing hash range when a new consumer joins key_shared subscription. If the chosen range is too small to split (range - lowerKey <= 1), it throws ConsumerAssignException because no further range can be assigned.","triggerScenarios":"Adding a consumer to a key_shared subscription with auto-split key sharing when the number of consumers exceeds the number of available hash-range units (range space exhausted, 65536 ranges).","commonSituations":"Subscribing with an extremely large number of consumers on one key_shared subscription; pathological range fragmentation after many consumer add/remove cycles; simulated/tests using tiny hash ranges.","solutions":["Reduce the number of consumers attached to the single key_shared subscription","Recreate the subscription (disconnect all consumers) to reset hash ranges to a fresh state","Switch key_shared mode to StickyKeyConsumerSelector hash ranges config or use a different subscription type (Shared) for very high consumer counts","Catch ConsumerAssignException on subscribe and retry later after consumers disconnect"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// keep consumer count of the key_shared subscription well below the range space\nlong consumers = subscription.getConsumers().size();\nboolean canJoin = consumers < 65536;","typeGuard":null,"tryCatchPattern":"try {\n    consumer = pulsarClient.newConsumer().subscriptionType(SubscriptionType.Key_Shared)...subscribe();\n} catch (PulsarClientException e) {\n    if (e.getCause() instanceof ConsumerAssignException) { /* backoff and retry */ }\n}","preventionTips":["Limit consumers per key_shared subscription","Prefer Shared subscription type for very large consumer fan-out","Monitor subscription consumer counts and alert before exhaustion"],"tags":["java","broker","key-shared","hash-range","consumer-assignment"],"backgroundTag":"hash-range-exhausted","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}