]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache/cdb: add it_del()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 24 Jun 2026 08:10:37 +0000 (10:10 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 15 Jul 2026 14:12:58 +0000 (16:12 +0200)
lib/cache/cdb_api.h
lib/cache/cdb_lmdb.c

index 15deb79c9bb616b1f2d487ba279232dbb6f4629e..b589b564a84d55ebb1b0369c6ba2bd76e147899c 100644 (file)
@@ -115,13 +115,19 @@ struct kr_cdb_api {
        int (*check_health)(kr_cdb_pt db, struct kr_cdb_stats *stat);
 
 
-       /** Start iterating; return the first *val with *key.
+       /** Start iterating: get the first *val with *key + return error code.
         *
         * - in cache: ensures a RO transaction (and commits the RW txn if any)
         * - in ruledb: transaction is preserved if exists, otherwise RO txn gets opened
         */
        int (*it_first)(kr_cdb_pt db, struct kr_cdb_stats *stat,
                        const knot_db_val_t *key, knot_db_val_t *val);
-       /** Advance to the next *val with the same key. */
+       /** Advance to the next *val with the same key.  Return error code. */
        int (*it_next)(kr_cdb_pt db, struct kr_cdb_stats *stat, knot_db_val_t *val);
+       /** Delete the current *val + return error code.
+        *
+        * You can it_next() to continue.
+        * This assumed that you got it_first() in a RW txn.
+        */
+       int (*it_del)(kr_cdb_pt db, struct kr_cdb_stats *stat);
 };
index 1adbf11e04c4b461364cb7c559d2a6bda57bb809..085a29244cfee9791d11912597606ac632981ddd 100644 (file)
@@ -973,6 +973,21 @@ static int cdb_it_next(kr_cdb_pt db, struct kr_cdb_stats *stats, knot_db_val_t *
        *val = val_mdb2knot(val2_m);
        return kr_ok();
 }
+static int cdb_it_del(kr_cdb_pt db, struct kr_cdb_stats *stats)
+{
+       if (kr_fails_assert(db))
+               return kr_error(EINVAL);
+       struct lmdb_env *env = db2env(db);
+       if (kr_fails_assert(!env->is_cache && env->txn.rw_curs))
+               return kr_error(EINVAL);
+
+       MDB_cursor *curs = NULL;
+       int ret = txn_curs_get(env, &curs, stats);
+       if (ret) return ret;
+       ret = mdb_cursor_del(curs, 0/*no flags*/);
+       if (ret) return lmdb_error(env, ret);
+       return kr_ok();
+}
 
 
 const struct kr_cdb_api *kr_cdb_lmdb(void)
@@ -986,7 +1001,7 @@ const struct kr_cdb_api *kr_cdb_lmdb(void)
                cdb_read_leq, cdb_read_less,
                cdb_usage_percent, cdb_get_maxsize,
                cdb_check_health,
-               cdb_it_first, cdb_it_next,
+               cdb_it_first, cdb_it_next, cdb_it_del,
        };
        return &api;
 }