]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: servers: Introduce src_manage_queues()
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 5 Feb 2026 09:14:41 +0000 (10:14 +0100)
committerOlivier Houchard <cognet@ci0.org>
Mon, 2 Mar 2026 12:46:17 +0000 (13:46 +0100)
Instead of having a common pattern of
if (may_dequeue_tasks())
process_srv_queue()
introduce an inline function to do that, and use it where appropriate
(mostly everywhere where the pattern was used).
Later on this function will be responsible for figuring out if, after
the queue has been processed, the server is full or not.

include/haproxy/server.h
include/haproxy/stream.h
src/backend.c
src/cli.c
src/server.c
src/stream.c

index ba4e6c10430001be0e24eaee7a69590d30b0e358..bad7fe71ff89ef9518817b46cb8874b6811d6b52 100644 (file)
@@ -30,6 +30,7 @@
 #include <haproxy/applet-t.h>
 #include <haproxy/arg-t.h>
 #include <haproxy/freq_ctr.h>
+#include <haproxy/queue.h>
 #include <haproxy/proxy-t.h>
 #include <haproxy/resolvers-t.h>
 #include <haproxy/sample-t.h>
@@ -390,6 +391,19 @@ static inline int srv_is_quic(const struct server *srv)
               srv->addr_type.xprt_type == PROTO_TYPE_STREAM;
 }
 
+/*
+ * Returns 1 if the server is full, 0 if it is not, and -1 if unknown
+ */
+static inline int srv_manage_queues(struct server *srv, struct proxy *px)
+{
+       int full = -1;
+
+       if (may_dequeue_tasks(srv, px))
+               full = process_srv_queue(srv);
+
+       return full;
+}
+
 #endif /* _HAPROXY_SERVER_H */
 
 /*
index 46464f8601147db9bef406b7dcbb0f22e36643e7..92a57d23d2ee82b200da524205ba3b9e1364fa15 100644 (file)
@@ -354,8 +354,7 @@ static inline void stream_choose_redispatch(struct stream *s)
             (!(s->flags & SF_DIRECT) && s->be->srv_act > 1 &&
              ((s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_HI)))) {
                sess_change_server(s, NULL);
-               if (may_dequeue_tasks(objt_server(s->target), s->be))
-                       process_srv_queue(objt_server(s->target));
+               srv_manage_queues(objt_server(s->target), s->be);
 
                sockaddr_free(&s->scb->dst);
                s->flags &= ~(SF_DIRECT | SF_ASSIGNED);
index 4b485b46d0f85da91364aa02e9f9dfe7afb2eb8c..5d018996f330bf65be8888e78a4ec57c7b0e15b6 100644 (file)
@@ -860,8 +860,7 @@ out_ok:
                if (conn_slot == srv) {
                        sess_change_server(s, srv);
                } else {
-                       if (may_dequeue_tasks(conn_slot, s->be))
-                               process_srv_queue(conn_slot);
+                       srv_manage_queues(conn_slot, s->be);
                }
        }
 
@@ -2400,8 +2399,8 @@ int srv_redispatch_connect(struct stream *s)
                 * Not needed for backend queues, already handled in
                 * assign_server_and_queue().
                 */
-               if (unlikely(srv && may_dequeue_tasks(srv, s->be)))
-                       process_srv_queue(srv);
+               if (unlikely(srv))
+                      srv_manage_queues(srv, s->be);
 
                return 1;
 
@@ -2421,8 +2420,7 @@ int srv_redispatch_connect(struct stream *s)
                        _HA_ATOMIC_INC(&s->be_tgcounters->failed_conns);
 
                /* release other streams waiting for this server */
-               if (may_dequeue_tasks(srv, s->be))
-                       process_srv_queue(srv);
+               srv_manage_queues(srv, s->be);
                return 1;
        }
        /* if we get here, it's because we got SRV_STATUS_OK, which also
@@ -2498,8 +2496,7 @@ void back_try_conn_req(struct stream *s)
 
                        /* release other streams waiting for this server */
                        sess_change_server(s, NULL);
-                       if (may_dequeue_tasks(srv, s->be))
-                               process_srv_queue(srv);
+                       srv_manage_queues(srv, s->be);
 
                        /* Failed and not retryable. */
                        sc_abort(sc);
