mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
MINOR: server: move idle tree insert in a dedicated function
Define a new function _srv_add_idle(). This is a simple wrapper to insert a connection in the server idle tree. This is reserved for simple usage and require to idle_conns lock. In most cases, srv_add_to_idle_list() should be used. This patch does not have any functional change. However, it will help with the next patch as idle connection will be always inserted in a list as secondary storage along with idle/safe trees.
This commit is contained in:
parent
77ac8eb4a6
commit
61fc9568fb
@ -85,6 +85,7 @@ void srv_release_conn(struct server *srv, struct connection *conn);
|
||||
struct connection *srv_lookup_conn(struct eb_root *tree, uint64_t hash);
|
||||
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);
|
||||
struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsigned int state);
|
||||
|
||||
|
@ -177,12 +177,8 @@ int conn_notify_mux(struct connection *conn, int old_flags, int forced_wake)
|
||||
goto done;
|
||||
|
||||
if (conn_in_list) {
|
||||
struct eb_root *root = (conn_in_list == CO_FL_SAFE_LIST) ?
|
||||
&srv->per_thr[tid].safe_conns :
|
||||
&srv->per_thr[tid].idle_conns;
|
||||
|
||||
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
eb64_insert(root, &conn->hash_node->node);
|
||||
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
|
||||
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
}
|
||||
}
|
||||
|
@ -2986,10 +2986,7 @@ struct task *fcgi_io_cb(struct task *t, void *ctx, unsigned int state)
|
||||
struct server *srv = objt_server(conn->target);
|
||||
|
||||
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
if (conn_in_list == CO_FL_SAFE_LIST)
|
||||
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
|
||||
else
|
||||
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
|
||||
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
|
||||
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
}
|
||||
return t;
|
||||
|
@ -3701,10 +3701,7 @@ struct task *h1_io_cb(struct task *t, void *ctx, unsigned int state)
|
||||
struct server *srv = objt_server(conn->target);
|
||||
|
||||
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
if (conn_in_list == CO_FL_SAFE_LIST)
|
||||
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
|
||||
else
|
||||
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
|
||||
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
|
||||
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
}
|
||||
return t;
|
||||
|
@ -4123,10 +4123,7 @@ struct task *h2_io_cb(struct task *t, void *ctx, unsigned int state)
|
||||
struct server *srv = objt_server(conn->target);
|
||||
|
||||
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
if (conn_in_list == CO_FL_SAFE_LIST)
|
||||
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
|
||||
else
|
||||
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
|
||||
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
|
||||
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
}
|
||||
|
||||
|
21
src/server.c
21
src/server.c
@ -5986,6 +5986,23 @@ struct connection *srv_lookup_conn_next(struct connection *conn)
|
||||
return next_conn;
|
||||
}
|
||||
|
||||
/* Add <conn> in <srv> idle trees. Set <is_safe> if connection is deemed safe
|
||||
* for reuse.
|
||||
*
|
||||
* This function is a simple wrapper for tree insert. It should only be used
|
||||
* for internal usage or when removing briefly the connection to avoid takeover
|
||||
* on it before reinserting it with this function. In other context, prefer to
|
||||
* use the full feature srv_add_to_idle_list().
|
||||
*
|
||||
* Must be called with idle_conns_lock.
|
||||
*/
|
||||
void _srv_add_idle(struct server *srv, struct connection *conn, int is_safe)
|
||||
{
|
||||
struct eb_root *tree = is_safe ? &srv->per_thr[tid].safe_conns :
|
||||
&srv->per_thr[tid].idle_conns;
|
||||
eb64_insert(tree, &conn->hash_node->node);
|
||||
}
|
||||
|
||||
/* This adds an idle connection to the server's list if the connection is
|
||||
* reusable, not held by any owner anymore, but still has available streams.
|
||||
*/
|
||||
@ -6022,11 +6039,11 @@ int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_saf
|
||||
|
||||
if (is_safe) {
|
||||
conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST;
|
||||
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
|
||||
_srv_add_idle(srv, conn, 1);
|
||||
_HA_ATOMIC_INC(&srv->curr_safe_nb);
|
||||
} else {
|
||||
conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_IDLE_LIST;
|
||||
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
|
||||
_srv_add_idle(srv, conn, 0);
|
||||
_HA_ATOMIC_INC(&srv->curr_idle_nb);
|
||||
}
|
||||
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
|
@ -6345,10 +6345,7 @@ struct task *ssl_sock_io_cb(struct task *t, void *context, unsigned int state)
|
||||
struct server *srv = objt_server(conn->target);
|
||||
|
||||
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
if (conn_in_list == CO_FL_SAFE_LIST)
|
||||
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
|
||||
else
|
||||
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
|
||||
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
|
||||
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
|
||||
}
|
||||
return t;
|
||||
|
Loading…
Reference in New Issue
Block a user