]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Handle freshness check timestamps similarly to notified serials.
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 29 Sep 2025 12:33:02 +0000 (14:33 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 29 Sep 2025 13:26:36 +0000 (15:26 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
docs/backends/lmdb.rst
modules/lmdbbackend/lmdbbackend.cc
modules/lmdbbackend/lmdbbackend.hh

index 18741ad16e2d06e15839143cba25e47954308506..ea8911e1228b7cfe2cc18a8be2dd4a7ae38d7009 100644 (file)
@@ -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.
 
index 3fe0e531cc40f3efc97801b20fe00caa7a177626..efdb5a100eb615438df9faef1745341e5d216625 100644 (file)
@@ -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<DomainInfo>* 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<DomainInfo>& updatedDomains, std::unordered_set<DNSName>& 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();
index 8bb5d996b1a21552466360099a6c59d90bd2f63c..c51ea7fe311af35f473b546b91f06923dc50b360 100644 (file)
@@ -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<DomainInfo>* domains, const std::function<bool(DomainInfo&)>& 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