]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: servers: MAke sess_change_server() return the number of requests
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 5 Feb 2026 09:54:06 +0000 (10:54 +0100)
committerOlivier Houchard <cognet@ci0.org>
Mon, 2 Mar 2026 12:46:17 +0000 (13:46 +0100)
Change sess_change_server() so that when it decrements the number of
requests on the old server, if any, it returns that number to the
caller.
It will be useful to detect if the server was full, and is not anymore.

include/haproxy/stream.h
src/stream.c

index 92a57d23d2ee82b200da524205ba3b9e1364fa15..b25f77c68c751dd6d61f7d3a100410037d3e447b 100644 (file)
@@ -72,7 +72,7 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
 struct ist stream_generate_unique_id(struct stream *strm, struct lf_expr *format);
 
 void stream_process_counters(struct stream *s);
-void sess_change_server(struct stream *strm, struct server *newsrv);
+int sess_change_server(struct stream *strm, struct server *newsrv);
 struct task *process_stream(struct task *t, void *context, unsigned int state);
 void default_srv_error(struct stream *s, struct stconn *sc);
 
index a139f3844c139992a9b81b84ae10d968d37f9197..fff7574794804ad83f4567abf90ba65fcfdfa2f1 100644 (file)
@@ -2850,10 +2850,12 @@ void stream_update_time_stats(struct stream *s)
  * current connection slot. This function also notifies any LB algo which might
  * expect to be informed about any change in the number of active streams on a
  * server.
+ * Returns the number of simultaneous requests on the old server.
  */
-void sess_change_server(struct stream *strm, struct server *newsrv)
+int sess_change_server(struct stream *strm, struct server *newsrv)
 {
        struct server *oldsrv = strm->srv_conn;
+       int count = -1;
 
        /* Dynamic servers may be deleted during process lifetime. This
         * operation is always conducted under thread isolation. Several
@@ -2875,8 +2877,8 @@ void sess_change_server(struct stream *strm, struct server *newsrv)
                 * served field has been incremented, so we have to decrement it now.
                 */
                if (oldsrv)
-                       _HA_ATOMIC_DEC(&oldsrv->served);
-               return;
+                       count = _HA_ATOMIC_SUB_FETCH(&oldsrv->served, 1);
+               return count;
        }
 
        if (oldsrv) {
@@ -2891,7 +2893,7 @@ void sess_change_server(struct stream *strm, struct server *newsrv)
                 */
                _HA_ATOMIC_DEC(&oldsrv->proxy->served);
                stream_del_srv_conn(strm);
-               _HA_ATOMIC_DEC(&oldsrv->served);
+               count = _HA_ATOMIC_SUB_FETCH(&oldsrv->served, 1);
                __ha_barrier_atomic_store();
                if (oldsrv->proxy->lbprm.server_drop_conn)
                        oldsrv->proxy->lbprm.server_drop_conn(oldsrv);
@@ -2904,6 +2906,7 @@ void sess_change_server(struct stream *strm, struct server *newsrv)
                        newsrv->proxy->lbprm.server_take_conn(newsrv);
                stream_add_srv_conn(strm, newsrv);
        }
+       return count;
 }
 
 /* Handle server-side errors for default protocols. It is called whenever a a