{"record":{"id":"6b27bfbbe57cabcf","repo":"apache/cassandra","slug":"consistency-level-s-not-compatible-with-replicati","errorCode":null,"errorMessage":"consistency level %s not compatible with replication strategy (%s)","messagePattern":"consistency level (.+?) not compatible with replication strategy \\((.+?)\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/ConsistencyLevel.java","lineNumber":300,"sourceCode":"        if (isSerialConsistency())\n            throw new InvalidRequestException(\"Counter operations are inherently non-serializable\");\n    }\n\n    /**\n     * With a replication factor greater than one, reads that contact more than one replica will require \n     * reconciliation of the individual replica results at the coordinator.\n     *\n     * @return true if reads at this consistency level require merging at the coordinator\n     */\n    public boolean needsReconciliation()\n    {\n        return this != ConsistencyLevel.ONE && this != ConsistencyLevel.LOCAL_ONE && this != ConsistencyLevel.NODE_LOCAL;\n    }\n\n    private void requireNetworkTopologyStrategy(AbstractReplicationStrategy replicationStrategy) throws InvalidRequestException\n    {\n        if (!(replicationStrategy instanceof NetworkTopologyStrategy))\n            throw new InvalidRequestException(String.format(\"consistency level %s not compatible with replication strategy (%s)\",\n                                                            this, replicationStrategy.getClass().getName()));\n    }\n}\n","sourceCodeStart":282,"sourceCodeEnd":304,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/ConsistencyLevel.java#L282-L304","documentation":"requireNetworkTopologyStrategy enforces that the keyspace's AbstractReplicationStrategy is a NetworkTopologyStrategy before applying topology-sensitive consistency checks (used by the CAS commit path). When the keyspace uses e.g. SimpleStrategy, the requested DC-aware consistency cannot be validated, so this InvalidRequestException is thrown naming the consistency level and strategy class.","triggerScenarios":"Performing a lightweight-transaction commit with a DC/topology-aware consistency level (e.g. EACH_QUORUM / LOCAL paths in validateForCasCommit) against a keyspace created with SimpleStrategy.","commonSituations":"Keyspaces created in dev with SimpleStrategy and moved to production multi-DC code; LWT code assuming NetworkTopologyStrategy; missed migration after adding a datacenter.","solutions":["Recreate or alter the keyspace to use NetworkTopologyStrategy: ALTER KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','dc1':3}; then run repair.","Use a non-topology-aware consistency level (e.g. QUORUM/ANY) for the CAS commit if single-DC SimpleStrategy is intentional.","Audit all keyspaces with `SELECT keyspace_name, replication FROM system_schema.keyspaces;` before deploying DC-aware LWT code.","Run nodetool repair/refresh schema after changing replication so all nodes agree."],"exampleFix":"// before: keyspace on SimpleStrategy, LOCAL-aware CAS commit fails\nCREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy','replication_factor':3};\n// after\nALTER KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','datacenter1':3};","handlingStrategy":"validation","validationCode":"// Verify replication strategy before topology-aware CAS\nRow r = session.execute(\"SELECT replication FROM system_schema.keyspaces WHERE keyspace_name = ?\", ks).one();\nString cls = r.getMap(\"replication\", String.class, String.class).get(\"class\");\nif (!cls.endsWith(\"NetworkTopologyStrategy\"))\n    throw new IllegalStateException(\"keyspace \" + ks + \" does not use NetworkTopologyStrategy\");","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"not compatible with replication strategy\")) {\n        // fall back to non-topology-aware commit CL while migrating keyspace\n        statement.setConsistencyLevel(ConsistencyLevel.QUORUM);\n        retry();\n    } else throw e;\n}","preventionTips":["Standardize on NetworkTopologyStrategy for all production keyspaces, even single-DC ones.","Check system_schema.keyspaces replication config during deployment health checks.","After ALTER KEYSPACE changes, run repair and verify schema agreement on all nodes.","Keep dev/prod replication configs aligned to catch strategy mismatches before production."],"tags":["cassandra","consistency-level","replication-strategy","lwt"],"backgroundTag":"invalid-config-value","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"}