]> granicus.if.org Git - apache/commitdiff
* mod_proxy: Remove load order and link dependency between mod_lbmethod_*
authorRuediger Pluem <rpluem@apache.org>
Fri, 20 Jul 2018 19:27:31 +0000 (19:27 +0000)
committerRuediger Pluem <rpluem@apache.org>
Fri, 20 Jul 2018 19:27:31 +0000 (19:27 +0000)
  modules and mod_proxy by providing mod_proxy's ap_proxy_balancer_get_best_worker
  as an optional function.

PR: 62557

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1836381 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
include/ap_mmn.h
modules/proxy/balancers/mod_lbmethod_bybusyness.c
modules/proxy/balancers/mod_lbmethod_byrequests.c
modules/proxy/balancers/mod_lbmethod_bytraffic.c
modules/proxy/mod_proxy.h
modules/proxy/proxy_util.c

diff --git a/CHANGES b/CHANGES
index 8d7c87b735ddd566055540e82e7effdff736c83b..4699a385c7cc1b61b9609b1c1c2302ba12045447 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.1
 
+  *) mod_proxy: Remove load order and link dependency between mod_lbmethod_*
+     modules and mod_proxy. PR 62557. [Ruediger Pluem]
+
   *) mod_md: more robust handling of http-01 challenges and hands-off when module
      should not be involved, e.g. challenge setup by another ACME client. [Stefan Eissing]
 
index 03dd7e7c24f18e83d81ad5ddd76578467008a8a7..af23d555075e815104405139ef562ee91f573f1d 100644 (file)
  *                         flush_max_threshold and flush_max_pipelined to
  *                         core_server_config, and ap_get_read_buf_size().
  * 20180720.1 (2.5.1-dev)  Axe data_in_{in,out}put_filter from conn_rec.
+ * 20180720.2 (2.5.1-dev)  Add optional function declaration for
+ *                         ap_proxy_balancer_get_best_worker to mod_proxy.h.
+ *
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20180720
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 1                 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 2                 /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index 709512bb5ee76906de0fcad7c50f68f4ce1ef9e4..99f8b14b0489512534d3c4da171db2dbac351a50 100644 (file)
@@ -22,6 +22,9 @@
 
 module AP_MODULE_DECLARE_DATA lbmethod_bybusyness_module;
 
