1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

mod_proxy: Make ap_proxy_retry_worker() into an optional function. Allows

mod_lbmethod_bybusyness, mod_lbmethod_byrequests, mod_lbmethod_bytraffic
and mod_lbmethod_heartbeat to be loaded without mod_proxy yet being present,
which happens when modules are loaded in alphabetical order.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1209754 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Graham Leggett
2011-12-02 22:42:39 +00:00
parent b3cde50489
commit 0182b1654f
9 changed files with 121 additions and 15 deletions

View File

@@ -22,6 +22,9 @@
module AP_MODULE_DECLARE_DATA lbmethod_bybusyness_module; module AP_MODULE_DECLARE_DATA lbmethod_bybusyness_module;
static int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
proxy_worker *worker, server_rec *s) = NULL;
static proxy_worker *find_best_bybusyness(proxy_balancer *balancer, static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,
request_rec *r) request_rec *r)
{ {
@@ -36,6 +39,15 @@ static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,
int total_factor = 0; int total_factor = 0;
if (!ap_proxy_retry_worker_fn) {
ap_proxy_retry_worker_fn =
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
if (!ap_proxy_retry_worker_fn) {
/* can only happen if mod_proxy isn't loaded */
return NULL;
}
}
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"proxy: Entering bybusyness for BALANCER (%s)", "proxy: Entering bybusyness for BALANCER (%s)",
balancer->s->name); balancer->s->name);
@@ -66,8 +78,9 @@ static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,
* The worker might still be unusable, but we try * The worker might still be unusable, but we try
* anyway. * anyway.
*/ */
if (!PROXY_WORKER_IS_USABLE(*worker)) if (!PROXY_WORKER_IS_USABLE(*worker)) {
ap_proxy_retry_worker("BALANCER", *worker, r->server); ap_proxy_retry_worker_fn("BALANCER", *worker, r->server);
}
/* Take into calculation only the workers that are /* Take into calculation only the workers that are
* not in error state or not disabled. * not in error state or not disabled.

View File

@@ -22,6 +22,9 @@
module AP_MODULE_DECLARE_DATA lbmethod_byrequests_module; module AP_MODULE_DECLARE_DATA lbmethod_byrequests_module;
static int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
proxy_worker *worker, server_rec *s) = NULL;
/* /*
* The idea behind the find_best_byrequests scheduler is the following: * The idea behind the find_best_byrequests scheduler is the following:
* *
@@ -80,6 +83,15 @@ static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
int checking_standby; int checking_standby;
int checked_standby; int checked_standby;
if (!ap_proxy_retry_worker_fn) {
ap_proxy_retry_worker_fn =
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
if (!ap_proxy_retry_worker_fn) {
/* can only happen if mod_proxy isn't loaded */
return NULL;
}
}
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"proxy: Entering byrequests for BALANCER (%s)", "proxy: Entering byrequests for BALANCER (%s)",
balancer->s->name); balancer->s->name);
@@ -109,7 +121,7 @@ static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
* anyway. * anyway.
*/ */
if (!PROXY_WORKER_IS_USABLE(*worker)) if (!PROXY_WORKER_IS_USABLE(*worker))
ap_proxy_retry_worker("BALANCER", *worker, r->server); ap_proxy_retry_worker_fn("BALANCER", *worker, r->server);
/* Take into calculation only the workers that are /* Take into calculation only the workers that are
* not in error state or not disabled. * not in error state or not disabled.
*/ */

View File

@@ -22,6 +22,9 @@
module AP_MODULE_DECLARE_DATA lbmethod_bytraffic_module; module AP_MODULE_DECLARE_DATA lbmethod_bytraffic_module;
static int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
proxy_worker *worker, server_rec *s) = NULL;
/* /*
* The idea behind the find_best_bytraffic scheduler is the following: * The idea behind the find_best_bytraffic scheduler is the following:
* *
@@ -52,6 +55,15 @@ static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
int checking_standby; int checking_standby;
int checked_standby; int checked_standby;
if (!ap_proxy_retry_worker_fn) {
ap_proxy_retry_worker_fn =
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
if (!ap_proxy_retry_worker_fn) {
/* can only happen if mod_proxy isn't loaded */
return NULL;
}
}
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"proxy: Entering bytraffic for BALANCER (%s)", "proxy: Entering bytraffic for BALANCER (%s)",
balancer->s->name); balancer->s->name);
@@ -81,7 +93,7 @@ static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
* anyway. * anyway.
*/ */
if (!PROXY_WORKER_IS_USABLE(*worker)) if (!PROXY_WORKER_IS_USABLE(*worker))
ap_proxy_retry_worker("BALANCER", *worker, r->server); ap_proxy_retry_worker_fn("BALANCER", *worker, r->server);
/* Take into calculation only the workers that are /* Take into calculation only the workers that are
* not in error state or not disabled. * not in error state or not disabled.
*/ */

