|
|
96af6c |
diff --git a/modules/proxy/mod_proxy_hcheck.c b/modules/proxy/mod_proxy_hcheck.c
|
|
|
96af6c |
index bd89779..d7c0a68 100644
|
|
|
96af6c |
--- a/modules/proxy/mod_proxy_hcheck.c
|
|
|
96af6c |
+++ b/modules/proxy/mod_proxy_hcheck.c
|
|
|
96af6c |
@@ -33,7 +33,6 @@ module AP_MODULE_DECLARE_DATA proxy_hcheck_module;
|
|
|
96af6c |
#endif
|
|
|
96af6c |
#else
|
|
|
96af6c |
#define HC_USE_THREADS 0
|
|
|
96af6c |
-typedef void apr_thread_pool_t;
|
|
|
96af6c |
#endif
|
|
|
96af6c |
|
|
|
96af6c |
typedef struct {
|
|
|
96af6c |
@@ -73,7 +72,7 @@ typedef struct {
|
|
|
96af6c |
proxy_balancer *balancer;
|
|
|
96af6c |
proxy_worker *worker;
|
|
|
96af6c |
proxy_worker *hc;
|
|
|
96af6c |
- apr_time_t now;
|
|
|
96af6c |
+ apr_time_t *now;
|
|
|
96af6c |
} baton_t;
|
|
|
96af6c |
|
|
|
96af6c |
static void *hc_create_config(apr_pool_t *p, server_rec *s)
|
|
|
96af6c |
@@ -89,7 +88,10 @@ static void *hc_create_config(apr_pool_t *p, server_rec *s)
|
|
|
96af6c |
}
|
|
|
96af6c |
|
|
|
96af6c |
static ap_watchdog_t *watchdog;
|
|
|
96af6c |
-static int tpsize = HC_THREADPOOL_SIZE;
|
|
|
96af6c |
+#if HC_USE_THREADS
|
|
|
96af6c |
+static apr_thread_pool_t *hctp;
|
|
|
96af6c |
+static int tpsize;
|
|
|
96af6c |
+#endif
|
|
|
96af6c |
|
|
|
96af6c |
/*
|
|
|
96af6c |
* This serves double duty by not only validating (and creating)
|
|
|
96af6c |
@@ -825,29 +827,28 @@ static void * APR_THREAD_FUNC hc_check(apr_thread_t *thread, void *b)
|
|
|
96af6c |
server_rec *s = baton->ctx->s;
|
|
|
96af6c |
proxy_worker *worker = baton->worker;
|
|
|
96af6c |
proxy_worker *hc = baton->hc;
|
|
|
96af6c |
- apr_time_t now = baton->now;
|
|
|
96af6c |
+ apr_time_t now;
|
|
|
96af6c |
apr_status_t rv;
|
|
|
96af6c |
|
|
|
96af6c |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(03256)
|
|
|
96af6c |
"%sHealth checking %s", (thread ? "Threaded " : ""),
|
|
|
96af6c |
worker->s->name);
|
|
|
96af6c |
|
|
|
96af6c |
- worker->s->updated = now;
|
|
|
96af6c |
if (hc->s->method == TCP) {
|
|
|
96af6c |
rv = hc_check_tcp(baton);
|
|
|
96af6c |
}
|
|
|
96af6c |
else {
|
|
|
96af6c |
rv = hc_check_http(baton);
|
|
|
96af6c |
}
|
|
|
96af6c |
+
|
|
|
96af6c |
+ now = apr_time_now();
|
|
|
96af6c |
if (rv == APR_ENOTIMPL) {
|
|
|
96af6c |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(03257)
|
|
|
96af6c |
"Somehow tried to use unimplemented hcheck method: %d",
|
|
|
96af6c |
(int)hc->s->method);
|
|
|
96af6c |
- apr_pool_destroy(baton->ptemp);
|
|
|
96af6c |
- return NULL;
|
|
|
96af6c |
}
|
|
|
96af6c |
/* what state are we in ? */
|
|
|
96af6c |
- if (PROXY_WORKER_IS_HCFAILED(worker)) {
|
|
|
96af6c |
+ else if (PROXY_WORKER_IS_HCFAILED(worker)) {
|
|
|
96af6c |
if (rv == APR_SUCCESS) {
|
|
|
96af6c |
worker->s->pcount += 1;
|
|
|
96af6c |
if (worker->s->pcount >= worker->s->passes) {
|
|
|
96af6c |
@@ -860,7 +861,8 @@ static void * APR_THREAD_FUNC hc_check(apr_thread_t *thread, void *b)
|
|
|
96af6c |
|
|
|
96af6c |
}
|
|
|
96af6c |
}
|
|
|
96af6c |
- } else {
|
|
|
96af6c |
+ }
|
|
|
96af6c |
+ else {
|
|
|
96af6c |
if (rv != APR_SUCCESS) {
|
|
|
96af6c |
worker->s->error_time = now;
|
|
|
96af6c |
worker->s->fcount += 1;
|
|
|
96af6c |
@@ -873,7 +875,12 @@ static void * APR_THREAD_FUNC hc_check(apr_thread_t *thread, void *b)
|
|
|
96af6c |
}
|
|
|
96af6c |
}
|
|
|
96af6c |
}
|
|
|
96af6c |
+ if (baton->now) {
|
|
|
96af6c |
+ *baton->now = now;
|
|
|
96af6c |
+ }
|
|
|
96af6c |
apr_pool_destroy(baton->ptemp);
|
|
|
96af6c |
+ worker->s->updated = now;
|
|
|
96af6c |
+
|
|
|
96af6c |
return NULL;
|
|
|
96af6c |
}
|
|
|
96af6c |
|
|
|
96af6c |
@@ -881,12 +888,10 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
|
|
|
96af6c |
apr_pool_t *pool)
|
|
|
96af6c |
{
|
|
|
96af6c |
apr_status_t rv = APR_SUCCESS;
|
|
|
96af6c |
- apr_time_t now = apr_time_now();
|
|
|
96af6c |
proxy_balancer *balancer;
|
|
|
96af6c |
sctx_t *ctx = (sctx_t *)data;
|
|
|
96af6c |
server_rec *s = ctx->s;
|
|
|
96af6c |
proxy_server_conf *conf;
|
|
|
96af6c |
- static apr_thread_pool_t *hctp = NULL;
|
|
|
96af6c |
|
|
|
96af6c |
switch (state) {
|
|
|
96af6c |
case AP_WATCHDOG_STATE_STARTING:
|
|
|
96af6c |
@@ -913,7 +918,6 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
|
|
|
96af6c |
"Skipping apr_thread_pool_create()");
|
|
|
96af6c |
hctp = NULL;
|
|
|
96af6c |
}
|
|
|
96af6c |
-
|
|
|
96af6c |
#endif
|
|
|
96af6c |
break;
|
|
|
96af6c |
|
|
|
96af6c |
@@ -929,45 +933,53 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
|
|
|
96af6c |
ctx->s = s;
|
|
|
96af6c |
for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
|
|
|
96af6c |
int n;
|
|
|
96af6c |
+ apr_time_t now;
|
|
|
96af6c |
proxy_worker **workers;
|
|
|
96af6c |
proxy_worker *worker;
|
|
|
96af6c |
/* Have any new balancers or workers been added dynamically? */
|
|
|
96af6c |
ap_proxy_sync_balancer(balancer, s, conf);
|
|
|
96af6c |
workers = (proxy_worker **)balancer->workers->elts;
|
|
|
96af6c |
+ now = apr_time_now();
|
|
|
96af6c |
for (n = 0; n < balancer->workers->nelts; n++) {
|
|
|
96af6c |
worker = *workers;
|
|
|
96af6c |
if (!PROXY_WORKER_IS(worker, PROXY_WORKER_STOPPED) &&
|
|
|
96af6c |
- (worker->s->method != NONE) &&
|
|
|
96af6c |
- (now > worker->s->updated + worker->s->interval)) {
|
|
|
96af6c |
+ (worker->s->method != NONE) &&
|
|
|
96af6c |
+ (worker->s->updated != 0) &&
|
|
|
96af6c |
+ (now > worker->s->updated + worker->s->interval)) {
|
|
|
96af6c |
baton_t *baton;
|
|
|
96af6c |
apr_pool_t *ptemp;
|
|
|
96af6c |
+
|
|
|
96af6c |
ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s,
|
|
|
96af6c |
"Checking %s worker: %s [%d] (%pp)", balancer->s->name,
|
|
|
96af6c |
worker->s->name, worker->s->method, worker);
|
|
|
96af6c |
|
|
|
96af6c |
if ((rv = hc_init_worker(ctx, worker)) != APR_SUCCESS) {
|
|
|
96af6c |
+ worker->s->updated = now;
|
|
|
96af6c |
return rv;
|
|
|
96af6c |
}
|
|
|
96af6c |
- /* This pool must last the lifetime of the (possible) thread */
|
|
|
96af6c |
+ worker->s->updated = 0;
|
|
|
96af6c |
+
|
|
|
96af6c |
+ /* This pool has the lifetime of the check */
|
|
|
96af6c |
apr_pool_create(&ptemp, ctx->p);
|
|
|
96af6c |
apr_pool_tag(ptemp, "hc_request");
|
|
|
96af6c |
- baton = apr_palloc(ptemp, sizeof(baton_t));
|
|
|
96af6c |
+ baton = apr_pcalloc(ptemp, sizeof(baton_t));
|
|
|
96af6c |
baton->ctx = ctx;
|
|
|
96af6c |
- baton->now = now;
|
|
|
96af6c |
baton->balancer = balancer;
|
|
|
96af6c |
baton->worker = worker;
|
|
|
96af6c |
baton->ptemp = ptemp;
|
|
|
96af6c |
baton->hc = hc_get_hcworker(ctx, worker, ptemp);
|
|
|
96af6c |
-
|
|
|
96af6c |
- if (!hctp) {
|
|
|
96af6c |
- hc_check(NULL, baton);
|
|
|
96af6c |
- }
|
|
|
96af6c |
#if HC_USE_THREADS
|
|
|
96af6c |
- else {
|
|
|
96af6c |
- rv = apr_thread_pool_push(hctp, hc_check, (void *)baton,
|
|
|
96af6c |
- APR_THREAD_TASK_PRIORITY_NORMAL, NULL);
|
|
|
96af6c |
+ if (hctp) {
|
|
|
96af6c |
+ apr_thread_pool_push(hctp, hc_check, (void *)baton,
|
|
|
96af6c |
+ APR_THREAD_TASK_PRIORITY_NORMAL,
|
|
|
96af6c |
+ NULL);
|
|
|
96af6c |
}
|
|
|
96af6c |
+ else
|
|
|
96af6c |
#endif
|
|
|
96af6c |
+ {
|
|
|
96af6c |
+ baton->now = &now;
|
|
|
96af6c |
+ hc_check(NULL, baton);
|
|
|
96af6c |
+ }
|
|
|
96af6c |
}
|
|
|
96af6c |
workers++;
|
|
|
96af6c |
}
|
|
|
96af6c |
@@ -986,9 +998,9 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
|
|
|
96af6c |
ap_log_error(APLOG_MARK, APLOG_INFO, rv, s, APLOGNO(03315)
|
|
|
96af6c |
"apr_thread_pool_destroy() failed");
|
|
|
96af6c |
}
|
|
|
96af6c |
+ hctp = NULL;
|
|
|
96af6c |
}
|
|
|
96af6c |
#endif
|
|
|
96af6c |
- hctp = NULL;
|
|
|
96af6c |
break;
|
|
|
96af6c |
}
|
|
|
96af6c |
return rv;
|
|
|
96af6c |
@@ -996,7 +1008,10 @@ static apr_status_t hc_watchdog_callback(int state, void *data,
|
|
|
96af6c |
static int hc_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
|
|
|
96af6c |
apr_pool_t *ptemp)
|
|
|
96af6c |
{
|
|
|
96af6c |
+#if HC_USE_THREADS
|
|
|
96af6c |
+ hctp = NULL;
|
|
|
96af6c |
tpsize = HC_THREADPOOL_SIZE;
|
|
|
96af6c |
+#endif
|
|
|
96af6c |
return OK;
|
|
|
96af6c |
}
|
|
|
96af6c |
static int hc_post_config(apr_pool_t *p, apr_pool_t *plog,
|