{"record":{"id":"cb5c46b6f06cf943","repo":"apache/cassandra","slug":"countercachesaveperiodinseconds-must-be-non-negati","errorCode":null,"errorMessage":"CounterCacheSavePeriodInSeconds must be non-negative.","messagePattern":"CounterCacheSavePeriodInSeconds must be non-negative\\.","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/CacheService.java","lineNumber":231,"sourceCode":"\n    public void setKeyCacheSavePeriodInSeconds(int seconds)\n    {\n        if (seconds < 0)\n            throw new RuntimeException(\"KeyCacheSavePeriodInSeconds must be non-negative.\");\n\n        DatabaseDescriptor.setKeyCacheSavePeriod(seconds);\n        keyCache.scheduleSaving(seconds, DatabaseDescriptor.getKeyCacheKeysToSave());\n    }\n\n    public int getCounterCacheSavePeriodInSeconds()\n    {\n        return DatabaseDescriptor.getCounterCacheSavePeriod();\n    }\n\n    public void setCounterCacheSavePeriodInSeconds(int seconds)\n    {\n        if (seconds < 0)\n            throw new RuntimeException(\"CounterCacheSavePeriodInSeconds must be non-negative.\");\n\n        DatabaseDescriptor.setCounterCacheSavePeriod(seconds);\n        counterCache.scheduleSaving(seconds, DatabaseDescriptor.getCounterCacheKeysToSave());\n    }\n\n    public int getRowCacheKeysToSave()\n    {\n        return DatabaseDescriptor.getRowCacheKeysToSave();\n    }\n\n    public void setRowCacheKeysToSave(int count)\n    {\n        if (count < 0)\n            throw new RuntimeException(\"RowCacheKeysToSave must be non-negative.\");\n        DatabaseDescriptor.setRowCacheKeysToSave(count);\n        rowCache.scheduleSaving(getRowCacheSavePeriodInSeconds(), count);\n    }\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/CacheService.java#L213-L249","documentation":"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.","triggerScenarios":"Calling setCounterCacheSavePeriodInSeconds(seconds) with seconds < 0 via JMX or internal callers.","commonSituations":"JMX-driven runtime reconfiguration with a miscalculated value; operator tooling converting minutes/hours to seconds and producing negative results; typos in JMX console input.","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."],"exampleFix":"// before\nmbean.setCounterCacheSavePeriodInSeconds(minutes * 60 - offset);\n// after\nint seconds = Math.max(0, minutes * 60 - offset);\nmbean.setCounterCacheSavePeriodInSeconds(seconds);","handlingStrategy":"validation","validationCode":"if (seconds < 0) throw new IllegalArgumentException(\"CounterCacheSavePeriodInSeconds must be >= 0\");\ncacheService.setCounterCacheSavePeriodInSeconds(seconds);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["jmx","configuration","cache","runtime-validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}