View File

@@ -31,6 +31,9 @@
module AP_MODULE_DECLARE_DATA lbmethod_heartbeat_module; module AP_MODULE_DECLARE_DATA lbmethod_heartbeat_module;
static int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
proxy_worker *worker, server_rec *s) = NULL;
static const ap_slotmem_provider_t *storage = NULL; static const ap_slotmem_provider_t *storage = NULL;
static ap_slotmem_instance_t *hm_serversmem = NULL; static ap_slotmem_instance_t *hm_serversmem = NULL;
@@ -270,6 +273,15 @@ static proxy_worker *find_best_hb(proxy_balancer *balancer,
ap_get_module_config(r->server->module_config, ap_get_module_config(r->server->module_config,
&lbmethod_heartbeat_module); &lbmethod_heartbeat_module);
if (!ap_proxy_retry_worker_fn) {
ap_proxy_retry_worker_fn =
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
if (!ap_proxy_retry_worker_fn) {
/* can only happen if mod_proxy isn't loaded */
return NULL;
}
}
apr_pool_create(&tpool, r->pool); apr_pool_create(&tpool, r->pool);
servers = apr_hash_make(tpool); servers = apr_hash_make(tpool);
@@ -297,7 +309,7 @@ static proxy_worker *find_best_hb(proxy_balancer *balancer,
} }
if (!PROXY_WORKER_IS_USABLE(*worker)) { if (!PROXY_WORKER_IS_USABLE(*worker)) {
ap_proxy_retry_worker("BALANCER", *worker, r->server); ap_proxy_retry_worker_fn("BALANCER", *worker, r->server);
} }
if (PROXY_WORKER_IS_USABLE(*worker)) { if (PROXY_WORKER_IS_USABLE(*worker)) {

View File

@@ -19,6 +19,7 @@
#include "apr_optional.h" #include "apr_optional.h"
#include "scoreboard.h" #include "scoreboard.h"
#include "mod_status.h" #include "mod_status.h"
#include "proxy_util.h"
#if (MODULE_MAGIC_NUMBER_MAJOR > 20020903) #if (MODULE_MAGIC_NUMBER_MAJOR > 20020903)
#include "mod_ssl.h" #include "mod_ssl.h"
@@ -2512,6 +2513,8 @@ static void register_hooks(apr_pool_t *p)
/* child init handling */ /* child init handling */
ap_hook_child_init(child_init, aszPred, NULL, APR_HOOK_MIDDLE); ap_hook_child_init(child_init, aszPred, NULL, APR_HOOK_MIDDLE);
/* register optional functions within proxy_util.c */
proxy_util_register_hooks(p);
} }
AP_DECLARE_MODULE(proxy) = AP_DECLARE_MODULE(proxy) =

View File

