]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Sync up with trunk
authorJim Jagielski <jim@apache.org>
Wed, 13 May 2009 16:55:06 +0000 (16:55 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 13 May 2009 16:55:06 +0000 (16:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/httpd-2.2-proxy@774427 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/examples/mod_lbmethod_rr.c
modules/proxy/mod_lbmethod_bybusyness.c
modules/proxy/mod_lbmethod_byrequests.c
modules/proxy/mod_lbmethod_bytraffic.c
modules/proxy/mod_proxy.c
modules/proxy/mod_proxy.h
modules/proxy/mod_proxy_balancer.c
modules/proxy/proxy_util.c

index 775f2c45e6c4c5ae1357250d4ebc4ea172322a7f..10406fda7148746440fd93fc3c6a19fe0a3aaecc 100644 (file)
@@ -95,11 +95,21 @@ static proxy_worker *find_best_roundrobin(proxy_balancer *balancer,
     return mycandidate;
 }
 
+static apr_status_t reset(proxy_balancer *balancer, server_rec *s) {
+        return APR_SUCCESS;
+}
+
+static apr_status_t age(proxy_balancer *balancer, server_rec *s) {
+        return APR_SUCCESS;
+}
+
 static const proxy_balancer_method roundrobin =
 {
     "roundrobin",
     &find_best_roundrobin,
-    NULL
+    NULL,
+    &reset,
+    &age
 };
 
 
index 212ce14b9a2161be73167597162431a1b3317556..232420c26593aa2d68488fbce903f1112ff89c98 100644 (file)
@@ -103,11 +103,11 @@ static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,
 
 }
 
-static apr_status_t reset(proxy_balancer *balancer, request_rec *r) {
+static apr_status_t reset(proxy_balancer *balancer, server_rec *s) {
         return APR_SUCCESS;
 }
 
-static apr_status_t age(proxy_balancer *balancer, request_rec *r) {
+static apr_status_t age(proxy_balancer *balancer, server_rec *s) {
         return APR_SUCCESS;
 }
 
@@ -115,7 +115,7 @@ const proxy_balancer_method proxy_balancer_bybusyness =
 {
     "bybusyness",
     &find_best_bybusyness,
+    NULL,
     &reset,
-    &age,
-    NULL
+    &age
 };
index 63278e12e07342d2d8d209ed4b20c0d19e3afb6f..a05ab4b868ebc76e42b9993c6e92356399ac2f1b 100644 (file)
@@ -130,11 +130,11 @@ static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
     return mycandidate;
 }
 
-static apr_status_t reset(proxy_balancer *balancer, request_rec *r) {
+static apr_status_t reset(proxy_balancer *balancer, server_rec *s) {
         return APR_SUCCESS;
 }
 
-static apr_status_t age(proxy_balancer *balancer, request_rec *r) {
+static apr_status_t age(proxy_balancer *balancer, server_rec *s) {
         return APR_SUCCESS;
 }
 
@@ -148,7 +148,7 @@ const proxy_balancer_method proxy_balancer_byrequests =
 {
     "byrequests",
     &find_best_byrequests,
+    NULL,
     &reset,
-    &age,
-    NULL
+    &age
 };
index 3e6fd6aa666d8aac4d89e298d942bcd25a850ee6..fede689887a692f93d2a830d56ddc40953bca295 100644 (file)
@@ -103,11 +103,11 @@ static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
     return mycandidate;
 }
 
-static apr_status_t reset(proxy_balancer *balancer, request_rec *r) {
+static apr_status_t reset(proxy_balancer *balancer, server_rec *s) {
         return APR_SUCCESS;
 }
 
-static apr_status_t age(proxy_balancer *balancer, request_rec *r) {
+static apr_status_t age(proxy_balancer *balancer, server_rec *s) {
         return APR_SUCCESS;
 }
 
@@ -115,7 +115,7 @@ const proxy_balancer_method proxy_balancer_bytraffic =
 {
     "bytraffic",
     &find_best_bytraffic,
+    NULL,
     &reset,
-    &age,
-    NULL
+    &age
 };
index 592f6352398bd5dc8e64955f875f3d0fa97b0629..0d0eada9ebcf7d6cd6baead5923bd295911f72d3 100644 (file)
@@ -933,6 +933,13 @@ static int proxy_handler(request_rec *r)
                 balancer = NULL;
             goto cleanup;
         }
+
+        /* Initialise worker if needed, note the shared area must be initialized by the balancer logic */
+        if (balancer) {
+            ap_proxy_initialize_worker(worker, r->server, conf->pool); 
+            ap_proxy_initialize_worker_share(conf, worker, r->server);
+        }
+
         if (balancer && balancer->max_attempts_set && !max_attempts)
             max_attempts = balancer->max_attempts;
         /* firstly, try a proxy, unless a NoProxy directive is active */
@@ -2286,7 +2293,7 @@ static void child_init(apr_pool_t *p, server_rec *s)
         worker = (proxy_worker *)conf->workers->elts;
         for (i = 0; i < conf->workers->nelts; i++) {
             ap_proxy_initialize_worker_share(conf, worker, s);
-            ap_proxy_initialize_worker(worker, s);
+            ap_proxy_initialize_worker(worker, s, p);
             worker++;
         }
         /* Create and initialize forward worker if defined */
@@ -2296,7 +2303,7 @@ static void child_init(apr_pool_t *p, server_rec *s)
             conf->forward->hostname = "*";
             conf->forward->scheme   = "*";
             ap_proxy_initialize_worker_share(conf, conf->forward, s);
-            ap_proxy_initialize_worker(conf->forward, s);
+            ap_proxy_initialize_worker(conf->forward, s, p);
             /* Do not disable worker in case of errors */
             conf->forward->s->status |= PROXY_WORKER_IGNORE_ERRORS;
             /* Disable address cache for generic forward worker */
@@ -2308,7 +2315,7 @@ static void child_init(apr_pool_t *p, server_rec *s)
             reverse->hostname = "*";
             reverse->scheme   = "*";
             ap_proxy_initialize_worker_share(conf, reverse, s);
-            ap_proxy_initialize_worker(reverse, s);
+            ap_proxy_initialize_worker(reverse, s, p);
             /* Do not disable worker in case of errors */
             reverse->s->status |= PROXY_WORKER_IGNORE_ERRORS;
             /* Disable address cache for generic reverse worker */
index 25590d1c81165f0e40369bc30f56d8e8be5a55a7..b63713414660b13019ec250846c5695efdd8a7f7 100644 (file)
@@ -392,9 +392,9 @@ struct proxy_balancer_method {
     const char *name;            /* name of the load balancer method*/
     proxy_worker *(*finder)(proxy_balancer *balancer,
                             request_rec *r);
-    apr_status_t (*reset)(proxy_balancer *balancer, request_rec *r);
-    apr_status_t (*age)(proxy_balancer *balancer, request_rec *r);
     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);
 };
 
 #if APR_HAS_THREADS
@@ -572,10 +572,12 @@ PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
  * Initize the worker
  * @param worker worker to initialize
  * @param s      current server record
+ * @param p      memory pool used for mutex and Connection pool.
  * @return       APR_SUCCESS or error code
  */
 PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker,
-                                                       server_rec *s);
+                                                       server_rec *s,
+                                                       apr_pool_t *p);
 /**
  * Get the balancer from proxy configuration
  * @param p     memory pool used for finding balancer
index 35bd48a5ead6ff8210e3237aabb22b0d7e0fbc07..8a7f66fb0412409b57d4cad74db21c1c054db467 100644 (file)
@@ -106,7 +106,7 @@ static int init_balancer_members(proxy_server_conf *conf, server_rec *s,
             }
         }
         ap_proxy_initialize_worker_share(conf, *workers, s);
-        ap_proxy_initialize_worker(*workers, s);
+        ap_proxy_initialize_worker(*workers, s, conf->pool);
         if (!worker_is_initialized) {
             /* Set to the original configuration */
             (*workers)->s->lbstatus = (*workers)->s->lbfactor =
@@ -943,6 +943,9 @@ static void child_init(apr_pool_t *p, server_rec *s)
         /* Initialize shared scoreboard data */
         balancer = (proxy_balancer *)conf->balancers->elts;
         for (i = 0; i < conf->balancers->nelts; i++) {
+            proxy_balancer_method *lbmethod = balancer->lbmethod;
+            if (balancer->lbmethod!=NULL && balancer->lbmethod->reset != NULL)
+               balancer->lbmethod->reset(balancer, s);
             init_balancer_members(conf, s, balancer);
             balancer++;
         }
index beb176faa19400e3a4c19962332733b715d2298f..81eb944ab5690dccc071cc04ea0f3d9a05018d99 100644 (file)
@@ -1443,14 +1443,8 @@ PROXY_DECLARE(const char *) ap_proxy_add_worker(proxy_worker **worker,
     (*worker)->smax = -1;
     /* Increase the total worker count */
     proxy_lb_workers++;
-    init_conn_pool(p, *worker);
-#if APR_HAS_THREADS
-    if (apr_thread_mutex_create(&((*worker)->mutex),
-                APR_THREAD_MUTEX_DEFAULT, p) != APR_SUCCESS) {
-        /* XXX: Do we need to log something here */
-        return "can not create thread mutex";
-    }
-#endif
+    (*worker)->cp = NULL;
+    (*worker)->mutex = NULL;
 
     return NULL;
 }
@@ -1464,7 +1458,8 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_create_worker(apr_pool_t *p)
     worker->smax = -1;
     /* Increase the total worker count */
     proxy_lb_workers++;
-    init_conn_pool(p, worker);
+    worker->cp = NULL;
+    worker->mutex = NULL;
 
     return worker;
 }
@@ -1839,7 +1834,7 @@ PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
 
 }
 
-PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, server_rec *s)
+PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, server_rec *s, apr_pool_t *p)
 {
     apr_status_t rv;
 
@@ -1864,7 +1859,24 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
         worker->is_address_reusable = 1;
     }
 
+    if (worker->cp == NULL)
+        init_conn_pool(p, worker);
+    if (worker->cp == NULL) {
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+            "can not create connection pool");
+        return APR_EGENERAL;
+    } 
+
 #if APR_HAS_THREADS
+    if (worker->mutex == NULL) {
+        rv = apr_thread_mutex_create(&(worker->mutex), APR_THREAD_MUTEX_DEFAULT, p);
+        if (rv != APR_SUCCESS) {
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+                "can not create thread mutex");
+            return rv;
+        }
+    }
+
     ap_mpm_query(AP_MPMQ_MAX_THREADS, &mpm_threads);
     if (mpm_threads > 1) {
         /* Set hard max to no more then mpm_threads */