]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kr_cache_gc: implemented dry-run (only occupation watching mode)
authorLibor Peltan <libor.peltan@nic.cz>
Fri, 11 May 2018 14:20:28 +0000 (16:20 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 10 Jul 2019 13:59:20 +0000 (15:59 +0200)
utils/kr_cache_gc/kr_cache_gc.c
utils/kr_cache_gc/kr_cache_gc.h
utils/kr_cache_gc/main.c

index 773c8a6da57d3aa396c9e9001d20d0892105d0fd..14985ac99a7b683d3c574a2eb31043966f328251 100644 (file)
@@ -153,7 +153,7 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg)
                return ret;
        }
 
-       if (db_usage < MAX_OK_PERCENT_USAGE) {
+       if (cfg->dry_run || db_usage < MAX_OK_PERCENT_USAGE) {
                kr_gc_cache_close(&kres_db, db);
                return KNOT_EOK;
        }
index 8031131e749a16c0bc6df92faa448a21ecbb7b74..fc1806b919ce493d22f8b9af6f9f6faaa033cad9 100644 (file)
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 
@@ -20,6 +21,8 @@ typedef struct {
         size_t rw_txn_items;             // maximum number of deleted records per RW transaction (0 = unlimited)
         unsigned long rw_txn_duration;   // maximum duration of RW transaction in usecs (0 = unlimited)
         unsigned long rw_txn_delay;      // waiting time between two RW transactions in usecs
+
+        bool dry_run;
 } kr_cache_gc_cfg_t;
 
 
index 7ef03a43ebf1c85d0a4ea8d22ddccb06f46e1017..a154386a0ca25721b51f948501fded922bd484e8 100644 (file)
@@ -35,6 +35,7 @@ static void print_help()
        printf(" -m <rw_txn_duration(usecs)>\n");
        printf(" -w <wait_next_rw_txn(usecs)>\n");
        printf(" -t <temporary_memory(MBytes)>\n");
+       printf(" -n (= dry run)\n");
 }
 
 int main(int argc, char *argv[])
@@ -50,7 +51,7 @@ int main(int argc, char *argv[])
        kr_cache_gc_cfg_t cfg = { 0 };
 
        int o;
-       while ((o = getopt(argc, argv, "hc:d:l:m:w:t:")) != -1) {
+       while ((o = getopt(argc, argv, "hnc:d:l:m:w:t:")) != -1) {
                switch (o) {
                case 'c':
                        cfg.cache_path = optarg;
@@ -74,6 +75,9 @@ int main(int argc, char *argv[])
                        cfg.temp_keys_space *= 1048576;
                        break;
 #undef get_nonneg_optarg
+               case 'n':
+                       cfg.dry_run = true;
+                       break;
                case ':':
                case '?':
                case 'h':