{"record":{"id":"f19e1ac71b6e6111","repo":"apache/cassandra","slug":"consistency-level-any-is-not-yet-supported-for-cou","errorCode":null,"errorMessage":"Consistency level ANY is not yet supported for counter table \" + metadata.name","messagePattern":"Consistency level ANY is not yet supported for counter table \" \\+ metadata\\.name","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/ConsistencyLevel.java","lineNumber":280,"sourceCode":"\n    public boolean isSerialConsistency()\n    {\n        switch (this)\n        {\n            case SERIAL:\n            case UNSAFE_DELAY_SERIAL:\n            case LOCAL_SERIAL:\n            case UNSAFE_DELAY_LOCAL_SERIAL:\n                return true;\n            default:\n                return false;\n        }\n    }\n\n    public void validateCounterForWrite(TableMetadata metadata) throws InvalidRequestException\n    {\n        if (this == ConsistencyLevel.ANY)\n            throw new InvalidRequestException(\"Consistency level ANY is not yet supported for counter table \" + metadata.name);\n\n        if (isSerialConsistency())\n            throw new InvalidRequestException(\"Counter operations are inherently non-serializable\");\n    }\n\n    /**\n     * With a replication factor greater than one, reads that contact more than one replica will require \n     * reconciliation of the individual replica results at the coordinator.\n     *\n     * @return true if reads at this consistency level require merging at the coordinator\n     */\n    public boolean needsReconciliation()\n    {\n        return this != ConsistencyLevel.ONE && this != ConsistencyLevel.LOCAL_ONE && this != ConsistencyLevel.NODE_LOCAL;\n    }\n\n    private void requireNetworkTopologyStrategy(AbstractReplicationStrategy replicationStrategy) throws InvalidRequestException\n    {","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/ConsistencyLevel.java#L262-L298","documentation":"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.","triggerScenarios":"Executing UPDATE <counter_table> SET c = c + 1 (or a counter INSERT) with consistency level ANY.","commonSituations":"Generic write helpers defaulting to ANY for 'fire and forget' writes; cqlsh session left at ANY; scripts shared between regular and counter tables.","solutions":["Use consistency ONE or higher for counter writes (LOCAL_ONE works for DC-local counters).","Ensure default consistency in the driver/session is at least ONE when writing counters.","Change cqlsh with `CONSISTENCY ONE;` before updating counter tables.","Separate counter-write code paths with their own consistency constants."],"exampleFix":"// before\nsession.execute(SimpleStatement.builder(\"UPDATE counts SET c = c + 1 WHERE k = 'x'\")\n    .setConsistencyLevel(ConsistencyLevel.ANY).build());\n// after\nsession.execute(SimpleStatement.builder(\"UPDATE counts SET c = c + 1 WHERE k = 'x'\")\n    .setConsistencyLevel(ConsistencyLevel.ONE).build());","handlingStrategy":"validation","validationCode":"// Reject ANY for counter writes before sending\nif (cl == ConsistencyLevel.ANY && isCounterTable(table))\n    throw new IllegalArgumentException(\"ANY is invalid for counter writes\");","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"ANY is not yet supported for counter table\")) {\n        statement.setConsistencyLevel(ConsistencyLevel.ONE);\n        retry();\n    } else throw e;\n}","preventionTips":["Never default write consistency to ANY in shared clients; use ONE minimum.","Tag counter-write code paths and enforce their own consistency policy in review.","Reset cqlsh consistency after ad-hoc ANY experiments.","Add integration tests covering counter writes at production consistency settings."],"tags":["cassandra","consistency-level","counter","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}