{"record":{"id":"ec1d97b8d7f3a057","repo":"apache/cassandra","slug":"caswritetimeoutexception-writetype-cas-consistenc","errorCode":null,"errorMessage":"CasWriteTimeoutException(writeType=CAS, consistency=%s, received=0, blockFor=%s, contentions=%s)","messagePattern":"CasWriteTimeoutException\\(writeType=CAS, consistency=(.+?), received=0, blockFor=(.+?), contentions=(.+?)\\)","errorType":"exception","errorClass":"CasWriteTimeoutException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/StorageProxy.java","lineNumber":666,"sourceCode":"        catch (CasWriteTimeoutException e)\n        {\n            // Might be thrown by beginRepairAndPaxos. In that case, any contention that happened within the method and\n            // led up to the timeout was not accounted in our local 'contentions' variable and we add it now so it the\n            // contention recorded in the finally is correct.\n            contentions += e.contentions;\n            throw e;\n        }\n        catch (WriteTimeoutException e)\n        {\n            // Might be thrown by proposePaxos or commitPaxos\n            throw new CasWriteTimeoutException(e.writeType, e.consistency, e.received, e.blockFor, contentions);\n        }\n        finally\n        {\n            recordCasContention(metadata, key, casMetrics, contentions);\n        }\n\n        throw new CasWriteTimeoutException(WriteType.CAS, consistencyForPaxos, 0, consistencyForPaxos.blockFor(latestRs), contentions);\n    }\n\n    /**\n     * begin a Paxos session by sending a prepare request and completing any in-progress requests seen in the replies\n     *\n     * @return the Paxos ballot promised by the replicas if no in-progress requests were seen and a quorum of\n     * nodes have seen the mostRecentCommit.  Otherwise, return null.\n     */\n    private static PaxosBallotAndContention beginAndRepairPaxos(Dispatcher.RequestTime requestTime,\n                                                                DecoratedKey key,\n                                                                TableMetadata metadata,\n                                                                ReplicaPlan.ForPaxosWrite paxosPlan,\n                                                                ConsistencyLevel consistencyForPaxos,\n                                                                ConsistencyLevel consistencyForCommit,\n                                                                CASClientRequestMetrics casMetrics)\n    throws WriteTimeoutException, WriteFailureException\n    {\n        long timeoutNanos = DatabaseDescriptor.getCasContentionTimeout(NANOSECONDS);","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/StorageProxy.java#L648-L684","documentation":"After the Paxos rounds in doPaxos exhaust their deadline without success, Cassandra throws a synthetic CasWriteTimeoutException with received=0 and writeType=CAS, indicating the overall Paxos attempt budget expired rather than a single RPC timing out. contentions reports how often concurrent ballots were seen.","triggerScenarios":"A CAS whose Paxos loop (beginAndRepairPaxos plus propose/commit) could not complete within cas_contention_timeout_in_ms — typically sustained contention on the same partition — so doPaxos falls out of the loop and throws with received=0.","commonSituations":"Many clients performing LWTs on one hot row (queue-head patterns); long-running in-progress Paxos ballots requiring repeated repair rounds; cas_contention_timeout too low for the workload.","solutions":["Increase cas_contention_timeout_in_ms so the Paxos loop gets more time to win.","Redesign the hot-key workload: avoid many writers contending on one LWT row (batch, queue sharding, or move to a non-LWT strategy).","Retry with exponential backoff; the transaction did not apply.","Upgrade away from legacy Paxos to the newer Paxos implementation / Accord-based paths if available."],"exampleFix":"// before\ncassandra.yaml: cas_contention_timeout_in_ms: 1000\n// after\ncassandra.yaml: cas_contention_timeout_in_ms: 10000","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    session.execute(lwt);\n} catch (CasWriteTimeoutException e) {\n    if (e.getContentions() > 0) backoffExponentially(e.getContentions());\n    retry(lwt);\n}","preventionTips":["Size cas_contention_timeout_in_ms above worst-case Paxos round-trip plus retries.","Avoid hot-row CAS loops; shard keys or redesign to reduce write contention.","Watch recordCasContention metrics / contention logs per partition."],"tags":["timeout","paxos","contention","lightweight-transactions"],"backgroundTag":"request-timeout","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"}