apache/cassandra · error · InvalidRequestException

Consistency level ANY is not yet supported for counter table

Error message

Consistency level ANY is not yet supported for counter table " + metadata.name

What it means

Counter writes cannot use ANY consistency because counter increments require reading and writing on replicas (a read-modify-write), so recording only a hint as ANY would lose the increment. validateCounterForWrite rejects ANY for writes to counter tables.

Source

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

    public boolean isSerialConsistency()
    {
        switch (this)
        {
            case SERIAL:
            case UNSAFE_DELAY_SERIAL:
            case LOCAL_SERIAL:
            case UNSAFE_DELAY_LOCAL_SERIAL:
                return true;
            default:
                return false;
        }
    }

    public void validateCounterForWrite(TableMetadata metadata) throws InvalidRequestException
    {
        if (this == ConsistencyLevel.ANY)
            throw new InvalidRequestException("Consistency level ANY is not yet supported for counter table " + metadata.name);

        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
    {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use consistency ONE or higher for counter writes (LOCAL_ONE works for DC-local counters).
  2. Ensure default consistency in the driver/session is at least ONE when writing counters.
  3. Change cqlsh with `CONSISTENCY ONE;` before updating counter tables.
  4. Separate counter-write code paths with their own consistency constants.

Example fix

// before
session.execute(SimpleStatement.builder("UPDATE counts SET c = c + 1 WHERE k = 'x'")
    .setConsistencyLevel(ConsistencyLevel.ANY).build());
// after
session.execute(SimpleStatement.builder("UPDATE counts SET c = c + 1 WHERE k = 'x'")
    .setConsistencyLevel(ConsistencyLevel.ONE).build());
Defensive patterns

Strategy: validation

Validate before calling

// Reject ANY for counter writes before sending
if (cl == ConsistencyLevel.ANY && isCounterTable(table))
    throw new IllegalArgumentException("ANY is invalid for counter writes");

Try / catch

catch (InvalidRequestException e) {
    if (e.getMessage().contains("ANY is not yet supported for counter table")) {
        statement.setConsistencyLevel(ConsistencyLevel.ONE);
        retry();
    } else throw e;
}

Prevention

When it happens

Trigger: Executing UPDATE <counter_table> SET c = c + 1 (or a counter INSERT) with consistency level ANY.

Common situations: Generic write helpers defaulting to ANY for 'fire and forget' writes; cqlsh session left at ANY; scripts shared between regular and counter tables.

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/f19e1ac71b6e6111. Report an issue: GitHub.