]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils/cache_gc: tolerate ESPACE unless twice in a row
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 18 Aug 2020 09:34:43 +0000 (11:34 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 7 Sep 2020 15:47:11 +0000 (17:47 +0200)
In the unlikely case that GC happens "too late", it could fail when
deleting, in which case it seems best to reopen the cache and try again,
as it will probably be deleted by a kresd instance by the next interval.

utils/cache_gc/kr_cache_gc.c
utils/cache_gc/main.c

index 71b96bbded4dfcb0e1d35a63fe615201876d2535..b4ef97993315fee51ad69f77d4382cb105cae25b 100644 (file)
@@ -284,6 +284,10 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg, kr_cache_gc_state_t **state)
                case KNOT_ENOENT:
                        already_gone++;
                        break;
+               case KNOT_ESPACE:
+                       printf("Warning: out of space, bailing out to retry later.\n");
+                       api->txn_abort(&txn);
+                       goto finish;
                default:
                        printf("Warning: skipping deletion because of error (%s)\n",
                               knot_strerror(ret));
index 45a18765c5c3c787912230f394b5d623b6727990..a2c05489f9b0c3e35be751c089b2a1489d6580b4 100644 (file)
@@ -134,10 +134,21 @@ int main(int argc, char *argv[])
 
        int exit_code = 0;
        kr_cache_gc_state_t *gc_state = NULL;
+       bool last_espace = false;
        do {
                int ret = kr_cache_gc(&cfg, &gc_state);
+
+               /* Let's tolerate ESPACE unless twice in a row. */
+               if (ret == KNOT_ESPACE) {
+                       if (!last_espace)
+                               ret = KNOT_EOK;
+                       last_espace = true;
+               } else {
+                       last_espace = false;
+               }
+
                // ENOENT: kresd may not be started yet or cleared the cache now
-               if (ret && ret != -ENOENT) {
+               if (ret && ret != KNOT_ENOENT) {
                        printf("Error (%s)\n", knot_strerror(ret));
                        exit_code = 10;
                        break;