You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jf...@apache.org on 2010/04/22 15:13:40 UTC

svn commit: r936828 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.h mod_proxy_balancer.c

Author: jfclere
Date: Thu Apr 22 13:13:40 2010
New Revision: 936828

URL: http://svn.apache.org/viewvc?rev=936828&view=rev
Log:
Add updatelbstatus to allow to have all the LB logic in the balancers.

Modified:
    httpd/httpd/trunk/modules/proxy/mod_proxy.h
    httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.h?rev=936828&r1=936827&r2=936828&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.h (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.h Thu Apr 22 13:13:40 2010
@@ -383,6 +383,7 @@ struct proxy_balancer_method {
     void            *context;   /* general purpose storage */
     apr_status_t (*reset)(proxy_balancer *balancer, server_rec *s);
     apr_status_t (*age)(proxy_balancer *balancer, server_rec *s);
+    apr_status_t (*updatelbstatus)(proxy_balancer *balancer, proxy_worker *elected, server_rec *s); 
 };
 
 #if APR_HAS_THREADS

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c?rev=936828&r1=936827&r2=936828&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c Thu Apr 22 13:13:40 2010
@@ -471,28 +471,31 @@ static int proxy_balancer_pre_request(pr
     /* Step 4: find the session route */
     runtime = find_session_route(*balancer, r, &route, &sticky, url);
     if (runtime) {
-        int i, total_factor = 0;
-        proxy_worker **workers;
-        /* We have a sticky load balancer
-         * Update the workers status
-         * so that even session routes get
-         * into account.
-         */
-        workers = (proxy_worker **)(*balancer)->workers->elts;
-        for (i = 0; i < (*balancer)->workers->nelts; i++) {
-            /* Take into calculation only the workers that are
-             * not in error state or not disabled.
-             *
-             * TODO: Abstract the below, since this is dependent
-             *       on the LB implementation
+        if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
+            /* Call the LB implementation */
+            (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
+        }
+        else { /* Use the default one */
+            int i, total_factor = 0;
+            proxy_worker **workers;
+            /* We have a sticky load balancer
+             * Update the workers status
+             * so that even session routes get
+             * into account.
              */
-            if (PROXY_WORKER_IS_USABLE(*workers)) {
-                (*workers)->s->lbstatus += (*workers)->s->lbfactor;
-                total_factor += (*workers)->s->lbfactor;
+            workers = (proxy_worker **)(*balancer)->workers->elts;
+            for (i = 0; i < (*balancer)->workers->nelts; i++) {
+                /* Take into calculation only the workers that are
+                 * not in error state or not disabled.
+                 */
+                if (PROXY_WORKER_IS_USABLE(*workers)) {
+                    (*workers)->s->lbstatus += (*workers)->s->lbfactor;
+                    total_factor += (*workers)->s->lbfactor;
+                }
+                workers++;
             }
-            workers++;
+            runtime->s->lbstatus -= total_factor;
         }
-        runtime->s->lbstatus -= total_factor;
         runtime->s->elected++;
 
         *worker = runtime;