{"record":{"id":"f33e28e44e98f23a","repo":"apache/cassandra","slug":"writetimeoutexception-writetype-view-consistency","errorCode":null,"errorMessage":"WriteTimeoutException (WriteType.VIEW, ConsistencyLevel.LOCAL_ONE, 0, 1)","messagePattern":"WriteTimeoutException \\(WriteType\\.VIEW, ConsistencyLevel\\.LOCAL_ONE, 0, 1\\)","errorType":"exception","errorClass":"WriteTimeoutException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/Keyspace.java","lineNumber":500,"sourceCode":"\n                    if (lock == null)\n                    {\n                        //throw WTE only if request is droppable\n                        if (isDroppable && (approxTime.isAfter(mutation.approxCreatedAtNanos + DatabaseDescriptor.getWriteRpcTimeout(NANOSECONDS))))\n                        {\n                            for (int j = 0; j < i; j++)\n                                locks[j].unlock();\n\n                            if (logger.isTraceEnabled())\n                                logger.trace(\"Could not acquire lock for {} and table {}\", ByteBufferUtil.bytesToHex(mutation.key().getKey()), columnFamilyStores.get(tableId).name);\n                            Tracing.trace(\"Could not acquire MV lock\");\n                            if (future != null)\n                            {\n                                future.tryFailure(new WriteTimeoutException(WriteType.VIEW, ConsistencyLevel.LOCAL_ONE, 0, 1));\n                                return future;\n                            }\n                            else\n                                throw new WriteTimeoutException(WriteType.VIEW, ConsistencyLevel.LOCAL_ONE, 0, 1);\n                        }\n                        else if (isDeferrable)\n                        {\n                            for (int j = 0; j < i; j++)\n                                locks[j].unlock();\n\n                            // This view update can't happen right now. so rather than keep this thread busy\n                            // we will re-apply ourself to the queue and try again later\n                            Stage.MUTATION.execute(() ->\n                                                   applyInternal(mutation, makeDurable, true, isDroppable, true, future)\n                            );\n                            return future;\n                        }\n                        else\n                        {\n                            // Retry lock on same thread, if mutation is not deferrable.\n                            // Mutation is not deferrable, if applied from MutationStage and caller is waiting for future to finish\n                            // If blocking caller defers future, this may lead to deadlock situation with all MutationStage workers","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/Keyspace.java#L482-L518","documentation":"In Keyspace.applyInternal, when a materialized-view write cannot acquire its required locks within the timeout, the mutation is failed with WriteTimeoutException(WriteType.VIEW, LOCAL_ONE, 0, 1) — acknowledging 0 of 1 required replicas. It signals that the view update could not be applied due to contention on the view lock, so the client's base-table write is timed out.","triggerScenarios":"Writing to a base table with a materialized view (or view-backed index) when concurrent updates to the same view partition contend on the per-partition lock and cannot be acquired within view_write_lock_timeout; heavy concurrent updates hitting the same view partition.","commonSituations":"Hot-partition workloads with materialized views; clusters where view_write_lock_timeout is too low for the write rate; batch jobs updating the same rows concurrently causing lock contention.","solutions":["Increase view_write_lock_timeout (cassandra.yaml / system property) if contention is transient.","Reduce write concurrency to the same base/view partition (application-side throttling or batching).","Retry the write with backoff; consider replacing materialized views with explicit denormalized tables written by the client.","Check for nodes under load (coordinator CPU/GC) that slow lock acquisition."],"exampleFix":"// before\ncassandra.yaml: view_write_lock_timeout: 1000  # ms, too low for hot partitions\n// after\ncassandra.yaml: view_write_lock_timeout: 10000  # ms, plus app-side backoff on WriteTimeout","handlingStrategy":"retry","validationCode":"// Before enabling materialized views, measure write concurrency per partition;\n// if hot-partition contention is expected, use explicit denormalized tables instead.","typeGuard":null,"tryCatchPattern":"try { session.execute(write); } catch (WriteTimeoutException e) {\n    if (e.writeType() == WriteType.VIEW) {\n        Thread.sleep(backoffMs); backoffMs = Math.min(backoffMs * 2, MAX_BACKOFF); retry();\n    } else throw e;\n}","preventionTips":["Prefer explicitly maintained denormalized tables over materialized views for hot write paths.","Tune view_write_lock_timeout to expected lock wait times.","Avoid many concurrent writers hitting the same base/view partition.","Monitor WriteTimeout metrics by WriteType."],"tags":["write-timeout","materialized-view","lock-contention","consistency"],"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"}