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