{"record":{"id":"e037744040da3833","repo":"apache/cassandra","slug":"dc-weights-must-be-zero-or-positive","errorCode":null,"errorMessage":"DC weights must be zero or positive","messagePattern":"DC weights must be zero or positive","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/accord/topology/ParameterizedFastPathStrategy.java","lineNumber":134,"sourceCode":"\n        public String toString()\n        {\n            return autoWeight ? name : name + ':' + weight;\n        }\n\n        static String validateDC(String dc)\n        {\n            dc = dc.trim();\n            if (dc.isEmpty())\n                throw cfe(\"dc name must not be empty\", DCS);\n            return dc;\n        }\n\n        static int validateWeight(String w)\n        {\n            int weight = Integer.parseInt(w);\n            if (weight < 0)\n                throw cfe(\"DC weights must be zero or positive\");\n            return weight;\n        }\n\n        static WeightedDc fromString(String s, int idx)\n        {\n            s = s.trim();\n            if (s.isEmpty())\n                throw cfe(\"%s entries must not be empty\", DCS);\n\n            String[] parts = COLON_SEPARATOR.split(s);\n            if (parts.length == 1)\n                return new WeightedDc(validateDC(parts[0]), idx, true);\n            else if (parts.length == 2)\n                return new WeightedDc(validateDC(parts[0]), validateWeight(parts[1]), false);\n            else\n                throw cfe(\"Invalid dc weighting syntax %s, use <dc>:<weight>\", s);\n        }\n    }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/accord/topology/ParameterizedFastPathStrategy.java#L116-L152","documentation":"WeightedDc.validateWeight parses the weight part of a dcs entry as an int and rejects negative values with a ConfigurationException ('DC weights must be zero or positive'). Weights determine how strongly a DC participates in Accord fast-path electorate selection; zero means least preferred.","triggerScenarios":"Providing a dcs entry with a negative weight such as 'dcs=dc1:-1' or 'dc2:-5' when configuring a parameterized fast_path strategy.","commonSituations":"Typo'd minus sign where the operator intended to deprioritize a DC (should be weight 0); arithmetic applied to weights yielding negatives; editing serialized asMap output by hand.","solutions":["Replace the negative weight with 0 to effectively deprioritize that DC","Use positive integers to rank DCs, e.g. dcs=dc1:1,dc2:3","Re-issue the ALTER/CREATE keyspace statement with corrected weights"],"exampleFix":"// before\n'dcs':'dc1:-2,dc2:5'\n\n// after\n'dcs':'dc1:0,dc2:5'","handlingStrategy":"validation","validationCode":"for (String entry : dcs.split(\",\")) {\n    String[] parts = entry.trim().split(\":\");\n    if (parts.length == 2 && Integer.parseInt(parts[1]) < 0)\n        throw new IllegalArgumentException(\"negative weight in dcs entry: \" + entry);\n}","typeGuard":null,"tryCatchPattern":"try { applyFastPathOption(opts); } catch (org.apache.cassandra.exceptions.ConfigurationException e) {\n    if (e.getMessage().contains(\"zero or positive\"))\n        log.error(\"Replace negative dc weights with 0 to deprioritize a DC\");\n}","preventionTips":["Use 0 (not negative) to deprioritize a DC","Compute weights with clamping: Math.max(0, w)","Document valid weight range (>= 0) wherever the option is exposed","Unit-test generated fast_path option maps for non-negative weights"],"tags":["cassandra","accord","configuration","validation"],"backgroundTag":"invalid-argument-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"}