Author: jfrederic.clere(a)jboss.com
Date: 2008-05-28 10:27:18 -0400 (Wed, 28 May 2008)
New Revision: 1625
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Arrange add and remove logic for workers.
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-05-27 20:44:52 UTC
(rev 1624)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-05-28 14:27:18 UTC
(rev 1625)
@@ -73,6 +73,7 @@
nodeinfo_t *node)
{
char url[6+64+7+4]; /* Type :// Host : Port */
+ char *ptr;
/* build the name (scheme and port) when needed */
strcpy(url, node->mess.Type);
@@ -83,8 +84,6 @@
*worker = ap_proxy_get_worker(conf->pool, conf, url);
if (*worker == NULL) {
- char *ptr;
- proxy_worker *proxy_worker;
/* creates it */
const char *err = ap_proxy_add_worker(worker, conf->pool, conf, url);
@@ -92,31 +91,37 @@
ap_log_error(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, server,
"Created: worker for %s failed: %s", url, err);
return;
- }
- proxy_worker = (struct proxy_worker *) *worker;
- /* Get the shared memory for this worker */
- ptr = (char *) node;
- ptr = ptr + node->offset;
- proxy_worker->s = (proxy_worker_stat *) ptr;
- proxy_worker->id = node->mess.id;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
"Created: worker for %s", url);
- /*
- * XXX: The Shared datastatus may already contains a valid information
- */
- if (!proxy_worker->s->status)
- proxy_worker->s->status = PROXY_WORKER_INITIALIZED;
-
- my_ap_proxy_add_worker_to_balancer(conf->pool, balancer, *worker);
+ }
+ } else if ((*worker)->id == 0) {
+ /* We are going to reuse a removed one */
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
- "Created: worker for %s %d (status): %d", url,
proxy_worker->id, proxy_worker->s->status);
+ "Created: reusing worker for %s", url);
+ } else {
+ return; /* Done Already existing */
+ }
+ /* Get the shared memory for this worker */
+ ptr = (char *) node;
+ ptr = ptr + node->offset;
+ (*worker)->s = (proxy_worker_stat *) ptr;
- /* XXX: it may be already filled... */
- strncpy(proxy_worker->s->route, node->mess.JVMRoute,
PROXY_WORKER_MAX_ROUTE_SIZ);
- proxy_worker->s->route[PROXY_WORKER_MAX_ROUTE_SIZ] = '\0';
- /* XXX: We need that information from TC */
- proxy_worker->s->redirect[0] = '\0';
- }
+ (*worker)->id = node->mess.id;
+ /*
+ * XXX: The Shared datastatus may already contains a valid information
+ */
+ if (!(*worker)->s->status)
+ (*worker)->s->status = PROXY_WORKER_INITIALIZED;
+
+ my_ap_proxy_add_worker_to_balancer(conf->pool, balancer, *worker);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
+ "Created: worker for %s %d (status): %d", url,
(*worker)->id, (*worker)->s->status);
+
+ /* XXX: it may be already filled... */
+ strncpy((*worker)->s->route, node->mess.JVMRoute,
PROXY_WORKER_MAX_ROUTE_SIZ);
+ (*worker)->s->route[PROXY_WORKER_MAX_ROUTE_SIZ] = '\0';
+ /* XXX: We need that information from TC */
+ (*worker)->s->redirect[0] = '\0';
}
/*
* Add a node to the worker conf
@@ -155,7 +160,7 @@
"add_workers_node done");
}
/*
- * Add a node to the worker conf
+ * Remove a node from the worker conf
*/
static int remove_workers_node(nodeinfo_t *node, proxy_server_conf *conf, apr_pool_t
*pool, server_rec *server)
{
@@ -184,6 +189,7 @@
/* No connection in use: clean the worker */
apr_pool_destroy(worker->cp->pool);
worker->cp->pool = NULL;
+ worker->id = 0;
/* XXX: How to remove the worker from the apr_array of the balancer */
@@ -628,7 +634,7 @@
while (!mycandidate && !checked_standby) {
worker = (proxy_worker *)balancer->workers->elts;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: bytraffic for BALANCER (%d)",
balancer->workers->nelts);
+ "proxy: bytraffic balancer (%d)",
balancer->workers->nelts);
for (i = 0; i < balancer->workers->nelts; i++, worker++) {
if (!checking_standby) { /* first time through */
if (worker->s->lbset > max_lbset)
@@ -1079,11 +1085,6 @@
if (candidate)
candidate->s->elected++;
-/*
- PROXY_THREAD_UNLOCK(balancer);
- return NULL;
-*/
-
if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
"proxy: CLUSTER: (%s). Unlock failed for find_best_worker()",
balancer->name);