@@ -2816,8 +2813,7 @@ void back_handle_st_cer(struct stream *s)
                if (s->be_tgcounters)
                        _HA_ATOMIC_INC(&s->be_tgcounters->failed_conns);
                sess_change_server(s, NULL);
-               if (may_dequeue_tasks(objt_server(s->target), s->be))
-                       process_srv_queue(objt_server(s->target));
+               srv_manage_queues(objt_server(s->target), s->be);
 
                /* shutw is enough to stop a connecting socket */
                sc_shutdown(sc);
@@ -2850,8 +2846,7 @@ void back_handle_st_cer(struct stream *s)
                if (s->be_tgcounters)
                        _HA_ATOMIC_INC(&s->be_tgcounters->internal_errors);
                sess_change_server(s, NULL);
-               if (may_dequeue_tasks(objt_server(s->target), s->be))
-                       process_srv_queue(objt_server(s->target));
+               srv_manage_queues(objt_server(s->target), s->be);
 
                /* shutw is enough to stop a connecting socket */
                sc_shutdown(sc);
index 75c35912e24ee444f5253e0528cffe62b964b5c0..1958de060b0f99b7d0924c0f261d7e9c91f8d594 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -3534,8 +3534,7 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
 
                stream_del_srv_conn(s);
                if (objt_server(s->target)) {
-                       if (may_dequeue_tasks(__objt_server(s->target), be))
-                               process_srv_queue(__objt_server(s->target));
+                       srv_manage_queues(__objt_server(s->target), be);
                }
 
                s->target = NULL;
index 5a340e53b75bfe6d21f3ae1de8c2ef4ec06bea76..2975a7e2b1f9403f6fe6728241bd3182170b39ba 100644 (file)
@@ -2597,9 +2597,7 @@ const char *server_parse_maxconn_change_request(struct server *sv,
                sv->maxconn = v;
        }
 
-       if (may_dequeue_tasks(sv, sv->proxy))
-               process_srv_queue(sv);
-
+       srv_manage_queues(sv, sv->proxy);
        return NULL;
 }
 
index 5938bd27416b80190004df8a27e99872b022e32e..a139f3844c139992a9b81b84ae10d968d37f9197 100644 (file)
@@ -630,8 +630,7 @@ void stream_free(struct stream *s)
        pendconn_free(s);
 
        if (objt_server(s->target)) { /* there may be requests left pending in queue */
-               if (may_dequeue_tasks(__objt_server(s->target), s->be))
-                       process_srv_queue(__objt_server(s->target));
+               srv_manage_queues(__objt_server(s->target), s->be);
        }
 
        if (unlikely(s->srv_conn)) {
@@ -647,8 +646,7 @@ void stream_free(struct stream *s)
                 */
                if (!(oldsrv->flags & SRV_F_STRICT_MAXCONN)) {
                        sess_change_server(s, NULL);
-                       if (may_dequeue_tasks(oldsrv, s->be))
-                               process_srv_queue(oldsrv);
+                       srv_manage_queues(oldsrv, s->be);
                }
        }
 
@@ -758,8 +756,7 @@ void stream_free(struct stream *s)
 
                if ((oldsrv->flags & SRV_F_STRICT_MAXCONN)) {
                        sess_change_server(s, NULL);
-                       if (may_dequeue_tasks(oldsrv, s->be))
-                               process_srv_queue(oldsrv);
+                       srv_manage_queues(oldsrv, s->be);
                }
        }
 
@@ -2060,8 +2057,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                         */
                        if (!(srv->flags & SRV_F_STRICT_MAXCONN)) {
                                sess_change_server(s, NULL);
-                               if (may_dequeue_tasks(srv, s->be))
-                                       process_srv_queue(srv);
+                               srv_manage_queues(srv, s->be);
                        }
                }
 
@@ -2975,8 +2971,7 @@ void stream_shutdown_self(struct stream *stream, int why)
 
        if (objt_server(stream->target)) {
                sess_change_server(stream, NULL);
-               if (may_dequeue_tasks(objt_server(stream->target), stream->be))
-                       process_srv_queue(objt_server(stream->target));
+               srv_manage_queues(__objt_server(stream->target), stream->be);
        }
 
        /* shutw is enough to stop a connecting socket */