{"record":{"id":"970f6f921df4ab65","repo":"apache/cassandra","slug":"at-most-s-bytes-may-be-in-a-compaction-level-you","errorCode":null,"errorMessage":"At most %s bytes may be in a compaction level; your maxSSTableSize must be absurdly high to compute %s","messagePattern":"At most (.+?) bytes may be in a compaction level; your maxSSTableSize must be absurdly high to compute (.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java","lineNumber":636,"sourceCode":"            if (fanoutSize < 1)\n            {\n                throw new ConfigurationException(String.format(\"%s must be larger than 0, but was %s\", LEVEL_FANOUT_SIZE_OPTION, fanoutSize));\n            }\n        }\n        catch (NumberFormatException ex)\n        {\n            throw new ConfigurationException(String.format(\"%s is not a parsable int (base10) for %s\", levelFanoutSize, LEVEL_FANOUT_SIZE_OPTION), ex);\n        }\n\n        // Validate max Bytes for a level\n        try\n        {\n            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes\n            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT - 1);\n            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));\n            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);\n            if (maxBytes.compareTo(longMaxValue) > 0)\n                throw new ConfigurationException(String.format(\"At most %s bytes may be in a compaction level; \" +\n                        \"your maxSSTableSize must be absurdly high to compute %s\", Long.MAX_VALUE, maxBytes));\n        }\n        catch (ArithmeticException ex)\n        {\n            throw new ConfigurationException(String.format(\"sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)\", ssSize, Long.MAX_VALUE), ex);\n        }\n\n        uncheckedOptions.remove(LEVEL_FANOUT_SIZE_OPTION);\n        uncheckedOptions.remove(SINGLE_SSTABLE_UPLEVEL_OPTION);\n\n        uncheckedOptions.remove(CompactionParams.Option.MIN_THRESHOLD.toString());\n        uncheckedOptions.remove(CompactionParams.Option.MAX_THRESHOLD.toString());\n\n        uncheckedOptions = SizeTieredCompactionStrategyOptions.validateOptions(options, uncheckedOptions);\n\n        return uncheckedOptions;\n    }\n}","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java#L618-L654","documentation":"LCS computes the maximum bytes in a level as fanoutSize^(MAX_LEVEL_COUNT-1) * maxSSTableSizeInBytes using BigInteger to avoid silent overflow. If this exceeds Long.MAX_VALUE, the strategy cannot represent level sizes and throws this ConfigurationException, telling the user their maxSSTableSize/fanout combination is absurdly large.","triggerScenarios":"Very large sstable_size_in_mb combined with a large level_fanout_size such that fanout^9 * sstableBytes > 2^63-1 during CREATE/ALTER TABLE or strategy construction.","commonSituations":"Copy-paste of extreme tuning values (e.g. sstable_size_in_mb of millions); accidental extra digits in config automation.","solutions":["Reduce sstable_size_in_mb to a sane value (e.g. 160) and/or keep level_fanout_size at the default 10","ALTER the table with realistic options and re-check","Compute fanout^9 * size_in_bytes offline to verify it fits in a signed 64-bit long before applying"],"exampleFix":"// before\n{'class':'LeveledCompactionStrategy','sstable_size_in_mb':'10000000','level_fanout_size':'50'}\n// after\n{'class':'LeveledCompactionStrategy','sstable_size_in_mb':'160','level_fanout_size':'10'}","handlingStrategy":"validation","validationCode":"long ssSize = Long.parseLong(opts.getOrDefault(\"sstable_size_in_mb\", \"160\"));\nint fanout = Integer.parseInt(opts.getOrDefault(\"level_fanout_size\", \"10\"));\nif (BigInteger.valueOf(fanout).pow(8).multiply(BigInteger.valueOf(ssSize).multiply(BigInteger.valueOf(1L<<20))).compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0)\n    throw new IllegalArgumentException(\"fanout^9 * sstable bytes exceeds Long.MAX_VALUE\");","typeGuard":null,"tryCatchPattern":"try { execute(alterStmt); }\ncatch (ConfigurationException e) { if (e.getMessage().startsWith(\"At most\")) { /* shrink sstable_size_in_mb or fanout */ } else throw e; }","preventionTips":["Compute fanout^(9) * sstableBytes offline before applying extreme tuning","Cap sstable_size_in_mb and level_fanout_size in tooling","Keep LCS options near defaults unless profiling justifies otherwise"],"tags":["compaction","configuration","overflow"],"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-17T15:17:12.973Z"}