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.

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)

Solutions

  1. Pass a non-negative count; 0 is the accepted way to limit saving behavior.
  2. Clamp with Math.max(0, count) before the call.
  3. If a sentinel for 'unlimited' was intended, use 0 or leave the cassandra.yaml value unchanged instead of a negative number.
  4. 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

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/bff006af64f81ebc. Report an issue: GitHub.