mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-14 23:44:41 +00:00
[MEDIUM] session: remove s->prev_srv which is not needed anymore
s->prev_srv is used by assign_server() only, but all code paths leading to it now take s->prev_srv from the existing s->srv. So assign_server() can do that copy into its own stack. If at one point a different srv is needed, we still have a copy of the last server on which we failed a connection attempt in s->target.
This commit is contained in:
parent
664beb8610
commit
3d80d911aa
@ -149,8 +149,8 @@ enum {
|
||||
* immediately assigned when SN_DIRECT is determined. Both must be cleared
|
||||
* when clearing SN_DIRECT (eg: redispatch).
|
||||
* - ->srv has no meaning without SN_ASSIGNED and must not be checked without
|
||||
* it. ->prev_srv should be used to check previous ->srv. If SN_ASSIGNED is
|
||||
* set and sess->srv is NULL, then it is a dispatch or proxy mode.
|
||||
* it. ->target and ->target_type may be used to check previous ->srv after
|
||||
* a failed connection attempt.
|
||||
* - a session being processed has srv_conn set.
|
||||
* - srv_conn might remain after SN_DIRECT has been reset, but the assigned
|
||||
* server should eventually be released.
|
||||
@ -170,7 +170,6 @@ struct session {
|
||||
struct stream_interface si[2]; /* client and server stream interfaces */
|
||||
struct server *srv; /* the server the session will be running or has been running on */
|
||||
struct server *srv_conn; /* session already has a slot on a server and is not in queue */
|
||||
struct server *prev_srv; /* the server the was running on, after a redispatch, otherwise NULL */
|
||||
struct target target; /* target to use for this session */
|
||||
struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */
|
||||
struct http_txn txn; /* current HTTP transaction being processed. Should become a list. */
|
||||
|
@ -445,7 +445,7 @@ struct server *get_server_rch(struct session *s)
|
||||
*
|
||||
* This function MAY NOT be called with SN_ASSIGNED already set. If the session
|
||||
* had a server previously assigned, it is rebalanced, trying to avoid the same
|
||||
* server.
|
||||
* server, which should still be present in s->srv before the call.
|
||||
* The function tries to keep the original connection slot if it reconnects to
|
||||
* the same server, otherwise it releases it and tries to offer it.
|
||||
*
|
||||
@ -467,6 +467,7 @@ int assign_server(struct session *s)
|
||||
{
|
||||
|
||||
struct server *conn_slot;
|
||||
struct server *prev_srv;
|
||||
int err;
|
||||
|
||||
#ifdef DEBUG_FULL
|
||||
@ -477,7 +478,7 @@ int assign_server(struct session *s)
|
||||
if (unlikely(s->pend_pos || s->flags & SN_ASSIGNED))
|
||||
goto out_err;
|
||||
|
||||
s->prev_srv = s->prev_srv;
|
||||
prev_srv = s->srv;
|
||||
conn_slot = s->srv_conn;
|
||||
|
||||
/* We have to release any connection slot before applying any LB algo,
|
||||
@ -509,20 +510,20 @@ int assign_server(struct session *s)
|
||||
*/
|
||||
switch (s->be->lbprm.algo & BE_LB_LKUP) {
|
||||
case BE_LB_LKUP_RRTREE:
|
||||
s->srv = fwrr_get_next_server(s->be, s->prev_srv);
|
||||
s->srv = fwrr_get_next_server(s->be, prev_srv);
|
||||
break;
|
||||
|
||||
case BE_LB_LKUP_LCTREE:
|
||||
s->srv = fwlc_get_next_server(s->be, s->prev_srv);
|
||||
s->srv = fwlc_get_next_server(s->be, prev_srv);
|
||||
break;
|
||||
|
||||
case BE_LB_LKUP_CHTREE:
|
||||
case BE_LB_LKUP_MAP:
|
||||
if ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR) {
|
||||
if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
|
||||
s->srv = chash_get_next_server(s->be, s->prev_srv);
|
||||
s->srv = chash_get_next_server(s->be, prev_srv);
|
||||
else
|
||||
s->srv = map_get_server_rr(s->be, s->prev_srv);
|
||||
s->srv = map_get_server_rr(s->be, prev_srv);
|
||||
break;
|
||||
}
|
||||
else if ((s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_HI) {
|
||||
@ -593,9 +594,9 @@ int assign_server(struct session *s)
|
||||
*/
|
||||
if (!s->srv) {
|
||||
if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
|
||||
s->srv = chash_get_next_server(s->be, s->prev_srv);
|
||||
s->srv = chash_get_next_server(s->be, prev_srv);
|
||||
else
|
||||
s->srv = map_get_server_rr(s->be, s->prev_srv);
|
||||
s->srv = map_get_server_rr(s->be, prev_srv);
|
||||
}
|
||||
|
||||
/* end of map-based LB */
|
||||
@ -611,7 +612,7 @@ int assign_server(struct session *s)
|
||||
err = SRV_STATUS_FULL;
|
||||
goto out;
|
||||
}
|
||||
else if (s->srv != s->prev_srv) {
|
||||
else if (s->srv != prev_srv) {
|
||||
s->be->counters.cum_lbconn++;
|
||||
s->srv->counters.cum_lbconn++;
|
||||
}
|
||||
@ -767,8 +768,10 @@ int assign_server_and_queue(struct session *s)
|
||||
|
||||
err = SRV_STATUS_OK;
|
||||
if (!(s->flags & SN_ASSIGNED)) {
|
||||
struct server *prev_srv = s->srv;
|
||||
|
||||
err = assign_server(s);
|
||||
if (s->prev_srv) {
|
||||
if (prev_srv) {
|
||||
/* This session was previously assigned to a server. We have to
|
||||
* update the session's and the server's stats :
|
||||
* - if the server changed :
|
||||
@ -778,16 +781,16 @@ int assign_server_and_queue(struct session *s)
|
||||
* - if the server remained the same : update retries.
|
||||
*/
|
||||
|
||||
if (s->prev_srv != s->srv) {
|
||||
if (prev_srv != s->srv) {
|
||||
if ((s->txn.flags & TX_CK_MASK) == TX_CK_VALID) {
|
||||
s->txn.flags &= ~TX_CK_MASK;
|
||||
s->txn.flags |= TX_CK_DOWN;
|
||||
}
|
||||
s->flags |= SN_REDISP;
|
||||
s->prev_srv->counters.redispatches++;
|
||||
prev_srv->counters.redispatches++;
|
||||
s->be->counters.redispatches++;
|
||||
} else {
|
||||
s->prev_srv->counters.retries++;
|
||||
prev_srv->counters.retries++;
|
||||
s->be->counters.retries++;
|
||||
}
|
||||
}
|
||||
@ -1002,7 +1005,6 @@ int srv_redispatch_connect(struct session *t)
|
||||
if (((t->flags & (SN_DIRECT|SN_FORCE_PRST)) == SN_DIRECT) &&
|
||||
(t->be->options & PR_O_REDISP)) {
|
||||
t->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET);
|
||||
t->prev_srv = t->srv;
|
||||
goto redispatch;
|
||||
}
|
||||
|
||||
|
@ -1186,7 +1186,7 @@ struct session *peer_session_create(struct peer *peer, struct peer_session *ps)
|
||||
stream_sock_prepare_interface(&s->si[1]);
|
||||
s->si[1].release = NULL;
|
||||
|
||||
s->srv = s->prev_srv = s->srv_conn = NULL;
|
||||
s->srv = s->srv_conn = NULL;
|
||||
s->target.type = TARG_TYPE_NONE;
|
||||
s->target.ptr.v = NULL;
|
||||
s->pend_pos = NULL;
|
||||
|
@ -7541,7 +7541,7 @@ void http_reset_txn(struct session *s)
|
||||
|
||||
s->be = s->fe;
|
||||
s->logs.logwait = s->fe->to_log;
|
||||
s->srv = s->prev_srv = s->srv_conn = NULL;
|
||||
s->srv = s->srv_conn = NULL;
|
||||
s->target.type = TARG_TYPE_NONE;
|
||||
s->target.ptr.v = NULL;
|
||||
/* re-init store persistence */
|
||||
|
@ -202,7 +202,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
||||
if (likely(s->fe->options2 & PR_O2_INDEPSTR))
|
||||
s->si[1].flags |= SI_FL_INDEP_STR;
|
||||
|
||||
s->srv = s->prev_srv = s->srv_conn = NULL;
|
||||
s->srv = s->srv_conn = NULL;
|
||||
s->target.type = TARG_TYPE_NONE;
|
||||
s->target.ptr.v = NULL;
|
||||
s->pend_pos = NULL;
|
||||
@ -638,7 +638,6 @@ int sess_update_st_cer(struct session *s, struct stream_interface *si)
|
||||
process_srv_queue(s->srv);
|
||||
|
||||
s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET);
|
||||
s->prev_srv = s->srv;
|
||||
si->state = SI_ST_REQ;
|
||||
} else {
|
||||
if (s->srv)
|
||||
|
Loading…
Reference in New Issue
Block a user