{"record":{"id":"7ac4b184926391d1","repo":"apache/cassandra","slug":"caswritetimeoutexception-writetype-cas-consistenc-7ac4b1","errorCode":null,"errorMessage":"CasWriteTimeoutException(writeType=CAS, consistency=%s, received=%s, blockFor=%s, contentions=%s)","messagePattern":"CasWriteTimeoutException\\(writeType=CAS, consistency=(.+?), received=(.+?), blockFor=(.+?), contentions=(.+?)\\)","errorType":"exception","errorClass":"CasWriteTimeoutException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/StorageProxy.java","lineNumber":776,"sourceCode":"                // mean we lost messages), we pro-actively \"repair\" those nodes, and retry.\n                Iterable<InetAddressAndPort> missingMRC = summary.replicasMissingMostRecentCommit(metadata);\n                if (Iterables.size(missingMRC) > 0)\n                {\n                    Tracing.trace(\"Repairing replicas that missed the most recent commit\");\n                    sendCommit(mostRecent, consistencyForPaxos, missingMRC);\n                    // TODO: provided commits don't invalid the prepare we just did above (which they don't), we could just wait\n                    // for all the missingMRC to acknowledge this commit and then move on with proposing our value. But that means\n                    // adding the ability to have commitPaxos block, which is exactly CASSANDRA-5442 will do. So once we have that\n                    // latter ticket, we can pass CL.ALL to the commit above and remove the 'continue'.\n                    continue;\n                }\n\n                return new PaxosBallotAndContention(ballot, contentions);\n            }\n            catch (WriteTimeoutException e)\n            {\n                // We're still doing preparation for the paxos rounds, so we want to use the CAS (see CASSANDRA-8672)\n                throw new CasWriteTimeoutException(WriteType.CAS, e.consistency, e.received, e.blockFor, contentions);\n            }\n        }\n\n        throw new CasWriteTimeoutException(WriteType.CAS, consistencyForPaxos, 0, consistencyForPaxos.blockFor(paxosPlan.replicationStrategy()), contentions);\n    }\n\n    /**\n     * Unlike commitPaxos, this does not wait for replies\n     */\n    private static void sendCommit(Commit commit, ConsistencyLevel consistencyForPaxos, Iterable<InetAddressAndPort> replicas)\n    {\n        Message<Commit> message = Message.out(PAXOS_COMMIT_REQ, commit);\n        for (InetAddressAndPort target : replicas)\n            MessagingService.instance().send(message, target);\n    }\n\n    private static PrepareCallback preparePaxos(Commit toPrepare, ReplicaPlan.ForPaxosWrite replicaPlan, Dispatcher.RequestTime requestTime)\n    throws WriteTimeoutException","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/StorageProxy.java#L758-L794","documentation":"beginAndRepairPaxos converts a WriteTimeoutException observed while preparing/repairing the Paxos ballot into a CasWriteTimeoutException with writeType=CAS, preserving the original received/blockFor. Per CASSANDRA-8672 the write type is reported as CAS because the failure occurs during Paxos preparation, not a normal write.","triggerScenarios":"During a CAS, the initial Paxos prepare/retry loop fails because a replica with a promised in-progress ballot times out on the prepare round; called from the pair()/execute path.","commonSituations":"A previous LWT coordinator died mid-ballot leaving an in-progress Paxos state that must be completed; slow replicas during the prepare phase; repeated contention increments.","solutions":["Retry the operation; a new coordinator will complete the stale ballot and proceed.","Increase cas_contention_timeout_in_ms and write_request_timeout_in_ms.","Investigate replicas with GC pauses or network issues that slow the prepare rounds.","Reduce LWT concurrency on the partition to avoid repeated ballot contention."],"exampleFix":"// before\nConsistencyLevel cl = ConsistencyLevel.SERIAL; // cross-dc LWT, slow prepares\n// after\nConsistencyLevel cl = ConsistencyLevel.LOCAL_SERIAL; // localize paxos rounds","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    session.execute(lwt);\n} catch (CasWriteTimeoutException e) {\n    // prepare-phase timeout; safe to retry with a fresh ballot\n    retryWithBackoff(lwt);\n}","preventionTips":["Ensure crashed coordinators' ballots complete quickly (healthy replicas).","Tune cas_contention_timeout_in_ms and write_request_timeout_in_ms together.","Use LOCAL_SERIAL where possible to shorten prepare rounds."],"tags":["timeout","paxos","lightweight-transactions","ballot"],"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"}