apache/cassandra · error · InvalidRequestException
The specified table is read-only.
Error message
The specified table is read-only.
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java:358
return BufferCell.live(column, 1L, value);
}
@Override
public TableMetadata metadata()
{
return this.metadata;
}
@Override
public UnfilteredPartitionIterator select(DataRange dataRange, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits)
{
throw new InvalidRequestException(UNSUPPORTED_RANGE_QUERY_ERROR);
}
@Override
public void truncate()
{
throw new InvalidRequestException(TABLE_READ_ONLY_ERROR);
}
@Override
public void apply(PartitionUpdate update)
{
throw new InvalidRequestException(TABLE_READ_ONLY_ERROR);
}
}
View on GitHub (pinned to 88fd0f6a0e)
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.
Example fix
// before TRUNCATE system_views.partitions; // after // no-op: read-only virtual table; filter it out of cleanup scripts
Defensive patterns
Strategy: validation
Validate before calling
// Exclude virtual tables from any truncate list
Set<String> virtualTables = session.execute("SELECT keyspace_name, table_name FROM system_schema.virtual_tables")
.all().stream().map(r -> r.getString(0)+"."+r.getString(1)).collect(Collectors.toSet());
if (virtualTables.contains(ks+"."+table)) throw new IllegalStateException("refusing to truncate virtual table"); Try / catch
try { session.execute("TRUNCATE system_views.partitions"); }
catch (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException e) {
if (e.getMessage().contains("read-only")) { /* skip virtual table */ }
else throw e;
} Prevention
- 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.
When it happens
Trigger: `TRUNCATE system_views.partitions;` or tooling that resets table contents including virtual keyspaces.
Common situations: Cleanup scripts iterating all keyspaces; test teardown code clearing system_views tables.
Related errors
- Truncation is not supported by table " + metadata
- Truncate is not supported by table
- Truncation is not supported by table %s
- Modification is not supported by table " + metadata
- Modification is not supported by table " + metadata
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/b2beab50cf7e2531.
Report an issue: GitHub.