apache/cassandra · error · RuntimeException
CounterCacheSavePeriodInSeconds must be non-negative.
Error message
CounterCacheSavePeriodInSeconds must be non-negative.
What it means
CacheService.setCounterCacheSavePeriodInSeconds validates the counter-cache autosave interval and throws an untyped RuntimeException when it is negative. Negative intervals cannot be scheduled, so the value is rejected before calling DatabaseDescriptor.setCounterCacheSavePeriod and rescheduling counterCache. Normally reached through the CacheService JMX mbean.
Source
Thrown at src/java/org/apache/cassandra/service/CacheService.java:231
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());
}
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);
}
View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Pass a non-negative interval; use 0 to disable periodic counter cache saving.
- Clamp the value with Math.max(0, seconds) at the call site.
- Fix the upstream calculation (unit conversion, subtraction) producing the negative number.
- Verify the JMX payload/attribute value before invoking the mbean operation.
Example fix
// before mbean.setCounterCacheSavePeriodInSeconds(minutes * 60 - offset); // after int seconds = Math.max(0, minutes * 60 - offset); mbean.setCounterCacheSavePeriodInSeconds(seconds);
Defensive patterns
Strategy: validation
Validate before calling
if (seconds < 0) throw new IllegalArgumentException("CounterCacheSavePeriodInSeconds must be >= 0");
cacheService.setCounterCacheSavePeriodInSeconds(seconds); Prevention
- Clamp runtime-computed intervals to Math.max(0, value).
- Document 0 as the disabled interval in tuning runbooks.
- Validate JMX payloads in automation scripts.
- Test config-migration math with edge inputs.
When it happens
Trigger: Calling setCounterCacheSavePeriodInSeconds(seconds) with seconds < 0 via JMX or internal callers.
Common situations: JMX-driven runtime reconfiguration with a miscalculated value; operator tooling converting minutes/hours to seconds and producing negative results; typos in JMX console input.
Related errors
- KeyCacheSavePeriodInSeconds must be non-negative.
- RowCacheKeysToSave must be non-negative.
- KeyCacheKeysToSave must be non-negative.
- CounterCacheKeysToSave must be non-negative.
- capacity should not be negative.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/cb5c46b6f06cf943.
Report an issue: GitHub.