From fa862b3f7e0737b5190320815772aa0505b85b0d Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Fri, 25 Nov 2011 17:32:03 +0000 Subject: [PATCH] Allow compile time changes of field sizes and be more "clear" regarding the diff between balancer and worker slots... git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1206268 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/mod_proxy.h | 16 ++++++++++++++-- modules/proxy/mod_proxy_balancer.c | 26 +++++++++++++------------- modules/proxy/proxy_util.c | 6 +++--- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index a45adf6434..b381e42a74 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -162,7 +162,7 @@ typedef struct { } proxy_status; /* Status display options */ apr_sockaddr_t *source_address; apr_global_mutex_t *mutex; /* global lock (needed??) */ - ap_slotmem_instance_t *slot; /* balancers shm data - runtime */ + ap_slotmem_instance_t *bslot; /* balancers shm data - runtime */ ap_slotmem_provider_t *storage; unsigned int req_set:1; @@ -296,13 +296,25 @@ PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR ) #define PROXY_WORKER_DEFAULT_RETRY 60 /* Some max char string sizes, for shm fields */ +#ifndef PROXY_WORKER_MAX_SCHEME_SIZE #define PROXY_WORKER_MAX_SCHEME_SIZE 16 +#endif +#ifndef PROXY_WORKER_MAX_ROUTE_SIZE #define PROXY_WORKER_MAX_ROUTE_SIZE 64 +#endif +#ifndef PROXY_WORKER_MAX_NAME_SIZE #define PROXY_WORKER_MAX_NAME_SIZE 96 +#endif +#ifndef PROXY_WORKER_MAX_HOSTNAME_SIZE #define PROXY_WORKER_MAX_HOSTNAME_SIZE 64 +#endif +#ifndef PROXY_BALANCER_MAX_STICKY_SIZE #define PROXY_BALANCER_MAX_STICKY_SIZE 64 +#endif +#ifndef PROXY_MAX_PROVIDER_NAME_SIZE #define PROXY_MAX_PROVIDER_NAME_SIZE 16 +#endif #define PROXY_STRNCPY(dst, src) apr_cpystrn((dst), (src), sizeof(dst)) @@ -413,7 +425,7 @@ typedef struct { struct proxy_balancer { apr_array_header_t *workers; /* initially configured workers */ apr_array_header_t *errstatuses; /* statuses to force members into error */ - ap_slotmem_instance_t *slot; /* worker shm data - runtime */ + ap_slotmem_instance_t *wslot; /* worker shm data - runtime */ ap_slotmem_provider_t *storage; int growth; /* number of post-config workers can added */ int max_workers; /* maximum number of allowed workers */ diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c index cb58afae99..b19d8f1864 100644 --- a/modules/proxy/mod_proxy_balancer.c +++ b/modules/proxy/mod_proxy_balancer.c @@ -735,7 +735,7 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog, ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "balancer slotmem_create failed"); return !OK; } - conf->slot = new; + conf->bslot = new; } conf->storage = storage; @@ -767,12 +767,12 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_cleanup_null); /* setup shm for balancers */ - if ((rv = storage->grab(conf->slot, &index)) != APR_SUCCESS) { + if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "balancer slotmem_grab failed"); return !OK; } - if ((rv = storage->dptr(conf->slot, index, (void *)&bshm)) != APR_SUCCESS) { + if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "balancer slotmem_dptr failed"); return !OK; } @@ -794,7 +794,7 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog, ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "worker slotmem_create failed"); return !OK; } - balancer->slot = new; + balancer->wslot = new; balancer->storage = storage; /* sync all timestamps */ @@ -806,12 +806,12 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog, proxy_worker_shared *shm; worker = *workers; - if ((rv = storage->grab(balancer->slot, &index)) != APR_SUCCESS) { + if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "worker slotmem_grab failed"); return !OK; } - if ((rv = storage->dptr(balancer->slot, index, (void *)&shm)) != APR_SUCCESS) { + if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "worker slotmem_dptr failed"); return !OK; } @@ -1084,7 +1084,7 @@ static int balancer_handler(request_rec *r) char *ret; proxy_worker *nworker; nworker = ap_proxy_get_worker(conf->pool, bsel, conf, val); - if (!nworker && storage->num_free_slots(bsel->slot)) { + if (!nworker && storage->num_free_slots(bsel->wslot)) { if ((rv = PROXY_GLOBAL_LOCK(bsel)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "%s: Lock failed for adding worker", @@ -1095,7 +1095,7 @@ static int balancer_handler(request_rec *r) unsigned int index; proxy_worker_shared *shm; PROXY_COPY_CONF_PARAMS(nworker, conf); - if ((rv = storage->grab(bsel->slot, &index)) != APR_SUCCESS) { + if ((rv = storage->grab(bsel->wslot, &index)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, "worker slotmem_grab failed"); if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) { @@ -1105,7 +1105,7 @@ static int balancer_handler(request_rec *r) } return HTTP_BAD_REQUEST; } - if ((rv = storage->dptr(bsel->slot, index, (void *)&shm)) != APR_SUCCESS) { + if ((rv = storage->dptr(bsel->wslot, index, (void *)&shm)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, "worker slotmem_dptr failed"); if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) { @@ -1209,7 +1209,7 @@ static int balancer_handler(request_rec *r) /* the below is a safe cast, since the number of slots total will * never be more than max_workers, which is restricted to int */ ap_rprintf(r, "%d [%d Used]\n", balancer->max_workers, - balancer->max_workers - (int)storage->num_free_slots(balancer->slot)); + balancer->max_workers - (int)storage->num_free_slots(balancer->wslot)); if (*balancer->s->sticky) { if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) { ap_rvputs(r, "", balancer->s->sticky, " | ", @@ -1340,7 +1340,7 @@ static int balancer_handler(request_rec *r) ap_rvputs(r, "value ='", bsel->s->sticky, NULL); } ap_rputs("'>    (Use '-' to delete)\n", r); - if (storage->num_free_slots(bsel->slot) != 0) { + if (storage->num_free_slots(bsel->wslot) != 0) { ap_rputs("Add New Worker:" "    Are you sure? " "", r); @@ -1373,8 +1373,8 @@ static void balancer_child_init(apr_pool_t *p, server_rec *s) if (conf->balancers->nelts) { apr_size_t size; unsigned int num; - storage->attach(&(conf->slot), conf->id, &size, &num, p); - if (!conf->slot) { + storage->attach(&(conf->bslot), conf->id, &size, &num, p); + if (!conf->bslot) { ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, "slotmem_attach failed"); exit(1); /* Ugly, but what else? */ } diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 356671d831..2677e8ce5f 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1422,8 +1422,8 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balance } /* now attach */ - storage->attach(&(balancer->slot), balancer->sname, &size, &num, p); - if (!balancer->slot) { + storage->attach(&(balancer->wslot), balancer->sname, &size, &num, p); + if (!balancer->wslot) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "slotmem_attach failed"); return APR_EGENERAL; } @@ -2917,7 +2917,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer(proxy_balancer *b, server_rec for (index = 0; index < b->max_workers; index++) { int found; apr_status_t rv; - if ((rv = storage->dptr(b->slot, (unsigned int)index, (void *)&shm)) != APR_SUCCESS) { + if ((rv = storage->dptr(b->wslot, (unsigned int)index, (void *)&shm)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, "worker slotmem_dptr failed"); return APR_EGENERAL; } -- 2.40.0