From: Otto Moerbeek Date: Wed, 23 Mar 2022 09:38:59 +0000 (+0100) Subject: Move implemenation of failed and non-resolving table to .cc file X-Git-Tag: rec-4.7.0-beta1~42^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F11443%2Fhead;p=thirdparty%2Fpdns.git Move implemenation of failed and non-resolving table to .cc file --- diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 6a39c7ea16..51f9a7e56e 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -38,6 +38,75 @@ #include "validate-recursor.hh" #include "rec-taskqueue.hh" +template +class fails_t : public boost::noncopyable +{ +public: + typedef uint64_t counter_t; + struct value_t { + value_t(const T &a) : key(a) {} + T key; + mutable counter_t value{0}; + time_t last{0}; + }; + + typedef multi_index_container, member>, + ordered_non_unique, member> + >> cont_t; + + cont_t getMapCopy() const { + return d_cont; + } + + counter_t value(const T& t) const + { + auto i = d_cont.find(t); + + if (i == d_cont.end()) { + return 0; + } + return i->value; + } + + counter_t incr(const T& key, const struct timeval& now) + { + auto i = d_cont.insert(key).first; + + if (i->value < std::numeric_limits::max()) { + i->value++; + } + auto &ind = d_cont.template get(); + time_t tm = now.tv_sec; + ind.modify(i, [tm](value_t &val) { val.last = tm; }); + return i->value; + } + + void clear(const T& a) + { + d_cont.erase(a); + } + + void clear() + { + d_cont.clear(); + } + + size_t size() const + { + return d_cont.size(); + } + + void prune(time_t cutoff) { + auto &ind = d_cont.template get(); + ind.erase(ind.begin(), ind.upper_bound(cutoff)); + } + +private: + cont_t d_cont; +}; + struct SavedParentEntry { SavedParentEntry(const DNSName& name, map>&& nsAddresses, time_t ttd) @@ -90,8 +159,8 @@ EDNSSubnetOpts SyncRes::s_ecsScopeZero; string SyncRes::s_serverID; SyncRes::LogMode SyncRes::s_lm; const std::unordered_set SyncRes::s_redirectionQTypes = {QType::CNAME, QType::DNAME}; -LockGuarded> SyncRes::s_fails; -LockGuarded> SyncRes::s_nonresolving; +static LockGuarded> s_fails; +static LockGuarded> s_nonresolving; unsigned int SyncRes::s_maxnegttl; unsigned int SyncRes::s_maxbogusttl; @@ -723,6 +792,26 @@ uint64_t SyncRes::doDumpThrottleMap(int fd) return count; } +uint64_t SyncRes::getFailedServersSize() +{ + return s_fails.lock()->size(); +} + +void SyncRes::clearFailedServers() +{ + s_fails.lock()->clear(); +} + +void SyncRes::pruneFailedServers(time_t cutoff) +{ + s_fails.lock()->prune(cutoff); +} + +unsigned long SyncRes::getServerFailsCount(const ComboAddress& server) +{ + return s_fails.lock()->value(server); +} + uint64_t SyncRes::doDumpFailedServers(int fd) { int newfd = dup(fd); @@ -750,6 +839,21 @@ uint64_t SyncRes::doDumpFailedServers(int fd) return count; } +uint64_t SyncRes::getNonResolvingNSSize() +{ + return s_nonresolving.lock()->size(); +} + +void SyncRes::clearNonResolvingNS() +{ + s_nonresolving.lock()->clear(); +} + +void SyncRes::pruneNonResolving(time_t cutoff) +{ + s_nonresolving.lock()->prune(cutoff); +} + uint64_t SyncRes::doDumpNonResolvingNS(int fd) { int newfd = dup(fd); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 3d9adb755c..cc37ca4629 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -192,75 +192,6 @@ private: float d_val{0}; }; -template -class fails_t : public boost::noncopyable -{ -public: - typedef uint64_t counter_t; - struct value_t { - value_t(const T &a) : key(a) {} - T key; - mutable counter_t value{0}; - time_t last{0}; - }; - - typedef multi_index_container, member>, - ordered_non_unique, member> - >> cont_t; - - cont_t getMapCopy() const { - return d_cont; - } - - counter_t value(const T& t) const - { - auto i = d_cont.find(t); - - if (i == d_cont.end()) { - return 0; - } - return i->value; - } - - counter_t incr(const T& key, const struct timeval& now) - { - auto i = d_cont.insert(key).first; - - if (i->value < std::numeric_limits::max()) { - i->value++; - } - auto &ind = d_cont.template get(); - time_t tm = now.tv_sec; - ind.modify(i, [tm](value_t &val) { val.last = tm; }); - return i->value; - } - - void clear(const T& a) - { - d_cont.erase(a); - } - - void clear() - { - d_cont.clear(); - } - - size_t size() const - { - return d_cont.size(); - } - - void prune(time_t cutoff) { - auto &ind = d_cont.template get(); - ind.erase(ind.begin(), ind.upper_bound(cutoff)); - } - -private: - cont_t d_cont; -}; - extern std::unique_ptr g_negCache; class SyncRes : public boost::noncopyable @@ -407,10 +338,6 @@ public: }; - - static LockGuarded> s_fails; - static LockGuarded> s_nonresolving; - struct ThreadLocalStorage { nsspeeds_t nsSpeeds; throttle_t throttle; @@ -545,34 +472,15 @@ public: { t_sstorage.throttle.throttle(now, std::make_tuple(server, g_rootdnsname, 0), duration, tries); } - static uint64_t getFailedServersSize() - { - return s_fails.lock()->size(); - } - static uint64_t getNonResolvingNSSize() - { - return s_nonresolving.lock()->size(); - } - static void clearFailedServers() - { - s_fails.lock()->clear(); - } - static void clearNonResolvingNS() - { - s_nonresolving.lock()->clear(); - } - static void pruneFailedServers(time_t cutoff) - { - s_fails.lock()->prune(cutoff); - } - static unsigned long getServerFailsCount(const ComboAddress& server) - { - return s_fails.lock()->value(server); - } - static void pruneNonResolving(time_t cutoff) - { - s_nonresolving.lock()->prune(cutoff); - } + + static uint64_t getFailedServersSize(); + static void clearFailedServers(); + static void pruneFailedServers(time_t cutoff); + static unsigned long getServerFailsCount(const ComboAddress& server); + + static void clearNonResolvingNS(); + static uint64_t getNonResolvingNSSize(); + static void pruneNonResolving(time_t cutoff); static void clearSaveParentsNSSets(); static size_t getSaveParentsNSSetsSize();