apache/cassandra · error · IllegalStateException
Keyspace count warn threshold should be positive, not {value
Error message
Keyspace count warn threshold should be positive, not {value} What it means
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.
Source
Thrown at src/java/org/apache/cassandra/service/StorageService.java:5341
throw new IllegalStateException("Table count warn threshold should be positive, not "+value);
logger.info("Changing table count warn threshold from {} to {}", getTableCountWarnThreshold(), value);
Guardrails.instance.setTablesThreshold((int) Converters.TABLE_COUNT_THRESHOLD_TO_GUARDRAIL.convert(value),
Guardrails.instance.getTablesFailThreshold());
}
/** @deprecated See CASSANDRA-17195 */
@Deprecated(since = "4.1")
public int getKeyspaceCountWarnThreshold()
{
return (int) Converters.KEYSPACE_COUNT_THRESHOLD_TO_GUARDRAIL.unconvert(Guardrails.instance.getKeyspacesWarnThreshold());
}
/** @deprecated See CASSANDRA-17195 */
@Deprecated(since = "4.1")
public void setKeyspaceCountWarnThreshold(int value)
{
if (value < 0)
throw new IllegalStateException("Keyspace count warn threshold should be positive, not "+value);
logger.info("Changing keyspace count warn threshold from {} to {}", getKeyspaceCountWarnThreshold(), value);
Guardrails.instance.setKeyspacesThreshold((int) Converters.KEYSPACE_COUNT_THRESHOLD_TO_GUARDRAIL.convert(value),
Guardrails.instance.getKeyspacesFailThreshold());
}
@Override
public void setCompactionTombstoneWarningThreshold(int count)
{
if (count < 0)
throw new IllegalStateException("compaction tombstone warning threshold needs to be >= 0, not "+count);
logger.info("Setting compaction_tombstone_warning_threshold to {}", count);
Guardrails.instance.setPartitionTombstonesThreshold(count, Guardrails.instance.getPartitionTombstonesFailThreshold());
}
@Override
public int getCompactionTombstoneWarningThreshold()
{
return Math.toIntExact(Guardrails.instance.getPartitionTombstonesWarnThreshold());View on GitHub (pinned to 88fd0f6a0e)
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.
Example fix
// before ss.setKeyspaceCountWarnThreshold(-1); // throws // after ss.setKeyspaceCountWarnThreshold(Math.max(0, requested));
Defensive patterns
Strategy: validation
Validate before calling
if (value < 0) throw new IllegalArgumentException("keyspace count warn threshold must be >= 0");
ss.setKeyspaceCountWarnThreshold(value); Type guard
boolean valid = value >= 0;
Try / catch
try { ss.setKeyspaceCountWarnThreshold(v); } catch (IllegalStateException e) { log.warn("rejecting negative threshold {}", v); } Prevention
- 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.
When it happens
Trigger: Calling setKeyspaceCountWarnThreshold(value) with value < 0 via JMX, nodetool, or code.
Common situations: Negative values from sentinel defaults (-1) in automation scripts; percentage-derived computations going negative; operators porting legacy cassandra.yaml threshold settings.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Table count warn threshold should be positive, not {value}
- compaction tombstone warning threshold needs to be >= 0, not
- Invalid guardrails configuration:
- Invalid value %d for %s: negative values are not allowed, ou
- Invalid values for %s: '%s' do not parse as valid %s propert
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/9fec774fd7917e8a.
Report an issue: GitHub.