diff options
author | Stefan Fritsch <sf@sfritsch.de> | 2011-12-27 19:42:13 +0100 |
---|---|---|
committer | Stefan Fritsch <sf@sfritsch.de> | 2011-12-27 19:42:13 +0100 |
commit | 1acac7a6b494db24f8f58e44dab7657b6de68742 (patch) | |
tree | 9a0dd3753dd6fb8c859ed299ee9794b88173c420 /modules/proxy/mod_proxy_balancer.c | |
parent | 80ba9f34b69a273d82f2f46d7fe231e30e127028 (diff) | |
download | apache2-1acac7a6b494db24f8f58e44dab7657b6de68742.tar.gz |
Upstream tarball 2.2.6upstream/2.2.6
Diffstat (limited to 'modules/proxy/mod_proxy_balancer.c')
-rw-r--r-- | modules/proxy/mod_proxy_balancer.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c index 02f5ac3a..e2f22235 100644 --- a/modules/proxy/mod_proxy_balancer.c +++ b/modules/proxy/mod_proxy_balancer.c @@ -234,16 +234,27 @@ static proxy_worker *find_route_worker(proxy_balancer *balancer, static proxy_worker *find_session_route(proxy_balancer *balancer, request_rec *r, char **route, + char **sticky_used, char **url) { proxy_worker *worker = NULL; + char *sticky, *sticky_path, *path; if (!balancer->sticky) return NULL; + sticky = sticky_path = apr_pstrdup(r->pool, balancer->sticky); + if ((path = strchr(sticky, '|'))) { + *path++ = '\0'; + sticky_path = path; + } + /* Try to find the sticky route inside url */ - *route = get_path_param(r->pool, *url, balancer->sticky); - if (!*route) - *route = get_cookie_param(r, balancer->sticky); + *sticky_used = sticky_path; + *route = get_path_param(r->pool, *url, sticky_path); + if (!*route) { + *route = get_cookie_param(r, sticky); + *sticky_used = sticky; + } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "proxy: BALANCER: Found value %s for " "stickysession %s", *route, balancer->sticky); @@ -369,6 +380,7 @@ static int proxy_balancer_pre_request(proxy_worker **worker, int access_status; proxy_worker *runtime; char *route = NULL; + char *sticky = NULL; apr_status_t rv; *worker = NULL; @@ -383,7 +395,7 @@ static int proxy_balancer_pre_request(proxy_worker **worker, /* Step 2: find the session route */ - runtime = find_session_route(*balancer, r, &route, url); + runtime = find_session_route(*balancer, r, &route, &sticky, url); /* Lock the LoadBalancer * XXX: perhaps we need the process lock here */ @@ -421,15 +433,32 @@ static int proxy_balancer_pre_request(proxy_worker **worker, *worker = runtime; } else if (route && (*balancer)->sticky_force) { - ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, - "proxy: BALANCER: (%s). All workers are in error state for route (%s)", - (*balancer)->name, route); - if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server, - "proxy: BALANCER: (%s). Unlock failed for pre_request", - (*balancer)->name); + int i, member_of = 0; + proxy_worker *workers; + /* + * We have a route provided that doesn't match the + * balancer name. See if the provider route is the + * member of the same balancer in which case return 503 + */ + workers = (proxy_worker *)(*balancer)->workers->elts; + for (i = 0; i < (*balancer)->workers->nelts; i++) { + if (*(workers->s->route) && strcmp(workers->s->route, route) == 0) { + member_of = 1; + break; + } + workers++; + } + if (member_of) { + ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, + "proxy: BALANCER: (%s). All workers are in error state for route (%s)", + (*balancer)->name, route); + if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server, + "proxy: BALANCER: (%s). Unlock failed for pre_request", + (*balancer)->name); + } + return HTTP_SERVICE_UNAVAILABLE; } - return HTTP_SERVICE_UNAVAILABLE; } if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) { @@ -476,12 +505,12 @@ static int proxy_balancer_pre_request(proxy_worker **worker, access_status = rewrite_url(r, *worker, url); /* Add the session route to request notes if present */ if (route) { - apr_table_setn(r->notes, "session-sticky", (*balancer)->sticky); + apr_table_setn(r->notes, "session-sticky", sticky); apr_table_setn(r->notes, "session-route", route); /* Add session info to env. */ apr_table_setn(r->subprocess_env, - "BALANCER_SESSION_STICKY", (*balancer)->sticky); + "BALANCER_SESSION_STICKY", sticky); apr_table_setn(r->subprocess_env, "BALANCER_SESSION_ROUTE", route); } @@ -497,6 +526,8 @@ static int proxy_balancer_post_request(proxy_worker *worker, request_rec *r, proxy_server_conf *conf) { + +#if 0 apr_status_t rv; if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) { @@ -505,12 +536,7 @@ static int proxy_balancer_post_request(proxy_worker *worker, balancer->name); return HTTP_INTERNAL_SERVER_ERROR; } - /* TODO: calculate the bytes transferred - * This will enable to elect the worker that has - * the lowest load. - * The bytes transferred depends on the protocol - * used, so each protocol handler should keep the - * track on that. + /* TODO: placeholder for post_request actions */ if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) { @@ -521,6 +547,8 @@ static int proxy_balancer_post_request(proxy_worker *worker, ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "proxy_balancer_post_request for (%s)", balancer->name); +#endif + return OK; } |