{"record":{"id":"76830d031cf5b576","repo":"apache/cassandra","slug":"scaling-parameter-s-must-match-s","errorCode":null,"errorMessage":"Scaling parameter %s must match %s","messagePattern":"Scaling parameter (.+?) must match (.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java","lineNumber":124,"sourceCode":"    {\n        return Controller.validateOptions(AbstractCompactionStrategy.validateOptions(options));\n    }\n\n    public static int fanoutFromScalingParameter(int w)\n    {\n        return w < 0 ? 2 - w : 2 + w; // see formula in design doc\n    }\n\n    public static int thresholdFromScalingParameter(int w)\n    {\n        return w <= 0 ? 2 : 2 + w; // see formula in design doc\n    }\n\n    public static int parseScalingParameter(String value)\n    {\n        Matcher m = SCALING_PARAMETER_PATTERN.matcher(value);\n        if (!m.matches())\n            throw new ConfigurationException(\"Scaling parameter \" + value + \" must match \" + SCALING_PARAMETER_PATTERN_SIMPLIFIED);\n\n        if (m.group(1) != null)\n            return 0;\n        else if (m.group(2) != null)\n            return 2 - atLeast2(Integer.parseInt(m.group(2)), value);\n        else if (m.group(3) != null)\n            return atLeast2(Integer.parseInt(m.group(3)), value) - 2;\n        else\n            return Integer.parseInt(m.group(4));\n    }\n\n    private static int atLeast2(int value, String str)\n    {\n        if (value < 2)\n            throw new ConfigurationException(\"Fan factor cannot be lower than 2 in \" + str);\n        return value;\n    }\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java#L106-L142","documentation":"UnifiedCompactionStrategy.parseScalingParameter validates the scaling parameter W against a fixed regex; the message echoes the simplified pattern the value must match (an optional minus, then either 0, a multi-digit number, 'L+n', or a plain positive number). A non-matching value throws ConfigurationException.","triggerScenarios":"Configuring scaling_wainer / scaling_parameter option of UnifiedCompactionStrategy (e.g. 'min_sstable_size', 'scaling_wainer' style entries) with a value like 'abc', '3.5', 'x2', '+5', or an empty string.","commonSituations":"Typos in the compaction option; copying documentation examples that omit the accepted grammar; tools writing floats instead of integers or 'L+n' expressions.","solutions":["Provide a value matching the pattern, e.g. '-1', '0', '5', or 'L+4'","Check the intended form: optional '-' prefix; 0; multi-digit integer; 'L+n'; or small positive integer","Catch ConfigurationException when applying the table option","Consult UCS documentation for the meaning of O(W) vs L(n) scaling forms"],"exampleFix":"// before\n'scaling_wainer': 'x2'\n// after\n'scaling_wainer': '2'","handlingStrategy":"validation","validationCode":"private static final Pattern SCALING = Pattern.compile(\"-?(0|\\\\d{2,}|L\\\\+\\\\d+|\\\\d)\");\nif (opts.containsKey(\"scaling_wainer\") && !SCALING.matcher(opts.get(\"scaling_wainer\")).matches())\n    throw new IllegalArgumentException(\"scaling parameter must match the simplified UCS pattern\");","typeGuard":"static boolean isValidScalingParameter(String s) { return s != null && s.matches(\"-?(0|\\\\d{2,}|L\\\\+\\\\d+|\\\\d)\"); }","tryCatchPattern":"try {\n    session.execute(alterStmt);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Scaling parameter\")) { /* correct the option and retry */ }\n    throw e;\n}","preventionTips":["Use only documented forms: negative, 0, multi-digit int, L+n, or single digit","Add a unit test that validates UCS option maps before applying","Copy examples from the Cassandra UCS documentation, not ad-hoc strings"],"tags":["cassandra","configuration","compaction","regex","ucs"],"backgroundTag":"invalid-argument-format","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"}