apache/cassandra · error · RuntimeException
capacity should not be negative.
Error message
capacity should not be negative.
What it means
CacheService.setRowCacheCapacityInMB resizes the row cache in MiB and rejects negative capacities with an untyped RuntimeException before calling rowCache.setCapacity. Cache capacity cannot be negative because it maps directly to a byte size (capacity * 1024 * 1024). Usually invoked via the CacheService JMX mbean at runtime.
Source
Thrown at src/java/org/apache/cassandra/service/CacheService.java:330
{
CounterCacheKey key = counterCacheIterator.next();
if (key.sameTable(tableMetadata))
counterCacheIterator.remove();
}
}
public void invalidateCounterCache()
{
counterCache.clear();
}
public void setRowCacheCapacityInMB(long capacity)
{
if (capacity < 0)
throw new RuntimeException("capacity should not be negative.");
rowCache.setCapacity(capacity * 1024 * 1024);
}
public void setKeyCacheCapacityInMB(long capacity)
{
if (capacity < 0)
throw new RuntimeException("capacity should not be negative.");
keyCache.setCapacity(capacity * 1024 * 1024);
}
public void setCounterCacheCapacityInMB(long capacity)
{
if (capacity < 0)
throw new RuntimeException("capacity should not be negative.");
View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Pass a non-negative capacity in MiB; use 0 to disable the row cache.
- Clamp with Math.max(0, capacityMB) before the call.
- Fix the sizing calculation (e.g. freeMemory deltas) that produced the negative value.
- Validate JMX inputs in automation before resizing caches.
Example fix
// before long newCap = currentFreeMB - usedMB; mbean.setRowCacheCapacityInMB(newCap); // may be negative // after long newCap = Math.max(0, currentFreeMB - usedMB); mbean.setRowCacheCapacityInMB(newCap);
Defensive patterns
Strategy: validation
Validate before calling
if (capacityMB < 0) throw new IllegalArgumentException("Row cache capacity must be >= 0 MiB");
cacheService.setRowCacheCapacityInMB(capacityMB); Prevention
- Floor capacity calculations at 0 MiB.
- Use 0 MiB to disable a cache rather than negative values.
- Guard auto-tuning loops against negative free-memory deltas.
- Persist validated values only after range checks.
When it happens
Trigger: Calling setRowCacheCapacityInMB(capacity) with capacity < 0 via JMX or internal code.
Common situations: Auto-tuning scripts that compute new capacity from free-memory deltas which can go negative under memory pressure; manual JMX edits with a minus sign; configuration migrators passing negative sentinels.
Related errors
- KeyCacheSavePeriodInSeconds must be non-negative.
- CounterCacheSavePeriodInSeconds must be non-negative.
- RowCacheKeysToSave must be non-negative.
- KeyCacheKeysToSave must be non-negative.
- CounterCacheKeysToSave must be non-negative.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/4521a06b1c132368.
Report an issue: GitHub.