{"record":{"id":"7f866e8cbd68c5f3","repo":"apache/cassandra","slug":"replication-factor-should-not-appear-as-an-option","errorCode":null,"errorMessage":"replication_factor should not appear as an option at construction time for NetworkTopologyStrategy","messagePattern":"replication_factor should not appear as an option at construction time for NetworkTopologyStrategy","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/locator/NetworkTopologyStrategy.java","lineNumber":95,"sourceCode":"    private final Map<String, ReplicationFactor> datacenters;\n    private final ReplicationFactor aggregateRf;\n    private static final Logger logger = LoggerFactory.getLogger(NetworkTopologyStrategy.class);\n\n    public NetworkTopologyStrategy(String keyspaceName, Map<String, String> configOptions) throws ConfigurationException\n    {\n        super(keyspaceName, configOptions);\n\n        int replicas = 0;\n        int trans = 0;\n        Map<String, ReplicationFactor> newDatacenters = new HashMap<>();\n        if (configOptions != null)\n        {\n            for (Entry<String, String> entry : configOptions.entrySet())\n            {\n                String dc = entry.getKey();\n                // prepareOptions should have transformed any \"replication_factor\" options by now\n                if (dc.equalsIgnoreCase(REPLICATION_FACTOR))\n                    throw new ConfigurationException(REPLICATION_FACTOR + \" should not appear as an option at construction time for NetworkTopologyStrategy\");\n                ReplicationFactor rf = ReplicationFactor.fromString(entry.getValue());\n                replicas += rf.allReplicas;\n                trans += rf.transientReplicas();\n                newDatacenters.put(dc, rf);\n            }\n        }\n\n        datacenters = Collections.unmodifiableMap(newDatacenters);\n        aggregateRf = ReplicationFactor.withTransient(replicas, trans);\n    }\n\n    /**\n     * Endpoint adder applying the replication rules for a given DC.\n     */\n    private static final class DatacenterEndpoints\n    {\n        /** List accepted endpoints get pushed into. */\n        EndpointsForRange.Builder replicas;","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/locator/NetworkTopologyStrategy.java#L77-L113","documentation":"NetworkTopologyStrategy assigns replication per datacenter, so a single global replication_factor option is meaningless. prepareOptions normally strips/transforms replication_factor into per-DC entries; if one still reaches the constructor, this ConfigurationException fires because the schema/creation path bypassed the transformation.","triggerScenarios":"CREATE KEYSPACE ... WITH replication = {'class':'NetworkTopologyStrategy','replication_factor':3} — replication_factor appears in configOptions at construction time, meaning prepareOptions did not remove it (e.g. direct constructor use or altered options map).","commonSituations":"Users porting SimpleStrategy configs to NetworkTopologyStrategy without converting replication_factor into per-DC options; tooling/migration scripts building strategy options programmatically; drivers or ORMs generating invalid replication maps.","solutions":["Replace replication_factor with explicit per-DC options: {'class':'NetworkTopologyStrategy','dc1':'3','dc2':'2'}","Fix the calling code so prepareOptions() runs before constructing NetworkTopologyStrategy","Use system_schema keyspace description to inspect and ALTER the keyspace replication settings correctly","If a default-per-DC factor is wanted, generate explicit per-DC values in tooling rather than passing replication_factor"],"exampleFix":"// before\nCREATE KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','replication_factor':3};\n// after\nCREATE KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','dc1':'3'};","handlingStrategy":"validation","validationCode":"Map<String,String> opts = replicationOptions;\nif (\"NetworkTopologyStrategy\".equals(opts.get(\"class\")) && opts.containsKey(\"replication_factor\")) throw new IllegalArgumentException(\"Use per-DC replication options instead of replication_factor\");","typeGuard":null,"tryCatchPattern":"try { session.execute(createKs); }\ncatch (InvalidQueryException e) { /* fix replication map: drop replication_factor */ }","preventionTips":["Never mix SimpleStrategy-style options into NetworkTopologyStrategy","Validate replication maps in schema-migration tooling","Generate per-DC options programmatically when automating keyspace creation"],"tags":["cql","replication","schema","networktopologystrategy"],"backgroundTag":"conflicting-config-options","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}