From: Miod Vallat Date: Fri, 18 Apr 2025 08:38:20 +0000 (+0200) Subject: Allow backends to provide faster lookupEnd() logic. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ada95a1a528955d1a016f795c84e0cd44dd91eed;p=thirdparty%2Fpdns.git Allow backends to provide faster lookupEnd() logic. --- diff --git a/pdns/dnsbackend.cc b/pdns/dnsbackend.cc index 8e1d436ea..2edbde4ee 100644 --- a/pdns/dnsbackend.cc +++ b/pdns/dnsbackend.cc @@ -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; diff --git a/pdns/dnsbackend.hh b/pdns/dnsbackend.hh index b5e0ffdcf..e2417de4f 100644 --- a/pdns/dnsbackend.hh +++ b/pdns/dnsbackend.hh @@ -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 diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index 0bda4ebfd..7a835c8b1 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -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(); + } +} diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index d9a0b7cb9..db0681e76 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -67,6 +67,7 @@ public: { public: bool get(DNSZoneRecord& record); + void lookupEnd() const; handle(); ~handle();