apache/cassandra · error · RuntimeException
RowCacheKeysToSave must be non-negative.
Error message
RowCacheKeysToSave must be non-negative.
What it means
CacheService.setRowCacheKeysToSave limits how many row-cache keys are written per save cycle; a negative count is meaningless and rejected with an untyped RuntimeException before the value is stored and the row cache saver rescheduled. Reached mainly through the CacheService JMX mbean.
Solutions
- Pass a non-negative count; 0 is the accepted way to limit saving behavior.
- Clamp with Math.max(0, count) before the call.
- If a sentinel for 'unlimited' was intended, use 0 or leave the cassandra.yaml value unchanged instead of a negative number.
- Validate config-derived values before pushing them via JMX.
Example fix
// before cacheService.setRowCacheKeysToSave(config.getSaveLimit()); // may be -1 // after int count = Math.max(0, config.getSaveLimit()); cacheService.setRowCacheKeysToSave(count);
Defensive patterns
Strategy: validation
Validate before calling
if (count < 0) throw new IllegalArgumentException("RowCacheKeysToSave must be >= 0");
cacheService.setRowCacheKeysToSave(count); Prevention
- Do not use -1 as an unlimited sentinel for cache settings in Cassandra.
- Clamp metrics-derived values to zero floor before applying them.
- Validate JMX console inputs before submission.
- Keep tuning scripts idempotent and range-checked.
When it happens
Trigger: Calling setRowCacheKeysToSave(count) with count < 0 via JMX or internal code.
Common situations: Runtime tuning scripts computing the count from another metric that can be negative; manual JMX console edits; misread configuration keys where a sentinel like -1 (unlimited) is mistakenly assumed valid.
Related errors
- CounterCacheKeysToSave must be non-negative.
- CounterCacheSavePeriodInSeconds must be non-negative.
- KeyCacheKeysToSave must be non-negative.
- KeyCacheSavePeriodInSeconds must be non-negative.
- capacity should not be negative.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/bff006af64f81ebc.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/service/CacheService.java:245
public void setCounterCacheSavePeriodInSeconds(int seconds)
{
if (seconds < 0)
throw new RuntimeException("CounterCacheSavePeriodInSeconds must be non-negative.");
DatabaseDescriptor.setCounterCacheSavePeriod(seconds);
counterCache.scheduleSaving(seconds, DatabaseDescriptor.getCounterCacheKeysToSave());
}
public int getRowCacheKeysToSave()
{
return DatabaseDescriptor.getRowCacheKeysToSave();
}
public void setRowCacheKeysToSave(int count)
{
if (count < 0)
throw new RuntimeException("RowCacheKeysToSave must be non-negative.");
DatabaseDescriptor.setRowCacheKeysToSave(count);
rowCache.scheduleSaving(getRowCacheSavePeriodInSeconds(), count);
}
public int getKeyCacheKeysToSave()
{
return DatabaseDescriptor.getKeyCacheKeysToSave();
}
public void setKeyCacheKeysToSave(int count)
{
if (count < 0)
throw new RuntimeException("KeyCacheKeysToSave must be non-negative.");
DatabaseDescriptor.setKeyCacheKeysToSave(count);
keyCache.scheduleSaving(getKeyCacheSavePeriodInSeconds(), count);
}
public int getCounterCacheKeysToSave()View on GitHub (pinned to 88fd0f6a0e)