{"record":{"id":"b2beab50cf7e2531","repo":"apache/cassandra","slug":"the-specified-table-is-read-only","errorCode":null,"errorMessage":"The specified table is read-only.","messagePattern":"The specified table is read-only\\.","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java","lineNumber":358,"sourceCode":"        return BufferCell.live(column, 1L, value);\n    }\n\n    @Override\n    public TableMetadata metadata()\n    {\n        return this.metadata;\n    }\n\n    @Override\n    public UnfilteredPartitionIterator select(DataRange dataRange, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits)\n    {\n        throw new InvalidRequestException(UNSUPPORTED_RANGE_QUERY_ERROR);\n    }\n\n    @Override\n    public void truncate()\n    {\n        throw new InvalidRequestException(TABLE_READ_ONLY_ERROR);\n    }\n\n    @Override\n    public void apply(PartitionUpdate update)\n    {\n        throw new InvalidRequestException(TABLE_READ_ONLY_ERROR);\n    }\n}\n","sourceCodeStart":340,"sourceCodeEnd":367,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java#L340-L367","documentation":"Virtual table PartitionKeyStatsTable.truncate always throws InvalidRequestException(TABLE_READ_ONLY_ERROR): virtual tables are backed by in-memory runtime state, not mutable data, so TRUNCATE against them is rejected by design. Any write path (apply) is similarly rejected.","triggerScenarios":"`TRUNCATE system_views.partitions;` or tooling that resets table contents including virtual keyspaces.","commonSituations":"Cleanup scripts iterating all keyspaces; test teardown code clearing system_views tables.","solutions":["Remove the TRUNCATE; virtual tables cannot be truncated.","Exclude virtual keyspaces (system_views, system_settings) from maintenance scripts.","Reset the underlying runtime state (e.g. via nodetool) if the goal is clearing reflected data."],"exampleFix":"// before\nTRUNCATE system_views.partitions;\n// after\n// no-op: read-only virtual table; filter it out of cleanup scripts","handlingStrategy":"validation","validationCode":"// Exclude virtual tables from any truncate list\nSet<String> virtualTables = session.execute(\"SELECT keyspace_name, table_name FROM system_schema.virtual_tables\")\n    .all().stream().map(r -> r.getString(0)+\".\"+r.getString(1)).collect(Collectors.toSet());\nif (virtualTables.contains(ks+\".\"+table)) throw new IllegalStateException(\"refusing to truncate virtual table\");","typeGuard":null,"tryCatchPattern":"try { session.execute(\"TRUNCATE system_views.partitions\"); }\ncatch (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException e) {\n    if (e.getMessage().contains(\"read-only\")) { /* skip virtual table */ }\n    else throw e;\n}","preventionTips":["Never include system_views/system_settings in truncation routines.","Treat virtual tables as immutable views.","Reset runtime state via nodetool/node operations rather than DML."],"tags":["cassandra","virtual-table","read-only","truncate"],"backgroundTag":"operation-not-supported","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"}