{"record":{"id":"feafa8cde0f73785","repo":"apache/cassandra","slug":"token-allocation-does-not-support-replication-stra","errorCode":null,"errorMessage":"Token allocation does not support replication strategy ","messagePattern":"Token allocation does not support replication strategy ","errorType":"exception","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/dht/tokenallocator/TokenAllocation.java","lineNumber":260,"sourceCode":"\n    private StrategyAdapter getOrCreateStrategy(InetAddressAndPort endpoint)\n    {\n        Location location = metadata.locator.location(endpoint);\n        return getOrCreateStrategy(location.datacenter, location.rack);\n    }\n\n    private StrategyAdapter getOrCreateStrategy(String dc, String rack)\n    {\n        return strategyByRackDc.computeIfAbsent(dc, k -> new HashMap<>()).computeIfAbsent(rack, k -> createStrategy(dc, rack));\n    }\n\n    private StrategyAdapter createStrategy(String dc, String rack)\n    {\n        if (replicationStrategy instanceof NetworkTopologyStrategy)\n            return createStrategy(metadata, (NetworkTopologyStrategy) replicationStrategy, dc, rack);\n        if (replicationStrategy instanceof SimpleStrategy)\n            return createStrategy(metadata, (SimpleStrategy) replicationStrategy);\n        throw new ConfigurationException(\"Token allocation does not support replication strategy \" + replicationStrategy.getClass().getSimpleName());\n    }\n\n    private StrategyAdapter createStrategy(ClusterMetadata metadata, final SimpleStrategy rs)\n    {\n        return createStrategy(() -> metadata.locator, null, null, rs.getReplicationFactor().allReplicas, false);\n    }\n\n    private StrategyAdapter createStrategy(ClusterMetadata metadata, NetworkTopologyStrategy strategy, String dc, String rack)\n    {\n        int replicas = strategy.getReplicationFactor(dc).allReplicas;\n\n        // if topology hasn't been setup yet for this dc+rack then treat it as a separate unit\n        Multimap<String, InetAddressAndPort> datacenterRacks = metadata.directory.datacenterRacks(dc);\n        Supplier<Locator> locator = () -> metadata.locator;\n        int racks = datacenterRacks != null && datacenterRacks.containsKey(rack)\n                ? datacenterRacks.asMap().size()\n                : 1;\n","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/dht/tokenallocator/TokenAllocation.java#L242-L278","documentation":"TokenAllocation only supports NetworkTopologyStrategy and SimpleStrategy replication strategies. When createStrategy encounters any other strategy (e.g. LocalStrategy or a custom IReplicationStrategy subclass) it throws ConfigurationException because no StrategyAdapter can be produced for computing allocation weights.","triggerScenarios":"Calling TokenAllocation.allocate (via createStrategy/getOrCreateStrategy) for a keyspace whose replication strategy is neither NetworkTopologyStrategy nor SimpleStrategy.","commonSituations":"Trying to allocate tokens for a keyspace using LocalStrategy (system keyspaces) or a third-party custom replication strategy.","solutions":["Use a supported strategy (SimpleStrategy or NetworkTopologyStrategy) on the keyspace being allocated for","If you need allocation for a custom strategy, implement a corresponding StrategyAdapter in TokenAllocation","Target a different keyspace when invoking token allocation","Check the keyspace's strategy via cqlsh: DESCRIBE KEYSPACE"],"exampleFix":"// before\ncqlsh> ALTER KEYSPACE myks WITH replication = {'class':'MyCustomStrategy','replication_factor':3};\n// token allocation fails\n// after\ncqlsh> ALTER KEYSPACE myks WITH replication = {'class':'NetworkTopologyStrategy','dc1':3};","handlingStrategy":"validation","validationCode":"// before allocation, check the strategy\nString cls = Keyspace.open(ks).getReplicationStrategy().getClass().getSimpleName();\nif (!cls.equals(\"NetworkTopologyStrategy\") && !cls.equals(\"SimpleStrategy\"))\n    throw new IllegalArgumentException(\"Unsupported strategy for token allocation: \" + cls);","typeGuard":null,"tryCatchPattern":"try {\n    TokenAllocation.allocate(metadata, ks, dc);\n} catch (ConfigurationException e) {\n    if (e.getMessage().contains(\"does not support replication strategy\")) {\n        // switch keyspace to NetworkTopologyStrategy or pick another keyspace\n    }\n}","preventionTips":["Use NetworkTopologyStrategy or SimpleStrategy for keyspaces you allocate tokens for","Never target system keyspaces (LocalStrategy) with token allocation","Review DESCRIBE KEYSPACE before running allocation tooling"],"tags":["token-allocation","replication-strategy","config"],"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"}