On 9/15/06, Ruediger Pluem <[EMAIL PROTECTED]> wrote:


On 09/15/2006 07:41 PM, Brian Rectanus wrote:


>
> I am thinking that there is still not a way to check if
> BALANCER_WORKER_ROUTE == BALANCER_SESSION_ROUTE at response time since
> I think 'SetEnvIf response ...' will not resolve env vars it did not

Yes, this is true. It was also my first thought to go this way and having 
setenvif
work on responses seems to be nice anyway (apart from balancing stuff).
But after a brief look I found that comparing two environment variables with 
setenvif
requires quite a bunch of changes to mod_setenvif and aboves patch seems to be 
a quicker
way (and still a good way) to get what is wanted.

> set (at least that is what the docs hint at - have not tried).
>
> So, this BALANCER_ROUTE_CHANGED patch is still needed.  I have been
> meaning to send it but you got to it first :)  Will you commit that to
> trunk?

Yes, this is my intention. I am just waiting for some further comments and then 
I will commit it.

>
> Also, I would like my patches (now in trunk) and this additional
> BALANCER_ROUTE_CHANGED patch to go into the next 2.2.x release if that

Once the above patch is in I will propose them for backport to 2.2.x.

> seems ok.  Is this something you would do, or do you want me to put
> togeather a 2.2.x patch?

I guess you already did most of it:

You tested it.
You gave feedback.
You even provided documentation (hadn't time to review it so far).

Thanks for that.


Regards

RĂ¼diger


Here is a backport to 2.2.x branch with my env vars (code and docs)
from trunk and your BALANCER_ROUTE_CHANGED addition with docs as well.

Would you please apply?

Thanks,
-B
Index: 2.2.x/docs/manual/mod/mod_proxy_balancer.xml
===================================================================
--- 2.2.x/docs/manual/mod/mod_proxy_balancer.xml        (revision 470831)
+++ 2.2.x/docs/manual/mod/mod_proxy_balancer.xml        (working copy)
@@ -271,6 +271,59 @@
 
 </section>
 
+<section id="environment">
+    <title>Exported Environment Variables</title>
+    <p>At present there are 6 environment variables exported:</p>
+
+    <dl>
+    <!-- ============= BALANCER_SESSION_STICKY =============== -->
+    <dt><var><a name="balancer_session_sticky" 
id="balancer_session_sticky">BALANCER_SESSION_STICKY</a></var></dt>
+    <dd>
+    <p>This is assigned the <var>stickysession</var> value used in the current
+    request.  It is the cookie or parameter name used for sticky sessions</p>
+    </dd>
+
+    <!-- ============= BALANCER_SESSION_ROUTE ================ -->
+    <dt><var><a name="balancer_session_route" 
id="balancer_session_route">BALANCER_SESSION_ROUTE</a></var></dt>
+    <dd>
+    <p>This is assigned the <var>route</var> parsed from the current 
+    request.</p>
+    </dd>
+
+    <!-- ============= BALANCER_NAME ========================= -->
+    <dt><var><a name="balancer_name" 
id="balancer_name">BALANCER_NAME</a></var></dt>
+    <dd>
+    <p>This is assigned the name of the balancer used for the current 
+    request. The value is something like <code>balancer://foo</code>.</p>
+    </dd>
+
+    <!-- ============= BALANCER_WORKER_NAME ================== -->
+    <dt><var><a name="balancer_worker_name" 
id="balancer_worker_name">BALANCER_WORKER_NAME</a></var></dt>
+    <dd>
+    <p>This is assigned the name of the worker used for the current request.
+    The value is something like <code>http://hostA:1234</code>.</p>
+    </dd>
+
+    <!-- ============= BALANCER_WORKER_ROUTE ================= -->
+    <dt><var><a name="balancer_worker_route" 
id="balancer_worker_route">BALANCER_WORKER_ROUTE</a></var></dt>
+    <dd>
+    <p>This is assigned the <var>route</var> of the worker that will be 
+    used for the current request.</p>
+    </dd>
+
+    <!-- ============= BALANCER_ROUTE_CHANGED ================= -->
+    <dt><var><a name="balancer_route_changed" 
id="balancer_route_changed">BALANCER_ROUTE_CHANGED</a></var></dt>
+    <dd>
+    <p>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.</p>
+    </dd>
+    </dl>
+
+</section>
+
 <section id="enable">
     <title>Enabling Balancer Manager Support</title>
     <p>This module <em>requires</em> the service of 
Index: 2.2.x/modules/proxy/mod_proxy_balancer.c
===================================================================
--- 2.2.x/modules/proxy/mod_proxy_balancer.c    (revision 470831)
+++ 2.2.x/modules/proxy/mod_proxy_balancer.c    (working copy)
@@ -262,6 +262,16 @@
          * 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
@@ -419,9 +429,28 @@
 
             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
@@ -432,6 +461,12 @@
     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",

Reply via email to