Skip to content

Commit

Permalink
mod_proxy: Make ap_proxy_retry_worker() into an optional function. Al…
Browse files Browse the repository at this point in the history
…lows

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
  • Loading branch information
minfrin committed Dec 2, 2011
1 parent 914444f commit 7e295ae
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 15 deletions.
17 changes: 15 additions & 2 deletions modules/proxy/balancers/mod_lbmethod_bybusyness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

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,
request_rec *r)
{
Expand All @@ -36,6 +39,15 @@ static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,

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,
"proxy: Entering bybusyness for BALANCER (%s)",
balancer->s->name);
Expand Down Expand Up @@ -66,8 +78,9 @@ static proxy_worker *find_best_bybusyness(proxy_balancer *balancer,
* The worker might still be unusable, but we try
* anyway.
*/
if (!PROXY_WORKER_IS_USABLE(*worker))
ap_proxy_retry_worker("BALANCER", *worker, r->server);
if (!PROXY_WORKER_IS_USABLE(*worker)) {
ap_proxy_retry_worker_fn("BALANCER", *worker, r->server);
}

/* Take into calculation only the workers that are
* not in error state or not disabled.
Expand Down
14 changes: 13 additions & 1 deletion modules/proxy/balancers/mod_lbmethod_byrequests.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

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:
*
Expand Down Expand Up @@ -80,6 +83,15 @@ static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
int checking_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,
"proxy: Entering byrequests for BALANCER (%s)",
balancer->s->name);
Expand Down Expand Up @@ -109,7 +121,7 @@ static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
* anyway.
*/
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
* not in error state or not disabled.
*/
Expand Down
14 changes: 13 additions & 1 deletion modules/proxy/balancers/mod_lbmethod_bytraffic.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

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:
*
Expand Down Expand Up @@ -52,6 +55,15 @@ static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
int checking_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,
"proxy: Entering bytraffic for BALANCER (%s)",
balancer->s->name);
Expand Down Expand Up @@ -81,7 +93,7 @@ static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
* anyway.
*/
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
* not in error state or not disabled.
*/
Expand Down
14 changes: 13 additions & 1 deletion modules/proxy/balancers/mod_lbmethod_heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

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 ap_slotmem_instance_t *hm_serversmem = NULL;

Expand Down Expand Up @@ -270,6 +273,15 @@ static proxy_worker *find_best_hb(proxy_balancer *balancer,
ap_get_module_config(r->server->module_config,
&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);

servers = apr_hash_make(tpool);
Expand Down Expand Up @@ -297,7 +309,7 @@ static proxy_worker *find_best_hb(proxy_balancer *balancer,
}

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)) {
Expand Down
3 changes: 3 additions & 0 deletions modules/proxy/mod_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "apr_optional.h"
#include "scoreboard.h"
#include "mod_status.h"
#include "proxy_util.h"

#if (MODULE_MAGIC_NUMBER_MAJOR > 20020903)
#include "mod_ssl.h"
Expand Down Expand Up @@ -2512,6 +2513,8 @@ static void register_hooks(apr_pool_t *p)
/* child init handling */
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) =
Expand Down
6 changes: 3 additions & 3 deletions modules/proxy/mod_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/

#include "apr_hooks.h"
#include "apr_optional.h"
#include "apr.h"
#include "apr_lib.h"
#include "apr_strings.h"
Expand Down Expand Up @@ -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
* elapsed since the last error.
*/
PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function,
proxy_worker *worker,
server_rec *s);
APR_DECLARE_OPTIONAL_FN(int, ap_proxy_retry_worker,
(const char *proxy_function, proxy_worker *worker, server_rec *s));

/**
* Acquire a connection from worker connection pool
Expand Down
22 changes: 18 additions & 4 deletions modules/proxy/mod_proxy_balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ap_slotmem_provider_t *storage = NULL;

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
* can adjust the mutex settings using the Mutex directive.
Expand Down Expand Up @@ -224,7 +227,7 @@ static proxy_worker *find_route_worker(proxy_balancer *balancer,
* The worker might still be unusable, but we try
* anyway.
*/
ap_proxy_retry_worker("BALANCER", worker, r->server);
ap_proxy_retry_worker_fn("BALANCER", worker, r->server);
if (PROXY_WORKER_IS_USABLE(worker)) {
return worker;
} else {
Expand All @@ -248,7 +251,7 @@ static proxy_worker *find_route_worker(proxy_balancer *balancer,
* The worker might still be unusable, but we try
* 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))
return rworker;
Expand Down Expand Up @@ -413,7 +416,7 @@ static void force_recovery(proxy_balancer *balancer, server_rec *s)
}
else {
/* 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)) {
ok = 1;
break;
Expand Down Expand Up @@ -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
* 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;
}

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
Expand Down
10 changes: 7 additions & 3 deletions modules/proxy/proxy_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "scoreboard.h"
#include "apr_version.h"
#include "apr_hash.h"
#include "proxy_util.h"

#if APR_HAVE_UNISTD_H
#include <unistd.h> /* for getpid() */
Expand Down Expand Up @@ -1977,9 +1978,8 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, ser
return rv;
}

PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function,
proxy_worker *worker,
server_rec *s)
static int ap_proxy_retry_worker(const char *proxy_function, proxy_worker *worker,
server_rec *s)
{
if (worker->s->status & PROXY_WORKER_IN_ERROR) {
if (apr_time_now() > worker->s->error_time + worker->s->retry) {
Expand Down Expand Up @@ -3024,3 +3024,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer(proxy_balancer *b, server_rec
return APR_SUCCESS;
}

void proxy_util_register_hooks(apr_pool_t *p)
{
APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);
}
36 changes: 36 additions & 0 deletions modules/proxy/proxy_util.h
Original file line number Diff line number Diff line change
@@ -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_ */

0 comments on commit 7e295ae

Please sign in to comment.