{"record":{"id":"0a423699a3eb4241","repo":"apache/cassandra","slug":"min-compress-ratio-can-either-be-0-or-greater-than","errorCode":null,"errorMessage":"min_compress_ratio can either be 0 or greater than or equal to 1","messagePattern":"min_compress_ratio can either be 0 or greater than or equal to 1","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/schema/CompressionParams.java","lineNumber":472,"sourceCode":"    }\n\n    // chunkLength must be a power of 2 because we assume so when\n    // computing the chunk number from an uncompressed file offset (see\n    // CompressedRandomAccessReader.decompresseChunk())\n    public void validate() throws ConfigurationException\n    {\n        // if chunk length was not set (chunkLength == null), this is fine, default will be used\n        if (chunkLength <= 0)\n            throw new ConfigurationException(\"Invalid negative or null \" + CHUNK_LENGTH_IN_KB);\n\n        if ((chunkLength & (chunkLength - 1)) != 0)\n            throw new ConfigurationException(CHUNK_LENGTH_IN_KB + \" must be a power of 2\");\n\n        if (maxCompressedLength < 0)\n            throw new ConfigurationException(\"Invalid negative \" + MIN_COMPRESS_RATIO);\n\n        if (maxCompressedLength > chunkLength && maxCompressedLength < Integer.MAX_VALUE)\n            throw new ConfigurationException(MIN_COMPRESS_RATIO + \" can either be 0 or greater than or equal to 1\");\n    }\n\n    public Map<String, String> asMap()\n    {\n        if (!isEnabled())\n            return Collections.singletonMap(ENABLED, \"false\");\n\n        Map<String, String> options = new HashMap<>(otherOptions);\n        // Use the one saved in the registry, we don't want to save the name of the service provider compressor here!\n        options.put(CLASS, sstableCompressor.serializedAs().getName());\n        options.put(CHUNK_LENGTH_IN_KB, chunkLengthInKB());\n        if (minCompressRatio != DEFAULT_MIN_COMPRESS_RATIO)\n            options.put(MIN_COMPRESS_RATIO, String.valueOf(minCompressRatio));\n\n        return options;\n    }\n\n    public String chunkLengthInKB()","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/schema/CompressionParams.java#L454-L490","documentation":"CompressionParams.validate enforces that min_compress_ratio (maxCompressedLength) is either 0 (disabled) or >= 1. A ratio between 0 and 1 exclusive would claim compression below the input size, and one greater than chunkLength is internally inconsistent, so values in (0,1) are invalid.","triggerScenarios":"Calling validate (via setCompressionParameters or fromMap) with min_compress_ratio between 0 and 1 (exclusive), or otherwise greater than chunkLength but below Integer.MAX_VALUE.","commonSituations":"Assuming the ratio is expressed as bytes-per-byte < 1 or entering a percentage like 0.75 intending 75% ratio instead of 1.75.","solutions":["Express the ratio as a value >= 1, e.g. 1.25 means compressed size must be at most 1/1.25 of the original","Use 0 to disable the ratio check entirely","If you meant 75% compression, write 1.33 (1/0.75) rather than 0.75"],"exampleFix":"// before\n{'class': 'LZ4Compressor', 'min_compress_ratio': '0.75'}\n// after\n{'class': 'LZ4Compressor', 'min_compress_ratio': '1.33'}","handlingStrategy":"validation","validationCode":"if (ratio != 0 && ratio < 1) throw new IllegalArgumentException(\"min_compress_ratio must be 0 or >= 1, got: \" + ratio);","typeGuard":null,"tryCatchPattern":"try { params.validate(); } catch (ConfigurationException e) { log.error(\"invalid min_compress_ratio\", e); }","preventionTips":["Remember the ratio is expressed as >= 1 (e.g. 1.25), never a fraction like 0.75","Convert percentage compression (75%) into its reciprocal ratio (1.33)","Use 0 to disable the ratio check"],"tags":["config","compression","validation"],"backgroundTag":"invalid-config-value","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"}