apache/cassandra · error · InvalidRequestException

Counter operations are inherently non-serializable

Error message

Counter operations are inherently non-serializable

What it means

Counter increments are implemented as non-commutative-safe read-modify-writes on replicas and are not coordinated through Paxos, so a serial consistency is meaningless for them. validateCounterForWrite rejects serial consistency levels on counter writes with this message.

Source

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

        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
    {
        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. Remove serial consistency from counter write statements; counters are inherently not serializable.
  2. Use regular consistency levels (QUORUM/LOCAL_QUORUM) for stronger counter write durability.
  3. If linearizability is required, move that state to a non-counter table with LWTs, or use an external coordination service.
  4. Scope serial-consistency configuration to LWT statements only.

Example fix

// before
stmt.setSerialConsistencyLevel(ConsistencyLevel.SERIAL); // on counter update
// after
stmt.setSerialConsistencyLevel(null); // use default; counters cannot be serializable
stmt.setConsistencyLevel(ConsistencyLevel.QUORUM);
Defensive patterns

Strategy: validation

Validate before calling

// Guard serial CL on counter writes
if (isCounterTable(table) && serialCl != null)
    throw new IllegalArgumentException("counters cannot use serial consistency");

Try / catch

catch (InvalidRequestException e) {
    if (e.getMessage().contains("Counter operations are inherently non-serializable")) {
        statement.setSerialConsistencyLevel(null); // clear serial CL
        statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
        retry();
    } else throw e;
}

Prevention

When it happens

Trigger: Executing a counter UPDATE/INSERT with consistency (or serial consistency) SERIAL or LOCAL_SERIAL, e.g. applying an application-wide serializable policy to counter tables.

Common situations: Global 'serializable mode' config applied to all statements; confusion between LWT-capable (non-counter) and counter tables; framework defaults propagating serial consistency.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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