{"record":{"id":"5d70816c24ef20c3","repo":"apache/cassandra","slug":"replication-factor-should-not-appear-as-an-option-5d7081","errorCode":null,"errorMessage":"replication_factor should not appear as an option to NetworkTopologyStrategy","messagePattern":"replication_factor should not appear as an option to NetworkTopologyStrategy","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/locator/NetworkTopologyStrategy.java","lineNumber":380,"sourceCode":"        if (keyspaceName.equalsIgnoreCase(SchemaConstants.AUTH_KEYSPACE_NAME))\n        {\n            Set<String> differenceSet = Sets.difference(metadata.directory.knownDatacenters(), configOptions.keySet());\n            if (!differenceSet.isEmpty())\n            {\n                throw new ConfigurationException(\"Following datacenters have active nodes and must be present in replication options for keyspace \" + SchemaConstants.AUTH_KEYSPACE_NAME + \": \" + differenceSet.toString());\n            }\n        }\n        logger.info(\"Configured datacenter replicas are {}\", FBUtilities.toString(datacenters));\n    }\n\n    @Override\n    public void validateOptions() throws ConfigurationException\n    {\n        for (Entry<String, String> e : this.configOptions.entrySet())\n        {\n            // prepareOptions should have transformed any \"replication_factor\" by now\n            if (e.getKey().equalsIgnoreCase(REPLICATION_FACTOR))\n                throw new ConfigurationException(REPLICATION_FACTOR + \" should not appear as an option to NetworkTopologyStrategy\");\n            validateReplicationFactor(e.getValue());\n        }\n    }\n\n    @Override\n    public void maybeWarnOnOptions(ClientState state)\n    {\n        if (!SchemaConstants.isSystemKeyspace(keyspaceName))\n        {\n            Directory directory = ClusterMetadata.current().directory;\n            Multimap<String, InetAddressAndPort> dcsNodes = directory.allDatacenterEndpoints();\n            for (Entry<String, String> e : this.configOptions.entrySet())\n            {\n                String dc = e.getKey();\n                ReplicationFactor rf = getReplicationFactor(dc);\n                Guardrails.minimumReplicationFactor.guard(rf.fullReplicas, keyspaceName, false, state);\n                Guardrails.maximumReplicationFactor.guard(rf.fullReplicas, keyspaceName, false, state);\n                int nodeCount = dcsNodes.containsKey(dc) ? dcsNodes.get(dc).size() : 0;","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/locator/NetworkTopologyStrategy.java#L362-L398","documentation":"NetworkTopologyStrategy assigns replication per datacenter (e.g. 'dc1': 3) and does not accept a flat 'replication_factor' option. prepareOptions normally converts legacy SimpleStrategy-style options, but if a literal 'replication_factor' key remains in the options when validateOptions runs, this ConfigurationException is thrown to reject the invalid configuration.","triggerScenarios":"CREATE/ALTER KEYSPACE with {'class':'NetworkTopologyStrategy','replication_factor':'3'} — i.e. passing a replication_factor option that was not normalized by prepareOptions.","commonSituations":"Copy-pasting a SimpleStrategy replication definition when switching strategies; migration scripts converting keyspaces from SimpleStrategy; hand-edited schema files.","solutions":["Remove 'replication_factor' from the options and specify per-DC factors instead: {'class':'NetworkTopologyStrategy','dc1':3,'dc2':2}","Run ALTER KEYSPACE with the corrected replication map and repair as needed","Check for tooling/ORM layers that inject replication_factor and fix their strategy templates"],"exampleFix":"// before\nCREATE KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','replication_factor':3};\n// after\nCREATE KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','dc1':3,'dc2':3};","handlingStrategy":"validation","validationCode":"if (replicationOpts.containsKey(\"replication_factor\") && \"NetworkTopologyStrategy\".equals(replicationOpts.get(\"class\")))\n    throw new IllegalArgumentException(\"replication_factor is invalid for NetworkTopologyStrategy; use per-DC values\");","typeGuard":null,"tryCatchPattern":"try { session.execute(alterKeyspaceCql); } catch (InvalidQueryException e) { if (e.getMessage().contains(\"replication_factor\")) { /* strip the option and retry */ } }","preventionTips":["Use per-DC replication maps when strategy is NetworkTopologyStrategy","Audit migration scripts that convert SimpleStrategy to NetworkTopologyStrategy","Keep strategy templates per strategy class in tooling"],"tags":["configuration","replication","invalid-option"],"backgroundTag":"unsupported-config-value","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"}