In the case where the weight of all records is set to zero, former code
was trying to compute probability by dividing by 0.
Another motivation to forbid the use of the "zero" weight is that the
desired behavior was not clear.
Using the ``weight`` attribute
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-You can use record attributes to define weight.
+You can use record attributes to define positive and non-zero weight.
If this is given, only one record is chosen randomly based on the weight.
Probability is calculated by summing up the weights and dividing each weight with the sum.
rr.content = content;
} else if (attr == "weight") {
rr.weight = iter->second.as<int>();
- if (rr.weight < 0) {
- g_log<<Logger::Error<<"Weight cannot be negative for " << rr.qname << endl;
- throw PDNSException(string("Weight cannot be negative for ") + rr.qname.toLogString());
+ if (rr.weight <= 0) {
+ g_log<<Logger::Error<<"Weight must be positive for " << rr.qname << endl;
+ throw PDNSException(string("Weight must be positive for ") + rr.qname.toLogString());
}
rr.has_weight = true;
} else if (attr == "ttl") {