apache/cassandra · error · IllegalStateException

compaction tombstone warning threshold needs to be >= 0, not

Error message

compaction tombstone warning threshold needs to be >= 0, not {count}

What it means

setCompactionTombstoneWarningThreshold() sets the guardrail warning threshold for tombstones per partition during compaction. It throws IllegalStateException when count is negative; a valid non-negative count is forwarded to the Guardrails partition_tombstones warning threshold.

Source

Thrown at src/java/org/apache/cassandra/service/StorageService.java:5351

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

    @Override
    public boolean getReadThresholdsEnabled()
    {
        return DatabaseDescriptor.getReadThresholdsEnabled();
    }

    @Override
    public void setReadThresholdsEnabled(boolean value)

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pass a non-negative integer; use 0 to disable the warning threshold.
  2. Clamp with Math.max(0, count) before calling.
  3. Configure compaction_tombstone_warning_threshold in cassandra.yaml instead of runtime tuning.

Example fix

// before
ss.setCompactionTombstoneWarningThreshold(-1); // throws
// after
ss.setCompactionTombstoneWarningThreshold(Math.max(0, requested)); // 0 disables warnings
Defensive patterns

Strategy: validation

Validate before calling

if (count < 0) throw new IllegalArgumentException("compaction tombstone warn threshold must be >= 0");
ss.setCompactionTombstoneWarningThreshold(count);

Type guard

boolean valid = count >= 0;

Try / catch

try { ss.setCompactionTombstoneWarningThreshold(c); } catch (IllegalStateException e) { log.warn("rejecting negative tombstone threshold {}", c); }

Prevention

When it happens

Trigger: Calling setCompactionTombstoneWarningThreshold(count) with count < 0 via JMX, nodetool, or code.

Common situations: Sentinel -1 'unset' values in tuning scripts; operators intending 0 (disable warnings) but passing negative; automated tooling converting percentages to absolute counts incorrectly.

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


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