From: Miod Vallat Date: Mon, 29 Sep 2025 12:33:02 +0000 (+0200) Subject: Handle freshness check timestamps similarly to notified serials. X-Git-Tag: rec-5.4.0-alpha1~237^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc22b370d4af51e3dede9a50d9677854e7f58fe1;p=thirdparty%2Fpdns.git Handle freshness check timestamps similarly to notified serials. Signed-off-by: Miod Vallat --- diff --git a/docs/backends/lmdb.rst b/docs/backends/lmdb.rst index 18741ad16e..ea8911e122 100644 --- a/docs/backends/lmdb.rst +++ b/docs/backends/lmdb.rst @@ -144,13 +144,13 @@ Only enable this if you are using Lightning Stream. - Default: yes Always update the domains table in the database when the last notification -timestamp is modified. +or the freshness check timestamp are modified. If disabled, these timestamps will only be written back to the database when other changes to the domain (such as accounts) occur. This setting is also available in version 4.9.9. **Warning**: Running with this flag disabled will cause spurious notifications -to be sent upon startup, unless a ``flush'' command is sent using +to be sent upon startup, unless a ``flush`` command is sent using :doc:`pdns_control <../manpages/pdns_control.1>` before stopping the PowerDNS Authoritative Server. diff --git a/modules/lmdbbackend/lmdbbackend.cc b/modules/lmdbbackend/lmdbbackend.cc index 3fe0e531cc..efdb5a100e 100644 --- a/modules/lmdbbackend/lmdbbackend.cc +++ b/modules/lmdbbackend/lmdbbackend.cc @@ -1257,6 +1257,7 @@ void LMDBBackend::consolidateDomainInfo(DomainInfo& info) const TransientDomainInfo tdi; container->get(info.id, tdi); info.notified_serial = tdi.notified_serial; + info.last_check = tdi.last_check; } } @@ -1268,7 +1269,7 @@ void LMDBBackend::writeDomainInfo(const DomainInfo& info) container->get(info.id, tdi); // Only remove the in-memory value if it has not been modified since the // DomainInfo data was set up. - if (tdi.notified_serial == info.notified_serial) { + if (tdi.notified_serial == info.notified_serial && tdi.last_check == info.last_check) { container->remove(info.id); } } @@ -2321,16 +2322,31 @@ void LMDBBackend::getUnfreshSecondaryInfos(vector* domains) void LMDBBackend::setStale(domainid_t domain_id) { - genChangeDomain(domain_id, [](DomainInfo& di) { - di.last_check = 0; - }); + setLastCheckTime(domain_id, 0); } void LMDBBackend::setFresh(domainid_t domain_id) { - genChangeDomain(domain_id, [](DomainInfo& di) { - di.last_check = time(nullptr); - }); + setLastCheckTime(domain_id, time(nullptr)); +} + +void LMDBBackend::setLastCheckTime(domainid_t domain_id, time_t last_check) +{ + if (d_write_notification_update) { + genChangeDomain(domain_id, [last_check](DomainInfo& info) { + info.last_check = last_check; + }); + return; + } + + DomainInfo info; + if (findDomain(domain_id, info)) { + auto container = s_transient_domain_info.write_lock(); + TransientDomainInfo tdi; + container->get(info.id, tdi); + tdi.last_check = last_check; + container->update(info.id, tdi); + } } void LMDBBackend::getUpdatedPrimaries(vector& updatedDomains, std::unordered_set& catalogs, CatalogHashMap& catalogHashes) @@ -2375,8 +2391,7 @@ void LMDBBackend::setNotified(domainid_t domain_id, uint32_t serial) if (findDomain(domain_id, info)) { auto container = s_transient_domain_info.write_lock(); TransientDomainInfo tdi; - // will need container->get(info.id, tdi); once TransientDomainInfo grows - // more fields. + container->get(info.id, tdi); tdi.notified_serial = serial; container->update(info.id, tdi); } @@ -3435,6 +3450,7 @@ void LMDBBackend::flush() DomainInfo info; if (findDomain(domid, info)) { info.notified_serial = tdi.notified_serial; + info.last_check = tdi.last_check; auto txn = d_tdomains->getRWTransaction(); txn.put(info, info.id); txn.commit(); diff --git a/modules/lmdbbackend/lmdbbackend.hh b/modules/lmdbbackend/lmdbbackend.hh index 8bb5d996b1..c51ea7fe31 100644 --- a/modules/lmdbbackend/lmdbbackend.hh +++ b/modules/lmdbbackend/lmdbbackend.hh @@ -343,6 +343,8 @@ private: void consolidateDomainInfo(DomainInfo& info) const; void writeDomainInfo(const DomainInfo& info); + void setLastCheckTime(domainid_t domain_id, time_t last_check); + void getAllDomainsFiltered(vector* domains, const std::function& allow); void lookupStart(domainid_t domain_id, const std::string& match, bool dolog); @@ -364,6 +366,7 @@ private: // database. struct TransientDomainInfo { + time_t last_check{}; uint32_t notified_serial{}; }; // Cache of DomainInfo notified_serial values