]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: jobs: support unstoppable jobs for soft stop
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 16 Nov 2018 15:57:20 +0000 (16:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 Nov 2018 16:05:40 +0000 (17:05 +0100)
This patch allows a process to properly quit when some jobs are still
active, this feature is handled by the unstoppable_jobs variable, which
must be atomically incremented.

During each new iteration of run_poll_loop() the break condition of the
loop is now (jobs - unstoppable_jobs) == 0.

The unique usage of this at the moment is to handle the socketpair CLI
of a the worker during the stopping of the process.  During the soft
stop, we could mark the CLI listener as an unstoppable job and still
handle new connections till every other jobs are stopped.

include/types/global.h
include/types/stats.h
src/haproxy.c
src/stats.c

index 344003a915aa03f6d63cf8f7674aef6b42a59152..5210323048c83251e67025d728eafe965f119c37 100644 (file)
@@ -224,6 +224,7 @@ extern unsigned long pid_bit;   /* bit corresponding to the process id */
 extern int  actconn;            /* # of active sessions */
 extern int  listeners;
 extern int  jobs;               /* # of active jobs (listeners, sessions, open devices) */
+extern int  unstoppable_jobs;   /* # of active jobs that can't be stopped during a soft stop */
 extern int  active_peers;       /* # of active peers (connection attempts and successes) */
 extern int  connected_peers;    /* # of really connected peers */
 extern THREAD_LOCAL struct buffer trash;
index 75250447ec2d597290f5a1a0c9475746b2820cfd..85cc906da1e76b9edaa1770993b65c73adabae15 100644 (file)
@@ -290,6 +290,7 @@ enum info_field {
        INF_DESCRIPTION,
        INF_STOPPING,
        INF_JOBS,
+       INF_UNSTOPPABLE_JOBS,
        INF_LISTENERS,
        INF_ACTIVE_PEERS,
        INF_CONNECTED_PEERS,
index 494160ad8e5a7cf43200bcc223942c6e09be9481..f066ec9784f60aaf56aec9f78a11112bb28012ca 100644 (file)
@@ -177,6 +177,7 @@ struct activity activity[MAX_THREADS] __attribute__((aligned(64))) = { };
 int stopping;  /* non zero means stopping in progress */
 int killed;    /* non zero means a hard-stop is triggered */
 int jobs = 0;   /* number of active jobs (conns, listeners, active tasks, ...) */
+int unstoppable_jobs = 0;  /* number of active jobs that can't be stopped during a soft stop */
 int active_peers = 0; /* number of active peers (connection attempts and connected) */
 int connected_peers = 0; /* number of connected peers (verified ones) */
 
@@ -2617,7 +2618,7 @@ static void run_poll_loop()
                next = wake_expired_tasks();
 
                /* stop when there's nothing left to do */
-               if (jobs == 0)
+               if ((jobs - unstoppable_jobs) == 0)
                        break;
 
                /* expire immediately if events are pending */
index 07a5ef74ea61d0e9a7604d2e83feb903038ec132..0574260d997ee926faa1b70e59663267b0a55d71 100644 (file)
@@ -132,6 +132,7 @@ const char *info_field_names[INF_TOTAL_FIELDS] = {
        [INF_DESCRIPTION]                    = "description",
        [INF_STOPPING]                       = "Stopping",
        [INF_JOBS]                           = "Jobs",
+       [INF_UNSTOPPABLE_JOBS]               = "Unstoppable Jobs",
        [INF_LISTENERS]                      = "Listeners",
        [INF_ACTIVE_PEERS]                   = "ActivePeers",
        [INF_CONNECTED_PEERS]                = "ConnectedPeers",
@@ -3300,6 +3301,7 @@ int stats_fill_info(struct field *info, int len)
                info[INF_DESCRIPTION]            = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc);
        info[INF_STOPPING]                       = mkf_u32(0, stopping);
        info[INF_JOBS]                           = mkf_u32(0, jobs);
+       info[INF_UNSTOPPABLE_JOBS]               = mkf_u32(0, unstoppable_jobs);
        info[INF_LISTENERS]                      = mkf_u32(0, listeners);
        info[INF_ACTIVE_PEERS]                   = mkf_u32(0, active_peers);
        info[INF_CONNECTED_PEERS]                = mkf_u32(0, connected_peers);