]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kr_cache_gc: randomized deleting of parts of huge categories
authorLibor Peltan <libor.peltan@nic.cz>
Fri, 11 May 2018 14:20:58 +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/categories.c

index db4a7104e0fb32cf91994ded2236838fb4df7139..bfdb465c010dfb09de3c0596a560be53b2313eec 100644 (file)
@@ -16,6 +16,11 @@ static bool rrtype_is_infrastructure(uint16_t r)
        }
 }
 
+static int get_random(int to)
+{
+       return rand() % to;
+}
+
 // TODO this is just an example, make this more clever
 category_t kr_gc_categorize(gc_record_info_t *info)
 {
@@ -23,25 +28,26 @@ category_t kr_gc_categorize(gc_record_info_t *info)
 
        switch (info->no_labels) {
        case 0:
-               return 1;
+               res = 5;
+               break;
        case 1:
-               return 2;
+               res = 10;
+               break;
        case 2:
-               return (rrtype_is_infrastructure(info->rrtype) ? 3 : 20);
+               res = (rrtype_is_infrastructure(info->rrtype) ? 15 : 20);
+               break;
        }
 
        if (info->entry_size > 300) {
-               return 90;
+               res += 30;
        }
 
        if (rrtype_is_infrastructure(info->rrtype)) {
                if (info->expires_in > 0) {
-                       res = 30;
-               } else {
-                       res = 45;
+                       res = res > 40 ? 40 : res;
                }
        }
 
-       return res;
+       return res + get_random(5);
 }