]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: simplify the code that sets PROC_O_LEAVING
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 2 Oct 2024 09:38:30 +0000 (11:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Oct 2024 20:02:39 +0000 (22:02 +0200)
When master performs a reexec it should set for an already existed worker the
flag PROC_O_LEAVING. It means that existed worked is marked as the previous one
and will be terminated after the reload.

In the previous implementation master process was need to do the reexec
twice (the first time for parsing its configuration and the second time to free
unused ressources). So the logic of setting PROC_O_LEAVING was based on
comparing the number of reloads, performed by each process from the processes
list, except the master.

Now, as being mentioned before, reexec is performed only once. So, in this case
we need to set PROC_O_LEAVING flag, when we deserialize the list. It is done for
all processes, which have the number of reloads stricly positive.

src/haproxy.c
src/mworker.c

index e5c00687cdd7716e82bd9abdc12064a93b9413c2..d163998620cf862058e0db248bc01a15e83d5801 100644 (file)
@@ -839,7 +839,10 @@ void mworker_reload(int hardreload)
        list_for_each_entry(ptdf, &per_thread_deinit_list, list)
                ptdf->fct();
 
-       /* increment the number of reloads */
+       /* increment the number of reloads, child->reloads is checked in
+        * mworker_env_to_proc_list() (after reload) in order to set
+        * PROC_O_LEAVING flag for the process
+        */
        list_for_each_entry(child, &proc_list, list) {
                child->reloads++;
        }
index 38c31139d77d39fcca0066cf8fd015429daafb95..46211c222f975d432b53ef3eb0870c4a6ef9aa35 100644 (file)
@@ -115,7 +115,6 @@ void mworker_proc_list_to_env()
 {
        char *msg = NULL;
        struct mworker_proc *child;
-       int minreloads = INT_MAX; /* minimum number of reloads to chose which processes are "current" ones */
 
        list_for_each_entry(child, &proc_list, list) {
                char type = '?';
@@ -127,22 +126,11 @@ void mworker_proc_list_to_env()
                else if (child->options &= PROC_O_TYPE_WORKER)
                        type = 'w';
 
-               if (child->reloads < minreloads)
-                       minreloads = child->reloads;
-
                if (child->pid > -1)
                        memprintf(&msg, "%s|type=%c;fd=%d;cfd=%d;pid=%d;reloads=%d;failedreloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->ipc_fd[1], child->pid, child->reloads, child->failedreloads, child->timestamp, child->id ? child->id : "", child->version);
        }
        if (msg)
                setenv("HAPROXY_PROCESSES", msg, 1);
-
-       list_for_each_entry(child, &proc_list, list) {
-               if (child->reloads > minreloads && !(child->options & PROC_O_TYPE_MASTER)) {
-                       child->options |= PROC_O_LEAVING;
-               }
-       }
-
-
 }
 
 struct mworker_proc *mworker_proc_new()
@@ -172,7 +160,6 @@ int mworker_env_to_proc_list()
 {
        char *env, *msg, *omsg = NULL, *token = NULL, *s1;
        struct mworker_proc *child;
-       int minreloads = INT_MAX; /* minimum number of reloads to chose which processes are "current" ones */
        int err = 0;
 
        env = getenv("HAPROXY_PROCESSES");
@@ -229,9 +216,6 @@ int mworker_env_to_proc_list()
                        } else if (strncmp(subtoken, "reloads=", 8) == 0) {
                                /* we only increment the number of asked reload */
                                child->reloads = atoi(subtoken+8);
-
-                               if (child->reloads < minreloads)
-                                       minreloads = child->reloads;
                        } else if (strncmp(subtoken, "failedreloads=", 14) == 0) {
                                child->failedreloads = atoi(subtoken+14);
                        } else if (strncmp(subtoken, "timestamp=", 10) == 0) {
@@ -252,7 +236,7 @@ int mworker_env_to_proc_list()
        /* set the leaving processes once we know which number of reloads are the current processes */
 
        list_for_each_entry(child, &proc_list, list) {
-               if (child->reloads > minreloads)
+               if (child->reloads > 0)
                        child->options |= PROC_O_LEAVING;
        }