{"record":{"id":"aa3ba901751a989c","repo":"apache/cassandra","slug":"caswritetimeoutexception-writetype-s-consistency","errorCode":null,"errorMessage":"CasWriteTimeoutException(writeType=%s, consistency=%s, received=%s, blockFor=%s, contentions=%s)","messagePattern":"CasWriteTimeoutException\\(writeType=(.+?), consistency=(.+?), received=(.+?), blockFor=(.+?), contentions=(.+?)\\)","errorType":"exception","errorClass":"CasWriteTimeoutException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/StorageProxy.java","lineNumber":505,"sourceCode":"            return casResult(doPaxos(metadata,\n                                     key,\n                                     consistencyForPaxos,\n                                     consistencyForCommit,\n                                     consistencyForCommit,\n                                     requestTime,\n                                     casWriteMetrics,\n                                     updateProposer));\n        }\n        catch (CasWriteUnknownResultException e)\n        {\n            casWriteMetrics.unknownResult.mark();\n            throw e;\n        }\n        catch (CasWriteTimeoutException wte)\n        {\n            casWriteMetrics.timeouts.mark();\n            writeMetricsForLevel(consistencyForPaxos).timeouts.mark();\n            throw new CasWriteTimeoutException(wte.writeType, wte.consistency, wte.received, wte.blockFor, wte.contentions);\n        }\n        catch (ReadTimeoutException e)\n        {\n            casWriteMetrics.timeouts.mark();\n            writeMetricsForLevel(consistencyForPaxos).timeouts.mark();\n            throw e;\n        }\n        catch (ReadAbortException e)\n        {\n            casWriteMetrics.markAbort(e);\n            writeMetricsForLevel(consistencyForPaxos).markAbort(e);\n            throw e;\n        }\n        catch (WriteFailureException | ReadFailureException e)\n        {\n            casWriteMetrics.failures.mark();\n            writeMetricsForLevel(consistencyForPaxos).failures.mark();\n            throw e;","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/StorageProxy.java#L487-L523","documentation":"legacyCas rethrows a CasWriteTimeoutException (with metrics marked) when the Paxos-based CAS write timed out before a quorum acknowledged. The exception carries writeType, consistency level, received/blockFor replica counts, and the number of contentions observed. It means the LWT did not commit within the write timeout.","triggerScenarios":"Executing a lightweight transaction via legacyCas when proposePaxos/commitPaxos raises WriteTimeoutException, converted to CasWriteTimeoutException with the original received/blockFor values; typically under contention or with slow replicas.","commonSituations":"LWT under heavy contention on a hot row; one replica down so quorum can't be met within write_request_timeout_in_ms; cross-DC LWT with high latency.","solutions":["Retry the CAS operation; timeout under contention is safe to retry (the transaction did not commit).","Increase write_request_timeout_in_ms if timeouts occur due to latency, not contention.","Reduce contention (rate-limit writes to the contested key) or shard work across more partition keys.","Check replica availability; ensure quorum of replicas is up and reachable."],"exampleFix":"// before\nsession.execute(\"UPDATE stock SET n = n - 1 WHERE sku = ? IF n > 0\", sku);\n// after: catch and retry with backoff\ntry {\n    session.execute(\"UPDATE stock SET n = n - 1 WHERE sku = ? IF n > 0\", sku);\n} catch (CasWriteTimeoutException e) {\n    Thread.sleep(50 * e.getContentions());\n    // retry the same LWT\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    session.execute(lwt);\n} catch (CasWriteTimeoutException e) {\n    Thread.sleep(Math.min(1000L, 20L * e.getContentions()));\n    // safe to retry: the transaction did not commit\n}","preventionTips":["Minimize writers contending on the same LWT partition.","Tune write_request_timeout_in_ms for your latency profile (cross-DC needs more).","Alert on casWriteMetrics.timeouts rate."],"tags":["timeout","lightweight-transactions","paxos","contention"],"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"}