]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Allow backends to provide faster lookupEnd() logic.
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 18 Apr 2025 08:38:20 +0000 (10:38 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 4 Aug 2025 13:17:02 +0000 (15:17 +0200)
pdns/dnsbackend.cc
pdns/dnsbackend.hh
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index 8e1d436eac91e8ba61c8607e7264a804918c2c10..2edbde4ee9a594311b5518a6a431c0649393ff19 100644 (file)
@@ -349,6 +349,18 @@ bool DNSBackend::get(DNSZoneRecord& zoneRecord)
   return true;
 }
 
+// This is a naive implementation which invokes get() until there are no more
+// records available and the backend closes any database handle it might have
+// allocated. Backends which can do better shall override this with smarter
+// code.
+void DNSBackend::lookupEnd()
+{
+  DNSZoneRecord zoneRecord;
+  while (get(zoneRecord)) {
+    // do nothing
+  }
+}
+
 bool DNSBackend::getBeforeAndAfterNames(domainid_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after)
 {
   DNSName unhashed;
index b5e0ffdcf8cde8b0b0f392ea95eefc479cb77680..e2417de4f3633692f31c34196bd7fa4ab83e8cdd 100644 (file)
@@ -174,6 +174,8 @@ public:
   virtual void APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, bool include_disabled = false);
   virtual bool get(DNSResourceRecord&) = 0; //!< retrieves one DNSResource record, returns false if no more were available
   virtual bool get(DNSZoneRecord& zoneRecord);
+  //! Close state created by lookup(...).
+  virtual void lookupEnd();
 
   //! Initiates a list of the specified domain
   /** Once initiated, DNSResourceRecord objects can be retrieved using get(). Should return false
index 0bda4ebfd06498f642c273fcc0a6e25066920284..7a835c8b11ee8f910fc6eabeb509eeb2c25ea32c 100644 (file)
@@ -896,11 +896,7 @@ bool UeberBackend::get(DNSZoneRecord& resourceRecord)
 void UeberBackend::lookupEnd()
 {
   if (!d_negcached && !d_cached) {
-    DNSZoneRecord zoneRecord;
-    while (d_handle.get(zoneRecord)) {
-      // Read all answers so the backends will close any database handles they might have allocated.
-      // One day this could be optimized.
-    }
+    d_handle.lookupEnd();
   }
 
   d_answers.clear();
@@ -1106,3 +1102,10 @@ bool UeberBackend::handle::get(DNSZoneRecord& record)
   i = parent->backends.size(); // don't go on to the next backend
   return true;
 }
+
+void UeberBackend::handle::lookupEnd() const
+{
+  if (d_hinterBackend != nullptr) {
+    d_hinterBackend->lookupEnd();
+  }
+}
index d9a0b7cb9400628b0cbe31a6f468d15e7ec58cb0..db0681e7642cbece2271056231ca54f05a35f585 100644 (file)
@@ -67,6 +67,7 @@ public:
   {
   public:
     bool get(DNSZoneRecord& record);
+    void lookupEnd() const;
     handle();
     ~handle();