From: Marek VavruĊĦa Date: Tue, 9 Jun 2015 17:09:05 +0000 (+0200) Subject: modules/cachectl: incremental pruning, can clear 64k items in one go X-Git-Tag: v1.0.0-beta1~120^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e57f56cd27874f6823e27d17ce3a93f07fb81ee;p=thirdparty%2Fknot-resolver.git modules/cachectl: incremental pruning, can clear 64k items in one go --- diff --git a/modules/cachectl/cachectl.c b/modules/cachectl/cachectl.c index e7dc22c2b..f89a68004 100644 --- a/modules/cachectl/cachectl.c +++ b/modules/cachectl/cachectl.c @@ -31,6 +31,9 @@ #include "lib/module.h" #include "lib/cache.h" +/* Max number of records pruned at one go. */ +#define PRUNE_GRANULARITY UINT16_MAX + /* * Properties. */ @@ -62,8 +65,8 @@ static char* prune(void *env, struct kr_module *module, const char *args) /* Iterate cache and find expired records. */ int pruned = 0; uint32_t now = time(NULL); - namedb_iter_t *it = storage->iter_begin((namedb_txn_t *)&txn, 0); - while (it) { + namedb_iter_t *it = storage->iter_begin(&txn.t, 0); + while (it && pruned < PRUNE_GRANULARITY) { /* Fetch RR from cache */ namedb_val_t key, val; if (storage->iter_key(it, &key) != 0 || @@ -73,7 +76,7 @@ static char* prune(void *env, struct kr_module *module, const char *args) /* Prune expired records. */ struct kr_cache_entry *entry = val.data; if (is_expired(entry, now - entry->timestamp)) { - storage->del((namedb_txn_t *)&txn, &key); + storage->del(&txn.t, &key); pruned += 1; } it = storage->iter_next(it);