From: Jim Jagielski Date: Tue, 7 Nov 2006 13:49:09 +0000 (+0000) Subject: Merge r417238, r437773, r446929, r453630 from trunk: X-Git-Tag: 2.2.4~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a0c72496b7b21deb2acb5a71e206e6148a90298;p=thirdparty%2Fapache%2Fhttpd.git Merge r417238, r437773, r446929, r453630 from trunk: * Add the following environment variables to expose the information * about the route, the sticky session and the worker used during a request to other modules: BALANCER_SESSION_STICKY BALANCER_SESSION_ROUTE BALANCER_NAME BALANCER_WORKER_NAME BALANCER_WORKER_ROUTE PR: 39806 Submitted by: Brian Reviewed by: rpluem fix validation error * Set the new environment variable BALANCER_ROUTE_CHANGED if a worker with a route different from the one supplied by the client had been chosen or if the client supplied no routing information for a balancer with sticky sessions. * mod_proxy_balancer: Document BALANCER_ROUTE_CHANGED environment variable. Submitted by: Brian Rectanus Reviewed by: rpluem Reviewed by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@472114 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 9298aee997f..93961a8ac93 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,15 @@ -*- coding: utf-8 -*- Changes with Apache 2.2.4 + *) mod_proxy_balancer: Set the new environment variable BALANCER_ROUTE_CHANGED + if a worker with a route different from the one supplied by the client + had been chosen or if the client supplied no routing information for + a balancer with sticky sessions. [Ruediger Pluem] + + *) mod_proxy_balancer: Add information about the route, the sticky session + and the worker used during a request as environment variables. PR 39806. + [Brian ] + *) mod_proxy: Don't try to use dead backend connection. PR 37770. [Olivier BOEL ] diff --git a/STATUS b/STATUS index f531812ed44..563f5a7d483 100644 --- a/STATUS +++ b/STATUS @@ -77,22 +77,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * mod_proxy_balancer: Implement new environment variables - BALANCER_NAME - BALANCER_WORKER_NAME - BALANCER_WORKER_ROUTE - BALANCER_SESSION_STICKY - BALANCER_SESSION_ROUTE - BALANCER_ROUTE_CHANGED - Trunk versions of patch: - http://svn.apache.org/viewvc?view=rev&revision=417238 (including docs) - http://svn.apache.org/viewvc?view=rev&revision=437773 (docs) - http://svn.apache.org/viewvc?view=rev&revision=446929 - http://svn.apache.org/viewvc?view=rev&revision=453630 (docs) - 2.2.x version of patch: - Trunk version works - +1: rpluem, mturk, jim - PATCHES PROPOSED TO BACKPORT FROM TRUNK: * mpm_winnt: Fix return values from wait_for_many_objects. diff --git a/docs/manual/mod/mod_proxy_balancer.xml b/docs/manual/mod/mod_proxy_balancer.xml index b035a19af14..532fc92fcb2 100644 --- a/docs/manual/mod/mod_proxy_balancer.xml +++ b/docs/manual/mod/mod_proxy_balancer.xml @@ -271,6 +271,59 @@ candidate lbstatus -= total factor +
+ Exported Environment Variables +

At present there are 6 environment variables exported:

+ +
+ +
BALANCER_SESSION_STICKY
+
+

This is assigned the stickysession value used in the current + request. It is the cookie or parameter name used for sticky sessions

+
+ + +
BALANCER_SESSION_ROUTE
+
+

This is assigned the route parsed from the current + request.

+
+ + +
BALANCER_NAME
+
+

This is assigned the name of the balancer used for the current + request. The value is something like balancer://foo.

+
+ + +
BALANCER_WORKER_NAME
+
+

This is assigned the name of the worker used for the current request. + The value is something like http://hostA:1234.

+
+ + +
BALANCER_WORKER_ROUTE
+
+

This is assigned the route of the worker that will be + used for the current request.

+
+ + +
BALANCER_ROUTE_CHANGED
+
+

This is set to 1 if the session route does not match the + worker route (BALANCER_SESSION_ROUTE != BALANCER_WORKER_ROUTE) or the + session does not yet have an established route. This can be used to + determine when/if the client needs to be sent an updated route + when sticky sessions are used.

+
+
+ +
+
Enabling Balancer Manager Support

This module requires the service of diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c index c4e33079011..b7d4466ba74 100644 --- a/modules/proxy/mod_proxy_balancer.c +++ b/modules/proxy/mod_proxy_balancer.c @@ -260,6 +260,16 @@ static proxy_worker *find_session_route(proxy_balancer *balancer, * Find the worker that has this route defined. */ worker = find_route_worker(balancer, *route, r); + if (worker && strcmp(*route, worker->s->route)) { + /* + * Notice that the route of the worker chosen is different from + * the route supplied by the client. + */ + apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1"); + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "proxy: BALANCER: Route changed from %s to %s", + *route, worker->s->route); + } return worker; } else @@ -417,9 +427,28 @@ static int proxy_balancer_pre_request(proxy_worker **worker, return HTTP_SERVICE_UNAVAILABLE; } + if ((*balancer)->sticky && runtime) { + /* + * This balancer has sticky sessions and the client either has not + * supplied any routing information or all workers for this route + * including possible redirect and hotstandby workers are in error + * state, but we have found another working worker for this + * balancer where we can send the request. Thus notice that we have + * changed the route to the backend. + */ + apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1"); + } *worker = runtime; } + /* Add balancer/worker info to env. */ + apr_table_setn(r->subprocess_env, + "BALANCER_NAME", (*balancer)->name); + apr_table_setn(r->subprocess_env, + "BALANCER_WORKER_NAME", (*worker)->name); + apr_table_setn(r->subprocess_env, + "BALANCER_WORKER_ROUTE", (*worker)->s->route); + /* Rewrite the url from 'balancer://url' * to the 'worker_scheme://worker_hostname[:worker_port]/url' * This replaces the balancers fictional name with the @@ -430,6 +459,12 @@ static int proxy_balancer_pre_request(proxy_worker **worker, if (route) { apr_table_setn(r->notes, "session-sticky", (*balancer)->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); + apr_table_setn(r->subprocess_env, + "BALANCER_SESSION_ROUTE", route); } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "proxy: BALANCER (%s) worker (%s) rewritten to %s",