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
- Use ONE for reads where latency matters and some staleness is acceptable.
- Use QUORUM or LOCAL_QUORUM when read consistency must match write quorums.
- In cqlsh, run `CONSISTENCY ONE;` (or similar) before issuing reads.
- 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
- Keep separate read/write consistency constants in application config.
- Never set session-global ANY in cqlsh; scope it to specific write statements.
- Code-review consistency-level literals; prefer named enums over magic values.
- Add unit tests asserting read paths use read-safe consistency levels.
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
- this + " is not supported as conditional update commit consi
- Invalid consistency for conditional update. Must be one of S
- Consistency level ANY is not yet supported for counter table
- REVOKE operation is not supported by AllowAllAuthorizer
- %s is not a valid data resource name
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/66d82f76d949c22b.
Report an issue: GitHub.