apache/cassandra · error · ConfigurationException

Invalid negative min_compress_ratio

Error message

Invalid negative min_compress_ratio

What it means

Fired in CompressionParams.validate: min_compress_ratio was set to a value < 1 (negative or otherwise invalid; ratio must be >= 1). Validation runs when compression parameters are applied via CREATE/ALTER TABLE (setCompressionParameters, fromMap), throwing ConfigurationException before the schema change commits.

Source

Thrown at src/java/org/apache/cassandra/schema/CompressionParams.java:469

    {
        String enabled = options.remove(ENABLED);
        return enabled == null || Boolean.parseBoolean(enabled);
    }

    // chunkLength must be a power of 2 because we assume so when
    // computing the chunk number from an uncompressed file offset (see
    // CompressedRandomAccessReader.decompresseChunk())
    public void validate() throws ConfigurationException
    {
        // if chunk length was not set (chunkLength == null), this is fine, default will be used
        if (chunkLength <= 0)
            throw new ConfigurationException("Invalid negative or null " + CHUNK_LENGTH_IN_KB);

        if ((chunkLength & (chunkLength - 1)) != 0)
            throw new ConfigurationException(CHUNK_LENGTH_IN_KB + " must be a power of 2");

        if (maxCompressedLength < 0)
            throw new ConfigurationException("Invalid negative " + MIN_COMPRESS_RATIO);

        if (maxCompressedLength > chunkLength && maxCompressedLength < Integer.MAX_VALUE)
            throw new ConfigurationException(MIN_COMPRESS_RATIO + " can either be 0 or greater than or equal to 1");
    }

    public Map<String, String> asMap()
    {
        if (!isEnabled())
            return Collections.singletonMap(ENABLED, "false");

        Map<String, String> options = new HashMap<>(otherOptions);
        // Use the one saved in the registry, we don't want to save the name of the service provider compressor here!
        options.put(CLASS, sstableCompressor.serializedAs().getName());
        options.put(CHUNK_LENGTH_IN_KB, chunkLengthInKB());
        if (minCompressRatio != DEFAULT_MIN_COMPRESS_RATIO)
            options.put(MIN_COMPRESS_RATIO, String.valueOf(minCompressRatio));

        return options;

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Set min_compress_ratio to 0 (no minimum) or a value >= 1
  2. Remove min_compress_ratio to use the default
  3. Clamp computed ratios with Math.max(0, ratio) in schema-building code

Example fix

// before
{'class': 'LZ4Compressor', 'min_compress_ratio': '-0.5'}
// after
{'class': 'LZ4Compressor', 'min_compress_ratio': '1.1'}
Defensive patterns

Strategy: validation

Validate before calling

if (ratio < 0) throw new IllegalArgumentException("min_compress_ratio must not be negative, got: " + ratio);

Try / catch

try { params.validate(); } catch (ConfigurationException e) { log.error("negative min_compress_ratio", e); }

Prevention

When it happens

Trigger: Calling validate (via setCompressionParameters or fromMap) with min_compress_ratio set to a negative number.

Common situations: Sign/typo mistakes like '-1' or '-0.5' in a compression map; templating where a ratio was computed as negative.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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