mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
MINOR: backend: refactor insertion in avail conns tree
Define a new function srv_add_to_avail_list(). This function is used to centralize connection insertion in available tree. It reuses a BUG_ON() statement to ensure the connection is not present in the idle list.
This commit is contained in:
parent
394bd4eb39
commit
f76e94d231
@ -87,6 +87,7 @@ struct connection *srv_lookup_conn_next(struct connection *conn);
|
||||
|
||||
void _srv_add_idle(struct server *srv, struct connection *conn, int is_safe);
|
||||
int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_safe);
|
||||
void srv_add_to_avail_list(struct server *srv, struct connection *conn);
|
||||
struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsigned int state);
|
||||
|
||||
int srv_apply_track(struct server *srv, struct proxy *curproxy);
|
||||
|
@ -1276,8 +1276,7 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv,
|
||||
session_add_conn(s->sess, conn, conn->target);
|
||||
}
|
||||
else {
|
||||
eb64_insert(&srv->per_thr[tid].avail_conns,
|
||||
&conn->hash_node->node);
|
||||
srv_add_to_avail_list(srv, conn);
|
||||
}
|
||||
}
|
||||
return conn;
|
||||
@ -1781,7 +1780,7 @@ static int connect_server(struct stream *s)
|
||||
if (srv && reuse_mode == PR_O_REUSE_ALWS &&
|
||||
!(srv_conn->flags & CO_FL_PRIVATE) &&
|
||||
srv_conn->mux->avail_streams(srv_conn) > 0) {
|
||||
eb64_insert(&srv->per_thr[tid].avail_conns, &srv_conn->hash_node->node);
|
||||
srv_add_to_avail_list(srv, srv_conn);
|
||||
}
|
||||
else if (srv_conn->flags & CO_FL_PRIVATE ||
|
||||
(reuse_mode == PR_O_REUSE_SAFE &&
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <haproxy/proto_tcp.h>
|
||||
#include <haproxy/sample.h>
|
||||
#include <haproxy/sc_strm.h>
|
||||
#include <haproxy/server.h>
|
||||
#include <haproxy/session.h>
|
||||
#include <haproxy/ssl_sock.h>
|
||||
#include <haproxy/stconn.h>
|
||||
@ -107,8 +108,9 @@ int conn_create_mux(struct connection *conn)
|
||||
* server list.
|
||||
*/
|
||||
if (srv && ((srv->proxy->options & PR_O_REUSE_MASK) == PR_O_REUSE_ALWS) &&
|
||||
!(conn->flags & CO_FL_PRIVATE) && conn->mux->avail_streams(conn) > 0)
|
||||
eb64_insert(&srv->per_thr[tid].avail_conns, &conn->hash_node->node);
|
||||
!(conn->flags & CO_FL_PRIVATE) && conn->mux->avail_streams(conn) > 0) {
|
||||
srv_add_to_avail_list(srv, conn);
|
||||
}
|
||||
else if (conn->flags & CO_FL_PRIVATE) {
|
||||
/* If it fail now, the same will be done in mux->detach() callback */
|
||||
session_add_conn(sess, conn, conn->target);
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <haproxy/proxy.h>
|
||||
#include <haproxy/regex.h>
|
||||
#include <haproxy/sc_strm.h>
|
||||
#include <haproxy/server.h>
|
||||
#include <haproxy/session-t.h>
|
||||
#include <haproxy/stconn.h>
|
||||
#include <haproxy/stream.h>
|
||||
@ -3603,8 +3604,7 @@ static void fcgi_detach(struct sedesc *sd)
|
||||
else if (!fconn->conn->hash_node->node.node.leaf_p &&
|
||||
fcgi_avail_streams(fconn->conn) > 0 && objt_server(fconn->conn->target) &&
|
||||
!LIST_INLIST(&fconn->conn->session_list)) {
|
||||
eb64_insert(&__objt_server(fconn->conn->target)->per_thr[tid].avail_conns,
|
||||
&fconn->conn->hash_node->node);
|
||||
srv_add_to_avail_list(__objt_server(fconn->conn->target), fconn->conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <haproxy/mux_h2-t.h>
|
||||
#include <haproxy/net_helper.h>
|
||||
#include <haproxy/proxy.h>
|
||||
#include <haproxy/server.h>
|
||||
#include <haproxy/session-t.h>
|
||||
#include <haproxy/stats.h>
|
||||
#include <haproxy/stconn.h>
|
||||
@ -4651,8 +4652,7 @@ static void h2_detach(struct sedesc *sd)
|
||||
else if (!h2c->conn->hash_node->node.node.leaf_p &&
|
||||
h2_avail_streams(h2c->conn) > 0 && objt_server(h2c->conn->target) &&
|
||||
!LIST_INLIST(&h2c->conn->session_list)) {
|
||||
eb64_insert(&__objt_server(h2c->conn->target)->per_thr[tid].avail_conns,
|
||||
&h2c->conn->hash_node->node);
|
||||
srv_add_to_avail_list(__objt_server(h2c->conn->target), h2c->conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
src/server.c
10
src/server.c
@ -6136,6 +6136,16 @@ int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_saf
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Insert <conn> connection in <srv> server available list. This is reserved
|
||||
* for backend connection currently in used with usable streams left.
|
||||
*/
|
||||
void srv_add_to_avail_list(struct server *srv, struct connection *conn)
|
||||
{
|
||||
/* connection cannot be in idle list if used as an avail idle conn. */
|
||||
BUG_ON(LIST_INLIST(&conn->idle_list));
|
||||
eb64_insert(&srv->per_thr[tid].avail_conns, &conn->hash_node->node);
|
||||
}
|
||||
|
||||
struct task *srv_cleanup_idle_conns(struct task *task, void *context, unsigned int state)
|
||||
{
|
||||
struct server *srv;
|
||||
|
Loading…
Reference in New Issue
Block a user