apache/cassandra · error · RuntimeException

RowCacheSavePeriodInSeconds must be non-negative.

Error message

RowCacheSavePeriodInSeconds must be non-negative.

What it means

setRowCacheSavePeriodInSeconds sets how often the row cache is persisted to disk. Negative values are invalid, so the setter throws RuntimeException before updating DatabaseDescriptor and rescheduling saving.

Source

Thrown at src/java/org/apache/cassandra/service/CacheService.java:203

        logger.info("Scheduling counter cache save to every {} seconds (going to save {} keys).",
                    DatabaseDescriptor.getCounterCacheSavePeriod(),
                    keysToSave == Integer.MAX_VALUE ? "all" : keysToSave);

        cache.scheduleSaving(DatabaseDescriptor.getCounterCacheSavePeriod(), keysToSave);

        return cache;
    }


    public int getRowCacheSavePeriodInSeconds()
    {
        return DatabaseDescriptor.getRowCacheSavePeriod();
    }

    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());
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pass a non-negative value (0 disables periodic saving; positive seconds enable it)
  2. Fix the script/config that computed the negative value
  3. Use setRowCacheSavePeriodInSeconds(0) to disable saving rather than a negative number

Example fix

// before
void configure(CacheService cs) { cs.setRowCacheSavePeriodInSeconds(-1); }
// after
void configure(CacheService cs) { cs.setRowCacheSavePeriodInSeconds(0); } // disable, or e.g. 60
Defensive patterns

Strategy: validation

Validate before calling

if (seconds < 0) throw new IllegalArgumentException("RowCacheSavePeriodInSeconds must be >= 0");
cacheService.setRowCacheSavePeriodInSeconds(seconds);

Try / catch

try { cacheService.setRowCacheSavePeriodInSeconds(seconds); } catch (RuntimeException e) { logger.warn("Rejected row cache save period: {}", seconds); }

Prevention

When it happens

Trigger: Calling CacheService.setRowCacheSavePeriodInSeconds with a negative int via JMX or programmatic configuration.

Common situations: Operational scripts computing the save period dynamically and producing a negative value; JMX console input mistakes; config loaders that pass sentinel values like -1.

Related errors


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