{"record":{"id":"9fec774fd7917e8a","repo":"apache/cassandra","slug":"keyspace-count-warn-threshold-should-be-positive","errorCode":null,"errorMessage":"Keyspace count warn threshold should be positive, not {value}","messagePattern":"Keyspace count warn threshold should be positive, not (.+?)","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/StorageService.java","lineNumber":5341,"sourceCode":"            throw new IllegalStateException(\"Table count warn threshold should be positive, not \"+value);\n        logger.info(\"Changing table count warn threshold from {} to {}\", getTableCountWarnThreshold(), value);\n        Guardrails.instance.setTablesThreshold((int) Converters.TABLE_COUNT_THRESHOLD_TO_GUARDRAIL.convert(value),\n                                               Guardrails.instance.getTablesFailThreshold());\n    }\n\n    /** @deprecated See CASSANDRA-17195 */\n    @Deprecated(since = \"4.1\")\n    public int getKeyspaceCountWarnThreshold()\n    {\n        return (int) Converters.KEYSPACE_COUNT_THRESHOLD_TO_GUARDRAIL.unconvert(Guardrails.instance.getKeyspacesWarnThreshold());\n    }\n\n    /** @deprecated See CASSANDRA-17195 */\n    @Deprecated(since = \"4.1\")\n    public void setKeyspaceCountWarnThreshold(int value)\n    {\n        if (value < 0)\n            throw new IllegalStateException(\"Keyspace count warn threshold should be positive, not \"+value);\n        logger.info(\"Changing keyspace count warn threshold from {} to {}\", getKeyspaceCountWarnThreshold(), value);\n        Guardrails.instance.setKeyspacesThreshold((int) Converters.KEYSPACE_COUNT_THRESHOLD_TO_GUARDRAIL.convert(value),\n                                                  Guardrails.instance.getKeyspacesFailThreshold());\n    }\n\n    @Override\n    public void setCompactionTombstoneWarningThreshold(int count)\n    {\n        if (count < 0)\n            throw new IllegalStateException(\"compaction tombstone warning threshold needs to be >= 0, not \"+count);\n        logger.info(\"Setting compaction_tombstone_warning_threshold to {}\", count);\n        Guardrails.instance.setPartitionTombstonesThreshold(count, Guardrails.instance.getPartitionTombstonesFailThreshold());\n    }\n\n    @Override\n    public int getCompactionTombstoneWarningThreshold()\n    {\n        return Math.toIntExact(Guardrails.instance.getPartitionTombstonesWarnThreshold());","sourceCodeStart":5323,"sourceCodeEnd":5359,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/StorageService.java#L5323-L5359","documentation":"setKeyspaceCountWarnThreshold() is the deprecated (since 4.1, CASSANDRA-17195) keyspace-count counterpart to the table threshold, forwarding to Guardrails.setKeyspacesThreshold. It throws IllegalStateException when the value is negative.","triggerScenarios":"Calling setKeyspaceCountWarnThreshold(value) with value < 0 via JMX, nodetool, or code.","commonSituations":"Negative values from sentinel defaults (-1) in automation scripts; percentage-derived computations going negative; operators porting legacy cassandra.yaml threshold settings.","solutions":["Pass a non-negative integer (0 disables the warning).","Clamp with Math.max(0, value) before the call.","Prefer configuring the keyspaces guardrail directly in cassandra.yaml, as this setter is deprecated."],"exampleFix":"// before\nss.setKeyspaceCountWarnThreshold(-1); // throws\n// after\nss.setKeyspaceCountWarnThreshold(Math.max(0, requested));","handlingStrategy":"validation","validationCode":"if (value < 0) throw new IllegalArgumentException(\"keyspace count warn threshold must be >= 0\");\nss.setKeyspaceCountWarnThreshold(value);","typeGuard":"boolean valid = value >= 0;","tryCatchPattern":"try { ss.setKeyspaceCountWarnThreshold(v); } catch (IllegalStateException e) { log.warn(\"rejecting negative threshold {}\", v); }","preventionTips":["Validate non-negativity before calling.","Use 0 instead of -1 to disable the warning.","Migrate to the keyspaces guardrail in cassandra.yaml.","Avoid deriving thresholds from percentages without clamping."],"tags":["jmx","guardrails","validation","deprecated"],"backgroundTag":"value-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"}