@@ -27,6 +27,7 @@
*/ */
#include "apr_hooks.h" #include "apr_hooks.h"
#include "apr_optional.h"
#include "apr.h" #include "apr.h"
#include "apr_lib.h" #include "apr_lib.h"
#include "apr_strings.h" #include "apr_strings.h"
@@ -769,9 +770,8 @@ PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
* @note The error status of the worker will cleared if the retry interval has * @note The error status of the worker will cleared if the retry interval has
* elapsed since the last error. * elapsed since the last error.
*/ */
PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function, APR_DECLARE_OPTIONAL_FN(int, ap_proxy_retry_worker,
proxy_worker *worker, (const char *proxy_function, proxy_worker *worker, server_rec *s));
server_rec *s);
/** /**
* Acquire a connection from worker connection pool * Acquire a connection from worker connection pool

View File

@@ -28,6 +28,9 @@ ap_slotmem_provider_t *storage = NULL;
module AP_MODULE_DECLARE_DATA proxy_balancer_module; module AP_MODULE_DECLARE_DATA proxy_balancer_module;
static int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
proxy_worker *worker, server_rec *s) = NULL;
/* /*
* Register our mutex type before the config is read so we * Register our mutex type before the config is read so we
* can adjust the mutex settings using the Mutex directive. * can adjust the mutex settings using the Mutex directive.
@@ -224,7 +227,7 @@ static proxy_worker *find_route_worker(proxy_balancer *balancer,
* The worker might still be unusable, but we try * The worker might still be unusable, but we try
* anyway. * anyway.
*/ */
ap_proxy_retry_worker("BALANCER", worker, r->server); ap_proxy_retry_worker_fn("BALANCER", worker, r->server);
if (PROXY_WORKER_IS_USABLE(worker)) { if (PROXY_WORKER_IS_USABLE(worker)) {
return worker; return worker;
} else { } else {
@@ -248,7 +251,7 @@ static proxy_worker *find_route_worker(proxy_balancer *balancer,
* The worker might still be unusable, but we try * The worker might still be unusable, but we try
* anyway. * anyway.
*/ */
ap_proxy_retry_worker("BALANCER", rworker, r->server); ap_proxy_retry_worker_fn("BALANCER", rworker, r->server);
} }
if (rworker && PROXY_WORKER_IS_USABLE(rworker)) if (rworker && PROXY_WORKER_IS_USABLE(rworker))
return rworker; return rworker;
@@ -413,7 +416,7 @@ static void force_recovery(proxy_balancer *balancer, server_rec *s)
} }
else { else {
/* Try if we can recover */ /* Try if we can recover */
ap_proxy_retry_worker("BALANCER", *worker, s); ap_proxy_retry_worker_fn("BALANCER", *worker, s);
if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) { if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
ok = 1; ok = 1;
break; break;
@@ -696,8 +699,19 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
/* balancer_post_config() will be called twice during startup. So, don't /* balancer_post_config() will be called twice during startup. So, don't
* set up the static data the 1st time through. */ * set up the static data the 1st time through. */
if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
return OK; return OK;
}
if (!ap_proxy_retry_worker_fn) {
ap_proxy_retry_worker_fn =
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
if (!ap_proxy_retry_worker_fn) {
ap_log_error(
APLOG_MARK, APLOG_EMERG, 0, s, "mod_proxy must be loaded for mod_proxy_balancer");
return !OK;
}
}
/* /*
* Get slotmem setups * Get slotmem setups

View File

@@ -20,6 +20,7 @@
#include "scoreboard.h" #include "scoreboard.h"
#include "apr_version.h" #include "apr_version.h"
#include "apr_hash.h" #include "apr_hash.h"
#include "proxy_util.h"
#if APR_HAVE_UNISTD_H #if APR_HAVE_UNISTD_H
#include <unistd.h> /* for getpid() */ #include <unistd.h> /* for getpid() */
@@ -1977,9 +1978,8 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
return rv; return rv;
} }
PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function, static int ap_proxy_retry_worker(const char *proxy_function, proxy_worker *worker,
proxy_worker *worker, server_rec *s)
server_rec *s)
{ {
if (worker->s->status & PROXY_WORKER_IN_ERROR) { if (worker->s->status & PROXY_WORKER_IN_ERROR) {
if (apr_time_now() > worker->s->error_time + worker->s->retry) { if (apr_time_now() > worker->s->error_time + worker->s->retry) {
@@ -3024,3 +3024,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer(proxy_balancer *b, server_rec
return APR_SUCCESS; return APR_SUCCESS;
} }
void proxy_util_register_hooks(apr_pool_t *p)
{
APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);
}

View File

@@ -0,0 +1,36 @@
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PROXY_UTIL_H_
#define PROXY_UTIL_H_
/**
* @file proxy_util.h
* @brief Internal interfaces private to mod_proxy.
*
* @defgroup MOD_PROXY_PRIVATE Private
* @ingroup MOD_PROXY
* @{
*/
/**
* Register optional functions declared within proxy_util.c.
*/
void proxy_util_register_hooks(apr_pool_t *p);
/** @} */
#endif /* PROXY_UTIL_H_ */