apache/cassandra · error · RuntimeException
KeyCacheSavePeriodInSeconds must be non-negative.
Error message
KeyCacheSavePeriodInSeconds must be non-negative.
What it means
CacheService.setKeyCacheSavePeriodInSeconds validates that the key-cache autosave interval is not negative before storing it and rescheduling the key cache saver. A negative value has no meaning as a periodic save interval, so the setter rejects it eagerly with an untyped RuntimeException. This setter is typically invoked via JMX at runtime rather than from application code.
Solutions
- Pass a non-negative value: clamp with Math.max(0, seconds) before calling the setter.
- Use 0 to disable periodic key cache saving instead of a negative number.
- Check the source of the value (config parsing, unit conversion) for sign errors.
- If the intent is a disabled interval, also consider removing the runtime update entirely so the cassandra.yaml value is kept.
Example fix
// before
cacheService.setKeyCacheSavePeriodInSeconds(getInterval());
// after
int seconds = getInterval();
if (seconds >= 0)
cacheService.setKeyCacheSavePeriodInSeconds(seconds); Defensive patterns
Strategy: validation
Validate before calling
if (seconds < 0) throw new IllegalArgumentException("KeyCacheSavePeriodInSeconds must be >= 0");
cacheService.setKeyCacheSavePeriodInSeconds(seconds); Prevention
- Treat all CacheService JMX setters as accepting non-negative values only.
- Use 0 to disable periodic cache saving, never negative numbers.
- Validate computed durations at the config layer before pushing via JMX.
- Sanity-check unit conversions (ms/s/min) for sign errors.
When it happens
Trigger: Calling CacheService.setKeyCacheSavePeriodInSeconds(seconds) with seconds < 0, e.g. via JMX (org.apache.cassandra.service.CacheService mbean) or internal code passing a negative duration value.
Common situations: Operators pushing a runtime JMX config change computed from a bad expression (e.g. unit conversion yielding a negative number), scripts that subtract timestamps, or hand-editing JMX console fields with a minus sign.
Related errors
- CounterCacheKeysToSave must be non-negative.
- CounterCacheSavePeriodInSeconds must be non-negative.
- KeyCacheKeysToSave must be non-negative.
- RowCacheKeysToSave must be non-negative.
- capacity should not be negative.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/2f779902bb8f4c7c.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/service/CacheService.java:217
public void setRowCacheSavePeriodInSeconds(int seconds)
{
if (seconds < 0)
throw new RuntimeException("RowCacheSavePeriodInSeconds must be non-negative.");
DatabaseDescriptor.setRowCacheSavePeriod(seconds);
rowCache.scheduleSaving(seconds, DatabaseDescriptor.getRowCacheKeysToSave());
}
public int getKeyCacheSavePeriodInSeconds()
{
return DatabaseDescriptor.getKeyCacheSavePeriod();
}
public void setKeyCacheSavePeriodInSeconds(int seconds)
{
if (seconds < 0)
throw new RuntimeException("KeyCacheSavePeriodInSeconds must be non-negative.");
DatabaseDescriptor.setKeyCacheSavePeriod(seconds);
keyCache.scheduleSaving(seconds, DatabaseDescriptor.getKeyCacheKeysToSave());
}
public int getCounterCacheSavePeriodInSeconds()
{
return DatabaseDescriptor.getCounterCacheSavePeriod();
}
public void setCounterCacheSavePeriodInSeconds(int seconds)
{
if (seconds < 0)
throw new RuntimeException("CounterCacheSavePeriodInSeconds must be non-negative.");
DatabaseDescriptor.setCounterCacheSavePeriod(seconds);
counterCache.scheduleSaving(seconds, DatabaseDescriptor.getCounterCacheKeysToSave());
}View on GitHub (pinned to 88fd0f6a0e)