summaryrefslogtreecommitdiffstats
path: root/modules/proxy
diff options
context:
space:
mode:
authorRuediger Pluem <rpluem@apache.org>2018-07-20 21:27:31 +0200
committerRuediger Pluem <rpluem@apache.org>2018-07-20 21:27:31 +0200
commit81e420cfb09bc89a819e4463746100793788d9a9 (patch)
treee8851d3b310591407cb8c0869b5576869eacfc59 /modules/proxy
parentcore: axe data_in_in/output_filter from conn_rec. (diff)
downloadapache2-81e420cfb09bc89a819e4463746100793788d9a9.tar.xz
apache2-81e420cfb09bc89a819e4463746100793788d9a9.zip
* mod_proxy: Remove load order and link dependency between mod_lbmethod_*
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
Diffstat (limited to 'modules/proxy')
-rw-r--r--modules/proxy/balancers/mod_lbmethod_bybusyness.c28
-rw-r--r--modules/proxy/balancers/mod_lbmethod_byrequests.c28
-rw-r--r--modules/proxy/balancers/mod_lbmethod_bytraffic.c28
-rw-r--r--modules/proxy/mod_proxy.h8
-rw-r--r--modules/proxy/proxy_util.c1
5 files changed, 90 insertions, 3 deletions
diff --git a/modules/proxy/balancers/mod_lbmethod_bybusyness.c b/modules/proxy/balancers/mod_lbmethod_bybusyness.c
index 709512bb5e..99f8b14b04 100644
--- a/modules/proxy/balancers/mod_lbmethod_bybusyness.c
+++ b/modules/proxy/balancers/mod_lbmethod_bybusyness.c
@@ -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) = {
diff --git a/modules/proxy/balancers/mod_lbmethod_byrequests.c b/modules/proxy/balancers/mod_lbmethod_byrequests.c
index 0483a70fec..07822e702b 100644
--- a/modules/proxy/balancers/mod_lbmethod_byrequests.c
+++ b/modules/proxy/balancers/mod_lbmethod_byrequests.c
@@ -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) = {
diff --git a/modules/proxy/balancers/mod_lbmethod_bytraffic.c b/modules/proxy/balancers/mod_lbmethod_bytraffic.c
index 343c59ac32..b87db5adc6 100644
--- a/modules/proxy/balancers/mod_lbmethod_bytraffic.c
+++ b/modules/proxy/balancers/mod_lbmethod_bytraffic.c
@@ -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) = {
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
index ae8be929bc..cec243840b 100644
--- a/modules/proxy/mod_proxy.h
+++ b/modules/proxy/mod_proxy.h
@@ -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
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
index e8eecb2070..bb24ca0802 100644
--- a/modules/proxy/proxy_util.c
+++ b/modules/proxy/proxy_util.c
@@ -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);
}