]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- fast-reload, option for fast-reload commandline, +d drops mesh queries.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Thu, 21 Mar 2024 14:36:30 +0000 (15:36 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Thu, 21 Mar 2024 14:36:30 +0000 (15:36 +0100)
daemon/daemon.h
daemon/remote.c
daemon/remote.h
daemon/worker.c
doc/unbound-control.8.in
smallapp/unbound-control.c

index 46cb5dbccc9338228797a83f63006b4e4d85f67a..f76ced23ab3cc432310807484b05e0ba13f6b23b 100644 (file)
@@ -152,6 +152,8 @@ struct daemon {
        struct fast_reload_thread* fast_reload_thread;
        /** the fast reload printq list */
        struct fast_reload_printq* fast_reload_printq_list;
+       /** the fast reload option to drop mesh queries, true if so. */
+       int fast_reload_drop_mesh;
        /** config file name */
        char* cfgfile;
 };
index 5ee3d4d32d9c1eae8945bb836e83696d22eaaf9d..ba4c8d26db18fe320577975ba6066392bda25458 100644 (file)
@@ -677,7 +677,8 @@ do_reload(RES* ssl, struct worker* worker, int reuse_cache)
 #ifndef THREADS_DISABLED
 /** parse fast reload command options. */
 static int
-fr_parse_options(RES* ssl, char* arg, int* fr_verb, int* fr_nopause)
+fr_parse_options(RES* ssl, char* arg, int* fr_verb, int* fr_nopause,
+       int* fr_drop_mesh)
 {
        char* argp = arg;
        while(*argp=='+') {
@@ -687,6 +688,8 @@ fr_parse_options(RES* ssl, char* arg, int* fr_verb, int* fr_nopause)
                                (*fr_verb)++;
                        } else if(*argp == 'p') {
                                (*fr_nopause) = 1;
+                       } else if(*argp == 'd') {
+                               (*fr_drop_mesh) = 1;
                        } else {
                                if(!ssl_printf(ssl,
                                        "error: unknown option '+%c'\n",
@@ -718,14 +721,15 @@ do_fast_reload(RES* ssl, struct worker* worker, struct rc_state* s, char* arg)
        (void)s;
        (void)arg;
 #else
-       int fr_verb = 0, fr_nopause = 0;
-       if(!fr_parse_options(ssl, arg, &fr_verb, &fr_nopause))
+       int fr_verb = 0, fr_nopause = 0, fr_drop_mesh = 0;
+       if(!fr_parse_options(ssl, arg, &fr_verb, &fr_nopause, &fr_drop_mesh))
                return;
        if(fr_verb >= 1) {
                if(!ssl_printf(ssl, "start fast_reload\n"))
                        return;
        }
-       fast_reload_thread_start(ssl, worker, s, fr_verb, fr_nopause);
+       fast_reload_thread_start(ssl, worker, s, fr_verb, fr_nopause,
+               fr_drop_mesh);
 #endif
 }
 
@@ -4677,7 +4681,8 @@ create_socketpair(int* pair, struct ub_randstate* rand)
 
 /** fast reload thread. setup the thread info */
 static int
-fast_reload_thread_setup(struct worker* worker, int fr_verb, int fr_nopause)
+fast_reload_thread_setup(struct worker* worker, int fr_verb, int fr_nopause,
+       int fr_drop_mesh)
 {
        struct fast_reload_thread* fr;
        int numworkers = worker->daemon->num;
@@ -4688,6 +4693,8 @@ fast_reload_thread_setup(struct worker* worker, int fr_verb, int fr_nopause)
        fr = worker->daemon->fast_reload_thread;
        fr->fr_verb = fr_verb;
        fr->fr_nopause = fr_nopause;
+       fr->fr_drop_mesh = fr_drop_mesh;
+       worker->daemon->fast_reload_drop_mesh = fr->fr_drop_mesh;
        /* The thread id printed in logs, numworker+1 is the dnstap thread.
         * This is numworkers+2. */
        fr->threadnum = numworkers+2;
@@ -5007,6 +5014,11 @@ fr_main_perform_reload_stop(struct fast_reload_thread* fr)
                        continue; /* Do not send to ourselves. */
                worker_send_cmd(daemon->workers[i], worker_cmd_reload_start);
        }
+
+       if(fr->worker->daemon->fast_reload_drop_mesh) {
+               verbose(VERB_ALGO, "worker: drop mesh queries after reload");
+               mesh_delete_all(fr->worker->env.mesh);
+       }
        verbose(VERB_ALGO, "worker resume after reload");
 }
 
@@ -5432,13 +5444,14 @@ fr_send_stop(struct fast_reload_thread* fr)
 
 void
 fast_reload_thread_start(RES* ssl, struct worker* worker, struct rc_state* s,
-       int fr_verb, int fr_nopause)
+       int fr_verb, int fr_nopause, int fr_drop_mesh)
 {
        if(worker->daemon->fast_reload_thread) {
                log_err("fast reload thread already running");
                return;
        }
-       if(!fast_reload_thread_setup(worker, fr_verb, fr_nopause)) {
+       if(!fast_reload_thread_setup(worker, fr_verb, fr_nopause,
+               fr_drop_mesh)) {
                if(!ssl_printf(ssl, "error could not setup thread\n"))
                        return;
                return;
index 0c7209e510d8a559ba258d28c7b873e446c71466..180fabed826eeb251ed95a354b271f882e3333f3 100644 (file)
@@ -191,6 +191,8 @@ struct fast_reload_thread {
        int fr_verb;
        /** option to not pause threads during reload */
        int fr_nopause;
+       /** option to drop mesh queries */
+       int fr_drop_mesh;
 
        /** the event that listens on the remote service worker to the
         * commpair, it receives content from the fast reload thread. */
@@ -316,9 +318,10 @@ int ssl_read_line(RES* ssl, char* buf, size_t max);
  * @param fr_verb: verbosity to print output at. 0 is nothing, 1 is some
  *     and 2 is more detail.
  * @param fr_nopause: option to not pause threads during reload.
+ * @param fr_drop_mesh: option to drop mesh queries.
  */
 void fast_reload_thread_start(RES* ssl, struct worker* worker,
-       struct rc_state* s, int fr_verb, int fr_nopause);
+       struct rc_state* s, int fr_verb, int fr_nopause, int fr_drop_mesh);
 
 /**
  * Stop fast reload thread
index 99faef8c3528da37feaf90191e0781f27d39bd1c..be8c81302dfbdf04cde80747a89a8cb1aea1e282 100644 (file)
@@ -422,6 +422,10 @@ worker_stop_and_wait(struct worker* worker)
        if(cmd != worker_cmd_reload_start) {
                log_err("worker reload reply, wrong reply command");
        }
+       if(worker->daemon->fast_reload_drop_mesh) {
+               verbose(VERB_ALGO, "worker: drop mesh queries after reload");
+               mesh_delete_all(worker->env.mesh);
+       }
        verbose(VERB_ALGO, "worker resume after reload");
 }
 
index c2df9e182d47773742f6c75ebb978fd4c8b9e503..e67a628d80f1b7557aeef9263a6ebf0f8e3bd94e 100644 (file)
@@ -60,7 +60,7 @@ Reload the server but try to keep the RRset and message cache if
 That means the caches sizes and the number of threads must not change between
 reloads.
 .TP
-.B fast_reload \fR[\fI+vp\fR]
+.B fast_reload \fR[\fI+dpv\fR]
 Reload the server, but keep downtime to a minimum, so that user queries
 keep seeing service. This needs the code compiled with threads. The config
 is loaded in a thread, and prepared, then it briefly pauses the existing
@@ -85,6 +85,12 @@ or new values together. The option makes the reload time take eg. 3
 microseconds instead of 0.3 milliseconds during which the worker threads are
 interrupted. So, the interruption is much shorter, at the expense of some
 inconsistency.
+.IP
+The '+d' option makes the reload drop queries that the worker threads are
+working on. This is like flush_requestlist. Without it the queries are kept
+so that users keep getting answers for those queries that are currently
+processed. The drop makes it so that queries during the life time of the
+query processing see only old, or only new config options.
 .TP
 .B verbosity \fInumber
 Change verbosity value for logging. Same values as \fBverbosity\fR keyword in
index e7f5797978a0ca4449d0c84def3f83d4b7afcf78..8d5aee63549e1c0a23a1006672e152ffcca54a9a 100644 (file)
@@ -109,7 +109,7 @@ usage(void)
        printf("                                That means the caches sizes and\n");
        printf("                                the number of threads must not\n");
        printf("                                change between reloads.\n");
-       printf("  fast_reload [+vp]             reloads the server but only briefly stops\n");
+       printf("  fast_reload [+dpv]            reloads the server but only briefly stops\n");
        printf("                                server processing, keeps cache, and only\n");
        printf("                                changes some options, like forwards\n");
        printf("                                and stubs.\n");