{"record":{"id":"7d6cdf2d526a1b59","repo":"apache/cassandra","slug":"token-type-s-does-not-support-token-allocation","errorCode":null,"errorMessage":"Token type %s does not support token allocation.","messagePattern":"Token type (.+?) does not support token allocation\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java","lineNumber":154,"sourceCode":"            return token;\n        }\n\n        @Override\n        public int tokenHash()\n        {\n            return hashCode();\n        }\n\n        @Override\n        public TokenFactory tokenFactory()\n        {\n            return tokenFactory;\n        }\n\n        @Override\n        public double size(Token next)\n        {\n            throw new UnsupportedOperationException(String.format(\"Token type %s does not support token allocation.\",\n                                                                  getClass().getSimpleName()));\n        }\n\n        @Override\n        public Token nextValidToken()\n        {\n            throw new UnsupportedOperationException(String.format(\"Token type %s does not support token allocation.\",\n                                                                  getClass().getSimpleName()));\n        }\n\n        public Token increaseSlightly()\n        {\n            // find first byte we can increment\n            int i = token.length - 1;\n            while (i >= 0)\n            {\n                if (token[i] != -1)\n                    break;","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java#L136-L172","documentation":"ByteOrderedPartitioner's token factory implements TokenFactory.size() as an unsupported operation because byte-ordered tokens have no uniform numeric ring size usable by the token-allocation code. Token allocation (e.g. allocate_tokens_for_local_replication_factor) is simply not supported for this partitioner. Any code path that asks a ByteOrderedPartitioner token for its ring 'size' gets UnsupportedOperationException.","triggerScenarios":"Calling Token.Factory.size(token) (directly or via TokenAllocation.allocateTokens) on a token whose partitioner is ByteOrderedPartitioner — e.g. bootstrap with allocate_tokens_for_local_replication_factor set while partitioner is ByteOrderedPartitioner.","commonSituations":"Clusters migrated to or running ByteOrderedPartitioner (deprecated, discouraged) with token-allocation options enabled; code written against RandomPartitioner/Murmur3Partitioner reused on a BOP cluster.","solutions":["Switch the cluster partitioner to Murmur3Partitioner (default) if token allocation is desired — requires a full cluster migration otherwise.","Disable token allocation (remove allocate_tokens_for_local_replication_factor) and assign ByteOrderedPartitioner tokens manually.","Guard code paths that call Factory.size with a partitioner check before invoking token allocation."],"exampleFix":"// before\ndouble w = FBUtilities.newPartitioner().getTokenFactory().size(next);\n// after\nIPartitioner p = FBUtilities.newPartitioner();\nif (p instanceof ByteOrderedPartitioner) throw new IllegalStateException(\"Token allocation unsupported for \" + p.getClass().getSimpleName());\ndouble w = p.getTokenFactory().size(next);","handlingStrategy":"type-guard","validationCode":"if (FBUtilities.newPartitioner() instanceof ByteOrderedPartitioner && allocateTokensEnabled)\n    throw new IllegalStateException(\"Token allocation is unsupported with ByteOrderedPartitioner\");","typeGuard":"boolean supportsTokenAllocation(IPartitioner p) { return p instanceof Murmur3Partitioner; }","tryCatchPattern":"try {\n    double s = factory.size(next);\n} catch (UnsupportedOperationException e) {\n    // partitioner does not support allocation; use manual tokens\n}","preventionTips":["Do not enable allocate_tokens_for_local_replication_factor on ByteOrderedPartitioner clusters.","Check partitioner type in tooling before invoking allocation APIs."],"tags":["partitioner","token-allocation","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}