{"record":{"id":"3e74155730d578bc","repo":"apache/cassandra","slug":"chunk-cache-size-cannot-be-changed","errorCode":null,"errorMessage":"Chunk cache size cannot be changed.","messagePattern":"Chunk cache size cannot be changed\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cache/ChunkCache.java","lineNumber":312,"sourceCode":"        }\n\n        @Override\n        public String toString()\n        {\n            return \"CachingRebufferer:\" + source;\n        }\n    }\n\n    @Override\n    public long capacity()\n    {\n        return cacheSize;\n    }\n\n    @Override\n    public void setCapacity(long capacity)\n    {\n        throw new UnsupportedOperationException(\"Chunk cache size cannot be changed.\");\n    }\n\n    @Override\n    public int size()\n    {\n        return cache.asMap().size();\n    }\n\n    @Override\n    public long weightedSize()\n    {\n        return cache.policy().eviction()\n                .map(policy -> policy.weightedSize().orElseGet(cache::estimatedSize))\n                .orElseGet(cache::estimatedSize);\n    }\n}","sourceCodeStart":294,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cache/ChunkCache.java#L294-L328","documentation":"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.","triggerScenarios":"Calling ChunkCache.setCapacity(anyValue), e.g. via JMX CacheService metrics MBean, via StorageService invalidate/resize paths, or programmatically through the ICache interface.","commonSituations":"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.","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."],"exampleFix":"// before\ncache.setCapacity(newCapacityBytes); // throws UnsupportedOperationException\n// after\nif (!(cache instanceof ChunkCache)) {\n    cache.setCapacity(newCapacityBytes);\n} // else: change cassandra.yaml and restart node","handlingStrategy":"try-catch","validationCode":"// check the concrete cache type before resizing\nif (cache instanceof org.apache.cassandra.cache.ChunkCache) {\n    throw new IllegalStateException(\"ChunkCache capacity is fixed; change yaml and restart instead\");\n}","typeGuard":"boolean isResizable(ICache<?,?> c) { return !(c instanceof org.apache.cassandra.cache.ChunkCache); }","tryCatchPattern":"try {\n    cache.setCapacity(newCapacity);\n} catch (UnsupportedOperationException e) {\n    // fall back: schedule yaml change + restart\n    logger.warn(\"{} is fixed-capacity: {}\", cache.getClass().getSimpleName(), e.getMessage());\n}","preventionTips":["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."],"tags":["cache","unsupported-operation","cassandra"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}