From 47dfc3aed44aeebc86d799cf359571f0c7e540f2 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 29 Sep 2020 15:46:20 +0200 Subject: [PATCH] Backport #9515 to 4.4.x: actually fix wipe-cache-typed --- pdns/rec_channel_rec.cc | 15 +++++---------- pdns/recursor_cache.cc | 10 +++++++--- pdns/reczones.cc | 2 +- pdns/syncres.hh | 1 - pdns/ws-recursor.cc | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index b84a203f2d..b92b80c94a 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -394,11 +394,6 @@ static string doDumpFailedServers(T begin, T end) return "dumped "+std::to_string(total)+" records\n"; } -uint64_t* pleaseWipeCache(const DNSName& canon, bool subtree, uint16_t qtype) -{ - return new uint64_t(s_RC->doWipeCache(canon, subtree)); -} - uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree, uint16_t qtype) { return new uint64_t(t_packetCache->doWipePacketCache(canon, qtype, subtree)); @@ -436,7 +431,7 @@ static string doWipeCache(T begin, T end, uint16_t qtype) int count=0, pcount=0, countNeg=0; for (auto wipe : toWipe) { try { - count+= broadcastAccFunction([=]{ return pleaseWipeCache(wipe.first, wipe.second, qtype);}); + count+= s_RC->doWipeCache(wipe.first, wipe.second, qtype); pcount+= broadcastAccFunction([=]{ return pleaseWipePacketCache(wipe.first, wipe.second, qtype);}); countNeg+=broadcastAccFunction([=]{ return pleaseWipeAndCountNegCache(wipe.first, wipe.second);}); } @@ -544,7 +539,7 @@ static string doAddNTA(T begin, T end) lci.negAnchors[who] = why; }); try { - broadcastAccFunction([=]{return pleaseWipeCache(who, true, 0xffff);}); + s_RC->doWipeCache(who, true, 0xffff); broadcastAccFunction([=]{return pleaseWipePacketCache(who, true, 0xffff);}); broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(who, true);}); } @@ -598,7 +593,7 @@ static string doClearNTA(T begin, T end) g_luaconfs.modify([entry](LuaConfigItems& lci) { lci.negAnchors.erase(entry); }); - broadcastAccFunction([=]{return pleaseWipeCache(entry, true, 0xffff);}); + s_RC->doWipeCache(entry, true, 0xffff); broadcastAccFunction([=]{return pleaseWipePacketCache(entry, true, 0xffff);}); broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(entry, true);}); if (!first) { @@ -661,7 +656,7 @@ static string doAddTA(T begin, T end) auto ds=std::dynamic_pointer_cast(DSRecordContent::make(what)); lci.dsAnchors[who].insert(*ds); }); - broadcastAccFunction([=]{return pleaseWipeCache(who, true, 0xffff);}); + s_RC->doWipeCache(who, true, 0xffff); broadcastAccFunction([=]{return pleaseWipePacketCache(who, true, 0xffff);}); broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(who, true);}); g_log<([=]{return pleaseWipeCache(entry, true, 0xffff);}); + s_RC->doWipeCache(entry, true, 0xffff); broadcastAccFunction([=]{return pleaseWipePacketCache(entry, true, 0xffff);}); broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(entry, true);}); if (!first) { diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index 953562123f..4f209d3147 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -412,9 +412,13 @@ size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, uint16_t qty auto range = idx.equal_range(name); auto i = range.first; while (i != range.second) { - i = idx.erase(i); - count++; - map.d_entriesCount--; + if (i->d_qtype == qtype || qtype == 0xffff) { + i = idx.erase(i); + count++; + map.d_entriesCount--; + } else { + ++i; + } } if (qtype == 0xffff) { diff --git a/pdns/reczones.cc b/pdns/reczones.cc index 8d2adbab98..bbcf3f2a53 100644 --- a/pdns/reczones.cc +++ b/pdns/reczones.cc @@ -366,7 +366,7 @@ string reloadAuthAndForwards() } for(const auto& i : oldAndNewDomains) { - broadcastAccFunction([&]{return pleaseWipeCache(i, true, 0xffff);}); + s_RC->doWipeCache(i, true, 0xffff); broadcastAccFunction([&]{return pleaseWipePacketCache(i, true, 0xffff);}); broadcastAccFunction([&]{return pleaseWipeAndCountNegCache(i, true);}); } diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 95a9aace06..1d2c3a97b0 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -1122,7 +1122,6 @@ uint64_t* pleaseGetConcurrentQueries(); uint64_t* pleaseGetThrottleSize(); uint64_t* pleaseGetPacketCacheHits(); uint64_t* pleaseGetPacketCacheSize(); -uint64_t* pleaseWipeCache(const DNSName& canon, bool subtree=false, uint16_t qtype=0xffff); uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree, uint16_t qtype=0xffff); uint64_t* pleaseWipeAndCountNegCache(const DNSName& canon, bool subtree=false); void doCarbonDump(void*); diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 83e3e43af3..661e8ecf82 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -382,7 +382,7 @@ static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { DNSName canon = apiNameToDNSName(req->getvars["domain"]); bool subtree = (req->getvars.count("subtree") > 0 && req->getvars["subtree"].compare("true") == 0); - int count = broadcastAccFunction([=]{return pleaseWipeCache(canon, subtree, 0xffff);}); + int count = s_RC->doWipeCache(canon, subtree, 0xffff); count += broadcastAccFunction([=]{return pleaseWipePacketCache(canon, subtree, 0xffff);}); count += broadcastAccFunction([=]{return pleaseWipeAndCountNegCache(canon, subtree);}); resp->setBody(Json::object { -- 2.47.2