From: Miod Vallat Date: Fri, 24 Oct 2025 09:32:30 +0000 (+0200) Subject: Factor duplicated code. X-Git-Tag: rec-5.4.0-alpha1~113^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43e97fe30780084c1b05e4dba58e3a681de399f8;p=thirdparty%2Fpdns.git Factor duplicated code. Signed-off-by: Miod Vallat --- diff --git a/pdns/auth-secondarycommunicator.cc b/pdns/auth-secondarycommunicator.cc index 25bf76974a..ea224b8f18 100644 --- a/pdns/auth-secondarycommunicator.cc +++ b/pdns/auth-secondarycommunicator.cc @@ -1016,18 +1016,10 @@ void CommunicatorClass::suck(const ZoneName& domain, const ComboAddress& remote, } catch (ResolverException& re) { { - auto data = d_data.lock(); // The AXFR probably failed due to a problem on the primary server. If SOA-checks against this primary // still succeed, we would constantly try to AXFR the zone. To avoid this, we add the zone to the list of // failed secondary-checks. This will suspend secondary-checks (and subsequent AXFR) for this zone for some time. - uint64_t newCount = 1; - time_t now = time(nullptr); - const auto failedEntry = data->d_failedSecondaryRefresh.find(domain); - if (failedEntry != data->d_failedSecondaryRefresh.end()) { - newCount = data->d_failedSecondaryRefresh[domain].first + 1; - } - time_t nextCheck = now + std::min(newCount * d_tickinterval, (uint64_t)::arg().asNum("default-ttl")); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) - data->d_failedSecondaryRefresh[domain] = {newCount, nextCheck}; + auto [newCount, nextCheck] = markAsFailed(domain); g_log << Logger::Warning << logPrefix << "unable to xfr zone (ResolverException): " << re.reason << " (This was attempt number " << newCount << ". Excluding zone from secondary-checks until " << humanTime(nextCheck) << ")" << endl; } if (ctx.domain.backend != nullptr && transaction) { @@ -1308,14 +1300,7 @@ void CommunicatorClass::secondaryRefresh(PacketHandler* P) // NOLINT(readability } if (ssr.d_freshness.count(di.id) == 0) { // If we don't have an answer for the domain - uint64_t newCount = 1; - auto data = d_data.lock(); - const auto failedEntry = data->d_failedSecondaryRefresh.find(di.zone); - if (failedEntry != data->d_failedSecondaryRefresh.end()) { - newCount = data->d_failedSecondaryRefresh[di.zone].first + 1; - } - time_t nextCheck = now + std::min(newCount * d_tickinterval, (uint64_t)::arg().asNum("default-ttl")); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) - data->d_failedSecondaryRefresh[di.zone] = {newCount, nextCheck}; + auto [newCount, nextCheck] = markAsFailed(di.zone); if (newCount == 1) { g_log << Logger::Warning << "Unable to retrieve SOA for " << di.zone << ", this was the first time. NOTE: For every subsequent failed SOA check the domain will be suspended from freshness checks for 'num-errors x " << d_tickinterval << " seconds', with a maximum of " << (uint64_t)::arg().asNum("default-ttl") << " seconds. Skipping SOA checks until " << humanTime(nextCheck) << endl; } @@ -1437,3 +1422,17 @@ size_t CommunicatorClass::getSuckRequestsWaiting() { return d_data.lock()->d_suckdomains.size(); } + +std::pair CommunicatorClass::markAsFailed(const ZoneName& domain) +{ + uint64_t newCount = 1; + auto data = d_data.lock(); + time_t now = time(nullptr); + const auto failedEntry = data->d_failedSecondaryRefresh.find(domain); + if (failedEntry != data->d_failedSecondaryRefresh.end()) { + newCount = data->d_failedSecondaryRefresh[domain].first + 1; + } + time_t nextCheck = now + std::min(newCount * d_tickinterval, (uint64_t)::arg().asNum("default-ttl")); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) + data->d_failedSecondaryRefresh[domain] = {newCount, nextCheck}; + return std::make_pair(newCount, nextCheck); +} diff --git a/pdns/communicator.hh b/pdns/communicator.hh index c4506cc1bb..f75f484b6e 100644 --- a/pdns/communicator.hh +++ b/pdns/communicator.hh @@ -195,6 +195,7 @@ private: void secondaryRefresh(PacketHandler* P); void primaryUpdateCheck(PacketHandler* P); void getUpdatedProducers(UeberBackend* B, vector& domains, const std::unordered_set& catalogs, CatalogHashMap& catalogHashes); + std::pair markAsFailed(const ZoneName& domain); Semaphore d_suck_sem; Semaphore d_any_sem;