apache/cassandra · error · ConfigurationException
DC weights must be zero or positive
Error message
DC weights must be zero or positive
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/service/accord/topology/ParameterizedFastPathStrategy.java:134
public String toString()
{
return autoWeight ? name : name + ':' + weight;
}
static String validateDC(String dc)
{
dc = dc.trim();
if (dc.isEmpty())
throw cfe("dc name must not be empty", DCS);
return dc;
}
static int validateWeight(String w)
{
int weight = Integer.parseInt(w);
if (weight < 0)
throw cfe("DC weights must be zero or positive");
return weight;
}
static WeightedDc fromString(String s, int idx)
{
s = s.trim();
if (s.isEmpty())
throw cfe("%s entries must not be empty", DCS);
String[] parts = COLON_SEPARATOR.split(s);
if (parts.length == 1)
return new WeightedDc(validateDC(parts[0]), idx, true);
else if (parts.length == 2)
return new WeightedDc(validateDC(parts[0]), validateWeight(parts[1]), false);
else
throw cfe("Invalid dc weighting syntax %s, use <dc>:<weight>", s);
}
}View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before 'dcs':'dc1:-2,dc2:5' // after 'dcs':'dc1:0,dc2:5'
Defensive patterns
Strategy: validation
Validate before calling
for (String entry : dcs.split(",")) {
String[] parts = entry.trim().split(":");
if (parts.length == 2 && Integer.parseInt(parts[1]) < 0)
throw new IllegalArgumentException("negative weight in dcs entry: " + entry);
} Try / catch
try { applyFastPathOption(opts); } catch (org.apache.cassandra.exceptions.ConfigurationException e) {
if (e.getMessage().contains("zero or positive"))
log.error("Replace negative dc weights with 0 to deprioritize a DC");
} Prevention
- 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
When it happens
Trigger: Providing a dcs entry with a negative weight such as 'dcs=dc1:-1' or 'dc2:-5' when configuring a parameterized fast_path strategy.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- accord.journal_directory must not be the same as any data_fi
- accord.cache_size option was set incorrectly to '<value>', s
- Invalid accord progress log configuration:
- Concurrent accord operations must be non-negative
- Fan factor cannot be lower than 2 in %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/e037744040da3833.
Report an issue: GitHub.