Author: jfrederic.clere(a)jboss.com
Date: 2008-06-26 11:04:18 -0400 (Thu, 26 Jun 2008)
New Revision: 1731
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Add the logic to "remove" the worker from the apr_array of the balancer.
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-26 08:47:20 UTC
(rev 1730)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-26 15:04:18 UTC
(rev 1731)
@@ -70,9 +70,9 @@
*/
static void create_worker(proxy_server_conf *conf, proxy_balancer *balancer,
server_rec *server, proxy_worker **worker,
- nodeinfo_t *node)
+ nodeinfo_t *node, apr_pool_t *pool)
{
- char url[SCHEMENDSZ+HOSTNODESZ+PORTNODESZ+5]; /* Type :// Host : Port */
+ char *url;
char *ptr;
int reuse = 0;
#if AP_MODULE_MAGIC_AT_LEAST(20051115,4)
@@ -81,11 +81,7 @@
#endif
/* build the name (scheme and port) when needed */
- strcpy(url, node->mess.Type);
- strcat(url, "://");
- strcat(url, node->mess.Host);
- strcat(url, ":");
- strcat(url, node->mess.Port);
+ url = apr_pstrcat(pool, node->mess.Type, "://", node->mess.Host,
":", node->mess.Port, NULL);
*worker = ap_proxy_get_worker(conf->pool, conf, url);
if ((*worker) == NULL) {
@@ -162,7 +158,8 @@
/* XXX: We need that information from TC */
(*worker)->s->redirect[0] = '\0';
}
- (*worker)->s->lbstatus = -1; /* prevent using the node using status message */
+ (*worker)->s->lbstatus = 0;
+ (*worker)->s->lbfactor = -1; /* prevent using the node using status message */
if (!reuse) {
/*
@@ -176,14 +173,11 @@
/* Update the corresponding balancer worker information */
proxy_worker *runtime;
int i;
- char name[HOSTNODESZ+PORTNODESZ+2];
+
runtime = (proxy_worker *)balancer->workers->elts;
- strcpy(name, node->mess.Host);
- strcat(name, ":");
- strcat(name, node->mess.Port);
for (i = 0; i < balancer->workers->nelts; i++, runtime++) {
if (runtime->name) {
- if (strcmp(name, runtime->name) == 0) {
+ if (strcmp(url, runtime->name) == 0) {
memcpy(runtime, (*worker), sizeof(proxy_worker));
}
}
@@ -244,7 +238,7 @@
}
}
if (balancer) {
- create_worker(conf, balancer, server, &worker, node);
+ create_worker(conf, balancer, server, &worker, node, pool);
} else {
ap_log_error(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, server,
"add_workers_node: Can't find balancer");
@@ -287,15 +281,32 @@
"remove_workers_node %d", i);
if (i == 0) {
/* No connection in use: clean the worker */
+ proxy_balancer *balancer;
+ char *name = apr_pstrcat(pool, "cluster://", node->mess.balancer,
NULL);
+
+ /* mark the worker removed in the apr_array of the balancer */
+ balancer = (proxy_balancer *)conf->balancers->elts;
+ for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
+ if (strcmp(balancer->name, name) == 0) {
+ int j;
+ proxy_worker *searched = (proxy_worker *)balancer->workers->elts;
+ for (j = 0; j < balancer->workers->nelts; j++, searched++) {
+ if (searched->id == worker->id) {
+ searched->id = 0; /* mark it removed */
+ }
+ }
+ }
+ }
+
+ /* Clear the connection pool (close the sockets) */
if (worker->cp->pool) {
apr_pool_destroy(worker->cp->pool);
worker->cp->pool = NULL;
}
- worker->id = 0;
/* XXX: Shouldnn't we remove the mutex too (worker->mutex) */
- /* XXX: How to remove the worker from the apr_array of the balancer */
+ worker->id = 0; /* mark it removed */
return (0);
} else
@@ -606,7 +617,7 @@
int i;
balancer = (proxy_balancer *)conf->balancers->elts;
- for (i = 0; i < conf->balancers->nelts; i++) {
+ for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
if (strcasecmp(balancer->name, uri) == 0)
break;
}
@@ -744,6 +755,8 @@
while (!mycandidate && !checked_standby) {
worker = (proxy_worker *)balancer->workers->elts;
for (i = 0; i < balancer->workers->nelts; i++, worker++) {
+ if (worker->id == 0)
+ continue; /* marked removed */
/* standby logic
* lbfactor: -1 broken node.