Author: jfrederic.clere(a)jboss.com
Date: 2008-06-04 10:14:25 -0400 (Wed, 04 Jun 2008)
New Revision: 1653
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Use a counter in apr_reslist_acquired_count().
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-03 20:34:37 UTC
(rev 1652)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-04 14:14:25 UTC
(rev 1653)
@@ -45,6 +45,11 @@
#include "context.h"
#include "balancer.h"
+struct proxy_cluster_helper {
+ int count_active; /* currently active request using the worker */
+};
+typedef struct proxy_cluster_helper proxy_cluster_helper;
+
static struct node_storage_method *node_storage = NULL;
static struct host_storage_method *host_storage = NULL;
static struct context_storage_method *context_storage = NULL;
@@ -69,7 +74,7 @@
strcat(url, node->mess.Port);
*worker = ap_proxy_get_worker(conf->pool, conf, url);
- if (*worker == NULL) {
+ if ((*worker) == NULL) {
/* creates it */
const char *err = ap_proxy_add_worker(worker, conf->pool, conf, url);
@@ -77,9 +82,12 @@
ap_log_error(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, server,
"Created: worker for %s failed: %s", url, err);
return;
+ }
+ (*worker)->opaque = apr_pcalloc(conf->pool,
sizeof(proxy_cluster_helper));
+ proxy_cluster_helper *helper = (*worker)->opaque;
+ helper->count_active = 0;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
"Created: worker for %s", url);
- }
} else if ((*worker)->id == 0) {
/* We are going to reuse a removed one */
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
@@ -88,6 +96,7 @@
} else {
return; /* Done Already existing */
}
+
/* Get the shared memory for this worker */
ptr = (char *) node;
ptr = ptr + node->offset;
@@ -208,8 +217,14 @@
/* apr_reslist_acquired_count */
i = 0;
+
+#if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION
>= 3)
if (worker->cp->res)
i = apr_reslist_acquired_count(worker->cp->res);
+#else
+ proxy_cluster_helper *helper = worker->opaque;
+ i = helper->count_active;
+#endif
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
"remove_workers_node %d", i);
if (i == 0) {
@@ -702,6 +717,13 @@
cur_lbset++;
} while (cur_lbset <= max_lbset && !mycandidate);
+ if (mycandidate) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "proxy: bytraffic balancer DONE (%s)",
mycandidate->name);
+ } else {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "proxy: bytraffic balancer FAILED");
+ }
return mycandidate;
}
static const proxy_balancer_method bytraffic =
@@ -1138,8 +1160,12 @@
candidate = (*balancer->lbmethod->finder)(balancer, r);
- if (candidate)
- candidate->s->elected++;
+ if (candidate) {
+ proxy_cluster_helper *helper;
+ candidate->s->elected++; /* mark it in use */
+ helper = (proxy_cluster_helper *) candidate->opaque;
+ helper->count_active++;
+ }
if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
@@ -1296,6 +1322,12 @@
}
}
+ /* Mark the worker used for the cleanup logic */
+ if (*worker) {
+ proxy_cluster_helper *helper;
+ helper = (proxy_cluster_helper *) (*worker)->opaque;
+ helper->count_active++;
+ }
if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
"proxy: CLUSTER: (%s). Unlock failed for pre_request",
@@ -1356,6 +1388,36 @@
return access_status;
}
+static int proxy_cluster_post_request(proxy_worker *worker,
+ proxy_balancer *balancer,
+ request_rec *r,
+ proxy_server_conf *conf)
+{
+
+ apr_status_t rv;
+
+ if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
+ "proxy: CLUSTER: (%s). Lock failed for post_request",
+ balancer->name);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ /* mark the work as not use */
+ proxy_cluster_helper *helper;
+ helper = (proxy_cluster_helper *) worker->opaque;
+ helper->count_active--;
+
+ if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
+ "proxy: CLUSTER: (%s). Unlock failed for post_request",
+ balancer->name);
+ }
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "proxy_cluster_post_request for (%s)", balancer->name);
+
+ return OK;
+}
+
/*
* Register the hooks on our module.
*/
@@ -1378,6 +1440,7 @@
proxy_hook_canon_handler(proxy_cluster_canon, NULL, NULL, APR_HOOK_FIRST);
proxy_hook_pre_request(proxy_cluster_pre_request, NULL, NULL, APR_HOOK_FIRST);
+ proxy_hook_post_request(proxy_cluster_post_request, NULL, NULL, APR_HOOK_FIRST);
ap_register_provider(p, "proxy_cluster" , "balancer",
"0", &balancerhandler);
}