apache/cassandra · error · InvalidRequestException

consistency level %s not compatible with replication strateg

Error message

consistency level %s not compatible with replication strategy (%s)

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/db/ConsistencyLevel.java:300

        if (isSerialConsistency())
            throw new InvalidRequestException("Counter operations are inherently non-serializable");
    }

    /**
     * With a replication factor greater than one, reads that contact more than one replica will require 
     * reconciliation of the individual replica results at the coordinator.
     *
     * @return true if reads at this consistency level require merging at the coordinator
     */
    public boolean needsReconciliation()
    {
        return this != ConsistencyLevel.ONE && this != ConsistencyLevel.LOCAL_ONE && this != ConsistencyLevel.NODE_LOCAL;
    }

    private void requireNetworkTopologyStrategy(AbstractReplicationStrategy replicationStrategy) throws InvalidRequestException
    {
        if (!(replicationStrategy instanceof NetworkTopologyStrategy))
            throw new InvalidRequestException(String.format("consistency level %s not compatible with replication strategy (%s)",
                                                            this, replicationStrategy.getClass().getName()));
    }
}

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Recreate or alter the keyspace to use NetworkTopologyStrategy: ALTER KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','dc1':3}; then run repair.
  2. Use a non-topology-aware consistency level (e.g. QUORUM/ANY) for the CAS commit if single-DC SimpleStrategy is intentional.
  3. Audit all keyspaces with `SELECT keyspace_name, replication FROM system_schema.keyspaces;` before deploying DC-aware LWT code.
  4. Run nodetool repair/refresh schema after changing replication so all nodes agree.

Example fix

// before: keyspace on SimpleStrategy, LOCAL-aware CAS commit fails
CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy','replication_factor':3};
// after
ALTER KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','datacenter1':3};
Defensive patterns

Strategy: validation

Validate before calling

// Verify replication strategy before topology-aware CAS
Row r = session.execute("SELECT replication FROM system_schema.keyspaces WHERE keyspace_name = ?", ks).one();
String cls = r.getMap("replication", String.class, String.class).get("class");
if (!cls.endsWith("NetworkTopologyStrategy"))
    throw new IllegalStateException("keyspace " + ks + " does not use NetworkTopologyStrategy");

Try / catch

catch (InvalidRequestException e) {
    if (e.getMessage().contains("not compatible with replication strategy")) {
        // fall back to non-topology-aware commit CL while migrating keyspace
        statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
        retry();
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Keyspaces created in dev with SimpleStrategy and moved to production multi-DC code; LWT code assuming NetworkTopologyStrategy; missed migration after adding a datacenter.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/6b27bfbbe57cabcf. Report an issue: GitHub.