]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Rework deleteDomainRecords() interface.
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 18 Jun 2025 09:26:49 +0000 (11:26 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 18 Jun 2025 10:50:25 +0000 (12:50 +0200)
NFC yet, will benefit upcoming commits.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
modules/lmdbbackend/lmdbbackend.cc
modules/lmdbbackend/lmdbbackend.hh

index acfac59dcf1ddda195a46a0077ed0ddb69c379d5..3e17a7f9bbfa9c66ab8ad9b612db4ce53712e303 100644 (file)
@@ -1111,20 +1111,20 @@ static std::shared_ptr<DNSRecordContent> deserializeContentZR(uint16_t qtype, co
 #define StringView string
 #endif
 
-void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, domainid_t domain_id, uint16_t qtype)
+void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, uint16_t qtype, const std::string& match)
 {
-  compoundOrdername co;
-  string match = co(domain_id);
-
   auto cursor = txn.txn->getCursor(txn.db->dbi);
-  MDBOutVal key, val;
-  //  cout<<"Match: "<<makeHexDump(match);
-  if (!cursor.lower_bound(match, key, val)) {
+  MDBOutVal key{};
+  MDBOutVal val{};
+
+  if (cursor.lower_bound(match, key, val) == 0) {
     while (key.getNoStripHeader<StringView>().rfind(match, 0) == 0) {
-      if (qtype == QType::ANY || co.getQType(key.getNoStripHeader<StringView>()) == qtype)
+      if (qtype == QType::ANY || compoundOrdername::getQType(key.getNoStripHeader<StringView>()) == qtype) {
         cursor.del();
-      if (cursor.next(key, val))
+      }
+      if (cursor.next(key, val) != 0) {
         break;
+      }
     }
   }
 }
@@ -1162,7 +1162,9 @@ bool LMDBBackend::startTransaction(const ZoneName& domain, domainid_t domain_id)
   d_transactiondomain = domain;
   d_transactiondomainid = real_id;
   if (domain_id != UnknownDomainID) {
-    LMDBBackend::deleteDomainRecords(*d_rwtxn, domain_id);
+    compoundOrdername order;
+    string match = order(domain_id);
+    LMDBBackend::deleteDomainRecords(*d_rwtxn, QType::ANY, match);
   }
 
   return true;
@@ -2776,7 +2778,9 @@ bool LMDBBackend::updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& in
 
   // if remove is set, all ENTs should be removed & nothing else should be done
   if (remove) {
-    LMDBBackend::deleteDomainRecords(*txn, domain_id, 0);
+    compoundOrdername order;
+    string match = order(domain_id);
+    LMDBBackend::deleteDomainRecords(*txn, QType::ENT, match);
   }
   else {
     DomainInfo di;
index a9aaeb02aa11920ed0dc089dd2f56809eeef5314..dd2b5142dc7d04f507d4a06437980a0687f0c3cc 100644 (file)
@@ -331,7 +331,7 @@ private:
   std::shared_ptr<RecordsROTransaction> getRecordsROTransaction(domainid_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn = nullptr);
   int genChangeDomain(const ZoneName& domain, const std::function<void(DomainInfo&)>& func);
   int genChangeDomain(domainid_t id, const std::function<void(DomainInfo&)>& func);
-  static void deleteDomainRecords(RecordsRWTransaction& txn, domainid_t domain_id, uint16_t qtype = QType::ANY);
+  static void deleteDomainRecords(RecordsRWTransaction& txn, uint16_t qtype, const std::string& match);
 
   void getAllDomainsFiltered(vector<DomainInfo>* domains, const std::function<bool(DomainInfo&)>& allow);