apache/cassandra · error · UnsupportedOperationException
Chunk cache size cannot be changed.
Error message
Chunk cache size cannot be changed.
What it means
ChunkCache wraps an off-heap region-based cache whose memory is allocated once at construction from the memtable cleanup policy, so its capacity is fixed for its lifetime. Calling setCapacity throws UnsupportedOperationException because resizing the underlying region set is not supported. The only way to change the size is to change the config and let the chunk cache be rebuilt.
Source
Thrown at src/java/org/apache/cassandra/cache/ChunkCache.java:312
}
@Override
public String toString()
{
return "CachingRebufferer:" + source;
}
}
@Override
public long capacity()
{
return cacheSize;
}
@Override
public void setCapacity(long capacity)
{
throw new UnsupportedOperationException("Chunk cache size cannot be changed.");
}
@Override
public int size()
{
return cache.asMap().size();
}
@Override
public long weightedSize()
{
return cache.policy().eviction()
.map(policy -> policy.weightedSize().orElseGet(cache::estimatedSize))
.orElseGet(cache::estimatedSize);
}
}View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Do not call setCapacity on ChunkCache; it is a fixed-capacity cache by design.
- To change chunk cache size, edit cassandra.yaml (memtable cleanup / chunk cache settings) and restart the node so the cache is rebuilt.
- If you call setCapacity generically on ICache instances, skip ChunkCache (check instanceof ChunkCache or catch UnsupportedOperationException).
- Set the desired capacity before the cache is created, i.e. in configuration at node startup.
Example fix
// before
cache.setCapacity(newCapacityBytes); // throws UnsupportedOperationException
// after
if (!(cache instanceof ChunkCache)) {
cache.setCapacity(newCapacityBytes);
} // else: change cassandra.yaml and restart node Defensive patterns
Strategy: try-catch
Validate before calling
// check the concrete cache type before resizing
if (cache instanceof org.apache.cassandra.cache.ChunkCache) {
throw new IllegalStateException("ChunkCache capacity is fixed; change yaml and restart instead");
} Type guard
boolean isResizable(ICache<?,?> c) { return !(c instanceof org.apache.cassandra.cache.ChunkCache); } Try / catch
try {
cache.setCapacity(newCapacity);
} catch (UnsupportedOperationException e) {
// fall back: schedule yaml change + restart
logger.warn("{} is fixed-capacity: {}", cache.getClass().getSimpleName(), e.getMessage());
} Prevention
- Never call setCapacity on ChunkCache; treat it as fixed-capacity.
- Change cache size via cassandra.yaml and node restart, not runtime resize.
- In generic cache-resize code, special-case ChunkCache.
- Guard JMX automation scripts against fixed-capacity caches.
When it happens
Trigger: Calling ChunkCache.setCapacity(anyValue), e.g. via JMX CacheService metrics MBean, via StorageService invalidate/resize paths, or programmatically through the ICache interface.
Common situations: Operators attempting to resize key/row/chunk caches at runtime through JMX (memtable cleanup works via CacheService.setKevs/... on ChunkCache instance); tooling that generically calls setCapacity on all registered caches; config tuning after startup expecting hot-resize like the standard SerializingCache.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Setting capacity of NopCache is not permitted as this cache
- prepared_statements_cache_size option was set incorrectly to
- key_cache_size option was set incorrectly to '<value>', supp
- counter_cache_size option was set incorrectly to '<value>',
- paxos_cache_size option was set incorrectly to '<value>', su
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/3e74155730d578bc.
Report an issue: GitHub.