]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/cachectl: incremental pruning, can clear 64k items in one go
authorMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 9 Jun 2015 17:09:05 +0000 (19:09 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 9 Jun 2015 17:09:05 +0000 (19:09 +0200)
modules/cachectl/cachectl.c

index e7dc22c2b8c01e8f91f5ceb5ea870fd9c9c9c6e9..f89a68004c152cc523bf29d80e0477a21ac9d00d 100644 (file)
@@ -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);