From 3e57f56cd27874f6823e27d17ce3a93f07fb81ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Vavru=C5=A1a?= Date: Tue, 9 Jun 2015 19:09:05 +0200 Subject: [PATCH] modules/cachectl: incremental pruning, can clear 64k items in one go --- modules/cachectl/cachectl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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); -- 2.47.3