apache/cassandra · error · InvalidRequestException

ANY ConsistencyLevel is only supported for writes

Error message

ANY ConsistencyLevel is only supported for writes

What it means

ConsistencyLevel.ANY means a write may succeed with zero live replicas (only a hint is recorded). That semantics is meaningless for reads, so validateForRead rejects ANY when a read request specifies it. This is a client request validation error, raised before any data is touched.

Source

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

     * Determine if this consistency level meets or exceeds the consistency requirements of the given cl for the given keyspace
     * WARNING: this is not locality aware; you cannot safely use this with mixed locality consistency levels (e.g. LOCAL_QUORUM and QUORUM)
     */
    public boolean satisfies(ConsistencyLevel other, AbstractReplicationStrategy replicationStrategy)
    {
        return blockFor(replicationStrategy) >= other.blockFor(replicationStrategy);
    }

    public boolean isDatacenterLocal()
    {
        return isDCLocal;
    }

    public void validateForRead() throws InvalidRequestException
    {
        switch (this)
        {
            case ANY:
                throw new InvalidRequestException("ANY ConsistencyLevel is only supported for writes");
        }
    }

    public void validateForWrite() throws InvalidRequestException
    {
        switch (this)
        {
            case SERIAL:
            case UNSAFE_DELAY_SERIAL:
            case LOCAL_SERIAL:
            case UNSAFE_DELAY_LOCAL_SERIAL:
                throw new InvalidRequestException("You must use conditional updates for serializable writes");
        }
    }

    // This is the same than validateForWrite really, but we include a slightly different error message for SERIAL/LOCAL_SERIAL
    public void validateForCasCommit(AbstractReplicationStrategy replicationStrategy) throws InvalidRequestException
    {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use ONE for reads where latency matters and some staleness is acceptable.
  2. Use QUORUM or LOCAL_QUORUM when read consistency must match write quorums.
  3. In cqlsh, run `CONSISTENCY ONE;` (or similar) before issuing reads.
  4. Split read and write consistency constants in application code instead of sharing one value.

Example fix

// before
session.execute(SimpleStatement.builder("SELECT * FROM t").setConsistencyLevel(ConsistencyLevel.ANY).build());
// after
session.execute(SimpleStatement.builder("SELECT * FROM t").setConsistencyLevel(ConsistencyLevel.ONE).build());
Defensive patterns

Strategy: validation

Validate before calling

// Guard before executing a read
private static final Set<ConsistencyLevel> READ_OK =
    Set.of(ConsistencyLevel.ONE, ConsistencyLevel.TWO, ConsistencyLevel.THREE,
           ConsistencyLevel.QUORUM, ConsistencyLevel.ALL,
           ConsistencyLevel.LOCAL_ONE, ConsistencyLevel.LOCAL_QUORUM);
if (!READ_OK.contains(cl)) throw new IllegalArgumentException("ANY not valid for reads");

Try / catch

catch (InvalidRequestException e) {
    if (e.getMessage().contains("ANY ConsistencyLevel")) {
        statement.setConsistencyLevel(ConsistencyLevel.ONE); // retry at ONE
    } else throw e;
}

Prevention

When it happens

Trigger: Executing a SELECT (or read-path statement) with consistency level ANY, e.g. `CONSISTENCY ANY;` in cqlsh followed by a SELECT, or setting cl=ANY on a read in a driver.

Common situations: cqlsh session left at ANY after testing writes; scripts that reuse one consistency constant for all operations; misunderstanding of ANY's write-only semantics.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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