+static APR_OPTIONAL_FN_TYPE(ap_proxy_balancer_get_best_worker)
+                            *ap_proxy_balancer_get_best_worker_fn = NULL;
+
 static int is_best_bybusyness(proxy_worker *current, proxy_worker *prev_best, void *baton)
 {
     int *total_factor = (int *)baton;
@@ -44,7 +47,7 @@ static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,
 {
     int total_factor = 0;
     proxy_worker *worker =
-        ap_proxy_balancer_get_best_worker(balancer, r, is_best_bybusyness,
+        ap_proxy_balancer_get_best_worker_fn(balancer, r, is_best_bybusyness,
                                           &total_factor);
 
     if (worker) {
@@ -82,9 +85,32 @@ static const proxy_balancer_method bybusyness =
     NULL
 };
 
+/* post_config hook: */
+static int lbmethod_bybusyness_post_config(apr_pool_t *pconf, apr_pool_t *plog,
+        apr_pool_t *ptemp, server_rec *s)
+{
+
+    /* lbmethod_bybusyness_post_config() will be called twice during startup.  So, don't
+     * set up the static data the 1st time through. */
+    if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
+        return OK;
+    }
+
+    ap_proxy_balancer_get_best_worker_fn =
+                 APR_RETRIEVE_OPTIONAL_FN(ap_proxy_balancer_get_best_worker);
+    if (!ap_proxy_balancer_get_best_worker_fn) {
+        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO()
+                     "mod_proxy must be loaded for mod_lbmethod_bybusyness");
+        return !OK;
+    }
+
+    return OK;
+}
+
 static void register_hook(apr_pool_t *p)
 {
     ap_register_provider(p, PROXY_LBMETHOD, "bybusyness", "0", &bybusyness);
+    ap_hook_post_config(lbmethod_bybusyness_post_config, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 AP_DECLARE_MODULE(lbmethod_bybusyness) = {
index 0483a70fecb712de392783f91e46e3ee3cd129d9..07822e702bd696be1bf1bc9fa74839104c799360 100644 (file)
@@ -22,6 +22,9 @@
 
 module AP_MODULE_DECLARE_DATA lbmethod_byrequests_module;
 
+static APR_OPTIONAL_FN_TYPE(ap_proxy_balancer_get_best_worker)
+                            *ap_proxy_balancer_get_best_worker_fn = NULL;
+
 static int is_best_byrequests(proxy_worker *current, proxy_worker *prev_best, void *baton)
 {
     int *total_factor = (int *)baton;
@@ -81,7 +84,7 @@ static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
                                 request_rec *r)
 {
     int total_factor = 0;
-    proxy_worker *worker = ap_proxy_balancer_get_best_worker(balancer, r, is_best_byrequests, &total_factor);
+    proxy_worker *worker = ap_proxy_balancer_get_best_worker_fn(balancer, r, is_best_byrequests, &total_factor);
 
     if (worker) {
         worker->s->lbstatus -= total_factor;
@@ -123,6 +126,28 @@ static const proxy_balancer_method byrequests =
     NULL
 };
 
+/* post_config hook: */
+static int lbmethod_byrequests_post_config(apr_pool_t *pconf, apr_pool_t *plog,
+        apr_pool_t *ptemp, server_rec *s)
+{
+
+    /* lbmethod_byrequests_post_config() will be called twice during startup.  So, don't
+     * set up the static data the 1st time through. */
+    if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
+        return OK;
+    }
+
+    ap_proxy_balancer_get_best_worker_fn =
+                 APR_RETRIEVE_OPTIONAL_FN(ap_proxy_balancer_get_best_worker);
+    if (!ap_proxy_balancer_get_best_worker_fn) {
+        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO()
+                     "mod_proxy must be loaded for mod_lbmethod_byrequests");
+        return !OK;
+    }
+
+    return OK;
+}
+
 static void register_hook(apr_pool_t *p)
 {
     /* Only the mpm_winnt has child init hook handler.
@@ -130,6 +155,7 @@ static void register_hook(apr_pool_t *p)
      * initializes and after the mod_proxy
      */
     ap_register_provider(p, PROXY_LBMETHOD, "byrequests", "0", &byrequests);
+    ap_hook_post_config(lbmethod_byrequests_post_config, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 AP_DECLARE_MODULE(lbmethod_byrequests) = {
index 343c59ac32a510dab1e5bd9ccc905182007fd110..b87db5adc6dfe67f0b5fa3d20cc1e6c6a75c1a34 100644 (file)
@@ -22,6 +22,9 @@
 
 module AP_MODULE_DECLARE_DATA lbmethod_bytraffic_module;
 
+static APR_OPTIONAL_FN_TYPE(ap_proxy_balancer_get_best_worker)
+                            *ap_proxy_balancer_get_best_worker_fn = NULL;
+
 static int is_best_bytraffic(proxy_worker *current, proxy_worker *prev_best, void *baton)
 {
     apr_off_t *min_traffic = (apr_off_t *)baton;
@@ -59,7 +62,7 @@ static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
 {
     apr_off_t min_traffic = 0;
 
-    return ap_proxy_balancer_get_best_worker(balancer, r, is_best_bytraffic,
+    return ap_proxy_balancer_get_best_worker_fn(balancer, r, is_best_bytraffic,
                                              &min_traffic);
 }
 
@@ -93,6 +96,28 @@ static const proxy_balancer_method bytraffic =
     NULL
 };
 
+/* post_config hook: */
+static int lbmethod_bytraffic_post_config(apr_pool_t *pconf, apr_pool_t *plog,
+        apr_pool_t *ptemp, server_rec *s)
+{
+
+    /* lbmethod_bytraffic_post_config() will be called twice during startup.  So, don't
+     * set up the static data the 1st time through. */
+    if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
+        return OK;
+    }
+
+    ap_proxy_balancer_get_best_worker_fn =
+                 APR_RETRIEVE_OPTIONAL_FN(ap_proxy_balancer_get_best_worker);
+    if (!ap_proxy_balancer_get_best_worker_fn) {
+        ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO()
+                     "mod_proxy must be loaded for mod_lbmethod_bytraffic");
+        return !OK;
+    }
+
+    return OK;
+}
+
 static void register_hook(apr_pool_t *p)
 {
     /* Only the mpm_winnt has child init hook handler.
@@ -100,6 +125,7 @@ static void register_hook(apr_pool_t *p)
      * initializes and after the mod_proxy
      */
     ap_register_provider(p, PROXY_LBMETHOD, "bytraffic", "0", &bytraffic);
+    ap_hook_post_config(lbmethod_bytraffic_post_config, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 AP_DECLARE_MODULE(lbmethod_bytraffic) = {
index ae8be929bccf8d043dfdc355be3323b253c418b6..cec243840b03bb375705224d9fa956a9d0d5c818 100644 (file)
@@ -880,6 +880,14 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_balancer_get_best_worker(proxy_balancer *
                                                                 request_rec *r,
                                                                 proxy_is_best_callback_fn_t *is_best,
                                                                 void *baton);
+/*
+ * Needed by the lb modules.
+ */
+APR_DECLARE_OPTIONAL_FN(proxy_worker *, ap_proxy_balancer_get_best_worker,
+                                        (proxy_balancer *balancer,
+                                         request_rec *r,
+                                         proxy_is_best_callback_fn_t *is_best,
+                                         void *baton));
 
 /**
  * Find the shm of the worker as needed
index e8eecb20709a39e73daf4281029342a016a60890..bb24ca0802ce9edb9bfef85e906b4d21162ece24 100644 (file)
@@ -4079,4 +4079,5 @@ void proxy_util_register_hooks(apr_pool_t *p)
 {
     APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);
     APR_REGISTER_OPTIONAL_FN(ap_proxy_clear_connection);
+    APR_REGISTER_OPTIONAL_FN(ap_proxy_balancer_get_best_worker);
 }