From 49b26e34fa3790a57e90c68f79c36dadfb78405c Mon Sep 17 00:00:00 2001 From: Jeremy Clerc Date: Wed, 20 Nov 2019 16:08:01 +0100 Subject: [PATCH] geoipbackend: propagate weighted rounding gap fix 618824cb73db384d52cf379c7d49744dbb5b8f6d (PR#7219) fixed computation of weighted round robin computation per Qtype. That commit also introduced a bug on the removal of the rounding gap. Because it works on a copy of a GeoIPDNSResourceRecord, the updated weight of the last record is not propagated to the domain object. The bug is as follow: 1. The total weight is < 1000 2. The random probabability gives 1000 3. There is no resource to be given This commit restore the original behavior of ensuring the gap is added to the last resource so we always have 1000. --- modules/geoipbackend/geoipbackend.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index b56d16f5d9..35a62c8d41 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -263,7 +263,7 @@ void GeoIPBackend::initialize() { for(auto &item: dom.records) { map weights; map sums; - map lasts; + map lasts; bool has_weight=false; // first we look for used weight for(const auto &rr: item.second) { @@ -277,13 +277,13 @@ void GeoIPBackend::initialize() { rr.weight=static_cast((static_cast(rr.weight) / weights[rr_type])*1000.0); sums[rr_type] += rr.weight; rr.has_weight = has_weight; - lasts[rr_type] = rr; + lasts[rr_type] = &rr; } // remove rounding gap for(auto &x: lasts) { float sum = sums[x.first]; if (sum < 1000) - x.second.weight += (1000-sum); + x.second->weight += (1000-sum); } } } -- 2.47.2