Commit 3e57f56c authored by Marek Vavruša's avatar Marek Vavruša

modules/cachectl: incremental pruning, can clear 64k items in one go

parent 080d4ffc
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment