From: Vladimír Čunát Date: Wed, 24 Jun 2026 08:10:37 +0000 (+0200) Subject: lib/cache/cdb: add it_del() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b601ecbc391880f4f9f9f7f622f75a8dd77baca3;p=thirdparty%2Fknot-resolver.git lib/cache/cdb: add it_del() --- diff --git a/lib/cache/cdb_api.h b/lib/cache/cdb_api.h index 15deb79c9..b589b564a 100644 --- a/lib/cache/cdb_api.h +++ b/lib/cache/cdb_api.h @@ -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); }; diff --git a/lib/cache/cdb_lmdb.c b/lib/cache/cdb_lmdb.c index 1adbf11e0..085a29244 100644 --- a/lib/cache/cdb_lmdb.c +++ b/lib/cache/cdb_lmdb.c @@ -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; }