]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Try and speedup deletion if flag-deleted by not doing get requests.
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 19 Jun 2025 13:14:32 +0000 (15:14 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 23 Jun 2025 13:28:00 +0000 (15:28 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
ext/lmdb-safe/lmdb-safe.hh
ext/lmdb-safe/lmdb-typed.hh
modules/lmdbbackend/lmdbbackend.cc

index dd0aa6d950543e17bb8f193abee7f526a9f24ee3..7621bf1271afedd4cb7dfa2982430dcfe2a0a299 100644 (file)
@@ -826,35 +826,34 @@ public:
 
   void del(MDBDbi& dbi, const MDBInVal& key)
   {
-    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
-    int mdbDelRc = mdb_del(d_txn, dbi, (MDB_val*)&key.d_mdbval, nullptr);
-    if ((mdbDelRc != 0) && mdbDelRc != MDB_NOTFOUND) {
-      throw std::runtime_error("deleting data: " + std::string(mdb_strerror(mdbDelRc)));
-    }
 #ifndef DNSDIST
-    if (mdbDelRc != MDB_NOTFOUND && LMDBLS::s_flag_deleted) {
-      // if it did exist, we need to mark it as deleted now
-
+    if (LMDBLS::s_flag_deleted) {
+      // Regardless of whether or not it did exist, we need to mark it
+      // as deleted now.
       size_t txid = mdb_txn_id(d_txn);
       if (d_txtime == 0) {
         throw std::runtime_error("got zero txtime");
       }
 
       std::string ins =
-        // std::string((const char*)&txid, sizeof(txid)) +
         LMDBLS::LSheader(d_txtime, txid, LMDBLS::LS_FLAG_DELETED).toString();
-
       MDBInVal pval = ins;
 
-      mdbDelRc = mdb_put(d_txn, dbi,
-                         // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
-                         const_cast<MDB_val*>(&key.d_mdbval),
-                         const_cast<MDB_val*>(&pval.d_mdbval), 0);
-      if (mdbDelRc != 0) {
-        throw std::runtime_error("marking data deleted: " + std::string(mdb_strerror(mdbDelRc)));
+      int mdbPutRc = mdb_put(d_txn, dbi,
+        // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
+        const_cast<MDB_val*>(&key.d_mdbval),
+        const_cast<MDB_val*>(&pval.d_mdbval), 0);
+      if (mdbPutRc != 0) {
+        throw std::runtime_error("marking data deleted: " + std::string(mdb_strerror(mdbPutRc)));
       }
+      return;
     }
 #endif
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
+    int mdbDelRc = mdb_del(d_txn, dbi, (MDB_val*)&key.d_mdbval, nullptr);
+    if (mdbDelRc != 0 && mdbDelRc != MDB_NOTFOUND) {
+      throw std::runtime_error("deleting data: " + std::string(mdb_strerror(mdbDelRc)));
+    }
   }
 
   int get(MDBDbi& dbi, const MDBInVal& key, MDBOutVal& val)
@@ -941,17 +940,9 @@ public:
 #endif
 
 #ifndef DNSDIST
-  void del()
+  void del(const MDBInVal& key)
   {
-    MDBOutVal key, val;
-
     if (LMDBLS::s_flag_deleted) {
-      int rc_get = mdb_cursor_get (*this, &key.d_mdbval, &val.d_mdbval, MDB_GET_CURRENT);
-
-      if(rc_get) {
-        throw std::runtime_error("getting key to mark data as deleted: " + std::string(mdb_strerror(rc_get)));
-      }
-
       size_t txid = mdb_txn_id(d_txn);
       if (d_txtime == 0) { throw std::runtime_error("got zero txtime"); }
 
index bf78f8253cf4edb2a4ed79c90a73b53bfa162002..f3421e1733c1845ed9eb00950f88d0208ebc87ba 100644 (file)
@@ -822,7 +822,7 @@ public:
         T value;
         deserializeFromBuffer(data.get<std::string>(), value);
         clearIndex(key.get<uint32_t>(), value);
-        cursor.del();
+        cursor.del(key);
       }
     }
 
index 77e498dfffbc4e8d1468eab19b31e9020db7cc05..a28eac00450d89f6e137fb147ac4fb509da5c187 100644 (file)
@@ -1120,7 +1120,7 @@ void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, uint16_t qtype,
   if (cursor.prefix(match, key, val) == 0) {
     do {
       if (qtype == QType::ANY || compoundOrdername::getQType(key.getNoStripHeader<StringView>()) == qtype) {
-        cursor.del();
+        cursor.del(key);
       }
     } while (cursor.next(key, val) == 0);
   }
@@ -1318,7 +1318,7 @@ bool LMDBBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const
     match = co(domain_id, relative, qt.getCode());
     // There should be at most one exact match here.
     if (cursor.find(match, key, val) == 0) {
-      cursor.del();
+      cursor.del(key);
     }
   }